/* * ======== registerFxn ======== */ Int registerFxn(Ptr *userObj, UInt16 remoteProcId) { Int status; if (remoteProcId != srcProc) { return (0); } status = Notify_registerEventSingle(srcProc, INTERRUPT_LINE, EVENTID, (Notify_FnNotifyCbck)cbFxn, NULL); if (status < 0) { System_abort("Notify_registerEvent failed\n"); } return (0); }
/* * ======== Notify_registerEvent ======== */ Int Notify_registerEvent(UInt16 procId, UInt16 lineId, UInt32 eventId, Notify_FnNotifyCbck fnNotifyCbck, UArg cbckArg) { UInt32 strippedEventId = (eventId & 0xFFFF); UInt16 clusterId = ti_sdo_utils_MultiProc_getClusterId(procId); Int status; ti_sdo_ipc_Notify_Object *obj; UInt modKey; List_Handle eventList; ti_sdo_ipc_Notify_EventListener *listener; Bool listWasEmpty; Error_Block eb; Assert_isTrue(procId < ti_sdo_utils_MultiProc_numProcessors && lineId < ti_sdo_ipc_Notify_numLines, ti_sdo_ipc_Notify_A_invArgument); Assert_isTrue(strippedEventId < ti_sdo_ipc_Notify_numEvents, ti_sdo_ipc_Notify_A_invArgument); Assert_isTrue(ISRESERVED(eventId), ti_sdo_ipc_Notify_A_reservedEvent); Error_init(&eb); modKey = Gate_enterModule(); obj = (ti_sdo_ipc_Notify_Object *) Notify_module->notifyHandles[clusterId][lineId]; Assert_isTrue(obj != NULL, ti_sdo_ipc_Notify_A_notRegistered); /* Allocate a new EventListener */ listener = Memory_alloc(ti_sdo_ipc_Notify_Object_heap(), sizeof(ti_sdo_ipc_Notify_EventListener), 0, &eb); if (listener == NULL) { /* Listener memory allocation failed. Leave module gate & return */ Gate_leaveModule(modKey); return (Notify_E_MEMORY); } listener->callback.fnNotifyCbck = (Fxn)fnNotifyCbck; listener->callback.cbckArg = cbckArg; eventList = List_Object_get(obj->eventList, strippedEventId); /* * Store whether the list was empty so we know whether to register the * callback */ listWasEmpty = List_empty(eventList); /* * Need to atomically add to the list using the system gate because * Notify_exec might preempt List_remove. List_put is atomic. */ List_put(eventList, (List_Elem *)listener); if (listWasEmpty) { /* * Registering this event for the first time. Need to register the * callback function. */ status = Notify_registerEventSingle(procId, lineId, eventId, Notify_execMany, (UArg)obj); /* Notify_registerEventSingle should always succeed */ Assert_isTrue(status == Notify_S_SUCCESS, ti_sdo_ipc_Notify_A_internal); } status = Notify_S_SUCCESS; Gate_leaveModule(modKey); return (status); }
Int App_create(UInt16 remoteProcId) { Int status =0; int retStatus =0; UInt32 event =0; HeapBufMP_Params heapParams; MessageQ_Params msgqParams; printf("--> App_create:\n"); /* setting default values */ Module.remoteProcId = remoteProcId; Module.lineId = SystemCfg_LineId; Module.eventId = SystemCfg_AppEventId; Module.head = 0; Module.tail = 0; Module.error = 0; Module.msgHeap = NULL; Module.hostQue = NULL; Module.videoQue = MessageQ_INVALIDMESSAGEQ; Module.heapId = App_MsgHeapId; Module.msgSize = sizeof(App_Msg); /* 1. create sync object */ retStatus = sem_init(&Module.semH, 0, 0); if (retStatus == -1) { printf("App_create: Failed to create a semaphore\n"); goto leave; } /* 2. register notify callback */ status = Notify_registerEventSingle(Module.remoteProcId, Module.lineId, Module.eventId, App_notifyCB, (UArg)&Module); if (status < 0) { printf("App_create: Host failed to register an event\n"); goto leave; } /* 3. wait until remote core has also registered notify callback */ do { status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_NOP, TRUE); if (status == Notify_E_EVTNOTREGISTERED) { sleep(1); } } while (status == Notify_E_EVTNOTREGISTERED); if (status < 0) { printf("App_create: Failed to send event\n"); goto leave; } /* 4. create local & shared resources (to be opened by remote processor) */ /* create heap for messages */ HeapBufMP_Params_init(&heapParams); heapParams.name = App_MsgHeapName; heapParams.regionId = App_MsgHeapSrId; heapParams.blockSize = 64; heapParams.numBlocks = 10; Module.msgHeap = HeapBufMP_create(&heapParams); if (Module.msgHeap == NULL) { printf("App_create: Failed to create a HeapBufMP\n"); status = -1; goto leave; } /* register heap with MessageQ */ status = MessageQ_registerHeap((Ptr)(Module.msgHeap), App_MsgHeapId); if (status < 0) { printf("App_create: Failed to register HeapBufMP with MessageQ\n"); goto leave; } /* create local message queue (inbound messages) */ MessageQ_Params_init(&msgqParams); Module.hostQue = MessageQ_create(App_HostMsgQueName, &msgqParams); if (Module.hostQue == NULL) { printf("App_create: Failed creating MessageQ\n"); status = -1; goto leave; } /* 5. send resource ready event */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_RESRDY, TRUE); if (status < 0) { printf("App_create: Failed to send event\n"); goto leave; } /* 6. wait for remote resource ready event */ do { event = App_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; printf("App_create: Failed waiting for event\n"); goto leave; } } while (event != App_CMD_RESRDY); /* 7. open remote resources */ /* open the video message queue */ status = MessageQ_open(App_VideoMsgQueName, &Module.videoQue); if (status < 0) { printf("App_create: Failed opening MessageQ\n"); goto leave; } /* 8. send application ready event */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_READY, TRUE); if (status < 0) { printf("App_create: Failed to send event\n"); goto leave; } /* 9. wait for remote server ready event */ do { event = App_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; printf("App_create: Failed waiting for event\n"); goto leave; } } while (event != App_CMD_READY); printf("App_create: Host is ready\n"); leave: printf("<-- App_create:\n"); return(status); }
/* * ======== Hello_start ======== * * 1. create semaphore object * 2. register notify callback * 3. wait until remote core has also registered notify callback * 4. create local & shared resources * 5. send resource ready event * 6. wait for remote resource ready event * 7. open remote resources * 8. handshake the ready event */ Int Hello_start(UInt16 remoteProcId) { Int status; UInt32 event; SemThread_Params semParams; HeapBufMP_Params heapParams; Error_Block eb; Error_init(&eb); Module.remoteProcId = remoteProcId; /* * 1. create semaphore object */ SemThread_Params_init(&semParams); semParams.mode = SemThread_Mode_COUNTING; SemThread_construct(&Module.semS, 0, &semParams, &eb); if (Error_check(&eb)) { status = -15; goto leave; } Module.semH = SemThread_handle(&Module.semS); /* * 2. register notify callback */ status = Notify_registerEventSingle(Module.remoteProcId, Module.lineId, Module.eventId, Hello_notifyCB, (UArg)&Module); if (status < 0) { goto leave; } /* * 3. wait until remote core has also registered notify callback */ do { status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_NOP, TRUE); if (status == Notify_E_EVTNOTREGISTERED) { Thread_sleep(1000, &eb); /* microseconds */ } } while (status == Notify_E_EVTNOTREGISTERED); if (status < 0) { goto leave; } /* * 4. create local & shared resources (to be opened by remote processor) */ /* create heap for rcm messages */ HeapBufMP_Params_init(&heapParams); heapParams.name = Global_RcmClientHeapName; heapParams.regionId = 0; heapParams.blockSize = 0x200; /* 512 B */ heapParams.numBlocks = 8; Module.msgHeap = HeapBufMP_create(&heapParams); if (Module.msgHeap == NULL) { Log_error0("Hello_start: HeapBuf_create() failed"); status = -1; goto leave; } /* register heap with MessageQ */ status = MessageQ_registerHeap((Ptr)(Module.msgHeap), Global_RcmClientHeapId); if (status < 0) { goto leave; } /* * 5. send resource ready event */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_RESRDY, TRUE); if (status < 0) { goto leave; } /* * 6. wait for remote resource ready event */ do { event = Hello_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_RESRDY); /* * 7. open remote resources */ /* * 8. handshake the ready event */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_READY, TRUE); if (status < 0) { goto leave; } do { event = Hello_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_READY); leave: return(status); }
/* * ======== TransportShm_Instance_init ======== */ Int TransportShm_Instance_init(TransportShm_Object *obj, UInt16 procId, const TransportShm_Params *params, Error_Block *eb) { Int localIndex; Int remoteIndex; Int status; Bool flag; UInt32 minAlign; ListMP_Params listMPParams[2]; Swi_Handle swiHandle; Swi_Params swiParams; Ptr localAddr; swiHandle = TransportShm_Instance_State_swiObj(obj); /* * Determine who gets the '0' slot in shared memory and who gets * the '1' slot. The '0' slot is given to the lower MultiProc id. */ if (MultiProc_self() < procId) { localIndex = 0; remoteIndex = 1; } else { localIndex = 1; remoteIndex = 0; } if (params->openFlag) { /* Open by sharedAddr */ obj->objType = ti_sdo_ipc_Ipc_ObjType_OPENDYNAMIC; obj->self = (TransportShm_Attrs *)params->sharedAddr; obj->regionId = SharedRegion_getId(params->sharedAddr); obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId); localAddr = SharedRegion_getPtr(obj->self->gateMPAddr); status = GateMP_openByAddr(localAddr, (GateMP_Handle *)&obj->gate); if (status < 0) { Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0); return(1); } } else { /* init the gate for ListMP create below */ if (params->gate != NULL) { obj->gate = params->gate; } else { obj->gate = (ti_sdo_ipc_GateMP_Handle)GateMP_getDefaultRemote(); } /* Creating using sharedAddr */ obj->regionId = SharedRegion_getId(params->sharedAddr); /* Assert that the buffer is in a valid shared region */ Assert_isTrue(obj->regionId != SharedRegion_INVALIDREGIONID, ti_sdo_ipc_Ipc_A_addrNotInSharedRegion); /* Assert that sharedAddr is cache aligned */ Assert_isTrue(((UInt32)params->sharedAddr % SharedRegion_getCacheLineSize(obj->regionId) == 0), ti_sdo_ipc_Ipc_A_addrNotCacheAligned); /* set object's cacheEnabled, type, self */ obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId); obj->objType = ti_sdo_ipc_Ipc_ObjType_CREATEDYNAMIC; obj->self = (TransportShm_Attrs *)params->sharedAddr; } /* determine the minimum alignment to align to */ minAlign = Memory_getMaxDefaultTypeAlign(); if (SharedRegion_getCacheLineSize(obj->regionId) > minAlign) { minAlign = SharedRegion_getCacheLineSize(obj->regionId); } /* * Carve up the shared memory. * If cache is enabled, these need to be on separate cache lines. * This is done with minAlign and _Ipc_roundup function. */ obj->other = (TransportShm_Attrs *)((UInt32)(obj->self) + (_Ipc_roundup(sizeof(TransportShm_Attrs), minAlign))); ListMP_Params_init(&(listMPParams[0])); listMPParams[0].gate = (GateMP_Handle)obj->gate; listMPParams[0].sharedAddr = (UInt32 *)((UInt32)(obj->other) + (_Ipc_roundup(sizeof(TransportShm_Attrs), minAlign))); ListMP_Params_init(&listMPParams[1]); listMPParams[1].gate = (GateMP_Handle)obj->gate; listMPParams[1].sharedAddr = (UInt32 *)((UInt32)(listMPParams[0].sharedAddr) + ListMP_sharedMemReq(&listMPParams[0])); obj->priority = params->priority; obj->remoteProcId = procId; Swi_Params_init(&swiParams); swiParams.arg0 = (UArg)obj; Swi_construct(Swi_struct(swiHandle), (Swi_FuncPtr)TransportShm_swiFxn, &swiParams, eb); if (params->openFlag == FALSE) { obj->localList = (ti_sdo_ipc_ListMP_Handle) ListMP_create(&(listMPParams[localIndex])); if (obj->localList == NULL) { Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0); return (2); } obj->remoteList = (ti_sdo_ipc_ListMP_Handle) ListMP_create(&(listMPParams[remoteIndex])); if (obj->localList == NULL) { Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0); return (2); } } else { /* Open the local ListMP instance */ status = ListMP_openByAddr(listMPParams[localIndex].sharedAddr, (ListMP_Handle *)&(obj->localList)); if (status < 0) { Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0); return (2); } /* Open the remote ListMP instance */ status = ListMP_openByAddr(listMPParams[remoteIndex].sharedAddr, (ListMP_Handle *)&(obj->remoteList)); if (status < 0) { Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0); return (2); } } /* register the event with Notify */ status = Notify_registerEventSingle( procId, /* remoteProcId */ 0, /* lineId */ TransportShm_notifyEventId, (Notify_FnNotifyCbck)TransportShm_notifyFxn, (UArg)swiHandle); if (status < 0) { Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0); return (3); } /* Register the transport with MessageQ */ flag = ti_sdo_ipc_MessageQ_registerTransport( TransportShm_Handle_upCast(obj), procId, params->priority); if (flag == FALSE) { Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0); return (4); } if (params->openFlag == FALSE) { obj->self->creatorProcId = MultiProc_self(); obj->self->notifyEventId = TransportShm_notifyEventId; obj->self->priority = obj->priority; /* Store the GateMP sharedAddr in the Attrs */ obj->self->gateMPAddr = ti_sdo_ipc_GateMP_getSharedAddr(obj->gate); obj->self->flag = TransportShm_UP; if (obj->cacheEnabled) { Cache_wbInv(obj->self, sizeof(TransportShm_Attrs), Cache_Type_ALL, TRUE); } } else { obj->other->flag = TransportShm_UP; if (obj->cacheEnabled) { Cache_wbInv(&(obj->other->flag), minAlign, Cache_Type_ALL, TRUE); } } obj->status = TransportShm_UP; return (0); }
/* * ======== Server_setup ======== * * 1. create semaphore object * 2. register notify callback * 3. wait until remote core has also registered notify callback * 4. create local & shared resources * 5. send resource ready event * 6. wait for remote resource ready event * 7. open remote resources * 8. handshake the ready event */ Int Server_setup(Void) { Int status; UInt32 event; Semaphore_Params semParams; RcmServer_Params rcmServerP; Log_print0(Diags_ENTRY | Diags_INFO, "--> Server_setup:"); /* * 1. create semaphore object */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_COUNTING; Semaphore_construct(&Module.semS, 0, &semParams); Module.semH = Semaphore_handle(&Module.semS); /* * 2. register notify callback */ status = Notify_registerEventSingle(Module.hostProcId, Module.lineId, Module.eventId, Server_notifyCB, (UArg)&Module); if (status < 0) { goto leave; } /* * 3. wait until remote core has also registered notify callback */ do { status = Notify_sendEvent(Module.hostProcId, Module.lineId, Module.eventId, App_CMD_NOP, TRUE); if (status == Notify_E_EVTNOTREGISTERED) { Task_sleep(200); /* ticks */ } } while (status == Notify_E_EVTNOTREGISTERED); if (status < 0) { goto leave; } /* * 4. create local & shared resources (to be opened by remote processor) */ /* * 5. send resource ready event */ status = Notify_sendEvent(Module.hostProcId, Module.lineId, Module.eventId, App_CMD_RESRDY, TRUE); if (status < 0) { goto leave; } /* * 6. wait for remote resource ready event */ do { event = Server_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_RESRDY); /* * 7. open remote resources */ /* open the rcm heap */ status = HeapBufMP_open(Global_RcmClientHeapName, &Module.heapH); if (status < 0) { Log_error1("Server_setup: HeapBufMP_open() returned error %d", (IArg)status); goto leave; } /* register the rcm heap with MessageQ */ status = MessageQ_registerHeap((Ptr)(Module.heapH), Global_RcmClientHeapId); if (status < 0) { Log_error1("Server_setup: MessageQ_restierHeap() returned error %d", (IArg)status); goto leave; } /* initialize RcmServer create params */ RcmServer_Params_init(&rcmServerP); rcmServerP.fxns.length = Server_fxnTab.length; rcmServerP.fxns.elem = Server_fxnTab.elem; /* create the RcmServer instance */ status = RcmServer_create(Global_RcmServerName, &rcmServerP, &Module.rcmServerH); if (status < 0) { Log_error1("Server_setup: RcmServer_create() returned error %d", (IArg)status); goto leave; } /* start the server */ RcmServer_start(Module.rcmServerH); /* * 8. handshake the ready event */ status = Notify_sendEvent(Module.hostProcId, Module.lineId, Module.eventId, App_CMD_READY, TRUE); if (status < 0) { goto leave; } do { event = Server_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_READY); leave: Log_print1(Diags_EXIT, "<-- Server_setup: %d", (IArg)status); return(status); }