/* * ======== Task_postInit ======== * Function to be called during module startup to complete the * initialization of any statically created or constructed task. * Initialize stack. * Build Initial stack image. * Add task to corresponding ready Queue. * * returns (0) and clean 'eb' on success * returns (0) and 'eb' if Task_SupportProxy_start() fails. * returns (n) and 'eb' for number of successful createFxn() calls iff * one of the createFxn() calls fails */ Int Task_postInit(Task_Object *tsk, Error_Block *eb) { UInt tskKey, hwiKey; Queue_Handle readyQ; #ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS Int i; #endif tsk->context = Task_SupportProxy_start(tsk, (Task_SupportProxy_FuncPtr)Task_enter, (Task_SupportProxy_FuncPtr)Task_exit, eb); if (Error_check(eb)) { return (0); } tsk->mode = Task_Mode_READY; tsk->pendElem = NULL; #ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS for (i = 0; i < Task_hooks.length; i++) { tsk->hookEnv[i] = (Ptr)0; if (Task_hooks.elem[i].createFxn != NULL) { Task_hooks.elem[i].createFxn(tsk, eb); if (Error_check(eb)) { return (i); } } } #endif if (tsk->priority < 0) { tsk->mask = 0; tsk->readyQ = Task_Module_State_inactiveQ(); Queue_put(tsk->readyQ, (Queue_Elem *)tsk); } else { tsk->mask = 1 << tsk->priority; readyQ = Queue_Object_get(Task_module->readyQ, tsk->priority); tsk->readyQ = readyQ; tskKey = Task_disable(); hwiKey = Hwi_disable(); Task_unblock(tsk); Hwi_restore(hwiKey); Task_restore(tskKey); } return (0); }
/* * ======== SemaphoreMP_post ======== */ Void SemaphoreMP_post(SemaphoreMP_Object *obj) { UInt tskKey; SemaphoreMP_PendElem *elem; IArg gateMPKey; Int status; /* Enter the gate */ gateMPKey = GateMP_enter((GateMP_Handle)obj->gate); if (ListMP_empty((ListMP_Handle)obj->pendQ)) { if (obj->mode == SemaphoreMP_Mode_BINARY) { obj->attrs->count = 1; } else { obj->attrs->count++; } if (obj->cacheEnabled) { Cache_wbInv(obj->attrs, sizeof(SemaphoreMP_Attrs), Cache_Type_ALL, TRUE); } /* Leave the gate */ GateMP_leave((GateMP_Handle)obj->gate, gateMPKey); return; } /* lock task scheduler */ tskKey = Task_disable(); /* dequeue tsk from semaphore queue */ elem = (SemaphoreMP_PendElem *)ListMP_getHead((ListMP_Handle)obj->pendQ); if (elem->procId != MultiProc_self()) { /* Unblock remote task */ status = Notify_sendEvent(elem->procId, 0, SemaphoreMP_notifyEventId, elem->task, TRUE); Assert_isTrue(status >= 0, ti_sdo_ipc_Ipc_A_internal); } else { /* put task back into readyQ */ Task_unblock((Task_Handle)elem->task); } /* Leave the gate */ GateMP_leave((GateMP_Handle)obj->gate, gateMPKey); Task_restore(tskKey); }
/* * ======== SemaphoreMP_cbFxn ======== */ Void SemaphoreMP_cbFxn(UInt16 procId, UInt16 lineId, UInt32 eventId, UArg arg, UInt32 payload) { Task_Handle task; UInt tskKey; task = (Task_Handle)payload; /* lock task scheduler */ tskKey = Task_disable(); /* put task back into readyQ */ Task_unblock(task); /* Force the task scheduler to run */ Task_restore(tskKey); }