/*! * @brief Function to execute the shutdown for ProcMgrApp sample application */ Int ProcMgrApp_shutdown (UInt16 procId) { Int status = 0; ProcMgr_Handle handle = NULL; ProcMgr_State state; PRINTF ("Entered ProcMgrApp_shutdown\n"); status = ProcMgr_open (&handle, procId); if (status >= 0) { status = Ipc_control (procId, Ipc_CONTROLCMD_STOPCALLBACK, NULL); PRINTF ("Ipc_control Ipc_CONTROLCMD_STOPCALLBACK status: [0x%x]\n", status); status = ProcMgr_detach (handle); PRINTF ("ProcMgr_detach status: [0x%x]\n", status); state = ProcMgr_getState (handle); PRINTF ("After detach: ProcMgr_getState\n" " state [0x%x]\n", state); status = ProcMgr_close (&handle); PRINTF ("ProcMgr_close status: [0x%x]\n", status); } PRINTF ("Leaving ProcMgrApp_shutdown\n"); return 0; }
Int FirmwareLoad_ipcStop(UInt16 procId) { Int status; status = Ipc_control (procId, Ipc_CONTROLCMD_STOPCALLBACK, NULL); printf ("After Ipc_stopCallback status: [0x%08x]\n", status); return status; }
Int FirmwareLoad_ipcLoad(UInt16 procId) { Int status; status = Ipc_control (procId, Ipc_CONTROLCMD_LOADCALLBACK, NULL); if (status < 0) { printf ("Error in Ipc_control " "Ipc_CONTROLCMD_LOADCALLBACK [0x%08x]\n", status); } else { printf ("After Ipc_loadcallback status [0x%08x]\n", status); } return status; }
Int FirmwareLoad_ipcStart(UInt16 procId) { Int status=0; status = FirmwareLoad_ipcLoad(procId); if (status >= 0) { status = Ipc_control (procId, Ipc_CONTROLCMD_STARTCALLBACK, NULL); if (status < 0) { printf ("Error in Ipc_control " "Ipc_CONTROLCMD_STARTCALLBACK [0x%08x]\n", status); } else { printf ("After Ipc_startcallback status [0x%08x]\n", status); } } return status; }
/* * ======== procDelete ======== */ static Void procDelete(Processor_Handle proc) { Int status = 0; Int16 heapId; Bool unregisterAndDeleteHeap; ProcMgr_AddrInfo CMEMAddrInfo; CMEM_BlockAttrs cmemBlockAttrs; Int blockNum; Int nCMEMBlocks; Log_print1(Diags_ENTRY, "[+E] Processor_delete_d> Enter (proc=0x%x)", (IArg)proc); if (proc == NULL) { goto procDelete_return; } /* close tranport and stop DSP, detach, destroy */ /* unregister this heap with MessageQ */ if (proc->startCallBackStatus >= 0) { blockNum = 0; nCMEMBlocks = 0; status = CMEM_getNumBlocks(&nCMEMBlocks); if (status != 0) { Log_print1(Diags_USER2, "[+2] Processor_delete_d> " "CMEM_getNumBlocks() failed: %d", status); } while (blockNum < nCMEMBlocks) { status = CMEM_getBlockAttrs(blockNum, &cmemBlockAttrs); if (status != 0) { Log_print2(Diags_USER7, "[+7] Processor_delete_d> " "CMEM_getBlockAttrs(%d) failed: %d", blockNum, status); goto cmemDone; } CMEMAddrInfo.addr[ProcMgr_AddrType_MasterPhys] = cmemBlockAttrs.phys_base; CMEMAddrInfo.addr[ProcMgr_AddrType_SlaveVirt] = cmemBlockAttrs.phys_base; CMEMAddrInfo.size = cmemBlockAttrs.size; CMEMAddrInfo.isCached = FALSE; Log_print3(Diags_USER1, "[+1] Processor_delete_d> CMEM block " "#%d found, doing ProcMgr_unmap(0x%x, 0x%x)...", blockNum, (IArg)cmemBlockAttrs.phys_base, (IArg)cmemBlockAttrs.size); status = ProcMgr_unmap(proc->procMgrH, ProcMgr_SLAVEVIRT, &CMEMAddrInfo, ProcMgr_AddrType_MasterPhys); if (status < 0) { Log_print1(Diags_USER7, "[+7] Processor_delete_d> " "ProcMgr_unmap() failed: %d", status); goto cmemDone; } blockNum++; } cmemDone: Log_print2(Diags_USER7, "[+2] Processor_delete_d> " "defaultHeapH: 0x%x, proc->heapH: 0x%x", (IArg)defaultHeapH, (IArg)proc->heapH); if (proc->heapH != NULL) { unregisterAndDeleteHeap = FALSE; if (proc->heapH == defaultHeapH) { Log_print1(Diags_USER1, "[+1] Processor_delete_d> " "defaultHeapRefCount = %d", (IArg)defaultHeapRefCount); if (--defaultHeapRefCount == 0) { /* this is the last one using the default heap */ unregisterAndDeleteHeap = TRUE; } } else { unregisterAndDeleteHeap = TRUE; } if (unregisterAndDeleteHeap) { heapId = proc->heapId; Log_print1(Diags_USER1, "[+1] Processor_delete_d> " "unregisterAndDeleteHeap, heapId = %d", (IArg)heapId); if (heapId != Processor_INVALID) { Log_print1(Diags_USER1, "[+1] Processor_delete_d> " "MessageQ_unregisterHeap(heapId: %d)", (IArg)heapId); if (MessageQ_unregisterHeap(heapId) !=MessageQ_S_SUCCESS) { Log_print1(Diags_USER7, "[+7] Processor_delete_d> " "MessageQ_unregisterHeap(heapId: %d) failed", heapId); } } /* delete heap used by message queue */ Log_print1(Diags_USER1, "[+1] Processor_delete_d> " "calling HeapBufMP_delete(heapH: 0x%x)", (IArg)(proc->heapH)); HeapBufMP_delete(&proc->heapH); } } /* Stop execution on DSP */ Log_print0(Diags_USER1, "[+2] Processor_delete_d> " "calling Ipc_control(STOPCALLBACK)..."); status = Ipc_control(proc->cpuId, Ipc_CONTROLCMD_STOPCALLBACK, NULL); Log_print2(Diags_USER2, "[+2] Processor_delete_d> " "Ipc_control(STOPCALLBACK) status: 0x%x [%d]", (IArg)status, (IArg)status); } else { Log_print2(Diags_USER2, "[+2] Processor_delete_d> Not calling " "Ipc_control(STOPCALLBACK) because startCallBackStatus = " "0x%x [%d]", (IArg)proc->startCallBackStatus, (IArg)proc->startCallBackStatus); } if (proc->useExtLoader == FALSE) { /* We unload the slave processor */ Log_print0(Diags_USER2, "[+2] Processor_delete_d> Stopping DSP..."); status = ProcMgr_stop(proc->procMgrH); if (status < 0) { Log_print1(Diags_USER6, "[+6] Processor_delete_d> " "Stopping DSP FAILED, status=0x%x", (IArg)status); } if (proc->fileId != 0xffffffff) { Log_print0(Diags_USER2, "[+2] Processor_delete_d> " "Unloading DSP..."); status = ProcMgr_unload(proc->procMgrH, proc->fileId); if (status < 0) { Log_print1(Diags_USER6, "[+6] Processor_delete_d> " "Unloading DSP FAILED, status=0x%x", (IArg)status); } } /* Unmap slave memory */ if (!mapByFile(proc->procMgrH, proc->memMapName, proc->cpuId, FALSE)) { Log_print0(Diags_USER6, "Processor_delete_d> mapByFile() failed!"); } /* Detach from the processor */ Log_print0(Diags_USER1, "[+1] Processor_delete_d> " "calling ProcMgr_detach()..."); status = ProcMgr_detach(proc->procMgrH); if (status < 0) { Log_print1(Diags_USER6, "[+6] Processor_delete_d> " "Detaching from DSP FAILED, status=0x%x", (IArg)status); } } // proc->useExtLoader == FALSE Log_print0(Diags_USER1, "[+1] Processor_delete_d> " "calling ProcMgr_close()..."); status = ProcMgr_close(&proc->procMgrH); if (status < 0) { Log_print1(Diags_USER6, "[+6] Processor_delete_d> " "Closing ProcMgr FAILED, status=0x%x", (IArg)status); } procDelete_return: Log_print0(Diags_EXIT, "[+X] Processor_delete_d> return"); }
/* * ======== procCreate ======== */ static Bool procCreate(Processor_Handle proc) { Int status = 0; Bool retVal; ProcMgr_AttachParams attachParams; ProcMgr_StartParams startParams; ProcMgr_State state; ProcMgr_AddrInfo CMEMAddrInfo; HeapBufMP_Params heapP; CMEM_BlockAttrs cmemBlockAttrs; Int blockNum; Int nCMEMBlocks; Bool createAndRegisterHeap; Int16 heapId; UInt16 regionId; UInt32 numMsgs; UInt32 msgSize; Char heapName[32]; Log_print1(Diags_ENTRY, "[+E] Processor_create_d> Enter(proc=0x%x)", (IArg)proc); /* Create and initialize the PROC object */ Log_print1(Diags_USER2, "[+2] Processor_create_d> " "Retrieving CPU ID for '%s'...", (IArg)(proc->attrs.cpuId)); proc->cpuId = Processor_getCoreId(proc->attrs.cpuId); if (proc->cpuId < 0) { Log_print1(Diags_USER7, "[+7] Processor_create_d> " "Processor_getCoreId() failed: %d", proc->cpuId); goto fail; } /* Open DSP ProcMgr */ Log_print2(Diags_USER2, "[+2] Processor_create_d> " "Opening %s ProcMgr for cpuId %d...", (IArg)proc->attrs.cpuId, proc->cpuId); status = ProcMgr_open(&proc->procMgrH, proc->cpuId); if (status < 0) { Log_print1(Diags_USER7, "[+7] Processor_create_d> " "ProcMgr_open() failed: %d", (IArg)status); goto fail; } /* Attach the DSP */ Log_print1(Diags_USER2, "[+2] Processor_create_d> " "Attaching to %s...", (IArg)proc->attrs.cpuId); if (proc->useExtLoader == FALSE) { /* We load the slave */ ProcMgr_getAttachParams(NULL, &attachParams); status = ProcMgr_attach(proc->procMgrH, &attachParams); if (status < 0) { Log_print1(Diags_USER7, "[+7] Processor_create_d> " "ProcMgr_attach() failed: %d", (IArg)status); goto fail; } /* Map slave memory */ if (!mapByFile(proc->procMgrH, proc->memMapName, proc->cpuId, TRUE)) { Log_print0(Diags_USER6, "Processor_create_d> mapByFile() failed!"); } /* Load the executable on the DSP */ Log_print3(Diags_USER2, "[+2] Processor_create_d> " "Loading %s on %s (%d args)...", (IArg)(proc->imageName), (IArg)(proc->attrs.cpuId), (IArg)(proc->attrs.argc)); status = ProcMgr_load(proc->procMgrH, proc->imageName, proc->attrs.argc, proc->attrs.argv, NULL, &proc->fileId); if (status < 0) { Log_print1(Diags_USER7, "[+7] Processor_create_d> " "ProcMgr_load() failed: %d", status); goto fail; } /* temporary: to be done by SysLink in the future */ Log_print0(Diags_USER1, "[+2] Processor_create_d> " "calling Ipc_control(LOADCALLBACK)..."); status = Ipc_control(proc->cpuId, Ipc_CONTROLCMD_LOADCALLBACK, NULL); Log_print1(Diags_USER1, "[+2] Processor_create_d> " "Ipc_control(LOADCALLBACK) status: %d", (IArg)status); /* Start execution on DSP */ Log_print1(Diags_USER2, "[+2] Processor_create_d> Starting %s ...", (IArg)proc->attrs.cpuId); ProcMgr_getStartParams(proc->procMgrH, &startParams); status = ProcMgr_start(proc->procMgrH, &startParams); if (status < 0) { Log_print1(Diags_USER7, "Processor_create_d> " "ProcMgr_start() failed: %d", status); goto fail; } } // if (proc->useExtLoader == FALSE) else { /* Check the state of the processor to make sure it's really running */ state = ProcMgr_getState(proc->procMgrH); if (state != ProcMgr_State_Running) { Log_print1(Diags_USER7, "Processor_create_d> Invalid processor " "state [%d].", state); goto fail; } Log_print0(Diags_USER1, "[+2] Processor_create_d> " "calling Ipc_control(LOADCALLBACK)..."); status = Ipc_control(proc->cpuId, Ipc_CONTROLCMD_LOADCALLBACK, NULL); proc->loadCallBackStatus = status; Log_print1(Diags_USER1, "[+2] Processor_create_d> " "Ipc_control(LOADCALLBACK) status: %d", (IArg)status); if (status < 0) { Log_print1(Diags_USER7, "Processor_create_d> " "Ipc_control(LOADCALLBACK) failed: %d", status); goto fail; } } status = Ipc_control(proc->cpuId, Ipc_CONTROLCMD_STARTCALLBACK, NULL); proc->startCallBackStatus = status; Log_print1(Diags_USER1, "[+2] Processor_create_d> " "Ipc_control(STARTCALLBACK) status: %d", (IArg)status); if (status < 0) { Log_print1(Diags_USER7, "Processor_create_d> " "Ipc_control(STARTCALLBACK) failed: %d", status); goto fail; } /* get user-specified heapId */ heapId = perCoreHeapId(proc->cpuId); createAndRegisterHeap = FALSE; if (heapId == Processor_INVALID) { /* runtime validation of user configuration */ if (perCoreUserCreatedHeapFlag(proc->cpuId) == TRUE || perCoreNumMsgs(proc->cpuId) != Processor_INVALID || perCoreMsgSize(proc->cpuId) != Processor_INVALID || perCoreSharedRegionId(proc->cpuId) != Processor_INVALID) { Log_print1(Diags_USER7, "[+7] Processor_create_d> " "Invalid heap configuration for core %d: " "attempting to set other Processor_CommDesc " "elements while Processor_CommDesc.heapId is " "undefined", proc->cpuId); goto fail; } /* will return default heapId since user didn't specify */ heapId = Processor_getHeapId(proc->cpuId); if (defaultHeapRefCount++ == 0) { createAndRegisterHeap = TRUE; /* tell code below to record heapH in defaultHeapH */ defaultHeapH = (HeapBufMP_Handle)-1; } } else { if (perCoreUserCreatedHeapFlag(proc->cpuId) == FALSE) { createAndRegisterHeap = TRUE; } } if (createAndRegisterHeap) { /* create a heap for message queue usage */ /* get either user-config'ed or module default */ numMsgs = Processor_getNumMsgs(proc->cpuId); msgSize = Processor_getMsgSize(proc->cpuId); regionId = Processor_getSharedRegionId(proc->cpuId); HeapBufMP_Params_init(&heapP); heapP.numBlocks = numMsgs; heapP.blockSize = msgSize; heapP.sharedAddr = NULL; heapP.regionId = regionId; if (defaultHeapH == (HeapBufMP_Handle)-1) { sprintf(heapName, "CE-default"); } else { sprintf(heapName, "CE<->Svr%d", proc->cpuId); } heapP.name = heapName; Log_print2(Diags_USER1, "[+2] Processor_create_d> " "calling HeapBufMP_create(): nblocks %d, blocksize 0x%x", heapP.numBlocks, heapP.blockSize); proc->heapH = HeapBufMP_create(&heapP); if (proc->heapH == NULL) { Log_print0(Diags_USER7, "[+7] Processor_create_d> " "HeapBufMP_create failed"); goto fail; } if (defaultHeapH == (HeapBufMP_Handle)-1) { /* we've just created the module default heap singleton */ defaultHeapH = proc->heapH; } /* register this heap with MessageQ */ Log_print2(Diags_USER1, "[+2] Processor_create_d> " "MessageQ_registerHeap(heapH: 0x%x, heapId: %d)", (IArg)(proc->heapH), (IArg)heapId); if (MessageQ_registerHeap((Ptr)(proc->heapH), heapId) != MessageQ_S_SUCCESS) { Log_print1(Diags_USER7, "[+7] Processor_create_d> " "MessageQ_registerHeap() failed for heapId %d", heapId); goto fail; } } else { /* * createAndRegisterHeap == FASLE * If using the default heap, need to set proc->heapH for use by * procDelete(). */ if (heapId == Processor_defaultHeapId) { proc->heapH = defaultHeapH; } } proc->heapId = heapId; blockNum = 0; nCMEMBlocks = 0; status = CMEM_getNumBlocks(&nCMEMBlocks); if (status != 0) { Log_print1(Diags_USER2, "[+2] Processor_create_d> " "CMEM_getNumBlocks() failed, not registering: %d", status); } while (blockNum < nCMEMBlocks) { status = CMEM_getBlockAttrs(blockNum, &cmemBlockAttrs); if (status != 0) { Log_print2(Diags_USER7, "[+7] Processor_create_d> " "CMEM_getBlockAttrs(%d) failed: %d", blockNum, status); goto fail; } CMEMAddrInfo.addr[ProcMgr_AddrType_MasterPhys] = cmemBlockAttrs.phys_base; CMEMAddrInfo.addr[ProcMgr_AddrType_SlaveVirt] = cmemBlockAttrs.phys_base; CMEMAddrInfo.size = cmemBlockAttrs.size; CMEMAddrInfo.isCached = FALSE; Log_print3(Diags_USER1, "[+1] Processor_create_d> CMEM block " "#%d found, doing ProcMgr_map(0x%x, 0x%x)...", blockNum, (IArg)cmemBlockAttrs.phys_base, (IArg)cmemBlockAttrs.size); status = ProcMgr_map(proc->procMgrH, ProcMgr_SLAVEVIRT, &CMEMAddrInfo, ProcMgr_AddrType_MasterPhys); if (status < 0) { Log_print1(Diags_USER7, "[+7] Processor_create_d> " "ProcMgr_map() failed: %d", status); goto fail; } if (CMEMAddrInfo.addr[ProcMgr_AddrType_SlaveVirt] != cmemBlockAttrs.phys_base) { Log_print2(Diags_USER1, "[+2] Processor_create_d> " "mapped CMEM slave virtual address 0x%x doesn't " "match expected value 0x%x", CMEMAddrInfo.addr[ProcMgr_AddrType_SlaveVirt], cmemBlockAttrs.phys_base); } blockNum++; } if (Global_getenv("CE_DSPDEBUG") != NULL) { printf("Codec Engine system message (b/c CE_DSPDEBUG=1) : %s image " "loaded and started, press Enter to continue: ", proc->attrs.cpuId); getchar(); } retVal = TRUE; goto procCreate_return; /* TODO:[4] should try those asyncErrorHandlers that link supports? * (MSGQ_SetErrorHandler) */ fail: Log_print3(Diags_USER7, "[+7] Processor_create_d> " "Loading and starting %s server '%s' FAILED, status=[0x%x]", (IArg)proc->attrs.cpuId, (IArg)proc->imageName, status); procDelete(proc); retVal = FALSE; procCreate_return: Log_print1(Diags_USER2, "[+2] Processor_create_d> return (%d)", (IArg)retVal); return (retVal); }
/*! * @brief Function to execute the startup for ProcMgrApp sample application */ Int ProcMgrApp_startup (UInt16 procId) { Int status = 0; ProcMgr_Handle handle = NULL; ProcMgr_AttachParams attachParams; ProcMgr_State state; UInt32 resetVector = 0x00800000; PRINTF ("Entered ProcMgrApp_startup\n"); status = ProcMgr_open (&handle, procId); if (status >= 0) { ProcMgr_getAttachParams (NULL, &attachParams); /* Default params will be used if NULL is passed. */ attachParams.bootMode = ProcMgr_BootMode_NoBoot; /* set the boot mode */ status = ProcMgr_attach (handle, &attachParams); if (status < 0) { PRINTF ("ProcMgr_attach failed [0x%x]\n", status); } else { PRINTF ("ProcMgr_attach status: [0x%x]\n", status); state = ProcMgr_getState (handle); PRINTF ("After attach: ProcMgr_getState\n" " state [0x%x]\n", state); /* Call Ipc_control for ProcMgr_BootMode_NoLoad_Pwr, ProcMgr_BootMode_NoLoad_NoPwr and ProcMgr_BootMode_NoBoot modes */ status = Ipc_control (procId, Ipc_CONTROLCMD_LOADCALLBACK, (Ptr)&resetVector); if (status < 0) { PRINTF ("Error in Ipc_control " "Ipc_CONTROLCMD_LOADCALLBACK [0x%x]\n", status); } else { state = ProcMgr_getState (handle); PRINTF ("After Ipc_loadcallback: ProcMgr_getState\n" " state [0x%x]\n", state); } } if (status >= 0) { status = Ipc_control (procId, Ipc_CONTROLCMD_STARTCALLBACK, NULL); if (status < 0) { PRINTF ("Error in Ipc_control " "Ipc_CONTROLCMD_STARTCALLBACK[0x%x]\n", status); } else { state = ProcMgr_getState (handle); PRINTF ("After Ipc_startcallback: ProcMgr_getState\n" " state [0x%x]\n", state); } } status = ProcMgr_close (&handle); PRINTF ("ProcMgr_close status: [0x%x]\n", status); } PRINTF ("Leaving ProcMgrApp_startup\n"); return 0; }