/* * ======== MessageQ_setMsgTrace ======== */ Void MessageQ_setMsgTrace(MessageQ_Msg msg, Bool traceFlag) { msg->flags = (msg->flags & ~ti_sdo_ipc_MessageQ_TRACEMASK) | (traceFlag << ti_sdo_ipc_MessageQ_TRACESHIFT); Log_write4(ti_sdo_ipc_MessageQ_LM_setTrace, (UArg)(msg), (UArg)(msg->seqNum), (UArg)(msg->srcProc), (UArg)(traceFlag)); }
/* * ======== Task_schedule ======== * Find highest priority task and invoke it. * * Must be called with interrupts disabled. */ Void Task_schedule() { Queue_Handle maxQ; Task_Object *prevTask; Task_Object *curTask; #ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS Int i; #endif do { Task_module->workFlag = 0; /* stall until a task is ready */ while (Task_module->curSet == 0) { Task_allBlockedFunction(); } /* Determine current max ready Task priority */ maxQ = (Queue_Handle)((UInt8 *)(Task_module->readyQ) + (UInt)(Intrinsics_maxbit(Task_module->curSet)*(2*sizeof(Ptr)))); /* if a higher priority task is ready - switch to it */ if (maxQ > Task_module->curQ) { prevTask = Task_module->curTask; Task_module->curQ = maxQ; Task_module->curTask = Queue_head(maxQ); curTask = Task_module->curTask; if (Task_checkStackFlag) { Task_checkStacks(prevTask, curTask); } #if !defined(ti_sysbios_knl_Task_DISABLE_ALL_HOOKS) \ || (xdc_runtime_Log_DISABLE_ALL == 0) /* It's safe to enable intrs here */ Hwi_enable(); #ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS for (i = 0; i < Task_hooks.length; i++) { if (Task_hooks.elem[i].switchFxn != NULL) { Task_hooks.elem[i].switchFxn(prevTask, curTask); } } #endif Log_write4(Task_LM_switch, (UArg)prevTask, (UArg)prevTask->fxn, (UArg)curTask, (UArg)curTask->fxn); /* Hard-disable intrs - this fxn is called with them disabled */ Hwi_disable(); #endif Task_SupportProxy_swap((Ptr)&prevTask->context, (Ptr)&curTask->context); } } while (Task_module->workFlag); }
/* * ======== Task_startup ======== */ Void Task_startup() { Queue_Handle maxQ; Task_Object *prevTask; Task_Struct dummyTask; Int i; Hwi_disable(); /* re-enabled in Task_enter of first task */ /* Use dummyTask as initial task to swap from */ prevTask = Task_handle(&dummyTask); /* stall until a task is ready */ while (Task_module->curSet == 0) { Task_allBlockedFunc(); } /* Determine current max ready Task priority */ maxQ = (Queue_Handle)((UInt8 *)(Task_module->readyQ) + (UInt)(Intrinsics_maxbit(Task_module->curSet)*(2*sizeof(Ptr)))); Task_module->curQ = maxQ; Task_module->curTask = Queue_head(maxQ); /* we've done the scheduler's work */ Task_module->workFlag = 0; /* Signal that we are entering task thread mode */ BIOS_setThreadType(BIOS_ThreadType_Task); /* should be safe to enable intrs here */ Hwi_enable(); #ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS /* Run switch hooks for first real Task */ for (i = 0; i < Task_hooks.length; i++) { if (Task_hooks.elem[i].switchFxn != NULL) { Task_hooks.elem[i].switchFxn(NULL, Task_module->curTask); } } #endif Log_write4(Task_LM_switch, (UArg)0, (UArg)0, (UArg)Task_module->curTask, (UArg)Task_module->curTask->fxn); /* must leave this function with ints disabled */ Hwi_disable(); /* inform dispatcher that we're running on task stack */ Hwi_switchFromBootStack(); /* start first task by way of enter() */ Task_SupportProxy_swap((Ptr)&prevTask->context, (Ptr)&Task_module->curTask->context); }
/* * ======== MessageQ_get ======== */ Int MessageQ_get(MessageQ_Handle handle, MessageQ_Msg *msg, UInt timeout) { Int status; List_Handle highList; List_Handle normalList; ti_sdo_ipc_MessageQ_Object *obj = (ti_sdo_ipc_MessageQ_Object *)handle; /* Get the list */ normalList = ti_sdo_ipc_MessageQ_Instance_State_normalList(obj); highList = ti_sdo_ipc_MessageQ_Instance_State_highList(obj); /* Keep looping while there are no elements on either list */ *msg = (MessageQ_Msg)List_get(highList); while (*msg == NULL) { *msg = (MessageQ_Msg)List_get(normalList); if (*msg == NULL) { /* Block until notified. */ status = ISync_wait(obj->synchronizer, timeout, NULL); if (status == ISync_WaitStatus_TIMEOUT) { return (MessageQ_E_TIMEOUT); } else if (status < 0) { return (MessageQ_E_FAIL); } if (obj->unblocked) { /* *(msg) may be NULL */ return (MessageQ_E_UNBLOCKED); } *msg = (MessageQ_Msg)List_get(highList); } } if ((ti_sdo_ipc_MessageQ_traceFlag == TRUE) || (((*msg)->flags & ti_sdo_ipc_MessageQ_TRACEMASK) != 0)) { Log_write4(ti_sdo_ipc_MessageQ_LM_get, (UArg)(*msg), (UArg)((*msg)->seqNum), (UArg)((*msg)->srcProc), (UArg)(obj)); } return (MessageQ_S_SUCCESS); }
Void interrupt Hwi_dispatchFIQC() { Hwi_Object *hwi; Int intNum; intNum = Hwi_cpIntc.HIPIR[0]; /* disable host interrupt 0 (FIQ) */ Hwi_cpIntc.HIDISR = 0; Hwi_cpIntc.SICR = intNum; /* clear interrupt */ hwi = Hwi_module->dispatchTable[intNum]; Log_write4(Hwi_LM_begin, (IArg)hwi, (IArg)hwi->fxn, (IArg)BIOS_ThreadType_Main, (IArg)intNum); (hwi->fxn)(hwi->arg); Log_write1(Hwi_LD_end, (IArg)hwi); /* enable host interrupt 0 (FIQ) */ Hwi_cpIntc.HIEISR = 0; }
/* * ======== MessageQ_put ======== */ Int MessageQ_put(MessageQ_QueueId queueId, MessageQ_Msg msg) { IMessageQTransport_Handle transport; MessageQ_QueueIndex dstProcId = (MessageQ_QueueIndex)(queueId >> 16); List_Handle listHandle; Int status; UInt priority; #ifndef xdc_runtime_Log_DISABLE_ALL UInt16 flags; UInt16 seqNum; UInt16 srcProc; #endif ti_sdo_ipc_MessageQ_Object *obj; Assert_isTrue((msg != NULL), ti_sdo_ipc_MessageQ_A_invalidMsg); msg->dstId = (UInt16)(queueId); msg->dstProc = (UInt16)(queueId >> 16); if (dstProcId != MultiProc_self()) { /* assert that dstProcId is valid */ Assert_isTrue(dstProcId < ti_sdo_utils_MultiProc_numProcessors, ti_sdo_ipc_MessageQ_A_procIdInvalid); /* Put the high and urgent messages to the high priority transport */ priority = (UInt)((msg->flags) & ti_sdo_ipc_MessageQ_TRANSPORTPRIORITYMASK); /* Call the transport associated with this message queue */ transport = MessageQ_module->transports[dstProcId][priority]; if (transport == NULL) { /* Try the other transport */ priority = !priority; transport = MessageQ_module->transports[dstProcId][priority]; } /* assert transport is not null */ Assert_isTrue(transport != NULL, ti_sdo_ipc_MessageQ_A_unregisteredTransport); #ifndef xdc_runtime_Log_DISABLE_ALL /* use local vars so msg does not get cached after put */ flags = msg->flags; if ((ti_sdo_ipc_MessageQ_traceFlag) || (flags & ti_sdo_ipc_MessageQ_TRACEMASK) != 0) { /* use local vars so msg does not get cached after put */ seqNum = msg->seqNum; srcProc = msg->srcProc; } #endif /* put msg to remote processor using transport */ if (IMessageQTransport_put(transport, msg)) { status = MessageQ_S_SUCCESS; #ifndef xdc_runtime_Log_DISABLE_ALL /* if trace enabled */ if ((ti_sdo_ipc_MessageQ_traceFlag) || (flags & ti_sdo_ipc_MessageQ_TRACEMASK) != 0) { Log_write4(ti_sdo_ipc_MessageQ_LM_putRemote, (UArg)(msg), (UArg)(seqNum), (UArg)(srcProc), (UArg)(dstProcId)); } #endif } else { status = MessageQ_E_FAIL; } } else { /* Assert queueId is valid */ Assert_isTrue((UInt16)queueId < MessageQ_module->numQueues, ti_sdo_ipc_MessageQ_A_invalidQueueId); /* It is a local MessageQ */ obj = MessageQ_module->queues[(UInt16)(queueId)]; /* Assert object is not NULL */ Assert_isTrue(obj != NULL, ti_sdo_ipc_MessageQ_A_invalidObj); if ((msg->flags & MessageQ_PRIORITYMASK) == MessageQ_URGENTPRI) { listHandle = ti_sdo_ipc_MessageQ_Instance_State_highList(obj); List_putHead(listHandle, (List_Elem *)msg); } else { if ((msg->flags & MessageQ_PRIORITYMASK) == MessageQ_NORMALPRI) { listHandle = ti_sdo_ipc_MessageQ_Instance_State_normalList(obj); } else { listHandle = ti_sdo_ipc_MessageQ_Instance_State_highList(obj); } /* put on the queue */ List_put(listHandle, (List_Elem *)msg); } ISync_signal(obj->synchronizer); status = MessageQ_S_SUCCESS; if ((ti_sdo_ipc_MessageQ_traceFlag) || (msg->flags & ti_sdo_ipc_MessageQ_TRACEMASK) != 0) { Log_write4(ti_sdo_ipc_MessageQ_LM_putLocal, (UArg)(msg), (UArg)(msg->seqNum), (UArg)(msg->srcProc), (UArg)(obj)); } } return (status); }
/* * ======== Task_setPri ======== */ UInt Task_setPri(Task_Object *tsk, Int priority) { Int oldPri; UInt newMask, tskKey, hwiKey; Queue_Handle newQ; Assert_isTrue((((priority == -1) || (priority > 0) || ((priority == 0 && Task_module->idleTask == NULL))) && (priority < (Int)Task_numPriorities)), Task_A_badPriority); Log_write4(Task_LM_setPri, (UArg)tsk, (UArg)tsk->fxn, (UArg)tsk->priority, (UArg)priority); tskKey = Task_disable(); hwiKey = Hwi_disable(); oldPri = tsk->priority; if (oldPri == priority) { Hwi_restore(hwiKey); Task_restore(tskKey); return (oldPri); } if (priority < 0) { newMask = 0; newQ = Task_Module_State_inactiveQ(); } else { newMask = 1 << priority; newQ = (Queue_Handle)((UInt8 *)(Task_module->readyQ) + (UInt)(priority*(2*sizeof(Ptr)))); } if (tsk->mode == Task_Mode_READY) { Queue_remove((Queue_Elem *)tsk); /* if last task in readyQ, remove corresponding bit in curSet */ if (Queue_empty(tsk->readyQ)) { Task_module->curSet &= ~tsk->mask; } if (Task_module->curTask == tsk) { Task_module->curQ = newQ; /* force a Task_switch() */ /* if no longer maxQ */ /* Put current task at front of its new readyQ */ Queue_insert(((Queue_Elem *)(newQ))->next, (Queue_Elem *)tsk); } else { /* place task at end of its readyQ */ Queue_enqueue(newQ, (Queue_Elem *)tsk); } Task_module->curSet |= newMask; } tsk->priority = priority; tsk->mask = newMask; tsk->readyQ = newQ; if (priority < 0) { Task_module->curQ = NULL; /* force a Task_switch() */ } Task_module->workFlag = 1; Hwi_restore(hwiKey); Task_restore(tskKey); return oldPri; }