/* * ======== 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); }
Int SystemCfg_create(const SystemCfg_Params *params, SystemCfg_Handle *handleP) { Int status, bufSize; Error_Block eb; SystemCfg_Object * obj; Semaphore_Params semParams; Log_print0(Diags_ENTRY, "--> "FXNN": ()"); /* initialize local vars */ status = 0; Error_init(&eb); *handleP = (SystemCfg_Handle)NULL; /* allocate the object */ obj = (SystemCfg_Handle)xdc_runtime_Memory_calloc(NULL, sizeof(SystemCfg_Object), sizeof(Int), &eb); if (obj == NULL) { Log_error1(FXNN": out of memory: size=%u", sizeof(SystemCfg_Object)); status = SystemCfg_E_NOMEMORY; goto leave; } /* object-specific initialization */ obj->remoteProcName = NULL; obj->remoteProcId = MultiProc_INVALIDID; obj->semH = NULL; obj->rcmHeapH = NULL; /* initialize structures to zero */ memset((Void *)&obj->semObj, 0, sizeof(Semaphore_Struct)); /* store the remote processor name */ bufSize = strlen(params->remoteProcName) + 1; obj->remoteProcName = (String)xdc_runtime_Memory_calloc(NULL, bufSize, sizeof(String), &eb); if (obj == NULL) { Log_error1(FXNN": out of memory: size=%u", bufSize); status = SystemCfg_E_NOMEMORY; goto leave; } strcpy(obj->remoteProcName, params->remoteProcName); /* lookup the remote processor id */ obj->remoteProcId = MultiProc_getId(obj->remoteProcName); /* create sync object used for synchronizing with remote core */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_COUNTING; Semaphore_construct(&obj->semObj, 0, &semParams); obj->semH = Semaphore_handle(&obj->semObj); /* add object to module list for register hook */ List_putHead(Mod_objList, &obj->link); /* success, return opaque pointer */ *handleP = (SystemCfg_Handle)obj; leave: Log_print1(Diags_EXIT, "<-- "FXNN": %d", (IArg)status); return(status); }
Void ListTest(Void) { List_Params listParams; List_Handle listHandle; List_Elem *elem; ListNode *node; UInt32 i, value; Bool failed = FALSE; IGateProvider_Handle gateHandle; List_Params_init(&listParams); gateHandle = (IGateProvider_Handle) GateMutex_create(); if(gateHandle == NULL) { Osal_printf("ListTest: GateMutex_create failed.\n"); goto exit; } listParams.gateHandle = gateHandle; listHandle = List_create(&listParams); if(listHandle == NULL) { Osal_printf("ListTest: List_create failed.\n"); goto gateExit; } node = Memory_alloc(NULL, LIST_SIZE * sizeof(ListNode), 0); if(node == NULL) { Osal_printf("ListTest: Memory_alloc failed.\n"); goto listExit; } // Put some nodes into the list for(i = 0; i < LIST_SIZE; i++) { node[i].value = i; List_put(listHandle, (List_Elem *)&node[i]); } // Traverse the list for(i = 0, elem = List_next(listHandle, NULL); elem != NULL && !failed; i++, elem = List_next(listHandle, elem)) { value = ((ListNode *)elem)->value; // Check against expected value if(value != i) { Osal_printf("ListTest: data mismatch, expected " "0x%x, actual 0x%x\n", i, i, value); failed = TRUE; } } // Remove nodes for(i = 0; i < LIST_SIZE && !List_empty(listHandle); i++) { // Get first element and put it back to test List_get and List_putHead elem = List_get(listHandle); List_putHead(listHandle, elem); // Now remove it permanently to test List_remove if(elem != NULL) { List_remove(listHandle, elem); } } // Did we remove the expected number of nodes? if(i != LIST_SIZE) { Osal_printf("ListTest: removed %d node(s), expected %d\n", i, LIST_SIZE); failed = TRUE; } if(!List_empty(listHandle)) { Osal_printf("ListTest: list not empty!\n"); failed = TRUE; } if(failed) Osal_printf("ListTest: FAILED!\n"); else Osal_printf("ListTest: PASSED!\n"); listExit: List_delete(&listHandle); gateExit: GateMutex_delete((GateMutex_Handle *)&gateHandle); exit: return; }