/*! * @brief Setup SysLinkMemUtils module. * * @sa _SysLinkMemUtils_exit */ static Void _SysLinkMemUtils_init (Void) { List_Params listParams; GT_0trace (curTrace, GT_ENTER, "_SysLinkMemUtils_init"); List_Params_init (&listParams); SysLinkMemUtils_module->addrTable = List_create (&listParams); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (!SysLinkMemUtils_module->addrTable) { GT_setFailureReason (curTrace, GT_4CLASS, (Char *)__func__, PROCMGR_E_MEMORY, "Translation list could not be created!"); } #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */ SysLinkMemUtils_module->semList = OsalSemaphore_create ( OsalSemaphore_Type_Counting, 1); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (!SysLinkMemUtils_module->semList) { GT_setFailureReason (curTrace, GT_4CLASS, (Char *)__func__, PROCMGR_E_MEMORY, "List semaphore could not be created!"); } #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */ GT_0trace (curTrace, GT_LEAVE, "_SysLinkMemUtils_init"); }
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; }
Int RcmClient_Instance_init(RcmClient_Object *obj, String server, const RcmClient_Params *params) { Error_Block eb; MessageQ_Params mqParams; SyncSemThread_Params syncParams; SemThread_Params semParams; SemThread_Handle semHndl; List_Params listP; Int rval; Int status = RcmClient_S_SUCCESS; Log_print2(Diags_ENTRY, "--> %s: (obj=0x%x)", (IArg)FXNN, (IArg)obj); /* must initialize error block */ Error_init(&eb); /* initialize instance data */ obj->msgId = 0xFFFF; obj->sync = NULL; obj->serverMsgQ = MessageQ_INVALIDMESSAGEQ; obj->msgQue = NULL; obj->errorMsgQue = NULL; obj->mbxLock = NULL; obj->queueLock = NULL; obj->recipients = NULL; obj->newMail = NULL; /* create the instance gate */ GateThread_construct(&obj->gate, NULL, &eb); if (Error_check(&eb)) { Log_error0(FXNN": could not create gate object"); status = RcmClient_E_FAIL; goto leave; } /* create a synchronizer for the message queue */ SyncSemThread_Params_init(&syncParams); obj->sync = SyncSemThread_create(&syncParams, &eb); if (Error_check(&eb)) { status = RcmClient_E_FAIL; goto leave; } /* create the message queue for return messages */ MessageQ_Params_init(&mqParams); obj->msgQue = MessageQ_create(NULL, &mqParams); if (obj->msgQue == NULL) { Log_error0(FXNN": could not create return message queue"); status = RcmClient_E_MSGQCREATEFAILED; goto leave; } /* create the message queue for error messages */ MessageQ_Params_init(&mqParams); obj->errorMsgQue = MessageQ_create(NULL, &mqParams); if (NULL == obj->errorMsgQue) { Log_error0(FXNN": could not create error message queue"); status = RcmClient_E_MSGQCREATEFAILED; goto leave; } /* locate server message queue */ rval = MessageQ_open(server, (MessageQ_QueueId *)(&obj->serverMsgQ)); if (MessageQ_E_NOTFOUND == rval) { Log_error1(FXNN": given server not found, server=0x%x", (IArg)server); status = RcmClient_E_SERVERNOTFOUND; goto leave; } else if (status < 0) { Log_error1(FXNN": could not open server message queue, server=0x%x", (IArg)server); status = RcmClient_E_MSGQOPENFAILED; goto leave; } /* create callback server */ if ((obj->cbNotify = params->callbackNotification)) { /* TODO create callback server thread */ /* make sure to free resources acquired by thread */ Error_raise(&eb, Error_E_generic, "Not Implemented", 0); goto leave; } /* register the heapId used for message allocation */ if ((obj->heapId = params->heapId) == RcmClient_INVALIDHEAPID) { Log_error0(FXNN": must specify a heap id in create params"); status = RcmClient_E_INVALIDHEAPID; goto leave; } /* create the mailbox lock */ SemThread_Params_init(&semParams); semHndl = SemThread_create(1, &semParams, &eb); if (Error_check(&eb)) { status = RcmClient_E_FAIL; goto leave; } obj->mbxLock = SemThread_Handle_upCast(semHndl); /* create the message queue lock */ SemThread_Params_init(&semParams); semHndl = SemThread_create(1, &semParams, &eb); if (Error_check(&eb)) { status = RcmClient_E_FAIL; goto leave; } obj->queueLock = SemThread_Handle_upCast(semHndl); /* create the return message recipient list */ #if defined(RCM_ti_ipc) List_Params_init(&listP); obj->recipients = List_create(&listP, &eb); if (Error_check(&eb)) { Log_error0(FXNN": could not create list object"); status = RcmClient_E_LISTCREATEFAILED; goto leave; } #elif defined(RCM_ti_syslink) List_Params_init(&listP); obj->recipients = List_create(&listP, NULL); if (NULL == obj->recipients) { Log_error0(FXNN": could not create list object"); status = RcmClient_E_LISTCREATEFAILED; goto leave; } #endif /* create list of undelivered messages (new mail) */ #if defined(RCM_ti_ipc) List_Params_init(&listP); obj->newMail = List_create(&listP, &eb); if (Error_check(&eb)) { Log_error0(FXNN": could not create list object"); status = RcmClient_E_LISTCREATEFAILED; goto leave; } #elif defined(RCM_ti_syslink) List_Params_init(&listP); obj->newMail = List_create(&listP, NULL); if (NULL == obj->newMail) { Log_error0(FXNN": could not create list object"); status = RcmClient_E_LISTCREATEFAILED; goto leave; } #endif leave: Log_print2(Diags_EXIT, "<-- %s: %d", (IArg)FXNN, (IArg)status); return(status); }