/* * ======== tsk0_func ======== * Wait to be released then send an interrupt to the ARM processor */ Void tsk0_func(UArg arg0, UArg arg1) { Int status; while (seq < NUMLOOPS) { /* Wait to be released by callback function */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); System_printf("Received request #%d from ARM (lineId = 0)\n", seq); status = Notify_sendEvent(armProcId, LINE_1, EVENTID, seq, TRUE); if (status < 0) { System_abort("sendEvent failed\n"); } System_printf("Sent request #%d to ARM (lineId = 1)\n", seq); /* Wait to be released by the cbFxn posting the semaphore */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); System_printf("Received request #%d from ARM (lineId = 1)\n"); /* Send an event to the ARM */ status = Notify_sendEvent(armProcId, LINE_0, EVENTID, seq, TRUE); if (status < 0) { System_abort("sendEvent failed\n"); } System_printf("Sent request #%d to ARM (lineId = 0)\n", seq); } System_printf("Test completed\n"); BIOS_exit(0); }
/* * ======== tsk0_func ======== * Sends an event to the remote processor then pends on a semaphore. * The semaphore is posted by the callback function. */ Void tsk0_func(UArg arg0, UArg arg1) { Int i = 1; Int status; if (MultiProc_self() == 0) { while (i <= NUMLOOPS) { /* Send an event to the remote processor */ status = Notify_sendEvent(dstProc, INTERRUPT_LINE, EVENTID, i, TRUE); /* Continue until remote side is up */ if (status < 0) { continue; } System_printf("tsk1_func: Sent request #%d to %s\n", seq, MultiProc_getName(dstProc)); /* Wait to be released by the cbFxn posting the semaphore */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); System_printf("tsk1_func: Received request #%d from %s\n", seq, MultiProc_getName(recvProcId)); /* increment for remote iteration */ i++; } } else { while (seq < NUMLOOPS) { /* wait forever on a semaphore, semaphore is posted in callback */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); System_printf("tsk1_func: Received request #%d from %s\n", seq, MultiProc_getName(recvProcId)); /* Send an event to the remote processor */ status = Notify_sendEvent(dstProc, INTERRUPT_LINE, EVENTID, seq, TRUE); if (status < 0) { System_abort("sendEvent failed\n"); } System_printf("tsk1_func: Sent request #%d to %s\n", seq, MultiProc_getName(dstProc)); } } System_printf("Test completed\n"); BIOS_exit(0); }
/* * ======== main ======== */ Int main(Int argc, Char* argv[]) { UInt32 myArg1 = 12345; UInt32 myArg2 = 67890; UInt16 myProcId = MultiProc_self(); Int status; /* Register the functions to be called */ System_printf("Registering myFxn1 & myArg1 to event #%d..\n", EVENT); Notify_registerEvent(myProcId, 0, EVENT, (Notify_FnNotifyCbck)myFxn1, (UArg)&myArg1); System_printf("Registering myFxn2 & myArg2 to event #%d..\n", EVENT); Notify_registerEvent(myProcId, 0, EVENT, (Notify_FnNotifyCbck)myFxn2, (UArg)&myArg2); /* Send an event */ System_printf("Sending event #%d (myFxn1 and myFxn2 should run)\n", EVENT); Notify_sendEvent(myProcId, 0, EVENT, 0xaaaaa, TRUE); /* Unregister one of the functions */ System_printf("Unregistering myFxn1 + myArg1\n"); status = Notify_unregisterEvent(myProcId, 0, EVENT, (Notify_FnNotifyCbck)myFxn1, (UArg)&myArg1); if (status < 0) { System_abort("Listener not found! (THIS IS UNEXPECTED)\n"); } /* Send an event */ System_printf("Sending event #%d (myFxn2 should run)\n", EVENT); Notify_sendEvent(myProcId, 0, EVENT, 0xbbbbb, TRUE); /* Disable event */ System_printf("Disabling event #%d:\n", EVENT); Notify_disableEvent(myProcId, 0, EVENT); /* Send an event (nothing should happen) */ System_printf("Sending event #%d (nothing should happen)\n", EVENT); Notify_sendEvent(myProcId, 0, EVENT, 0xbbbbb, TRUE); /* Enable event */ System_printf("Enabling event #%d:\n", EVENT); Notify_enableEvent(myProcId, 0, EVENT); /* Send an event */ System_printf("Sending event #%d (myFxn2 should run)\n", EVENT); Notify_sendEvent(myProcId, 0, EVENT, 0xbbbbb, TRUE); System_printf("Test completed\n"); return (0); }
/* * ======== Server_run ======== */ Int Server_run(Void) { Int status = 0; UInt32 event; Log_print0(Diags_ENTRY, "--> Server_run:"); /* wait for the shutdown command */ do { event = Server_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_SHUTDOWN); /* send shutdown acknowledgement */ Notify_sendEvent(Module.hostProcId, Module.lineId, Module.eventId, App_CMD_SDACK, TRUE); leave: Log_print1(Diags_EXIT, "<-- Server_run: %d", (IArg)status); return(status); }
Int SystemCfg_closeSharedResources(SystemCfg_AppFxn appShutdownFxn, Ptr arg) { Error_Block eb; Int status = 0; struct SystemCfg *stateObj = &SystemCfg_State; Log_print1(Diags_ENTRY, "--> %s: ()", (IArg)FXNN); Error_init(&eb); /* invoke the application shutdown function */ if (appShutdownFxn != NULL) { status = appShutdownFxn(arg); if (status < 0) { goto leave; } } /* close shared resources from remote core */ /* <add code here> */ /* send close done event to remote core */ Log_print0(Diags_USER1, FXNN": send EvtCloseDone to remote core"); status = Notify_sendEvent(stateObj->hostProcId, Global_NotifyLineId, Global_HostDspEvtNum, Global_EvtCloseDone, TRUE); if (status < 0) { /* Log_error() */ Log_print4(Diags_USER8, "Error: %s, line %d: %s: Notify_sendEvent() returned error %d", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN, (IArg)status); goto leave; } /* wait for close event from remote core */ Log_print0(Diags_USER1, FXNN": waiting for EvtCloseDone event..."); SemThread_pend(stateObj->semH, SemThread_FOREVER, &eb); if (Error_check(&eb)) { /* Log_error() */ Log_print3(Diags_USER8, "Error: %s, line %d: %s: SemThread_pend() returned with error", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN); status = -1; goto leave; } Log_print0(Diags_USER1, FXNN": ...received EvtCloseDone event"); leave: Log_print2(Diags_EXIT, "<-- %s: %d", (IArg)FXNN, (IArg)status); return(status); }
/* * ======== tsk0_func ======== * Send an interrupt to the DSP processor and wait on semaphore. */ Void tsk0_func(UArg arg0, UArg arg1) { Int i = 1; Int status; Int16 remoteProcId = MultiProc_getId("DSP"); while (i <= NUMLOOPS) { /* Send an event to the DSP */ status = Notify_sendEvent(dspProcId, LINE_0, EVENTID, i, TRUE); /* Continue until remote side is up */ if (status < 0) { continue; } System_printf("Sent request #%d to DSP (lineId = 0)\n", i); /* Wait to be released by the cbFxn posting the semaphore */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); System_printf("Received request #%d from DSP (lineId = 1)\n", seq); /* Send an event to the DSP */ status = Notify_sendEvent(dspProcId, LINE_1, EVENTID, i, TRUE); /* Continue until remote side is up */ if (status < 0) { continue; } System_printf("Sent request #%d to DSP (lineId = 1)\n", i); /* Wait to be released by the cbFxn posting the semaphore */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); System_printf("Received request #%d from DSP (lineId = 0)\n", seq); /* increment for next iteration */ i++; } System_printf("Test completed\n"); BIOS_exit(0); }
Int SystemCfg_sendEvent(SystemCfg_Object *obj, UInt32 event) { Int status; /* send event to remote core */ status = Notify_sendEvent(obj->remoteProcId, SystemCfg_NotifyLineId, SystemCfg_HostDspEvtNum, event, TRUE); if (status < 0) { Log_error1(FXNN": Notify_sendEvent() error %d", (IArg)status); } return(status); }
/* * ======== SemaphoreMP_post ======== */ Void SemaphoreMP_post(SemaphoreMP_Object *obj) { UInt tskKey; SemaphoreMP_PendElem *elem; IArg gateMPKey; Int status; /* Enter the gate */ gateMPKey = GateMP_enter((GateMP_Handle)obj->gate); if (ListMP_empty((ListMP_Handle)obj->pendQ)) { if (obj->mode == SemaphoreMP_Mode_BINARY) { obj->attrs->count = 1; } else { obj->attrs->count++; } if (obj->cacheEnabled) { Cache_wbInv(obj->attrs, sizeof(SemaphoreMP_Attrs), Cache_Type_ALL, TRUE); } /* Leave the gate */ GateMP_leave((GateMP_Handle)obj->gate, gateMPKey); return; } /* lock task scheduler */ tskKey = Task_disable(); /* dequeue tsk from semaphore queue */ elem = (SemaphoreMP_PendElem *)ListMP_getHead((ListMP_Handle)obj->pendQ); if (elem->procId != MultiProc_self()) { /* Unblock remote task */ status = Notify_sendEvent(elem->procId, 0, SemaphoreMP_notifyEventId, elem->task, TRUE); Assert_isTrue(status >= 0, ti_sdo_ipc_Ipc_A_internal); } else { /* put task back into readyQ */ Task_unblock((Task_Handle)elem->task); } /* Leave the gate */ GateMP_leave((GateMP_Handle)obj->gate, gateMPKey); Task_restore(tskKey); }
/* * ======== tsk0_func ======== * This function is executed only on CORE0. * It sends an event to the next processor then pends on a semaphore. * The semaphore is posted by the callback function. */ Void tsk0_func(UArg arg0, UArg arg1) { Int status; /* Send an event to the next processor */ if (MultiProc_self() == 0) { rawtimestamps[seq++] = Timestamp_get32(); status = Notify_sendEvent(dstProc, INTERRUPT_LINE, EVENTID, NULL, TRUE); if (status < 0) { System_abort("Notify_sendEvent failed\n"); } } Task_exit(); }
/* * ======== cbFxn ======== * This function was registered with Notify. It is called when any event is * sent to this processor. */ Void cbFxn(UInt16 procId, UInt16 lineId, UInt32 eventId, UArg arg, UInt32 payload) { Int status; if (selfId == 0) { rawtimestamps[seq] = Timestamp_get32(); } seq++; status = Notify_sendEvent(dstProc, INTERRUPT_LINE, EVENTID, NULL, TRUE); if (status < 0) { System_abort("Notify_sendEvent failed\n"); } }
/*! * @brief Function to execute the shutdown for uiaDemo sample application * * @sa */ Int uiaDemo_shutdown (Void) { Int i; Int status = 0; for (i = 0; i < uiaDemo_numProcessors; i++) { status = Notify_sendEvent(uiaDemo_procId[i], 0, SHUTDOWN, 0, FALSE); Osal_printf ("Notify_sendEvent status [%d]\n", status); } for (i = 0; i < uiaDemo_numProcessors; i++) { /* shutdown the logic one by one for each processor */ status = ProcMgrApp_shutdown (uiaDemo_procId[i]); } return (status); }
/* * ======== TransportShm_put ======== * Assuming MessageQ_put is making sure that the arguments are ok */ Bool TransportShm_put(TransportShm_Object *obj, Ptr msg) { Int32 status; Bool retval = TRUE; IArg key; UInt16 id = SharedRegion_getId(msg); /* This transport only deals with messages allocated from SR's */ Assert_isTrue(id != SharedRegion_INVALIDREGIONID, ti_sdo_ipc_SharedRegion_A_regionInvalid); /* writeback invalidate the message */ if (SharedRegion_isCacheEnabled(id)) { Cache_wbInv(msg, ((MessageQ_Msg)(msg))->msgSize, Cache_Type_ALL, TRUE); } /* make sure ListMP_put and sendEvent are done before remote executes */ key = GateMP_enter((GateMP_Handle)obj->gate); /* Put the message on the remoteList */ ListMP_putTail((ListMP_Handle)obj->remoteList, (ListMP_Elem *)msg); /* Notify the remote processor */ status = Notify_sendEvent(obj->remoteProcId, 0, TransportShm_notifyEventId, 0, FALSE); /* check the status of the sendEvent */ if (status < 0) { /* remove the message from the List and return 'FALSE' */ ListMP_remove((ListMP_Handle)obj->remoteList, (ListMP_Elem *)msg); retval = FALSE; } /* leave the gate */ GateMP_leave((GateMP_Handle)obj->gate, key); return (retval); }
Int32 System_ipcSendNotify(UInt32 linkId) { Int32 status; UInt32 procId = SYSTEM_GET_PROC_ID(linkId); UTILS_assert(procId < SYSTEM_PROC_MAX); status = Notify_sendEvent(procId, SYSTEM_IPC_NOTIFY_LINE_ID, SYSTEM_IPC_NOTIFY_EVENT_ID, linkId, TRUE); if (status != Notify_S_SUCCESS) { Vps_printf (" %d: NOTIFY: Send Event to [%s][%d] failed !!! (status = %d)\n", Utils_getCurTimeInMsec(), MultiProc_getName(SYSTEM_GET_PROC_ID(linkId)), SYSTEM_GET_LINK_ID(linkId), status); UTILS_assert(status == Notify_S_SUCCESS); } return FVID2_SOK; }
/* * ======== Server_finish ======== * * 1. close remote resources * 2. handshake close event * 3. delete shared resoures * 4. send disconnect event (last event sent) * 5. wait for disconnect event * 6. unregister notify callback * 9. delete semaphore object */ Int Server_finish(Void) { Int status; UInt32 event; /* * 1. close remote resources */ /* delete the RcmServer instance */ status = RcmServer_delete(&Module.rcmServerH); if (status < 0) { Log_error1("Server_finish: RcmServer_delete() returned error %d", (IArg)status); goto leave; } /* unregister rcm heap with MessageQ */ status = MessageQ_unregisterHeap(Global_RcmClientHeapId); if (status < 0) { goto leave; } /* close the rcm heap */ status = HeapBufMP_close(&Module.heapH); if (status < 0) { Log_error1("Server_finish: HeapBufMP_close() returned error %d", (IArg)status); goto leave; } /* * 2. handshake close event */ status = Notify_sendEvent(Module.hostProcId, Module.lineId, Module.eventId, App_CMD_CLOSED, TRUE); if (status < 0) { goto leave; } do { event = Server_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_CLOSED); /* * 3. delete shared resoures */ /* * 4. send disconnect event (last event sent) */ status = Notify_sendEvent(Module.hostProcId, Module.lineId, Module.eventId, App_CMD_DONE, TRUE); if (status < 0) { goto leave; } /* * 5. wait for disconnect event (last event received) */ do { event = Server_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_DONE); /* * 6. unregister notify callback */ status = Notify_unregisterEventSingle(Module.hostProcId, Module.lineId, Module.eventId); if (status < 0) { goto leave; } /* * 9. delete semaphore object */ Semaphore_destruct(&Module.semS); Module.semH = NULL; leave: return(status); }
/* * ======== App_delete ======== * * 1. send shutdown event * 2. wait for shutdown acknowledgement event * * 3. close remote resources * 4. send close done event * 5. wait for remote close done event * * 6. delete shared resoures * 7. send disconnect event (last sent event) * 8. wait for disconnect event * * 9. unregister notify callback * 10. delete sync object */ Int App_delete(Void) { Int status; UInt32 event; /* 1. send shutdown command (out-of-band) */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_SHUTDOWN, TRUE); if (status < 0) { goto leave; } /* 2. wait for shutdown acknowledgement */ do { event = App_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_SDACK); /* 3. close remote resources */ status = MessageQ_close(&Module.videoQue); if (status < 0) { goto leave; } /* 4. send close done event */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_CLOSED, TRUE); if (status < 0) { goto leave; } /* 5. wait for remote close done event */ do { event = App_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_CLOSED); /* 6. delete shared resoures */ /* delete the host message queue */ status = MessageQ_delete(&Module.hostQue); if (status < 0) { goto leave; } /* unregister heap with MessageQ */ status = MessageQ_unregisterHeap(App_MsgHeapId); if (status < 0) { goto leave; } /* delete the message heap */ status = HeapBufMP_delete(&Module.msgHeap); if (status < 0) { goto leave; } /* 7. send disconnect event (last sent event) */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_DONE, TRUE); if (status < 0) { goto leave; } /* 8. wait for disconnect event (last event received) */ do { event = App_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_DONE); /* 9. unregister notify callback */ status = Notify_unregisterEventSingle(Module.remoteProcId, Module.lineId, Module.eventId); if (status < 0) { goto leave; } /* 10. delete sync object */ sem_destroy(&Module.semH); leave: 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); }
/* * ======== 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); }
/* * ======== Hello_stop ======== * * 1. send shutdown event * 2. wait for shutdown acknowledgement * 3. close remote resources * 4. handshake close event * 5. delete shared resoures * 6. send disconnect event (last event sent) * 7. wait for disconnect event * 8. unregister notify callback * 9. delete semaphore object */ Int Hello_stop(Void) { Int status; UInt32 event; /* * 1. send shutdown command (out-of-band) */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_SHUTDOWN, TRUE); if (status < 0) { goto leave; } /* * 2. wait for shutdown acknowledgement */ do { event = Hello_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_SDACK); /* * 3. close remote resources */ /* * 4. handshake close event */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_CLOSED, TRUE); if (status < 0) { goto leave; } do { event = Hello_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_CLOSED); /* * 5. delete shared resoures */ /* unregister heap with MessageQ */ status = MessageQ_unregisterHeap(Global_RcmClientHeapId); if (status < 0) { goto leave; } /* delete the message heap */ status = HeapBufMP_delete(&Module.msgHeap); if (status < 0) { goto leave; } /* * 6. send disconnect event (last event sent) */ status = Notify_sendEvent(Module.remoteProcId, Module.lineId, Module.eventId, App_CMD_DONE, TRUE); if (status < 0) { goto leave; } /* * 7. wait for disconnect event (last event received) */ do { event = Hello_waitForEvent(); if (event >= App_E_FAILURE) { status = -1; goto leave; } } while (event != App_CMD_DONE); /* * 8. unregister notify callback */ status = Notify_unregisterEventSingle(Module.remoteProcId, Module.lineId, Module.eventId); if (status < 0) { goto leave; } /* * 9. delete semaphore object */ SemThread_destruct(&Module.semS); leave: return(status); }
Int SystemCfg_deleteLocalResources(Void) { Error_Block eb; Int status = 0; struct SystemCfg *stateObj = &SystemCfg_State; Log_print1(Diags_ENTRY, "--> %s: ()", (IArg)FXNN); Error_init(&eb); /* unregister heap with MessageQ */ MessageQ_unregisterHeap(Global_TilerHeapId); /* delete heap used for rcm message queue */ HeapBufMP_delete(&stateObj->heapH); /* send done event to remote core */ Log_print0(Diags_USER1, FXNN": send done event to remote core"); status = Notify_sendEvent(stateObj->hostProcId, Global_NotifyLineId, Global_HostDspEvtNum, Global_EvtDone, TRUE); if (status < 0) { /* Log_error() */ Log_print4(Diags_USER8, "Error: %s, line %d: %s: Notify_sendEvent() returned error %d", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN, (IArg)status); goto leave; } /* wait for done event from remote core */ Log_print0(Diags_USER1, FXNN": waiting for done event..."); SemThread_pend(stateObj->semH, SemThread_FOREVER, &eb); if (Error_check(&eb)) { /* Log_error() */ Log_print3(Diags_USER8, "Error: %s, line %d: %s: SemThread_pend() returned with error", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN); status = -1; goto leave; } Log_print0(Diags_USER1, FXNN": ...received done event"); /* unregister notify callback */ status = Notify_unregisterEvent(stateObj->hostProcId, Global_NotifyLineId, Global_HostDspEvtNum, SystemCfg_notifyCB__P, (UArg)stateObj); if (status < 0) { /* Log_error() */ Log_print4(Diags_USER8, "Error: %s, line %d: %s: " "Notify_unregisterEventSingle() returned error %d", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN, (IArg)status); goto leave; } /* delete sync object */ if (stateObj->semH != NULL) { SemThread_destruct(&stateObj->semObj); stateObj->semH = NULL; } leave: Log_print2(Diags_EXIT, "<-- %s: %d", (IArg)FXNN, (IArg)status); return(status); }
Int SystemCfg_createLocalResources(Void) { Error_Block eb; SemThread_Params semThreadP; HeapBufMP_Params heapBufMPP; Int count; Char heapName[32]; Int status = 0; struct SystemCfg *stateObj = &SystemCfg_State; static Int heapId = 1; Log_print1(Diags_ENTRY, "--> %s: ()", (IArg)FXNN); Error_init(&eb); /* create sync object used to wait on remote core startup */ SemThread_Params_init(&semThreadP); semThreadP.mode = SemThread_Mode_COUNTING; SemThread_construct(&stateObj->semObj, 0, &semThreadP, &eb); if (Error_check(&eb)) { /* Log_error() */ Log_print3(Diags_USER8, "Error: %s, line %d: %s: SemThread_construct() failed", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN); status = -1; goto leave; } stateObj->semH = SemThread_handle(&stateObj->semObj); /* register notify callback for ready event from remote core */ status = Notify_registerEvent(stateObj->hostProcId, Global_NotifyLineId, Global_HostDspEvtNum, SystemCfg_notifyCB__P, (UArg)stateObj); if (status < 0) { /* Log_error() */ Log_print4(Diags_USER8, "Error: %s, line %d: %s: " "Notify_registerEventSingle() returned error %d", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN, (IArg)status); goto leave; } /* create a heap for tiler usage */ Log_print0(Diags_USER2, FXNN": HeapBufMP_create for tiler"); HeapBufMP_Params_init(&heapBufMPP); heapBufMPP.regionId = 0; heapBufMPP.blockSize = 0x200; /* 512 B */ heapBufMPP.numBlocks = 8; /* hack: make a unique heap name */ System_sprintf(heapName, "rcmHeap-%d", heapId); heapBufMPP.name = heapName; stateObj->heapH = HeapBufMP_create(&heapBufMPP); if (stateObj->heapH == NULL) { /* Log_error() */ Log_print3(Diags_USER8, "Error: %s, line %d: %s: HeapBuf_create() failed", (IArg)FXNN, (IArg)__FILE__, (IArg)__LINE__); status = -1; goto leave; } /* register this heap with MessageQ */ Log_print2(Diags_USER2, FXNN": MessageQ_registerHeap: (heapH: 0x%x, heapId: %d)", (IArg)(stateObj->heapH), (IArg)Global_TilerHeapId); MessageQ_registerHeap((Ptr)(stateObj->heapH), Global_TilerHeapId); /* Send create done event to remote core. Need to loop in case * the remote core has not yet registered with notify to receive * this event. */ Log_print0(Diags_USER1, FXNN": send EvtCreateDone to remote core"); count = 0; do { status = Notify_sendEvent(stateObj->hostProcId, Global_NotifyLineId, Global_HostDspEvtNum, Global_EvtCreateDone, TRUE); if (status == Notify_E_EVTNOTREGISTERED) { Thread_sleep(500, &eb); /* 0.5 ms */ } } while ((++count < 10) && (status == Notify_E_EVTNOTREGISTERED)); if (status < 0) { /* Log_error() */ Log_print5(Diags_USER8, "Error: %s, line %d: %s: Notify_sendEvent() returned error %d," "giving up after %d tries", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN, (IArg)status, (IArg)count); goto leave; } /* wait for create done event from remote core */ Log_print0(Diags_USER1, FXNN": waiting for EvtCreateDone event..."); SemThread_pend(stateObj->semH, SemThread_FOREVER, &eb); if (Error_check(&eb)) { /* Log_error() */ Log_print3(Diags_USER8, "Error: %s, line %d: %s: SemThread_pend() returned with error", (IArg)__FILE__, (IArg)__LINE__, (IArg)FXNN); status = -1; goto leave; } Log_print0(Diags_USER1, FXNN": ...received EvtCreatDone event"); leave: Log_print2(Diags_EXIT, "<-- %s: %d", (IArg)FXNN, (IArg)status); return(status); }