STATUS msgQInit(FAST MSG_Q* pMsgQ, int maxMsgs, int maxMsgLength, int options, void* pMsgPool) { FAST int nodeSize = MSG_NODE_SIZE(maxMsgLength); FAST int ix; FAST QUEUE_ID msgQType; if ((!msgQLibInstalled) && (msgQLibInit () != OK)) { return (ERROR); /* package init problem */ } memset((char*)pMsgQ, 0, sizeof(*pMsgQ)); switch(options & MSG_Q_TYPE_MASK) { case MSG_Q_FIFO: msgQType = Q_FIFO; break; case MSG_Q_PRIORITY: msgQType = Q_PRI_LIST; break; default: msgQType = Q_FIFO; break; } if((qInit(&pMsgQ->msgQ, qJobClassId, msgQType, 2,3,4,5) != OK) || (qInit(&pMsgQ->freeQ, qJobClassId, msgQType, 2,3,4,5) != OK)) { return (ERROR); } for(ix = 0; ix < maxMsgs; ix++) { qJobPut(pMsgQ, &pMsgQ->freeQ, (Q_JOB_NODE*)pMsgPool, Q_JOB_PRI_DONT_CARE); pMsgPool = (void*)((char*)pMsgPool + nodeSize); } /*printf("pMsgQ->freeQ.first:0x%x\n", pMsgQ->freeQ.first);*/ pMsgQ->options = options; pMsgQ->maxMsgs = maxMsgs; pMsgQ->maxMsgLength = maxMsgLength; objCoreInit(&pMsgQ->objCore, msgQClassId); return (OK); }
void usrKernelCoreInit (void) { eventLibInit (); /* VxWorks events */ semDeleteLibInit (); /* semaphore deletion routines */ /* binary semaphores */ /* counting semaphores */ /* reader/writer semaphores */ semOpenInit (); /* open/close/unlink semaphore modules */ msgQLibInit (); /* message queues */ msgQOpenInit (); /* open/close/unlink message queue modules */ wdLibInit (); /* watchdog timers */ taskOpenInit (); /* open/close/unlink task modules */ taskHookInit (); /* user callouts on task creation/deletion/context switch */ /* binary semaphore creation routine */ /* counting semaphore creation routine */ /* reader/writer semaphore creation routine */ taskCreateLibInit (); /* Capability to dynamically instantiate and delete tasks */ msgQCreateLibInit (); /* message queue creation and deletion library */ wdCreateLibInit (); /* watchdog timers creation and deletion library */ wdbTaskHookInit (); /* task hooks debug support */ }
MSG_Q_ID msgQCreate(int maxMsgs, int maxMsgLength, int options) { MSG_Q_ID msgQId; void * pPool; /* pointer to memory for messages */ UINT size = (UINT) maxMsgs * MSG_NODE_SIZE (maxMsgLength); /* TODO restrict ISR from calling */ if ((!msgQLibInstalled) && (msgQLibInit () != OK)) return (NULL); /* package init problem */ if ((msgQId = (MSG_Q_ID)objAllocExtra (msgQClassId, size, &pPool)) == NULL) return (NULL); if (msgQInit (msgQId, maxMsgs, maxMsgLength, options, pPool) != OK) { objFree (msgQClassId, (char *) msgQId); return (NULL); } return ((MSG_Q_ID) msgQId); }