Int32 SWOSD_open(SWOSD_Obj * pObj, SWOSD_OpenPrm *openPrm) { Int32 status = SWOSD_SOK; Int32 scratchId = g_scratchIndex; SWOSD_Params prm; IALG_Fxns * algFxns = (IALG_Fxns *)&SWOSD_TI_IALG; IRES_Fxns * resFxns = &SWOSD_TI_IRES; if(openPrm==NULL || pObj==NULL) return SWOSD_EFAIL; if( openPrm->maxWidth==0 || openPrm->maxHeight==0 || openPrm->maxWidth > SWOSD_MAX_WIDTH || openPrm->maxHeight > 1080 ) { return NULL; } memset(pObj, 0, sizeof(SWOSD_Obj)); memcpy(&pObj->openPrm, openPrm, sizeof(SWOSD_OpenPrm)); memset(&prm, 0, sizeof(prm)); prm.size = sizeof(prm); prm.maxHeight = pObj->openPrm.maxHeight; prm.maxWidth = pObj->openPrm.maxWidth; pObj->algHndl = DSKT2_createAlg((Int)scratchId, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)&prm); if(pObj->algHndl==NULL) { status = SWOSD_EFAIL; return status; } /* Assign resources to the algorithm */ status = RMAN_assignResources((IALG_Handle)pObj->algHndl, resFxns, scratchId); if (status != IRES_OK) { status = SWOSD_EFAIL; return status; } return status; }
static Int32 HelloWorldLink_algCreate(HelloWorldLink_Obj * pObj) { HELLOWORLDALG_createPrm algCreatePrm; IALG_Fxns *algFxns = (IALG_Fxns *)&HELLOWORLDALG_TI_IALG; Vps_printf(" %d: HELLOWORLD : Algorithm Create in progress !!!\n", Utils_getCurTimeInMsec()); algCreatePrm.maxWidth = pObj->createArgs.maxWidth; algCreatePrm.maxHeight = pObj->createArgs.maxHeight; algCreatePrm.maxStride = pObj->createArgs.maxStride; algCreatePrm.maxChannels = pObj->createArgs.maxChannels; /*************************************************************************/ /* Create algorithm instance and get hello world algo handle. */ /* DSKT2 is memory manager and creates instance for algorithm that has */ /* XDAIS/Alg interface APIs implemented (numAlloc, memAlloc and algInit) */ /*************************************************************************/ pObj->algHndl = DSKT2_createAlg((Int)gScratchId, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)&algCreatePrm); if(pObj->algHndl == NULL) { Vps_printf(" %d: HELLOWORLD : Algorithm Create ERROR !!!\n", Utils_getCurTimeInMsec()); return FVID2_EFAIL; } /*************************************************************************/ /* Once algorithm instace is created, initialize channel specific */ /* parameters here */ /*************************************************************************/ /* for(chNum = 0; chNum < algCreatePrm.maxChannels; chNum++) { HELLOWORLDALG_TI_setPrms(pObj->algHndl, HELLOWORLDALG_chPrm, chNum) } */ Vps_printf(" %d: HELLOWORLD : Algorithm Create Done !!!\n", Utils_getCurTimeInMsec()); return FVID2_SOK; }
/* ARGSUSED */ Void smain(Int argc, Char * argv[]) { BUFALG_TI_Handle alg; IBUFALG_Fxns fxns = BUFALG_TI_IBUFALG; IRES_Fxns iresFxns = BUFALG_TI_IRES; Int scratchId; Bool passed = FALSE; scratchId = 1; alg = (BUFALG_TI_Handle)DSKT2_createAlg(scratchId, (IALG_Fxns *)&fxns, NULL, NULL); if (alg == NULL) { System_printf("Alg creation failed\n"); goto done; } if (!getResources(alg, &iresFxns, scratchId)) { goto done; } if (!freeAlgResources(alg, &iresFxns, scratchId)) { goto done; } DSKT2_freeAlg(scratchId, (IALG_Handle)alg); passed = TRUE; done: if (passed) { System_printf("TEST PASSED\n"); } else { System_printf("TEST FAILED\n"); } }
/* * ======== Algorithm_create ======== */ Algorithm_Handle Algorithm_create(IALG_Fxns *fxns, Void *idma3FxnsVoid, Void *iresFxnsVoid, IALG_Params *params, Algorithm_Attrs *attrs) { Algorithm_Obj *pObject = NULL; IDMA3_Fxns *idma3Fxns = (IDMA3_Fxns *)idma3FxnsVoid; IRES_Fxns *iresFxns = (IRES_Fxns *)iresFxnsVoid; IRES_Status iresStatus; Log_print5(Diags_ENTRY, "[+E] Algorithm_create> Enter(" "fxns=0x%x, idma3Fxns=0x%x, iresFxns=0x%x, params=0x%x, " "attrs=0x%x)", (IArg)fxns, (IArg)idma3Fxns, (IArg)iresFxns, (IArg)params, (IArg)attrs); assert(attrs != NULL); pObject = Memory_alloc(sizeof(Algorithm_Obj), NULL); if (pObject == NULL) { Log_print0(Diags_USER7, "[+7] Algorithm_create> " "Alloc for a small object FAILED -- out of memory?"); goto Algorithm_create_return; } /* * Note that we don't have to validate groupId as that's done at * config time. */ pObject->idma3Fxns = NULL; pObject->iresFxns = NULL; pObject->groupId = attrs->groupId; /* Call appropriate DSKT2 function, depending on attrs->useExtHeap */ if (attrs->useExtHeap == FALSE) { /* * Create alg normally, attempting to allocate algorithm memory * in the requested memory spaces. */ pObject->alg = DSKT2_createAlg(attrs->groupId, fxns, NULL, params); } else { /* * Create alg with all algorithm memory allocated in external memory. */ pObject->alg = DSKT2_createAlgExt(attrs->groupId, fxns, NULL, params); } if (pObject->alg == NULL) { Log_print0(Diags_USER7, "[+7] Algorithm_create> " "Algorithm creation FAILED; make sure that 1) alg params are " "correct/appropriate, 2) there is enough internal and external " "algorithm memory available -- check DSKT2 settings for heap " "assignments and scratch allocation"); Algorithm_delete(pObject); pObject = NULL; goto Algorithm_create_return; } /* If alg implements IRES, allocate resources */ if (iresFxns != NULL) { iresStatus = RMAN_assignResources(pObject->alg, iresFxns, pObject->groupId); if (iresStatus != IRES_OK) { Log_print1(Diags_USER7, "[+7] Algorithm_create> Assignment of " "alg resources through RMAN FAILED (0x%x)", (IArg)iresStatus); Algorithm_delete(pObject); pObject = NULL; goto Algorithm_create_return; } pObject->iresFxns = iresFxns; } Algorithm_create_return: Log_print1(Diags_EXIT, "[+X] Algorithm_create> return (0x%x)", (IArg)pObject); return (pObject); }
/* * ======== rmanTask ======== */ Void rmanTask(UArg arg0, UArg arg1) { Int taskId = (Int)arg0; Int index = (Int)arg1; /* index into attrsTable */ IALG_Fxns * algFxns = (IALG_Fxns *)&DUMALG_TI_IDUMALG; IRES_Fxns * resFxns = &DUMALG_TI_IRES; IDUMALG_Handle dumHandle = NULL; IDUMALG_Params params; Int scratchId = attrsTable[index].scratchId; Int yieldFlag = attrsTable[index].yieldFlag; Int priority = attrsTable[index].priority; Arg resourceId = (Arg)(&(attrsTable[index].id)); Int i; IRES_Status status; Log_print0(Diags_ENTRY, "[+E] rmanTask> Enter "); params.size = sizeof(IDUMALG_Params); Log_print4(Diags_USER4, "[+4] rmanTask> " "Task #%d: ScratchId %d, Priority %d Yield %d", (IArg)taskId, (IArg)scratchId, (IArg)priority, (IArg)yieldFlag); params.yieldFlag = yieldFlag; params.taskId = taskId; for (i = 0; i < NUM_RESOURCES; i++) { params.hdvicp[i] = *((IRES_HDVICP_RequestType *)resourceId + i); Log_print1(Diags_USER4, "[+4] rmanTask> " "Requesting resource %d (2 => ANY)", (IArg)((Int)params.hdvicp[i])); } /* * Create an instance of the algorithm using "algFxns" */ SemThread_pend(mutex, SemThread_FOREVER, NULL); dumHandle = (IDUMALG_Handle)DSKT2_createAlg((Int)scratchId, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)¶ms); if (dumHandle == NULL) { Log_print0(Diags_USER7, "[+7] rmanTask> Alg creation failed"); System_abort("DSKT2_createAlg() failed, aborting...\n"); } SemThread_post(mutex, NULL); /* Assign resources to the algorithm */ status = RMAN_assignResources((IALG_Handle)dumHandle, resFxns, scratchId); if (status != IRES_OK) { Log_print1(Diags_USER7, "[+7] rmanTask> Assign resource failed [%d]", (IArg)status); System_abort("RMAN_assignResources() failed, aborting...\n"); } /* Activate the Algorithm */ DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle); /* Activate All Resources */ RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, scratchId); /* Use IALG interfaces to do something */ dumHandle->fxns->useHDVICP(dumHandle, taskId); /* Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, scratchId); /* Deactivate algorithm */ DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle); /* Free resources assigned to this algorihtm */ status = RMAN_freeResources((IALG_Handle)(dumHandle), resFxns, scratchId); if (status != IRES_OK) { Log_print1(Diags_USER7, "[+7] rmanTask> Free resource failed [%d]", (IArg)status); System_abort("RMAN_freeResources() failed, aborting...\n"); } /* * Free instance of the algorithm created */ SemThread_pend(mutex, SemThread_FOREVER, NULL); DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle); SemThread_post(mutex, NULL); SemThread_post(done, NULL); Log_print0(Diags_EXIT, "[+X] rmanTask> Exit "); }
/* ARGSUSED - this line tells the compiler to not generate compiler warnings * for unused arguments */ Int smain(Int argc, Char * argv[]) { IRES_Status status; Int size = 0; Int scratchId = 2; IALG_Fxns * algFxns = (IALG_Fxns *)&TEMPLATE_TI_CODECIRES; IRES_Fxns * resFxns = &TEMPLATE_TI_IRES; IALG_Handle dumHandle = NULL; ITEMPLATE_Status algStatus; /* * Create an instance of the algorithm using "algFxns" */ dumHandle = DSKT2_createAlg(scratchId, (IALG_Fxns *)algFxns, NULL, (IALG_Params *)NULL); if (dumHandle == NULL) { printf("Alg creation failed \n"); return -1; } /* * Supply initialization information for the RESMAN while registering */ size = sizeof(IRESMAN_Params); configParams.allocFxn = RMAN_PARAMS.allocFxn; configParams.freeFxn = RMAN_PARAMS.freeFxn; configParams.size = size; /* * Register the NULL protocol/resource manager with the generic resource * manager */ status = RMAN_register(&IRESMAN_NULLRES, (IRESMAN_Params *)&configParams); if (IRES_EEXISTS == status) { printf("Protocol Already Registered\n"); } /* Create an instance of an algorithm that implements IALG and IRES_Fxns */ if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle, resFxns,scratchId)) { printf("Assign Resource Failed \n"); return (-1); } /* Activate the Algorithm */ DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle); /* Activate All Resources */ RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, -1); /* Use IALG interfaces to do something */ ((ITEMPLATE_Handle)dumHandle)->fxns->process((ITEMPLATE_Handle)dumHandle, (ITEMPLATE_InArgs *)NULL, (ITEMPLATE_OutArgs *)NULL); ((ITEMPLATE_Handle)dumHandle)->fxns->control((ITEMPLATE_Handle)dumHandle, (ITEMPLATE_Cmd )0, (ITEMPLATE_DynamicParams *)NULL, &algStatus); /* Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, -1); /* Deactivate algorithm */ DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle); /* Free resources assigned to this algorihtm */ if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle), resFxns, -1)) { printf("Free Resource Failed\n"); return (-1); } /* Free instance of the algorithm created */ DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle); /* Unregister the protocol */ if (IRES_OK != RMAN_unregister(&IRESMAN_NULLRES)) { printf("Unregister Protocol Failed\n"); return (-1); } RMAN_exit(); return (0); }
Int rmanTask(Arg scratchId, Arg resourceId, Arg priority, Arg taskId, Arg yieldFlag) { Int i; IALG_Fxns * algFxns = &DUMALG_TI_IALG; IRES_Fxns * resFxns = &DUMALG_TI_IRES; IDUMALG_Handle dumHandle = NULL; IDUMALG_Params params; GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_ENTER, "_rmanTask> Enter \n"); params.size = sizeof(IDUMALG_Params); GT_4trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS, "_rmanTask> " "Task #%d: ScratchId %d, Priority %d Yield %d\n",taskId, scratchId, priority, yieldFlag); params.yieldFlag = yieldFlag; params.taskId = taskId; for (i = 0; i < NUM_RESOURCES; i++) { params.hdvicp[i] = *((IRES_HDVICP_RequestType *)resourceId + i); GT_1trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS, "_rmanTask> " "Requesting resource %d (2 => ANY)\n",(Int)params.hdvicp[i]); } /* * Create an instance of the algorithm using "algFxns" */ SEM_pend(mutex, SYS_FOREVER); dumHandle = (IDUMALG_Handle)DSKT2_createAlg((Int)scratchId, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)¶ms); if (dumHandle == NULL) { GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> " "Alg creation failed\n"); return -1; } SEM_post(mutex); /* Assign resources to the algorithm */ if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle, resFxns, scratchId)) { GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> " "Assign resource failed\n"); return -1; } /* * Activate the Algorithm */ DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle); /* * Activate All Resources */ RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, scratchId); /* * Use IALG interfaces to do something */ dumHandle->fxns->useHDVICP(dumHandle, taskId); /* * Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, scratchId); /* * Deactivate algorithm */ DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle); /* * Free resources assigned to this algorihtm */ if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle), resFxns, scratchId)) { GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_7CLASS, "_rmanTask> " "Free resource failed\n"); return -1; } /* * Free instance of the algorithm created */ SEM_pend(mutex, SYS_FOREVER); DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle); SEM_post(mutex); SEM_post(done); GT_0trace(ti_sdo_fc_rman_examples_hdvicp, GT_ENTER, "_rmanTask> Exit \n"); return 0; }
Int32 AlgLink_ScdalgCreate(AlgLink_ScdObj * pObj) { Int32 status, chId, scdChId; SCD_createPrm algCreatePrm; SCD_chPrm chDefaultParams[16]; AlgLink_ScdChParams *pChLinkPrm; AlgLink_ScdchPrm *pScdChPrm; IALG_Fxns *algFxns = (IALG_Fxns *)&SCD_TI; // IRES_Fxns *resFxns = &SCD_TI_IRES; #ifdef SYSTEM_DEBUG_SCD Vps_printf(" %d: SCD : Create in progress !!!\n", Utils_getCurTimeInMsec()); #endif pObj->totalFrameCount = 0; if(pObj->createArgs.numBufPerCh == 0) pObj->createArgs.numBufPerCh = ALG_LINK_SCD_MAX_OUT_FRAMES_PER_CH; if(pObj->createArgs.numBufPerCh > ALG_LINK_SCD_MAX_OUT_FRAMES_PER_CH) { Vps_printf("\n SCDLINK: WARNING: User is asking for %d buffers per CH. But max allowed is %d. \n" " Over riding user requested with max allowed \n\n", pObj->createArgs.numBufPerCh, ALG_LINK_SCD_MAX_OUT_FRAMES_PER_CH ); pObj->createArgs.numBufPerCh = ALG_LINK_SCD_MAX_OUT_FRAMES_PER_CH; } #ifdef SYSTEM_DEBUG_SCD Vps_printf(" %d: SCD : Max WxH = %d x %d, Max CH = %d, FPS = %d !!!\n", Utils_getCurTimeInMsec(), pObj->createArgs.maxWidth, pObj->createArgs.maxHeight, //pObj->createArgs.startChNoForSCD, pObj->createArgs.numValidChForSCD, pObj->createArgs.outputFrameRate ); #endif if((/*pObj->createArgs.startChNoForSCD + */ pObj->createArgs.numValidChForSCD) > pObj->inQueInfo->numCh) { #ifdef SYSTEM_DEBUG_SCD Vps_printf(" %d: SCD : Create ERROR - SCD channels < InQueue Channels !!!\n", Utils_getCurTimeInMsec()); #endif return FVID2_EFAIL; } algCreatePrm.maxWidth = pObj->createArgs.maxWidth; algCreatePrm.maxHeight = pObj->createArgs.maxHeight; algCreatePrm.maxStride = pObj->createArgs.maxStride; algCreatePrm.maxChannels = pObj->createArgs.numValidChForSCD; algCreatePrm.numSecs2WaitB4Init = pObj->createArgs.numSecs2WaitB4Init; algCreatePrm.numSecs2WaitB4FrmAlert = pObj->createArgs.numSecs2WaitB4FrmAlert; algCreatePrm.fps = (SCD_Fps) pObj->createArgs.outputFrameRate; algCreatePrm.chDefaultParams = (SCD_chPrm *)&chDefaultParams[0]; for(chId=0; chId < algCreatePrm.maxChannels; chId++) { SCD_chPrm * chl = &(algCreatePrm.chDefaultParams[chId]); AlgLink_ScdChParams * chPrm = &(pObj->createArgs.chDefaultParams[chId]); if ((chPrm->mode == SCD_DETECTMODE_MONITOR_BLOCKS) || (chPrm->mode == SCD_DETECTMODE_MONITOR_BLOCKS_FRAME)) { Vps_printf("Setting block configuration data \n"); chl->blkConfig = (SCD_blkChngConfig *)chPrm->blkConfig; /* for (blk=0; blk < chPrm->blkNumBlksInFrame; blk++) { chl->blkConfig[blk].sensitivity = (SCD_Sensitivity) chPrm->blkConfig[blk].sensitivity; chl->blkConfig[blk].monitored = (UInt32) chPrm->blkConfig[blk].monitored; } */ } else { chl->blkConfig = NULL; } // The remaining parameter values filled in here do not really matter as // they will be over-written by calls to SCD_TI_setPrms. We'll fill in // just a few chl->chId = chPrm->chId; chl->mode = (SCD_Mode)chPrm->mode; chl->width = pObj->createArgs.maxWidth; chl->height = pObj->createArgs.maxHeight; chl->stride = pObj->createArgs.maxStride; chl->curFrame = NULL; chl->frmSensitivity = (SCD_Sensitivity)chPrm->frmSensitivity; chl->frmIgnoreLightsON = chPrm->frmIgnoreLightsON; chl->frmIgnoreLightsOFF = chPrm->frmIgnoreLightsOFF; chl->frmEdgeThreshold = chPrm->frmEdgeThreshold; } /* Create algorithm instance and get algo handle */ pObj->algHndl = DSKT2_createAlg((Int)gScratchId, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)&algCreatePrm); if(pObj->algHndl == NULL) { #ifdef SYSTEM_DEBUG_SCD Vps_printf(" %d: SCD : Create ERROR !!!\n", Utils_getCurTimeInMsec()); #endif return FVID2_EFAIL; } #if 0 /* Assign resources to the algorithm */ status = RMAN_assignResources((IALG_Handle)pObj->algHndl, resFxns, gScratchId); if (status != IRES_OK) { return FVID2_EFAIL; } #endif for(scdChId = 0; scdChId<pObj->createArgs.numValidChForSCD; scdChId++) { pObj->chObj[scdChId].frameSkipCtx.firstTime = TRUE; pObj->chObj[scdChId].frameSkipCtx.inputFrameRate = pObj->createArgs.inputFrameRate; pObj->chObj[scdChId].frameSkipCtx.outputFrameRate = pObj->createArgs.outputFrameRate; pScdChPrm = &pObj->chParams[scdChId]; pChLinkPrm = &pObj->createArgs.chDefaultParams[scdChId]; pScdChPrm->chId = pChLinkPrm->chId; pScdChPrm->chBlkConfigUpdate = FALSE; status = AlgLink_ScdalgSetChScdPrm(pScdChPrm, pChLinkPrm); UTILS_assert(status==0); pScdChPrm->width = pObj->inQueInfo->chInfo[pScdChPrm->chId].width + pObj->inQueInfo->chInfo[pScdChPrm->chId].startX; pScdChPrm->height = pObj->inQueInfo->chInfo[pScdChPrm->chId].height + pObj->inQueInfo->chInfo[pScdChPrm->chId].startY; pScdChPrm->stride = pObj->inQueInfo->chInfo[pScdChPrm->chId].pitch[0]; #ifdef SYSTEM_DEBUG_SCD Vps_printf(" %d: SCD : %d: %d x %d, In FPS = %d, Out FPS = %d!!!\n", Utils_getCurTimeInMsec(), pScdChPrm->chId, pScdChPrm->width, pScdChPrm->height, pObj->chObj[scdChId].frameSkipCtx.inputFrameRate, pObj->chObj[scdChId].frameSkipCtx.outputFrameRate ); #endif } AlgLink_ScdresetStatistics(pObj); #ifdef SYSTEM_DEBUG_SCD Vps_printf(" %d: SCD : Create Done !!!\n", Utils_getCurTimeInMsec()); #endif return FVID2_SOK; }
/* * ======== smain ======== */ Int smain(Int argc, Char * argv[]) { ISHMALG_Handle alg; ISHMALG_Fxns fxns = SHMALG_TI_ISHMALG; ISHMALG_Params params = ISHMALG_PARAMS; IRES_Fxns iresFxns = SHMALG_TI_IRES; IRES_Status status; Int scratchId; Bool passed = FALSE; Bool retVal = TRUE; Int fillVal = 1; if (argc > 1) { fillVal = atoi(argv[1]); } params.fillVal = fillVal; System_printf("shmbuf_test2> Started. buffer fill value: %d\n", fillVal); /* Initialize and register resource manager */ System_printf("Calling RMAN_init()...\n"); status = RMAN_init(); if (status != IRES_OK) { /* Test failed */ System_printf("RMAN_init() failed: %s [%d]\n", getError(status), status); goto done; } SHMBUF_PARAMS.bufsize = SHMBUFSIZE; SHMBUF_PARAMS.isScratch = TRUE; /* Make the buffer sharable */ System_printf("Calling RMAN_register()...\n"); status = RMAN_register(&SHMBUF_MGRFXNS, (IRESMAN_Params *)&SHMBUF_PARAMS); if (status != IRES_OK) { /* Test failed */ System_printf("RMAN_register() failed %s [%d]\n", getError(status), status); goto done; } scratchId = 1; System_printf("Calling DSKT2_createAlg()...\n"); alg = (ISHMALG_Handle)DSKT2_createAlg(scratchId, (IALG_Fxns *)&fxns, NULL, (IALG_Params *)¶ms); if (alg == NULL) { System_printf("DSKT2_createAlg() failed\n"); goto done; } /* Assign resources to the algorithm */ System_printf("Calling RMAN_assignResources()...\n"); status = RMAN_assignResources((IALG_Handle)alg, &iresFxns, scratchId); if (status != IRES_OK) { System_printf("RMAN_assignResources() failed %s [%d]\n", getError(status), status); goto done; } System_printf("Calling DSKT2_activateAlg()...\n"); DSKT2_activateAlg(scratchId, (IALG_Handle)alg); /* Activate All Resources */ System_printf("Calling RMAN_activateAllResources()...\n"); status = RMAN_activateAllResources((IALG_Handle)alg, &iresFxns, scratchId); if (status != IRES_OK) { System_printf("RMAN_activateAllResourceRMAN_unregister(&SHMBUF_MGRFXNS);s() failed %s [%d]\n", getError(status), status); goto done; } /* Use the buffer */ alg->fxns->useBufs(alg); /* Hold onto the resource for awhile */ System_printf("Sleeping...\n"); sleep(10); /* Check contents of the buffer */ if (!(retVal = alg->fxns->checkBufs(alg))) { System_printf("Buffer overwritten by another alg.\n"); } /* Deactivate All Resources */ System_printf("Calling RMAN_deactivateAllResources()...\n"); status = RMAN_deactivateAllResources((IALG_Handle)alg, &iresFxns, scratchId); if (status != IRES_OK) { System_printf("RMAN_deactivateAllResources() failed %s [%d]\n", getError(status), status); goto done; } /* Deactivate algorithm */ System_printf("Calling DSKT2_deactivateAlg()...\n"); DSKT2_deactivateAlg(scratchId, (IALG_Handle)alg); /* Free resources assigned to this algorihtm */ System_printf("Calling RMAN_freeResources()...\n"); status = RMAN_freeResources((IALG_Handle)(alg), &iresFxns, scratchId); if (status != IRES_OK) { System_printf("RMAN_freeResources() failed %s [%d]\n", getError(status), status); goto done; } /* Free instance of the algorithm created */ System_printf("Calling DSKT2_freeAlg()...\n"); DSKT2_freeAlg(scratchId, (IALG_Handle)alg); System_printf("Calling RMAN_unregister()...\n"); status = RMAN_unregister(&SHMBUF_MGRFXNS); if (status != IRES_OK) { System_printf("RMAN_unregister() failed %s [%d]\n", getError(status), status); goto done; } System_printf("Calling RMAN_exit()...\n"); status = RMAN_exit(); if (status != IRES_OK) { System_printf("RMAN_exit() failed %s [%d]\n", getError(status), status); goto done; } else { if (retVal) { passed = TRUE; } } done: RMAN_exit(); if (passed) { System_printf("TEST PASSED\n"); } else { System_printf("TEST FAILED\n"); } return (0); }
/* ARGSUSED - this line tells the compiler to not generate compiler warnings * for unused arguments */ Int smain(Int argc, Char * argv[]) { Int scratchId1 = 0; Int scratchId2 = 0; IALG_Status algStatus; IALG_Fxns * algFxns = &DUMRES_TI_IALG; IRES_Fxns * resFxns = &DUMRES_TI_IRES; DUMRES_TI_Handle algHandle1 = NULL; DUMRES_TI_Handle algHandle2 = NULL; EDMA3_RM_Handle rmHandle = NULL; EDMA3_RM_ResDesc resObj; MEM_Stat stat; Bool retVal; Int i = 0; /* * Create 2 instances of the algorithm using "algFxns" */ algHandle1 = (DUMRES_TI_Handle)DSKT2_createAlg(scratchId1, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)NULL); if (algHandle1 == NULL) { printf("Alg creation failed for algHandle1\n"); return -1; } algHandle2 = (DUMRES_TI_Handle)DSKT2_createAlg(scratchId2, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)NULL); if (algHandle2 == NULL) { printf("Alg creation failed for algHandle2\n"); return -1; } /* Assign resources to the algorithm */ if (IRES_OK != RMAN_assignResources((IALG_Handle)algHandle1, resFxns, scratchId1)) { GT_0trace(ti_sdo_fc_rman_examples_scratchEdma3_GTMask, GT_7CLASS, "Assign Resource Failed \n"); goto AppEnd1; } /* * Activate the Algorithm */ DSKT2_activateAlg(scratchId1, (IALG_Handle)algHandle1); /* * Activate All Resources */ RMAN_activateAllResources((IALG_Handle)algHandle1, resFxns, scratchId1); /* * Use IALG interfaces to do something */ DSKT2_controlAlg((IALG_Handle)algHandle1, (IALG_Cmd)NULL, &algStatus); /* Assign resources to the second algorithm */ if (IRES_OK != RMAN_assignResources((IALG_Handle)algHandle2, resFxns, scratchId2)) { printf("Assign Resource Failed \n"); return -1; } /* * Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)algHandle1, resFxns, scratchId1); /* * Deactivate algorithm */ DSKT2_deactivateAlg(scratchId1, (IALG_Handle)algHandle1); /* * Activate the Algorithm */ DSKT2_activateAlg(scratchId2, (IALG_Handle)algHandle2); /* * Activate All Resources */ RMAN_activateAllResources((IALG_Handle)algHandle2, resFxns, scratchId2); /* * Free resources assigned to this algorihtm */ if (IRES_OK != RMAN_freeResources((IALG_Handle)(algHandle1), resFxns, scratchId1)) { printf("Free Resource Failed \n"); return -1; } /* * Acquire the EDMA3 handle first */ rmHandle = EDMA3_getResourceManager(NULL, -1); if (NULL == rmHandle) { printf("Error obtaining SYSTEM resource Manager Handle \n"); return (-1); } resObj.resId = 151; resObj.type = EDMA3_RM_RES_PARAM_SET; if (EDMA3_RM_SOK != EDMA3_RM_allocResource(rmHandle, &resObj)) { printf("Could not allocate this resource, as it is already owned by " "the algorithm\n"); } resObj.resId = 256; if (EDMA3_RM_SOK != EDMA3_RM_allocResource(rmHandle, &resObj)) { printf("Error, could not allocate resource %d\n" "ERROR for 6467, OK for 6446\n", resObj.resId); } if (EDMA3_RM_SOK != EDMA3_releaseResourceManager(NULL, -1)) { printf("Error releasing system resource manager handle\n"); } /* * Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)algHandle2, resFxns, scratchId2); /* * Deactivate algorithm */ DSKT2_deactivateAlg(scratchId2, (IALG_Handle)algHandle2); /* * Free resources assigned to this algorihtm */ if (IRES_OK != RMAN_freeResources((IALG_Handle)(algHandle2), resFxns, scratchId2)) { printf("Free Resource Failed \n"); return -1; } AppEnd1: /* * Free instance of the algorithm created */ DSKT2_freeAlg(scratchId1, (IALG_Handle)algHandle1); /* * Free instance of the algorithm created */ DSKT2_freeAlg(scratchId2, (IALG_Handle)algHandle2); /* * Unregister the protocol */ if (IRES_OK != RMAN_unregister(&IRESMAN_EDMA3CHAN)) { printf("Unregister Protocol Failed \n"); return -1; } for (i = 0; i < MAXMEMSEGMENTS; i++) { retVal = MEM_stat(i, &stat); if (!retVal) { GT_assert(ti_sdo_fc_rman_examples_scratchEdma3_GTMask, memStat[i].size == 0); } else { if (memStat[i].used != stat.used) { GT_3trace(ti_sdo_fc_rman_examples_scratchEdma3_GTMask, GT_7CLASS, "MEM seg [%d]: orig used = 0x%x, " "curr used = 0x%x", i, memStat[i].used, stat.used); return (-1); } } } RMAN_exit(); return (0); }
/* * ======== SCALESOCKET_TI_create ======== */ RMS_STATUS SCALESOCKET_TI_create(Int argLength, Char * argData, IALG_Fxns *algFxns, Int numInStreams, RMS_WORD inDef[], Int numOutStreams, RMS_WORD outDef[], NODE_EnvPtr node) { struct SSKT_Obj *dataPtr; Int nodePriority; Int segId; /* Using bitwise OR to prevent compiler warning */ argLength |= argLength; *argData |= *argData; numInStreams |= numInStreams; numOutStreams |= numOutStreams; /* Get the node's external heap segment Id, if it exists */ segId = NODE_getHeapSeg(node); if (segId < 0) { /* * Use heap 0 to allocate the node object if no external heap * was defined for the node. */ segId = 0; } if ((dataPtr = MEM_calloc(segId, sizeof(SSKT_Obj), 0)) != MEM_ILLEGAL) { /* attach socket's context structure to the node environment */ node->moreEnv = dataPtr; /* Save the external heap segment for delete phase. */ dataPtr->segId = segId; /* parse stream definition params, create input stream */ dataPtr->inStream = _createStream((RMS_StrmDef *)inDef[0], STRM_INPUT, &dataPtr->inSize, segId); /* parse stream definition params, create output stream */ dataPtr->outStream = _createStream((RMS_StrmDef *)outDef[0], STRM_OUTPUT, &dataPtr->outSize, segId); /* check for stream creation failure */ if((dataPtr->inStream == NULL) || (dataPtr->outStream == NULL)) { return (RMS_ESTREAM); } /* allocate data buffers */ dataPtr->inBuf = STRM_allocateBuffer(dataPtr->inStream, dataPtr->inSize); dataPtr->outBuf = STRM_allocateBuffer(dataPtr->outStream, dataPtr->outSize); /* check for buffer allocation failure */ if((dataPtr->inBuf == NULL) || (dataPtr->outBuf == NULL)) { return (RMS_EOUTOFMEMORY); } /* create an algorithm instance object */ nodePriority = NODE_getPri(node); if (segId > 0) { dataPtr->algHandle = DSKT2_createAlg2(nodePriority, (IALG_Fxns *)algFxns, (IALG_Handle)NULL, (IALG_Params *)NULL, segId); } else { dataPtr->algHandle = DSKT2_createAlg(nodePriority, (IALG_Fxns *)algFxns, (IALG_Handle)NULL, (IALG_Params *)NULL); } /* check for algorithm instance creation failure */ if (dataPtr->algHandle == NULL) { return (RMS_EOUTOFMEMORY); } /* activation done during exec phase */ // dataPtr->algHandle->fxns->algActivate(dataPtr->algHandle); return (RMS_EOK); } else { return (RMS_EOUTOFMEMORY); } }
/* ARGSUSED - this line tells the compiler to not generate compiler warnings * for unused arguments */ Int smain(UArg arg0, UArg arg1) { IRES_Status status; Int size = 0; Int scratchId = 2; IALG_Status algStatus; IALG_Fxns * algFxns = &DUMRES_TI_IALG; IRES_Fxns * resFxns = &DUMRES_TI_IRES; DUMRES_TI_Handle dumHandle = NULL; status = RMAN_init(); if (IRES_OK != status) { System_abort("RMAN initialization Failed \n"); } /* * Create an instance of the algorithm using "algFxns" */ dumHandle = (DUMRES_TI_Handle)DSKT2_createAlg(scratchId, (IALG_Fxns *)algFxns, NULL, (IALG_Params *)NULL); if (dumHandle == NULL) { System_abort("Alg creation failed \n"); } /* Create an instance of an algorithm that implements IALG and IRES_Fxns */ status = RMAN_assignResources((IALG_Handle)dumHandle, resFxns, scratchId); if (status != IRES_OK) { System_printf("Assign Resource Failed [%d]\n", status); System_abort("Aborting...\n"); } /* Activate the Algorithm */ DSKT2_activateAlg(scratchId, (IALG_Handle)dumHandle); /* Activate All Resources */ RMAN_activateAllResources((IALG_Handle)dumHandle, resFxns, scratchId); /* Use IALG interfaces to do something */ DSKT2_controlAlg((IALG_Handle)dumHandle, (IALG_Cmd)NULL, &algStatus); /* Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)dumHandle, resFxns, scratchId); /* Deactivate algorithm */ DSKT2_deactivateAlg(scratchId, (IALG_Handle)dumHandle); /* Free resources assigned to this algorihtm */ status = RMAN_freeResources((IALG_Handle)(dumHandle), resFxns, scratchId); if (status != IRES_OK) { System_printf("Free Resource Failed [%d]\n", status); System_abort("Aborting...\n"); } /* Free instance of the algorithm created */ DSKT2_freeAlg(scratchId, (IALG_Handle)dumHandle); RMAN_exit(); return (1); }