You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

objectdetection.c 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. /*
  2. * @file objectdetection.c
  3. *
  4. * @brief
  5. * Object Detection DPC implementation using DSP.
  6. *
  7. * \par
  8. * NOTE:
  9. * (C) Copyright 2019 Texas Instruments, Inc.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the
  21. * distribution.
  22. *
  23. * Neither the name of Texas Instruments Incorporated nor the names of
  24. * its contributors may be used to endorse or promote products derived
  25. * from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  35. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. */
  39. /**************************************************************************
  40. *************************** Include Files ********************************
  41. **************************************************************************/
  42. #include <stdint.h>
  43. #include <string.h>
  44. #include <stdio.h>
  45. /* mmWave SDK Include Files: */
  46. #include <ti/drivers/soc/soc.h>
  47. #include <ti/common/sys_common.h>
  48. #include <ti/drivers/osal/DebugP.h>
  49. #include <ti/drivers/osal/MemoryP.h>
  50. #include <ti/utils/mathutils/mathutils.h>
  51. #include <ti/utils/cycleprofiler/cycle_profiler.h>
  52. #include <ti/control/dpm/dpm.h>
  53. #include <xdc/runtime/System.h>
  54. /* C674x mathlib */
  55. /* Suppress the mathlib.h warnings
  56. * #48-D: incompatible redefinition of macro "TRUE"
  57. * #48-D: incompatible redefinition of macro "FALSE"
  58. */
  59. //#pragma diag_push
  60. //#pragma diag_suppress 48
  61. //#include <ti/mathlib/mathlib.h>
  62. //#pragma diag_pop
  63. /*! This is supplied at command line when application builds this file. This file
  64. * is owned by the application and contains all resource partitioning, an
  65. * application may include more than one DPC and also use resources outside of DPCs.
  66. * The resource definitions used by this object detection DPC are prefixed by DPC_OBJDET_ */
  67. #include APP_RESOURCE_FILE
  68. #include <ti/control/mmwavelink/mmwavelink.h>
  69. /* Obj Det instance etc */
  70. #include <common/src/dpc/capon3d/include/objectdetectioninternal.h>
  71. #include <common/src/dpc/capon3d/objectdetection.h>
  72. //#define DBG_DPC_OBJDET
  73. #ifdef DBG_DPC_OBJDET
  74. ObjDetObj *gObjDetObj;
  75. #endif
  76. /**************************************************************************
  77. ************************** Local Definitions **********************************
  78. **************************************************************************/
  79. /**
  80. @}
  81. */
  82. /*! Maximum Number of objects that can be detected in a frame */
  83. #define DPC_OBJDET_MAX_NUM_OBJECTS DOA_OUTPUT_MAXPOINTS
  84. /**************************************************************************
  85. ************************** Local Functions Prototype **************************
  86. **************************************************************************/
  87. static DPM_DPCHandle DPC_ObjectDetection_init
  88. (
  89. DPM_Handle dpmHandle,
  90. DPM_InitCfg* ptrInitCfg,
  91. int32_t* errCode
  92. );
  93. static int32_t DPC_ObjectDetection_execute
  94. (
  95. DPM_DPCHandle handle,
  96. DPM_Buffer* ptrResult
  97. );
  98. static int32_t DPC_ObjectDetection_ioctl
  99. (
  100. DPM_DPCHandle handle,
  101. uint32_t cmd,
  102. void* arg,
  103. uint32_t argLen
  104. );
  105. static int32_t DPC_ObjectDetection_start (DPM_DPCHandle handle);
  106. static int32_t DPC_ObjectDetection_stop (DPM_DPCHandle handle);
  107. static int32_t DPC_ObjectDetection_deinit (DPM_DPCHandle handle);
  108. static void DPC_ObjectDetection_frameStart (DPM_DPCHandle handle);
  109. int32_t DPC_ObjectDetection_dataInjection(DPM_DPCHandle handle, DPM_Buffer* ptrBuffer);
  110. /**************************************************************************
  111. ************************** Local Functions *******************************
  112. **************************************************************************/
  113. /**
  114. * @b Description
  115. * @n
  116. * Sends Assert
  117. *
  118. * @retval
  119. * Not Applicable.
  120. */
  121. void _DPC_Objdet_Assert(DPM_Handle handle, int32_t expression,
  122. const char *file, int32_t line)
  123. {
  124. DPM_DPCAssert fault;
  125. if (!expression)
  126. {
  127. fault.lineNum = (uint32_t)line;
  128. fault.arg0 = 0U;
  129. fault.arg1 = 0U;
  130. strncpy (fault.fileName, file, (DPM_MAX_FILE_NAME_LEN-1));
  131. /* Report the fault to the DPM entities */
  132. DPM_ioctl (handle,
  133. DPM_CMD_DPC_ASSERT,
  134. (void*)&fault,
  135. sizeof(DPM_DPCAssert));
  136. }
  137. }
  138. /**
  139. * @b Description
  140. * @n
  141. * DPC data injection function registered with DPM. This is invoked on reception
  142. * of the data injection from DPM.
  143. *
  144. * @param[in] handle DPM's DPC handle
  145. * @param[in] ptrBuffer Buffer for data injected
  146. *
  147. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  148. *
  149. * @retval
  150. * Not applicable
  151. */
  152. int32_t DPC_ObjectDetection_dataInjection(DPM_DPCHandle handle, DPM_Buffer* ptrBuffer)
  153. {
  154. ObjDetObj *objDetObj = (ObjDetObj *) handle;
  155. /* Notify the DPM Module that the DPC is ready for execution */
  156. //DebugP_log1("ObjDet DPC: DPC_ObjectDetection_dataInjection, handle = 0x%x\n", (uint32_t)handle);
  157. DebugP_assert (DPM_notifyExecute (objDetObj->dpmHandle, handle, true) == 0);
  158. return 0;
  159. }
  160. /**
  161. * @b Description
  162. * @n
  163. * Sub-frame reconfiguration, used when switching sub-frames. Invokes the
  164. * DPU configuration using the configuration that was stored during the
  165. * pre-start configuration so reconstruction time is saved because this will
  166. * happen in real-time.
  167. * @param[in] objDetObj Pointer to DPC object
  168. * @param[in] subFrameIndx Sub-frame index.
  169. *
  170. * @retval
  171. * Success - 0
  172. * @retval
  173. * Error - <0
  174. *
  175. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  176. */
  177. static int32_t DPC_ObjDetDSP_reconfigSubFrame(ObjDetObj *objDetObj, uint8_t subFrameIndx)
  178. {
  179. int32_t retVal = 0;
  180. //SubFrameObj *subFrmObj;
  181. //subFrmObj = &objDetObj->subFrameObj[subFrameIndx];
  182. //retVal = DPU_CFARCAProcDSP_config(subFrmObj->dpuCFARCAObj, &subFrmObj->dpuCfg.cfarCfg);
  183. if (retVal != 0)
  184. {
  185. goto exit;
  186. }
  187. exit:
  188. return(retVal);
  189. }
  190. /**
  191. * @b Description
  192. * @n
  193. * Function to initialize all DPUs used in the DPC chain
  194. *
  195. * @param[in] objDetObj Pointer to sub-frame object
  196. * @param[in] numSubFrames Number of sub-frames
  197. *
  198. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  199. *
  200. * @retval
  201. * Success - 0
  202. * @retval
  203. * Error - <0
  204. */
  205. static inline int32_t DPC_ObjDetDSP_initDPU
  206. (
  207. ObjDetObj *objDetObj,
  208. uint8_t numSubFrames
  209. )
  210. {
  211. int32_t retVal = 0;
  212. return(retVal);
  213. }
  214. /**
  215. * @b Description
  216. * @n
  217. * Function to de-initialize all DPUs used in the DPC chain
  218. *
  219. * @param[in] objDetObj Pointer to sub-frame object
  220. * @param[in] numSubFrames Number of sub-frames
  221. *
  222. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  223. *
  224. * @retval
  225. * Success - 0
  226. * @retval
  227. * Error - <0
  228. */
  229. static inline int32_t DPC_ObjDetDSP_deinitDPU
  230. (
  231. ObjDetObj *objDetObj,
  232. uint8_t numSubFrames
  233. )
  234. {
  235. int32_t retVal = 0;
  236. radarOsal_memDeInit();
  237. return(retVal);
  238. }
  239. /**
  240. * @b Description
  241. * @n
  242. * Performs processing related to pre-start configuration, which is per sub-frame,
  243. * by configuring each of the DPUs involved in the processing chain.
  244. * Memory management notes:
  245. * 1. Core Local Memory that needs to be preserved across sub-frames (such as range DPU's calib DC buffer)
  246. * will be allocated using MemoryP_alloc.
  247. * 2. Core Local Memory that needs to be preserved within a sub-frame across DPU calls
  248. * (the DPIF * type memory) or for intermediate private scratch memory for
  249. * DPU (i.e no preservation is required from process call to process call of the DPUs
  250. * within the sub-frame) will be allocated from the Core Local RAM configuration supplied in
  251. * @ref DPC_ObjectDetection_InitParams given to @ref DPC_ObjectDetection_init API
  252. * 3. L3 memory will only be allocated from the L3 RAM configuration supplied in
  253. * @ref DPC_ObjectDetection_InitParams given to @ref DPC_ObjectDetection_init API
  254. * No L3 buffers are presently required that need to be preserved across sub-frames
  255. * (type described in #1 above), neither are L3 scratch buffers required for
  256. * intermediate processing within DPU process call.
  257. *
  258. * @param[in] subFrameObj Pointer to sub-frame object
  259. * @param[in] commonCfg Pointer to pre-start common configuration
  260. * @param[in] preStartCfg Pointer to pre-start configuration of the sub-frame
  261. * @param[in] edmaHandle Pointer to array of EDMA handles for the device, this
  262. * can be distributed among the DPUs, the actual EDMA handle used
  263. * in DPC is determined by definition in application resource file
  264. * @param[in] L3ramObj Pointer to L3 RAM memory pool object
  265. * @param[in] CoreL2RamObj Pointer to Core Local L2 memory pool object
  266. * @param[in] CoreL1RamObj Pointer to Core Local L1 memory pool object
  267. * @param[out] L3RamUsage Net L3 RAM memory usage in bytes as a result of allocation
  268. * by the DPUs.
  269. * @param[out] CoreL2RamUsage Net Local L2 RAM memory usage in bytes
  270. * @param[out] CoreL1RamUsage Net Core L1 RAM memory usage in bytes
  271. *
  272. * @retval
  273. * Success - 0
  274. * @retval
  275. * Error - <0
  276. *
  277. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  278. */
  279. static int32_t DPC_ObjDetDSP_preStartConfig
  280. (
  281. SubFrameObj *subFrameObj,
  282. DPC_ObjectDetection_PreStartCfg *preStartCfg
  283. )
  284. {
  285. int32_t retVal = 0;
  286. DPC_ObjectDetection_DynCfg *dynCfg;
  287. DPIF_RadarCube radarCube;
  288. DPU_ProcessErrorCodes procErrorCode;
  289. dynCfg = &preStartCfg->dynCfg;
  290. /* Save configs to object. We need to pass this stored config (instead of
  291. the input arguments to this function which will be in stack) to
  292. the DPU config functions inside of this function because the DPUs
  293. have pointers to dynamic configurations which are later going to be
  294. reused during re-configuration (intra sub-frame or inter sub-frame)
  295. */
  296. subFrameObj->dynCfg = * dynCfg;
  297. /* L3 allocations */
  298. /* L3 - radar cube */
  299. radarCube.dataSize = dynCfg->caponChainCfg.numRangeBins * dynCfg->caponChainCfg.numChirpPerFrame *
  300. dynCfg->caponChainCfg.numAntenna * sizeof(cplx16_t);
  301. DebugP_log1("ObjDet DPC: DPC_ObjDetDSP_preStartConfig, radarCubeFormat = %d\n", dynCfg->radarCubeFormat);
  302. if(preStartCfg->shareMemCfg.shareMemEnable == true)
  303. {
  304. if((preStartCfg->shareMemCfg.radarCubeMem.addr != NULL) &&
  305. (preStartCfg->shareMemCfg.radarCubeMem.size == radarCube.dataSize))
  306. {
  307. /* Use assigned radar cube address */
  308. radarCube.data = preStartCfg->shareMemCfg.radarCubeMem.addr;
  309. }
  310. else
  311. {
  312. retVal = DPC_OBJECTDETECTION_EINVAL__COMMAND;
  313. goto exit;
  314. }
  315. #ifdef RADARDEMO_AOARADARCUDE_RNGCHIRPANT
  316. if (subFrameObj->dynCfg.radarCubeFormat != DPIF_RADARCUBE_FORMAT_2)
  317. {
  318. retVal = DPC_OBJECTDETECTION_EINVAL_CUBE;
  319. goto exit;
  320. }
  321. #endif
  322. }
  323. else
  324. {
  325. retVal = DPC_OBJECTDETECTION_EINVAL_CUBE;
  326. goto exit;
  327. }
  328. /* Only supported radar Cube format in this DPC */
  329. radarCube.datafmt = DPIF_RADARCUBE_FORMAT_3;
  330. subFrameObj->dataIn = radarCube.data;
  331. subFrameObj->dpuCaponObj = DPU_radarProcess_init(&subFrameObj->dynCfg.caponChainCfg, &procErrorCode);
  332. if (procErrorCode > PROCESS_OK)
  333. {
  334. retVal = DPC_OBJECTDETECTION_EINTERNAL;
  335. DebugP_log1("DPC config error %d\n", procErrorCode);
  336. goto exit;
  337. }
  338. //printf("DPC configuration done!\n");
  339. DebugP_log0("DPC config done\n");
  340. /* Report RAM usage */
  341. radarOsal_printHeapStats();
  342. exit:
  343. return retVal;
  344. }
  345. /**
  346. * @b Description
  347. * @n
  348. * DPC frame start function registered with DPM. This is invoked on reception
  349. * of the frame start ISR from the RF front-end. This API is also invoked
  350. * when application issues @ref DPC_OBJDET_IOCTL__TRIGGER_FRAME to simulate
  351. * a frame trigger (e.g for unit testing purpose).
  352. *
  353. * @param[in] handle DPM's DPC handle
  354. *
  355. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  356. *
  357. * @retval
  358. * Not applicable
  359. */
  360. static void DPC_ObjectDetection_frameStart (DPM_DPCHandle handle)
  361. {
  362. ObjDetObj *objDetObj = (ObjDetObj *) handle;
  363. objDetObj->stats->frameStartTimeStamp = Cycleprofiler_getTimeStamp();
  364. //DebugP_log2("ObjDet DPC: Frame Start, frameIndx = %d, subFrameIndx = %d\n",
  365. // objDetObj->stats.frameStartIntCounter, objDetObj->subFrameIndx);
  366. /* Check if previous frame (sub-frame) processing has completed */
  367. DPC_Objdet_Assert(objDetObj->dpmHandle, (objDetObj->interSubFrameProcToken == 0));
  368. objDetObj->interSubFrameProcToken++;
  369. /* Increment interrupt counter for debugging purpose */
  370. if (objDetObj->subFrameIndx == 0)
  371. {
  372. objDetObj->stats->frameStartIntCounter++;
  373. }
  374. return;
  375. }
  376. /**
  377. * @b Description
  378. * @n
  379. * DPC's (DPM registered) start function which is invoked by the
  380. * application using DPM_start API.
  381. *
  382. * @param[in] handle DPM's DPC handle
  383. *
  384. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  385. *
  386. * @retval
  387. * Success - 0
  388. * @retval
  389. * Error - <0
  390. */
  391. static int32_t DPC_ObjectDetection_start (DPM_DPCHandle handle)
  392. {
  393. ObjDetObj *objDetObj;
  394. int32_t retVal = 0;
  395. objDetObj = (ObjDetObj *) handle;
  396. DebugP_assert (objDetObj != NULL);
  397. objDetObj->stats->frameStartIntCounter = 0;
  398. /* Start marks consumption of all pre-start configs, reset the flag to check
  399. * if pre-starts were issued only after common config was issued for the next
  400. * time full configuration happens between stop and start */
  401. objDetObj->isCommonCfgReceived = false;
  402. /* App must issue export of last frame after stop which will switch to sub-frame 0,
  403. * so start should always see sub-frame indx of 0, check */
  404. DebugP_assert(objDetObj->subFrameIndx == 0);
  405. if(objDetObj->numSubframes > 1U)
  406. {
  407. /* Pre-start cfgs for sub-frames may have come in any order, so need
  408. * to ensure we reconfig for the current (0) sub-frame before starting */
  409. DPC_ObjDetDSP_reconfigSubFrame(objDetObj, objDetObj->subFrameIndx);
  410. }
  411. DebugP_log0("ObjDet DPC: Start done\n");
  412. return(retVal);
  413. }
  414. /**
  415. * @b Description
  416. * @n
  417. * DPC's (DPM registered) stop function which is invoked by the
  418. * application using DPM_stop API.
  419. *
  420. * @param[in] handle DPM's DPC handle
  421. *
  422. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  423. *
  424. * @retval
  425. * Success - 0
  426. * @retval
  427. * Error - <0
  428. */
  429. static int32_t DPC_ObjectDetection_stop (DPM_DPCHandle handle)
  430. {
  431. ObjDetObj *objDetObj;
  432. objDetObj = (ObjDetObj *) handle;
  433. DebugP_assert (objDetObj != NULL);
  434. /* We can be here only after complete frame processing is done, which means
  435. * processing token must be 0 and subFrameIndx also 0 */
  436. DebugP_assert((objDetObj->interSubFrameProcToken == 0) && (objDetObj->subFrameIndx == 0));
  437. DebugP_log0("ObjDet DPC: Stop done\n");
  438. return(0);
  439. }
  440. /**
  441. * @b Description
  442. * @n
  443. * DPC's (DPM registered) execute function which is invoked by the application
  444. * in the DPM's execute context when the DPC issues DPM_notifyExecute API from
  445. * its registered @ref DPC_ObjectDetection_frameStart API that is invoked every
  446. * frame interrupt.
  447. *
  448. * @param[in] handle DPM's DPC handle
  449. * @param[out] ptrResult Pointer to the result
  450. *
  451. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  452. *
  453. * @retval
  454. * Success - 0
  455. * @retval
  456. * Error - <0
  457. */
  458. int32_t DPC_ObjectDetection_execute
  459. (
  460. DPM_DPCHandle handle,
  461. DPM_Buffer* ptrResult
  462. )
  463. {
  464. ObjDetObj *objDetObj;
  465. SubFrameObj *subFrmObj;
  466. DPC_ObjectDetection_ProcessCallBackCfg *processCallBack;
  467. int32_t procErrorCode;
  468. radarProcessOutput *result;
  469. int32_t retVal = 0;
  470. volatile uint32_t startTime;
  471. int32_t i;
  472. objDetObj = (ObjDetObj *) handle;
  473. DebugP_assert (objDetObj != NULL);
  474. DebugP_assert (ptrResult != NULL);
  475. DebugP_log1("ObjDet DPC: Processing sub-frame %d\n", objDetObj->subFrameIndx);
  476. processCallBack = &objDetObj->processCallBackCfg;
  477. objDetObj->executeResult->subFrameIdx = objDetObj->subFrameIndx;
  478. result = &objDetObj->executeResult->objOut;
  479. subFrmObj = &objDetObj->subFrameObj[objDetObj->subFrameIndx];
  480. if (processCallBack->processInterFrameBeginCallBackFxn != NULL)
  481. {
  482. (*processCallBack->processInterFrameBeginCallBackFxn)(objDetObj->subFrameIndx);
  483. }
  484. //DebugP_log0("ObjDet DPC: Range Proc Output Ready\n");
  485. startTime = Cycleprofiler_getTimeStamp();
  486. DPU_radarProcess_process(subFrmObj->dpuCaponObj, subFrmObj->dataIn, result, &procErrorCode);
  487. if (procErrorCode > PROCESS_OK)
  488. {
  489. retVal = -1;
  490. goto exit;
  491. }
  492. DebugP_log0("ObjDet DPC: Frame Proc Done\n");
  493. objDetObj->stats->interFrameEndTimeStamp = Cycleprofiler_getTimeStamp();
  494. memcpy(&(objDetObj->stats->subFrbenchmarkDetails), result->benchmarkOut, sizeof(radarProcessBenchmarkElem));
  495. objDetObj->stats->interFrameExecTimeInUsec = (uint32_t)((float)(objDetObj->stats->interFrameEndTimeStamp - objDetObj->stats->frameStartTimeStamp) * _rcpsp((float)DSP_CLOCK_MHZ));
  496. objDetObj->stats->activeFrameProcTimeInUsec = (uint32_t)((float)(objDetObj->stats->interFrameEndTimeStamp - startTime) * _rcpsp((float)DSP_CLOCK_MHZ));
  497. /* populate DPM_resultBuf - first pointer and size are for results of the processing */
  498. ptrResult->ptrBuffer[0] = (uint8_t *)objDetObj->executeResult;
  499. ptrResult->size[0] = sizeof(DPC_ObjectDetection_ExecuteResult);
  500. ptrResult->ptrBuffer[1] = (uint8_t *)objDetObj->stats;
  501. ptrResult->size[1] = sizeof(DPC_ObjectDetection_Stats);
  502. /* clear rest of the result */
  503. for (i = 2; i < DPM_MAX_BUFFER; i++)
  504. {
  505. ptrResult->ptrBuffer[i] = NULL;
  506. ptrResult->size[i] = 0;
  507. }
  508. exit:
  509. return retVal;
  510. }
  511. /**
  512. * @b Description
  513. * @n
  514. * DPC IOCTL commands configuration API which will be invoked by the
  515. * application using DPM_ioctl API
  516. *
  517. * @param[in] handle DPM's DPC handle
  518. * @param[in] cmd Capture DPC specific commands
  519. * @param[in] arg Command specific arguments
  520. * @param[in] argLen Length of the arguments which is also command specific
  521. *
  522. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  523. *
  524. * @retval
  525. * Success - 0
  526. * @retval
  527. * Error - <0
  528. */
  529. static int32_t DPC_ObjectDetection_ioctl
  530. (
  531. DPM_DPCHandle handle,
  532. uint32_t cmd,
  533. void* arg,
  534. uint32_t argLen
  535. )
  536. {
  537. ObjDetObj *objDetObj;
  538. SubFrameObj *subFrmObj;
  539. int32_t retVal = 0;
  540. /* Get the DSS MCB: */
  541. objDetObj = (ObjDetObj *) handle;
  542. DebugP_assert(objDetObj != NULL);
  543. /* Process the commands. Process non sub-frame specific ones first
  544. * so the sub-frame specific ones can share some code. */
  545. if((cmd < DPC_OBJDET_IOCTL__STATIC_PRE_START_CFG) || (cmd > DPC_OBJDET_IOCTL__MAX))
  546. {
  547. retVal = DPM_EINVCMD;
  548. }
  549. else if (cmd == DPC_OBJDET_IOCTL__TRIGGER_FRAME)
  550. {
  551. DPC_ObjectDetection_frameStart(handle);
  552. }
  553. else if (cmd == DPC_OBJDET_IOCTL__STATIC_PRE_START_COMMON_CFG)
  554. {
  555. objDetObj->numSubframes = *(uint8_t *)arg;
  556. objDetObj->isCommonCfgReceived = true;
  557. //DebugP_log1("ObjDet DPC: Pre-start Config IOCTL processed common config (numSubframes = %d)\n", objDetObj->numSubframes);
  558. }
  559. else if (cmd == DPC_OBJDET_IOCTL__DYNAMIC_EXECUTE_RESULT_EXPORTED)
  560. {
  561. DPC_ObjectDetection_ExecuteResultExportedInfo *inp;
  562. DebugP_assert(argLen == sizeof(DPC_ObjectDetection_ExecuteResultExportedInfo));
  563. inp = (DPC_ObjectDetection_ExecuteResultExportedInfo *)arg;
  564. /* input sub-frame index must match current sub-frame index */
  565. DebugP_assert(inp->subFrameIdx == objDetObj->subFrameIndx);
  566. /* Reconfigure all DPUs resources for next sub-frame as EDMA and scrach buffer
  567. * resources overlap across sub-frames */
  568. if (objDetObj->numSubframes > 1)
  569. {
  570. /* Next sub-frame */
  571. objDetObj->subFrameIndx++;
  572. if (objDetObj->subFrameIndx == objDetObj->numSubframes)
  573. {
  574. objDetObj->subFrameIndx = 0;
  575. }
  576. DPC_ObjDetDSP_reconfigSubFrame(objDetObj, objDetObj->subFrameIndx);
  577. }
  578. DebugP_log0("ObjDet DPC: received ack from MSS for output data\n");
  579. /* mark end of processing of the frame/sub-frame by the DPC and the app */
  580. objDetObj->interSubFrameProcToken--;
  581. }
  582. else
  583. {
  584. uint8_t subFrameNum;
  585. /* First argument is sub-frame number */
  586. DebugP_assert(arg != NULL);
  587. subFrameNum = *(uint8_t *)arg;
  588. subFrmObj = &objDetObj->subFrameObj[subFrameNum];
  589. switch (cmd)
  590. {
  591. /* Related to pre-start configuration */
  592. case DPC_OBJDET_IOCTL__STATIC_PRE_START_CFG:
  593. {
  594. DPC_ObjectDetection_PreStartCfg *cfg;
  595. /* Pre-start common config must be received before pre-start configs
  596. * are received. */
  597. if (objDetObj->isCommonCfgReceived == false)
  598. {
  599. //DebugP_log0("ObjDet DPC IOCTL: false isCommonCfgReceived\n");
  600. retVal = DPC_OBJECTDETECTION_PRE_START_CONFIG_BEFORE_PRE_START_COMMON_CONFIG;
  601. goto exit;
  602. }
  603. DebugP_assert(argLen == sizeof(DPC_ObjectDetection_PreStartCfg));
  604. cfg = (DPC_ObjectDetection_PreStartCfg*)arg;
  605. //DebugP_log4("ObjDet DPC IOCTL: function called with cfg = 0x%x, subFrmObj = 0x%x, cmd = %d, subFrameNum = %d\n", (uint32_t )arg, (uint32_t )subFrmObj, cmd, *(uint8_t *)arg);
  606. retVal = DPC_ObjDetDSP_preStartConfig(subFrmObj,
  607. cfg);
  608. if (retVal != 0)
  609. {
  610. goto exit;
  611. }
  612. DebugP_log1("ObjDet DPC: Pre-start Config IOCTL processed (subFrameIndx = %d)\n", subFrameNum);
  613. break;
  614. }
  615. default:
  616. {
  617. /* Error: This is an unsupported command */
  618. retVal = DPM_EINVCMD;
  619. break;
  620. }
  621. }
  622. }
  623. exit:
  624. return retVal;
  625. }
  626. /**
  627. * @b Description
  628. * @n
  629. * DPC's (DPM registered) initialization function which is invoked by the
  630. * application using DPM_init API. Among other things, this API allocates DPC instance
  631. * and DPU instances (by calling DPU's init APIs) from the MemoryP osal
  632. * heap. If this API returns an error of any type, the heap is not guaranteed
  633. * to be in the same state as before calling the API (i.e any allocations
  634. * from the heap while executing the API are not guaranteed to be deallocated
  635. * in case of error), so any error from this API should be considered fatal and
  636. * if the error is of _ENOMEM type, the application will
  637. * have to be built again with a bigger heap size to address the problem.
  638. *
  639. * @param[in] dpmHandle DPM's DPC handle
  640. * @param[in] ptrInitCfg Handle to the framework semaphore
  641. * @param[out] errCode Error code populated on error
  642. *
  643. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  644. *
  645. * @retval
  646. * Success - 0
  647. * @retval
  648. * Error - <0
  649. */
  650. static DPM_DPCHandle DPC_ObjectDetection_init
  651. (
  652. DPM_Handle dpmHandle,
  653. DPM_InitCfg* ptrInitCfg,
  654. int32_t* errCode
  655. )
  656. {
  657. ObjDetObj *objDetObj = NULL;
  658. DPC_ObjectDetection_InitParams *dpcInitParams;
  659. radarOsal_heapConfig heapconfig[3];
  660. *errCode = 0;
  661. //DebugP_log0("DPC: DPC_ObjectDetection_init\n");
  662. if ((ptrInitCfg == NULL) || (ptrInitCfg->arg == NULL))
  663. {
  664. *errCode = DPC_OBJECTDETECTION_EINVAL;
  665. goto exit;
  666. }
  667. if (ptrInitCfg->argSize != sizeof(DPC_ObjectDetection_InitParams))
  668. {
  669. *errCode = DPC_OBJECTDETECTION_EINVAL__INIT_CFG_ARGSIZE;
  670. goto exit;
  671. }
  672. dpcInitParams = (DPC_ObjectDetection_InitParams *) ptrInitCfg->arg;
  673. /*Set up heap and mem osal*/
  674. {
  675. memset(heapconfig, 0, sizeof(heapconfig));
  676. heapconfig[RADARMEMOSAL_HEAPTYPE_DDR_CACHED].heapType = RADARMEMOSAL_HEAPTYPE_DDR_CACHED;
  677. heapconfig[RADARMEMOSAL_HEAPTYPE_DDR_CACHED].heapAddr = (int8_t *) dpcInitParams->L3HeapCfg.addr;
  678. heapconfig[RADARMEMOSAL_HEAPTYPE_DDR_CACHED].heapSize = dpcInitParams->L3HeapCfg.size;
  679. heapconfig[RADARMEMOSAL_HEAPTYPE_DDR_CACHED].scratchAddr= (int8_t *) dpcInitParams->L3ScratchCfg.addr;
  680. heapconfig[RADARMEMOSAL_HEAPTYPE_DDR_CACHED].scratchSize= dpcInitParams->L3ScratchCfg.size;
  681. heapconfig[RADARMEMOSAL_HEAPTYPE_LL2].heapType = RADARMEMOSAL_HEAPTYPE_LL2;
  682. heapconfig[RADARMEMOSAL_HEAPTYPE_LL2].heapAddr = (int8_t *) dpcInitParams->CoreL2HeapCfg.addr;
  683. heapconfig[RADARMEMOSAL_HEAPTYPE_LL2].heapSize = dpcInitParams->CoreL2HeapCfg.size;
  684. heapconfig[RADARMEMOSAL_HEAPTYPE_LL2].scratchAddr = (int8_t *) dpcInitParams->CoreL2ScratchCfg.addr;
  685. heapconfig[RADARMEMOSAL_HEAPTYPE_LL2].scratchSize = dpcInitParams->CoreL2ScratchCfg.size;
  686. heapconfig[RADARMEMOSAL_HEAPTYPE_LL1].heapType = RADARMEMOSAL_HEAPTYPE_LL1;
  687. heapconfig[RADARMEMOSAL_HEAPTYPE_LL1].heapAddr = (int8_t *) dpcInitParams->CoreL1HeapCfg.addr;
  688. heapconfig[RADARMEMOSAL_HEAPTYPE_LL1].heapSize = dpcInitParams->CoreL1HeapCfg.size;
  689. heapconfig[RADARMEMOSAL_HEAPTYPE_LL1].scratchAddr = (int8_t *) dpcInitParams->CoreL1ScratchCfg.addr;
  690. heapconfig[RADARMEMOSAL_HEAPTYPE_LL1].scratchSize = dpcInitParams->CoreL1ScratchCfg.size;
  691. if(radarOsal_memInit(&heapconfig[0], 3) == RADARMEMOSAL_FAIL)
  692. {
  693. *errCode = DPC_OBJECTDETECTION_MEMINITERR;
  694. goto exit;
  695. }
  696. }
  697. objDetObj = MemoryP_ctrlAlloc(sizeof(ObjDetObj), 0);
  698. #ifdef DBG_DPC_OBJDET
  699. gObjDetObj = objDetObj;
  700. #endif
  701. System_printf("ObjDet DPC: objDetObj address = (ObjDetObj *) 0x%x\n", (uint32_t) objDetObj);
  702. if(objDetObj == NULL)
  703. {
  704. *errCode = DPC_OBJECTDETECTION_ENOMEM;
  705. goto exit;
  706. }
  707. /* Initialize memory */
  708. memset((void *)objDetObj, 0, sizeof(ObjDetObj));
  709. /* Copy over the DPM configuration: */
  710. memcpy ((void*)&objDetObj->dpmInitCfg, (void*)ptrInitCfg, sizeof(DPM_InitCfg));
  711. objDetObj->dpmHandle = dpmHandle;
  712. objDetObj->socHandle = ptrInitCfg->socHandle;
  713. objDetObj->processCallBackCfg = dpcInitParams->processCallBackCfg;
  714. objDetObj->executeResult = (DPC_ObjectDetection_ExecuteResult *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_DDR_CACHED, 0, sizeof(DPC_ObjectDetection_ExecuteResult), 1);
  715. objDetObj->stats = (DPC_ObjectDetection_Stats *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_DDR_CACHED, 0, sizeof(DPC_ObjectDetection_Stats), 1);
  716. *errCode = DPC_ObjDetDSP_initDPU(objDetObj, RL_MAX_SUBFRAMES);
  717. //printf ("DPC init done!\n");
  718. exit:
  719. if(*errCode != 0)
  720. {
  721. if(objDetObj != NULL)
  722. {
  723. MemoryP_ctrlFree(objDetObj, sizeof(ObjDetObj));
  724. objDetObj = NULL;
  725. }
  726. }
  727. return ((DPM_DPCHandle)objDetObj);
  728. }
  729. /**
  730. * @b Description
  731. * @n
  732. * DPC's (DPM registered) de-initialization function which is invoked by the
  733. * application using DPM_deinit API.
  734. *
  735. * @param[in] handle DPM's DPC handle
  736. *
  737. * \ingroup DPC_OBJDET__INTERNAL_FUNCTION
  738. *
  739. * @retval
  740. * Success - 0
  741. * @retval
  742. * Error - <0
  743. */
  744. static int32_t DPC_ObjectDetection_deinit (DPM_DPCHandle handle)
  745. {
  746. ObjDetObj *objDetObj = (ObjDetObj *) handle;
  747. int32_t retVal = 0;
  748. if (handle == NULL)
  749. {
  750. retVal = DPC_OBJECTDETECTION_EINVAL;
  751. goto exit;
  752. }
  753. retVal = DPC_ObjDetDSP_deinitDPU(objDetObj, RL_MAX_SUBFRAMES);
  754. MemoryP_ctrlFree(handle, sizeof(ObjDetObj));
  755. exit:
  756. return (retVal);
  757. }
  758. /**************************************************************************
  759. ************************* Global Declarations ****************************
  760. **************************************************************************/
  761. /** @addtogroup DPC_OBJDET__GLOBAL
  762. @{ */
  763. /**
  764. * @brief Global used to register Object Detection DPC in DPM
  765. */
  766. DPM_ProcChainCfg gDPC_ObjectDetectionCfg =
  767. {
  768. DPC_ObjectDetection_init, /* Initialization Function: */
  769. DPC_ObjectDetection_start, /* Start Function: */
  770. DPC_ObjectDetection_execute, /* Execute Function: */
  771. DPC_ObjectDetection_ioctl, /* Configuration Function: */
  772. DPC_ObjectDetection_stop, /* Stop Function: */
  773. DPC_ObjectDetection_deinit, /* Deinitialization Function: */
  774. DPC_ObjectDetection_dataInjection, /* Inject Data Function: */
  775. NULL, /* Chirp Available Function: */
  776. DPC_ObjectDetection_frameStart /* Frame Start Function: */
  777. };
  778. /* @} */