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.

dss_main.c 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /**
  2. * @file dss_main.c
  3. *
  4. * @brief
  5. * This is the main file which implements the 3D people counting Demo on DSS.
  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. /* Standard Include Files. */
  43. #include <stdint.h>
  44. #include <stdlib.h>
  45. #include <stddef.h>
  46. #include <string.h>
  47. #include <stdio.h>
  48. #include <math.h>
  49. /* BIOS/XDC Include Files. */
  50. #include <xdc/std.h>
  51. #include <xdc/cfg/global.h>
  52. #include <xdc/runtime/IHeap.h>
  53. #include <xdc/runtime/System.h>
  54. #include <xdc/runtime/Error.h>
  55. #include <xdc/runtime/Memory.h>
  56. #include <ti/sysbios/BIOS.h>
  57. #include <ti/sysbios/knl/Task.h>
  58. #include <ti/sysbios/knl/Event.h>
  59. #include <ti/sysbios/knl/Semaphore.h>
  60. #include <ti/sysbios/knl/Clock.h>
  61. #include <ti/sysbios/heaps/HeapBuf.h>
  62. #include <ti/sysbios/heaps/HeapMem.h>
  63. #include <ti/sysbios/knl/Event.h>
  64. #include <ti/sysbios/utils/Load.h>
  65. #include <ti/sysbios/family/c64p/Hwi.h>
  66. /* mmWave SDK Include Files: */
  67. #include <ti/common/sys_common.h>
  68. #include <ti/control/dpm/dpm.h>
  69. #include <ti/drivers/soc/soc.h>
  70. #include <ti/drivers/esm/esm.h>
  71. #include <ti/drivers/crc/crc.h>
  72. #include <ti/drivers/osal/DebugP.h>
  73. /* Data path Include Files */
  74. #include <common/src/dpc/capon3d/objectdetection.h>
  75. /* Demo Include Files */
  76. #include <people_counting/68xx_3D_people_counting/src/common/pcount3D_output.h>
  77. #include "pcount3D_dss.h"
  78. #include <people_counting/68xx_3D_people_counting/src/common/pcount3D_hwres.h>
  79. /* Demo Profiling Include Files */
  80. #include <ti/utils/cycleprofiler/cycle_profiler.h>
  81. /**
  82. * @brief Task Priority settings:
  83. */
  84. #define MMWDEMO_DPC_OBJDET_DPM_TASK_PRIORITY 5
  85. #define DEBUG(_x) //_x
  86. //#define BUILDFORMETHOD2
  87. #ifdef BUILDFORMETHOD2
  88. #define L2HEAPSIZE (0x1B000) // for method 2 and full FoV support of ODS
  89. #define L3HEAPSIZE (0x2D000) // for method 2 and full FoV support of ODS
  90. #else
  91. #define L2HEAPSIZE (0x19600) // for method 1 ISK and +/- 20 degree elev FOV of ODS
  92. #define L3HEAPSIZE (0x21000) // for method 1 ISK and +/- 20 degree elev FOV of ODS
  93. #endif
  94. #define L2SCRATCHSIZE (0x900)
  95. #define L1SCRATCHSIZE (0x1200)
  96. #define L1HEAPSIZE (0x2E00)
  97. #pragma DATA_SECTION(memHeapL2, ".dpc_l2Heap")
  98. uint8_t memHeapL2[L2HEAPSIZE];
  99. #pragma DATA_SECTION(memHeapL3, ".l3data")
  100. uint8_t memHeapL3[L3HEAPSIZE];
  101. #pragma DATA_SECTION(l2ScratchMem, ".dpc_l2Heap")
  102. uint8_t l2ScratchMem[L2SCRATCHSIZE];
  103. #pragma DATA_SECTION(l1ScratchMem, ".dpc_l1Heap")
  104. uint8_t l1ScratchMem[L1SCRATCHSIZE];
  105. #pragma DATA_SECTION(l1HeapMem, ".dpc_l1Heap")
  106. uint8_t l1HeapMem[L1HEAPSIZE];
  107. #define DPC_OBJDET_DSP_INSTANCEID (0xDEEDDEED)
  108. /**************************************************************************
  109. *************************** Global Definitions ***************************
  110. **************************************************************************/
  111. /**
  112. * @brief
  113. * Global Variable for tracking information required by the mmw Demo
  114. */
  115. Pcount3DDemo_DSS_MCB gPcount3DDssMCB;
  116. /**
  117. * @brief
  118. * Global Variable for DPM result buffer
  119. */
  120. DPM_Buffer resultBuffer;
  121. /**************************************************************************
  122. ******************* Millimeter Wave Demo Functions Prototype *******************
  123. **************************************************************************/
  124. static void Pcount3DDemo_dssInitTask(UArg arg0, UArg arg1);
  125. static void Pcount3DDemo_DPC_RadarProc_reportFxn
  126. (
  127. DPM_Report reportType,
  128. uint32_t instanceId,
  129. int32_t errCode,
  130. uint32_t arg0,
  131. uint32_t arg1
  132. );
  133. static void Pcount3DDemo_DPC_processFrameBeginCallBackFxn(uint8_t subFrameIndx);
  134. static void Pcount3DDemo_DPC_processInterFrameBeginCallBackFxn(uint8_t subFrameIndx);
  135. static void Pcount3DDemo_DPC_RadarProc_dpmTask(UArg arg0, UArg arg1);
  136. static void Pcount3DDemo_sensorStopEpilog(void);
  137. /* copy table related */
  138. extern far COPY_TABLE _pcount3DDemo_fastCode_L1PSRAM_copy_table;
  139. extern far COPY_TABLE _pcount3DDemo_configCode_HSRAM_copy_table;
  140. static void MmwDemo_copyTable(EDMA_Handle handle, COPY_TABLE *tp);
  141. static void MmwDemo_edmaBlockCopy(EDMA_Handle handle, uint32_t loadAddr, uint32_t runAddr, uint16_t size);
  142. /**
  143. * @b Description
  144. * @n
  145. * Performs linker generated copy table copy using EDMA. Currently this is
  146. * used to page in fast code from L3 to L1PSRAM.
  147. * @param[in] handle EDMA handle
  148. * @param[in] tp Pointer to copy table
  149. *
  150. * @retval
  151. * Not Applicable.
  152. */
  153. static void MmwDemo_copyTable(EDMA_Handle handle, COPY_TABLE *tp)
  154. {
  155. uint16_t i;
  156. COPY_RECORD crp;
  157. uint32_t loadAddr;
  158. uint32_t runAddr;
  159. for (i = 0; i < tp->num_recs; i++)
  160. {
  161. crp = tp->recs[i];
  162. loadAddr = (uint32_t)crp.load_addr;
  163. runAddr = (uint32_t)crp.run_addr;
  164. /* currently we use only one count of EDMA which is 16-bit so we cannot
  165. handle tables bigger than 64 KB */
  166. DebugP_assert(crp.size <= 65536U);
  167. if (crp.size)
  168. {
  169. MmwDemo_edmaBlockCopy(handle, loadAddr, runAddr, crp.size);
  170. }
  171. }
  172. }
  173. /**
  174. * @b Description
  175. * @n
  176. * Performs simple block copy using EDMA. Used for the purpose of copying
  177. * linker table for L3 to L1PSRAM copy. memcpy cannot be used because there is
  178. * no data bus access to L1PSRAM.
  179. *
  180. * @param[in] handle EDMA handle
  181. * @param[in] loadAddr load address
  182. * @param[in] runAddr run address
  183. * @param[in] size size in bytes
  184. *
  185. * @retval
  186. * Not Applicable.
  187. */
  188. static void MmwDemo_edmaBlockCopy(EDMA_Handle handle, uint32_t loadAddr, uint32_t runAddr, uint16_t size)
  189. {
  190. EDMA_channelConfig_t config;
  191. volatile bool isTransferDone;
  192. config.channelId = EDMA_TPCC0_REQ_FREE_0;
  193. config.channelType = (uint8_t)EDMA3_CHANNEL_TYPE_DMA;
  194. config.paramId = (uint16_t)EDMA_TPCC0_REQ_FREE_0;
  195. config.eventQueueId = 0;
  196. config.paramSetConfig.sourceAddress = (uint32_t) SOC_translateAddress((uint32_t)loadAddr,
  197. SOC_TranslateAddr_Dir_TO_EDMA, NULL);
  198. config.paramSetConfig.destinationAddress = (uint32_t) SOC_translateAddress((uint32_t)runAddr,
  199. SOC_TranslateAddr_Dir_TO_EDMA, NULL);
  200. config.paramSetConfig.aCount = size;
  201. config.paramSetConfig.bCount = 1U;
  202. config.paramSetConfig.cCount = 1U;
  203. config.paramSetConfig.bCountReload = 0U;
  204. config.paramSetConfig.sourceBindex = 0U;
  205. config.paramSetConfig.destinationBindex = 0U;
  206. config.paramSetConfig.sourceCindex = 0U;
  207. config.paramSetConfig.destinationCindex = 0U;
  208. config.paramSetConfig.linkAddress = EDMA_NULL_LINK_ADDRESS;
  209. config.paramSetConfig.transferType = (uint8_t)EDMA3_SYNC_A;
  210. config.paramSetConfig.transferCompletionCode = (uint8_t) EDMA_TPCC0_REQ_FREE_0;
  211. config.paramSetConfig.sourceAddressingMode = (uint8_t) EDMA3_ADDRESSING_MODE_LINEAR;
  212. config.paramSetConfig.destinationAddressingMode = (uint8_t) EDMA3_ADDRESSING_MODE_LINEAR;
  213. /* don't care because of linear addressing modes above */
  214. config.paramSetConfig.fifoWidth = (uint8_t) EDMA3_FIFO_WIDTH_8BIT;
  215. config.paramSetConfig.isStaticSet = false;
  216. config.paramSetConfig.isEarlyCompletion = false;
  217. config.paramSetConfig.isFinalTransferInterruptEnabled = true;
  218. config.paramSetConfig.isIntermediateTransferInterruptEnabled = false;
  219. config.paramSetConfig.isFinalChainingEnabled = false;
  220. config.paramSetConfig.isIntermediateChainingEnabled = false;
  221. config.transferCompletionCallbackFxn = NULL;
  222. config.transferCompletionCallbackFxnArg = NULL;
  223. if (EDMA_configChannel(handle, &config, false) != EDMA_NO_ERROR)
  224. {
  225. DebugP_assert(0);
  226. }
  227. if (EDMA_startDmaTransfer(handle, config.channelId) != EDMA_NO_ERROR)
  228. {
  229. DebugP_assert(0);
  230. }
  231. /* wait until transfer done */
  232. do {
  233. if (EDMA_isTransferComplete(handle,
  234. config.paramSetConfig.transferCompletionCode,
  235. (bool *)&isTransferDone) != EDMA_NO_ERROR)
  236. {
  237. DebugP_assert(0);
  238. }
  239. } while (isTransferDone == false);
  240. /* make sure to disable channel so it is usable later */
  241. EDMA_disableChannel(handle, config.channelId, config.channelType);
  242. }
  243. /**
  244. * @b Description
  245. * @n
  246. * EDMA driver init
  247. *
  248. * @param[in] obj Pointer to data path object
  249. *
  250. * @retval
  251. * Not Applicable.
  252. */
  253. void MmwDemo_edmaInit(Pcount3DDemo_DataPathObj *obj, uint8_t instance)
  254. {
  255. int32_t errorCode;
  256. errorCode = EDMA_init(instance);
  257. if (errorCode != EDMA_NO_ERROR)
  258. {
  259. //System_printf ("Debug: EDMA instance %d initialization returned error %d\n", errorCode);
  260. Pcount3DDemo_debugAssert (0);
  261. return;
  262. }
  263. memset(&obj->EDMA_errorInfo, 0, sizeof(obj->EDMA_errorInfo));
  264. memset(&obj->EDMA_transferControllerErrorInfo, 0, sizeof(obj->EDMA_transferControllerErrorInfo));
  265. }
  266. /**
  267. * @b Description
  268. * @n
  269. * Call back function for EDMA CC (Channel controller) error as per EDMA API.
  270. * Declare fatal error if happens, the output errorInfo can be examined if code
  271. * gets trapped here.
  272. */
  273. void MmwDemo_EDMA_errorCallbackFxn(EDMA_Handle handle, EDMA_errorInfo_t *errorInfo)
  274. {
  275. gPcount3DDssMCB.dataPathObj.EDMA_errorInfo = *errorInfo;
  276. Pcount3DDemo_debugAssert(0);
  277. }
  278. /**
  279. * @b Description
  280. * @n
  281. * Call back function for EDMA transfer controller error as per EDMA API.
  282. * Declare fatal error if happens, the output errorInfo can be examined if code
  283. * gets trapped here.
  284. */
  285. void MmwDemo_EDMA_transferControllerErrorCallbackFxn(EDMA_Handle handle,
  286. EDMA_transferControllerErrorInfo_t *errorInfo)
  287. {
  288. gPcount3DDssMCB.dataPathObj.EDMA_transferControllerErrorInfo = *errorInfo;
  289. Pcount3DDemo_debugAssert(0);
  290. }
  291. /**
  292. * @b Description
  293. * @n
  294. * Open EDMA driver instance
  295. *
  296. * @param[in] obj Pointer to data path object
  297. * @param[in] instance EDMA instance
  298. *
  299. * @retval
  300. * Not Applicable.
  301. */
  302. static void MmwDemo_edmaOpen(Pcount3DDemo_DataPathObj *obj, uint8_t instance)
  303. {
  304. int32_t errCode;
  305. EDMA_instanceInfo_t edmaInstanceInfo;
  306. EDMA_errorConfig_t errorConfig;
  307. obj->edmaHandle = EDMA_open(
  308. instance,
  309. &errCode,
  310. &edmaInstanceInfo);
  311. if (obj->edmaHandle == NULL)
  312. {
  313. Pcount3DDemo_debugAssert (0);
  314. return;
  315. }
  316. errorConfig.isConfigAllEventQueues = true;
  317. errorConfig.isConfigAllTransferControllers = true;
  318. errorConfig.isEventQueueThresholdingEnabled = true;
  319. errorConfig.eventQueueThreshold = EDMA_EVENT_QUEUE_THRESHOLD_MAX;
  320. errorConfig.isEnableAllTransferControllerErrors = true;
  321. errorConfig.callbackFxn = MmwDemo_EDMA_errorCallbackFxn;
  322. errorConfig.transferControllerCallbackFxn = MmwDemo_EDMA_transferControllerErrorCallbackFxn;
  323. if ((errCode = EDMA_configErrorMonitoring(obj->edmaHandle, &errorConfig)) != EDMA_NO_ERROR)
  324. {
  325. //System_printf("Error: EDMA_configErrorMonitoring() failed with errorCode = %d\n", errCode);
  326. Pcount3DDemo_debugAssert (0);
  327. return;
  328. }
  329. }
  330. /**
  331. * @b Description
  332. * @n
  333. * Close EDMA driver instance
  334. *
  335. * @param[in] obj Pointer to data path object
  336. *
  337. * @retval
  338. * Not Applicable.
  339. */
  340. void MmwDemo_edmaClose(Pcount3DDemo_DataPathObj *obj)
  341. {
  342. EDMA_close(obj->edmaHandle);
  343. }
  344. /**
  345. * @b Description
  346. * @n
  347. * Epilog processing after sensor has stopped
  348. *
  349. * @retval None
  350. */
  351. static void Pcount3DDemo_sensorStopEpilog(void)
  352. {
  353. Hwi_StackInfo stackInfo;
  354. Task_Stat stat;
  355. bool hwiStackOverflow;
  356. DEBUG(System_printf("Data Path Stopped (last frame processing done)\n");)
  357. /* Print DSS task statistics */
  358. DEBUG(System_printf("DSS Task Stack Usage (Note: Task Stack Usage) ==========\n");)
  359. Task_stat(gPcount3DDssMCB.initTaskHandle, &stat);
  360. DEBUG(System_printf("%20s %12d %12d %12d\n", "initTask",
  361. stat.stackSize,
  362. stat.used,
  363. stat.stackSize - stat.used);)
  364. Task_stat(gPcount3DDssMCB.radarProcDpmTaskHandle, &stat);
  365. DEBUG(System_printf("%20s %12s %12s %12s\n", "Task Name", "Size", "Used", "Free");)
  366. DEBUG(System_printf("%20s %12d %12d %12d\n", "ObjDet DPM",
  367. stat.stackSize,
  368. stat.used,
  369. stat.stackSize - stat.used);)
  370. DEBUG(System_printf("HWI Stack (same as System Stack) Usage ============\n");)
  371. hwiStackOverflow = Hwi_getStackInfo(&stackInfo, TRUE);
  372. if (hwiStackOverflow == TRUE)
  373. {
  374. DEBUG(System_printf("DSS HWI Stack overflowed\n");)
  375. Pcount3DDemo_debugAssert(0);
  376. }
  377. else
  378. {
  379. DEBUG(System_printf("%20s %12s %12s %12s\n", " ", "Size", "Used", "Free");)
  380. DEBUG(System_printf("%20s %12d %12d %12d\n", " ",
  381. stackInfo.hwiStackSize,
  382. stackInfo.hwiStackPeak,
  383. stackInfo.hwiStackSize - stackInfo.hwiStackPeak);)
  384. }
  385. }
  386. /**
  387. * @b Description
  388. * @n
  389. * DPM Registered Report Handler. The DPM Module uses this registered function to notify
  390. * the application about DPM reports.
  391. *
  392. * @param[in] reportType
  393. * Report Type
  394. * @param[in] instanceId
  395. * Instance Identifier which generated the report
  396. * @param[in] errCode
  397. * Error code if any.
  398. * @param[in] arg0
  399. * Argument 0 interpreted with the report type
  400. * @param[in] arg1
  401. * Argument 1 interpreted with the report type
  402. *
  403. * @retval
  404. * Not Applicable.
  405. */
  406. static void Pcount3DDemo_DPC_RadarProc_reportFxn
  407. (
  408. DPM_Report reportType,
  409. uint32_t instanceId,
  410. int32_t errCode,
  411. uint32_t arg0,
  412. uint32_t arg1
  413. )
  414. {
  415. /* Only errors are logged on the console: */
  416. if (errCode != 0)
  417. {
  418. /* Error: Detected log on the console and die all errors are FATAL currently. */
  419. DEBUG(System_printf ("Error: DPM Report %d received with error:%d arg0:0x%x arg1:0x%x\n",
  420. reportType, errCode, arg0, arg1);)
  421. DebugP_assert (0);
  422. }
  423. /* Processing further is based on the reports received: This is the control of the profile
  424. * state machine: */
  425. switch (reportType)
  426. {
  427. case DPM_Report_IOCTL:
  428. {
  429. /*****************************************************************
  430. * DPC has been configured without an error:
  431. * - This is an indication that the profile configuration commands
  432. * went through without any issues.
  433. *****************************************************************/
  434. DebugP_log1("DSSApp: DPM Report IOCTL, command = %d\n", arg0);
  435. break;
  436. }
  437. case DPM_Report_DPC_STARTED:
  438. {
  439. /*****************************************************************
  440. * DPC has been started without an error:
  441. * - notify sensor management task that DPC is started.
  442. *****************************************************************/
  443. DebugP_log0("DSSApp: DPM Report start\n");
  444. gPcount3DDssMCB.dpmStartEvents++;
  445. break;
  446. }
  447. case DPM_Report_NOTIFY_DPC_RESULT:
  448. {
  449. /*****************************************************************
  450. * DPC Results have been passed:
  451. * - This implies that we have valid profile results which have
  452. * been received from the profile.
  453. *****************************************************************/
  454. break;
  455. }
  456. case DPM_Report_NOTIFY_DPC_RESULT_ACKED:
  457. {
  458. /*****************************************************************
  459. * DPC Results have been acked:
  460. * - This implies that MSS received the results.
  461. *****************************************************************/
  462. break;
  463. }
  464. case DPM_Report_DPC_ASSERT:
  465. {
  466. DPM_DPCAssert* ptrAssert;
  467. /*****************************************************************
  468. * DPC Fault has been detected:
  469. * - This implies that the DPC has crashed.
  470. * - The argument0 points to the DPC assertion information
  471. *****************************************************************/
  472. ptrAssert = (DPM_DPCAssert*)arg0;
  473. System_printf ("DSS Exception: %s, line %d.\n", ptrAssert->fileName,
  474. ptrAssert->lineNum);
  475. break;
  476. }
  477. case DPM_Report_DPC_STOPPED:
  478. {
  479. /*****************************************************************
  480. * DPC has been stopped without an error:
  481. * - This implies that the DPC can either be reconfigured or
  482. * restarted.
  483. *****************************************************************/
  484. DebugP_log0("DSSApp: DPM Report stop\n");
  485. gPcount3DDssMCB.dpmStopEvents++;
  486. if (gPcount3DDssMCB.dpmStopEvents % 2 == 1) {
  487. Pcount3DDemo_sensorStopEpilog();
  488. }
  489. break;
  490. }
  491. case DPM_Report_DPC_INFO:
  492. {
  493. /* Currently chain does not use this feature. */
  494. break;
  495. }
  496. default:
  497. {
  498. DebugP_assert (0);
  499. break;
  500. }
  501. }
  502. return;
  503. }
  504. /**
  505. * @b Description
  506. * @n
  507. * Call back function that was registered during config time and is going
  508. * to be called in DPC processing at the beginning of frame/sub-frame processing.
  509. * Note: In this demo objdetdsp DPC only have inter-frame processing, hence this
  510. * callback function won't be called.
  511. *
  512. * @param[in] subFrameIndx Sub-frame index of the sub-frame during which processing
  513. * this function was called.
  514. *
  515. * @retval None
  516. */
  517. static void Pcount3DDemo_DPC_processFrameBeginCallBackFxn(uint8_t subFrameIndx)
  518. {
  519. /* Empty function */
  520. }
  521. /**
  522. * @b Description
  523. * @n
  524. * Call back function that was registered during config time and is going
  525. * to be called in DPC processing at the beginning of inter-frame/inter-sub-frame processing,
  526. * we use this to issue BIOS calls for computing CPU load during active frame (chirping)
  527. *
  528. * @param[in] subFrameIndx Sub-frame index of the sub-frame during which processing
  529. * this function was called.
  530. *
  531. * @retval None
  532. */
  533. static void Pcount3DDemo_DPC_processInterFrameBeginCallBackFxn(uint8_t subFrameIndx)
  534. {
  535. Load_update();
  536. gPcount3DDssMCB.dataPathObj.subFrameStats[subFrameIndx].interFrameCPULoad = Load_getCPULoad();
  537. }
  538. /**
  539. * @b Description
  540. * @n
  541. * DPM Execution Task. DPM execute results are processed here:
  542. * a) Update states based on timestamp from DPC.
  543. * b) Copy results to shared memory to be shared with MSS.
  544. * c) Send Results to MSS by calling DPM_sendResult()
  545. *
  546. * @retval
  547. * Not Applicable.
  548. */
  549. static void Pcount3DDemo_DPC_RadarProc_dpmTask(UArg arg0, UArg arg1)
  550. {
  551. int32_t retVal;
  552. //DPC_ObjectDetection_ExecuteResult *result;
  553. volatile uint32_t startTime;
  554. while (1)
  555. {
  556. /* Execute the DPM module: */
  557. //DebugP_log0("DSS main: Pcount3DDemo_DPC_RadarProc_dpmTask\n");
  558. retVal = DPM_execute (gPcount3DDssMCB.dataPathObj.radarProcDpmHandle, &resultBuffer);
  559. if (retVal < 0) {
  560. DEBUG(System_printf ("Error: DPM execution failed [Error code %d]\n", retVal);)
  561. Pcount3DDemo_debugAssert (0);
  562. }
  563. else
  564. {
  565. if ((resultBuffer.size[0] == sizeof(DPC_ObjectDetection_ExecuteResult)))
  566. {
  567. retVal = DPM_sendResult (gPcount3DDssMCB.dataPathObj.radarProcDpmHandle, true, &resultBuffer);
  568. if (retVal < 0)
  569. {
  570. DEBUG(System_printf ("Error: Failed to send results [Error: %d] to remote\n", retVal);)
  571. }
  572. }
  573. }
  574. //writeback all the data shared with R4 in L3, and prepare cache for next frames radar cube from R4.
  575. cache_wbInvAllL2Wait();
  576. }
  577. }
  578. /**
  579. * @b Description
  580. * @n
  581. * System Initialization Task which initializes the various
  582. * components in the system.
  583. *
  584. * @retval
  585. * Not Applicable.
  586. */
  587. static void Pcount3DDemo_dssInitTask(UArg arg0, UArg arg1)
  588. {
  589. int32_t errCode;
  590. Task_Params taskParams;
  591. DPM_InitCfg dpmInitCfg;
  592. DPC_ObjectDetection_InitParams objDetInitParams;
  593. /*****************************************************************************
  594. * Driver Init:
  595. *****************************************************************************/
  596. /*****************************************************************************
  597. * Driver Open/Configuraiton:
  598. *****************************************************************************/
  599. /* Initialize EDMA */
  600. MmwDemo_edmaInit(&gPcount3DDssMCB.dataPathObj, DPC_OBJDET_DSP_EDMA_INSTANCE);
  601. /* Use instance 1 on DSS */
  602. MmwDemo_edmaOpen(&gPcount3DDssMCB.dataPathObj, DPC_OBJDET_DSP_EDMA_INSTANCE);
  603. /* Copy code from L3 to L1PSRAM, this code related to data path processing */
  604. MmwDemo_copyTable(gPcount3DDssMCB.dataPathObj.edmaHandle, &_pcount3DDemo_fastCode_L1PSRAM_copy_table);
  605. MmwDemo_copyTable(gPcount3DDssMCB.dataPathObj.edmaHandle, &_pcount3DDemo_configCode_HSRAM_copy_table);
  606. /* Initialize the Mailbox */
  607. Mailbox_init(MAILBOX_TYPE_DSS);
  608. /*****************************************************************************
  609. * Initialization of the DPM Module:
  610. *****************************************************************************/
  611. DebugP_log0("DSS main: Pcount3DDemo_dssInitTask\n");
  612. memset ((void *)&objDetInitParams, 0, sizeof(DPC_ObjectDetection_InitParams));
  613. /*Set up init params for memory osal*/
  614. objDetInitParams.L3HeapCfg.addr = (void *) &memHeapL3[0];
  615. objDetInitParams.L3HeapCfg.size = L3HEAPSIZE;
  616. objDetInitParams.L3ScratchCfg.addr = (void *) NULL;
  617. objDetInitParams.L3ScratchCfg.size = 0;
  618. objDetInitParams.CoreL2HeapCfg.addr = (void *) &memHeapL2[0];
  619. objDetInitParams.CoreL2HeapCfg.size = L2HEAPSIZE;
  620. objDetInitParams.CoreL2ScratchCfg.addr = (void *) &l2ScratchMem[0];
  621. objDetInitParams.CoreL2ScratchCfg.size = L2SCRATCHSIZE;
  622. objDetInitParams.CoreL1HeapCfg.addr = (void *) &l1HeapMem[0];
  623. objDetInitParams.CoreL1HeapCfg.size = L1HEAPSIZE;
  624. objDetInitParams.CoreL1ScratchCfg.addr = (void *) &l1ScratchMem[0];
  625. objDetInitParams.CoreL1ScratchCfg.size = L1SCRATCHSIZE;
  626. /* DPC Call-back config */
  627. objDetInitParams.processCallBackCfg.processFrameBeginCallBackFxn =
  628. Pcount3DDemo_DPC_processFrameBeginCallBackFxn;
  629. objDetInitParams.processCallBackCfg.processInterFrameBeginCallBackFxn =
  630. Pcount3DDemo_DPC_processInterFrameBeginCallBackFxn;
  631. memset ((void *)&dpmInitCfg, 0, sizeof(DPM_InitCfg));
  632. /* Setup the configuration: */
  633. dpmInitCfg.socHandle = gPcount3DDssMCB.socHandle;
  634. dpmInitCfg.ptrProcChainCfg = &gDPC_ObjectDetectionCfg;
  635. dpmInitCfg.instanceId = DPC_OBJDET_DSP_INSTANCEID;
  636. dpmInitCfg.domain = DPM_Domain_DISTRIBUTED;
  637. dpmInitCfg.reportFxn = Pcount3DDemo_DPC_RadarProc_reportFxn;
  638. dpmInitCfg.arg = &objDetInitParams;
  639. dpmInitCfg.argSize = sizeof(DPC_ObjectDetection_InitParams);
  640. /* Initialize the DPM Module: */
  641. gPcount3DDssMCB.dataPathObj.radarProcDpmHandle = DPM_init (&dpmInitCfg, &errCode);
  642. if (gPcount3DDssMCB.dataPathObj.radarProcDpmHandle == NULL)
  643. {
  644. DEBUG(System_printf ("Error: Unable to initialize the DPM Module [Error: %d]\n", errCode);)
  645. Pcount3DDemo_debugAssert (0);
  646. return;
  647. }
  648. /* Synchronization: This will synchronize the execution of the control module
  649. * between the domains. This is a prerequiste and always needs to be invoked. */
  650. while (1)
  651. {
  652. int32_t syncStatus;
  653. /* Get the synchronization status: */
  654. syncStatus = DPM_synch (gPcount3DDssMCB.dataPathObj.radarProcDpmHandle, &errCode);
  655. if (syncStatus < 0)
  656. {
  657. /* Error: Unable to synchronize the framework */
  658. DEBUG(System_printf ("Error: DPM Synchronization failed [Error code %d]\n", errCode);)
  659. Pcount3DDemo_debugAssert (0);
  660. return;
  661. }
  662. if (syncStatus == 1)
  663. {
  664. /* Synchronization acheived: */
  665. break;
  666. }
  667. /* Sleep and poll again: */
  668. Task_sleep(1);
  669. }
  670. System_printf ("Debug: DPM Module Sync is done\n");
  671. /* Launch the DPM Task */
  672. Task_Params_init(&taskParams);
  673. taskParams.priority = MMWDEMO_DPC_OBJDET_DPM_TASK_PRIORITY;
  674. taskParams.stackSize = 3*1024;
  675. gPcount3DDssMCB.radarProcDpmTaskHandle = Task_create(Pcount3DDemo_DPC_RadarProc_dpmTask, &taskParams, NULL);
  676. return;
  677. }
  678. /**
  679. * @b Description
  680. * @n
  681. * Function to sleep the DSP using IDLE instruction.
  682. * When DSP has no work left to do,
  683. * the BIOS will be in Idle thread and will call this function.
  684. *
  685. * @retval
  686. * Not Applicable.
  687. */
  688. void Pcount3DDemo_sleep(void)
  689. {
  690. /* issue WFI (Wait For Interrupt) instruction */
  691. asm(" IDLE ");
  692. }
  693. /**
  694. * @b Description
  695. * @n
  696. * Entry point into the Millimeter Wave Demo
  697. *
  698. * @retval
  699. * Not Applicable.
  700. */
  701. int main (void)
  702. {
  703. Task_Params taskParams;
  704. int32_t errCode;
  705. SOC_Handle socHandle;
  706. SOC_Cfg socCfg;
  707. // set cache state for l3 and hsram
  708. cache_setMar((unsigned int *)0x20000000, 0xC0000, Cache_PC | Cache_PFX);
  709. //cache_setMar((unsigned int *)0x21080000, 0x8000, Cache_PC | Cache_PFX);
  710. /* Initialize and populate the demo MCB */
  711. memset ((void*)&gPcount3DDssMCB, 0, sizeof(Pcount3DDemo_DSS_MCB));
  712. /* Initialize the SOC confiugration: */
  713. memset ((void *)&socCfg, 0, sizeof(SOC_Cfg));
  714. /* Populate the SOC configuration: */
  715. socCfg.clockCfg = SOC_SysClock_BYPASS_INIT;
  716. /* Initialize the SOC Module: This is done as soon as the application is started
  717. * to ensure that the MPU is correctly configured. */
  718. socHandle = SOC_init (&socCfg, &errCode);
  719. if (socHandle == NULL)
  720. {
  721. DEBUG(System_printf ("Error: SOC Module Initialization failed [Error code %d]\n", errCode);)
  722. Pcount3DDemo_debugAssert (0);
  723. return -1;
  724. }
  725. gPcount3DDssMCB.socHandle = socHandle;
  726. /* Initialize the Task Parameters. */
  727. Task_Params_init(&taskParams);
  728. taskParams.stackSize = 1536;
  729. gPcount3DDssMCB.initTaskHandle = Task_create(Pcount3DDemo_dssInitTask, &taskParams, NULL);
  730. /* Start BIOS */
  731. BIOS_start();
  732. return 0;
  733. }