/* * ======== Event_pendTimeout ======== * called by Clock when timeout for a event expires */ Void Event_pendTimeout(UArg arg) { UInt hwiKey; Event_PendElem *elem = (Event_PendElem *)xdc_uargToPtr(arg); hwiKey = Hwi_disable(); /* * Verify that Event_post() hasn't already serviced this qElem. */ if (elem->pendState == Event_PendState_CLOCK_WAIT) { /* remove eventElem from event_Elem queue */ Queue_remove((Queue_Elem *)elem); elem->pendState = Event_PendState_TIMEOUT; /* * put task back into readyQ * No need for Task_disable/restore sandwich since this * is called within Swi (or Hwi) thread */ Task_unblockI(elem->tpElem.task, hwiKey); } Hwi_restore(hwiKey); }
/* * ======== Rta_readMask ======== */ Void Rta_readMask(Rta_ResponsePacket *resp, UArg addr) { /* * The address passed in is the address of diagsMask__C, which holds the * address of the actual diagsMask in the module state structure. So * the address passed in must be dereferenced twice. * The diagsMask is a Bits16. */ Bits16 *maskAddr = *((Bits16 **) xdc_uargToPtr(addr)); resp->resp0 = *maskAddr; }
/* * ======== Task_sleepTimeout ======== * called by Clock when timeout for a Task_sleep() expires */ Void Task_sleepTimeout(UArg arg) { UInt hwiKey; Task_PendElem *elem = (Task_PendElem *)xdc_uargToPtr(arg); hwiKey = Hwi_disable(); /* * put tsk back into readyQ * No need for Task_disable/restore sandwich since this * is called within Swi (or Hwi) thread */ Task_unblockI(elem->task, hwiKey); Hwi_restore(hwiKey); }
/* * ======== Rta_writeMask ======== */ Void Rta_writeMask(Rta_ResponsePacket *resp, UArg addr, UArg val) { /* * The address passed in is the address of diagsMask__C, which holds the * address of the actual diagsMask in the module state structure. So * the address passed in must be dereferenced twice. */ Bits16 *maskAddr = *((Bits16 **) xdc_uargToPtr(addr)); /* The diagsMask is a Bits16. */ *maskAddr = (Bits16) val; Log_write2(Rta_LD_writeMask, (UArg) maskAddr, (Bits16) val); /* Acknowledge the command. */ Rta_acknowledgeCmd(resp); }
/* * ======== _pthread_runStub ======== */ static void _pthread_runStub(UArg arg0, UArg arg1) { UInt key; Ptr arg; pthread_Obj *thread = (pthread_Obj *)(xdc_uargToPtr(arg1)); arg = Task_getEnv(thread->task); thread->ret = thread->fxn(arg); /* Pop and execute the cleanup handlers */ while (thread->cleanupList != NULL) { _pthread_cleanup_pop(thread->cleanupList, 1); } /* Cleanup any pthread specific data */ _pthread_removeThreadKeys((pthread_t)thread); key = Task_disable(); if (!thread->detached) { Semaphore_post(Semaphore_handle(&(thread->joinSem))); /* * Set this task's priority to -1 to prevent it from being put * on the terminated queue (and deleted if Task.deleteTerminatedTasks * is true). pthread_join() will delete the Task object. */ Task_setPri(thread->task, -1); Task_restore(key); } else { Task_restore(key); /* Free memory */ #if ti_sysbios_posix_Settings_supportsMutexPriority__D Queue_destruct(&(thread->mutexList)); #endif Semaphore_destruct(&(thread->joinSem)); Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj)); /* The system will have to clean up the Task object */ } /* Task_exit() is called when returning from this function */ }
/* * ======== Task_Instance_init ======== */ Int Task_Instance_init(Task_Object *tsk, Task_FuncPtr fxn, const Task_Params *params, Error_Block *eb) { Int align; Int status; SizeT stackSize; Assert_isTrue((BIOS_taskEnabled == TRUE), Task_A_taskDisabled); Assert_isTrue(((BIOS_getThreadType() != BIOS_ThreadType_Hwi) && (BIOS_getThreadType() != BIOS_ThreadType_Swi)), Task_A_badThreadType); Assert_isTrue((((params->priority == -1) || (params->priority > 0)) && (params->priority < (Int)Task_numPriorities)), Task_A_badPriority); tsk->priority = params->priority; /* deal with undefined Task_Params defaults */ if (params->stackHeap == NULL) { tsk->stackHeap = Task_defaultStackHeap; } else { tsk->stackHeap = params->stackHeap; } if (params->stackSize == 0) { stackSize = Task_defaultStackSize; } else { stackSize = params->stackSize; } align = Task_SupportProxy_getStackAlignment(); if (params->stack != NULL) { if (align != 0) { UArg stackTemp; /* align low address to stackAlignment */ stackTemp = (UArg)params->stack; stackTemp += align - 1; stackTemp &= -align; tsk->stack = (Ptr)xdc_uargToPtr(stackTemp); /* subtract what we removed from the low address from stackSize */ tsk->stackSize = stackSize - (stackTemp - (UArg)params->stack); /* lower the high address as necessary */ tsk->stackSize &= -align; } else { tsk->stack = params->stack; tsk->stackSize = stackSize; } /* tell Task_delete that stack was provided */ tsk->stackHeap = (xdc_runtime_IHeap_Handle)(-1); } else { if (BIOS_runtimeCreatesEnabled) { if (align != 0) { /* * round stackSize up to the nearest multiple of the alignment. */ tsk->stackSize = (stackSize + align - 1) & -align; } else { tsk->stackSize = stackSize; } tsk->stack = Memory_alloc(tsk->stackHeap, tsk->stackSize, align, eb); if (tsk->stack == NULL) { return (1); } } } tsk->fxn = fxn; tsk->arg0 = params->arg0; tsk->arg1 = params->arg1; tsk->env = params->env; tsk->vitalTaskFlag = params->vitalTaskFlag; if (tsk->vitalTaskFlag == TRUE) { Task_module->vitalTasks += 1; } #ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS if (Task_hooks.length > 0) { tsk->hookEnv = Memory_calloc(Task_Object_heap(), Task_hooks.length * sizeof (Ptr), 0, eb); if (tsk->hookEnv == NULL) { return (2); } } #endif status = Task_postInit(tsk, eb); if (Error_check(eb)) { return (3 + status); } return (0); /* no failure states */ }
/* * ======== pthread_self ======== */ pthread_t pthread_self(void) { return ((pthread_t)(xdc_uargToPtr(Task_getArg1(Task_self())))); }