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.

mss_main.c 99KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587
  1. /**
  2. * @file mss_main.c
  3. *
  4. * @brief
  5. * This is the main file which implements the millimeter wave Demo
  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. /** @mainpage 3D People Counting Demo for XWR68XX
  40. * [TOC]
  41. * @section intro_sec Introduction
  42. *
  43. * The 3D People Counting Demo shows the indoor people counting capabilities using XWR68xx SoC.
  44. * The demo uses adapted range HWA DPU and DPC offerred by the mmWave SDK (Software Development Kit)
  45. * for range processing on R4F and HWA, and uses advanced Capon beamforming on DSP to estimate
  46. * range, Doppler, azimuth angle and elevation angle of indoor targets.
  47. *
  48. * Please refer to SDK documentation for range HWA DPU and DPC details. The additional adaptions are
  49. * the following:
  50. * - In rangeHWA DPU, modified range FFT scaling settings for HWA to maximize the SNR and dynamic
  51. * range for indoor environment and the particular FFT size we use.
  52. * - In rangeHWA DPC, added support for radar cube format 2.
  53. * - Modified mmwdemo_rfparser.c to output chirp interval and frame period. Also fixed the error
  54. * in Doppler step calculation.
  55. *
  56. * For Capon beamforming technique on DSP, please refer to document included in the packages for details.
  57. *
  58. * Please refer to the users guide for UART output format and chirp configuration details.
  59. *
  60. */
  61. /**************************************************************************
  62. *************************** Include Files ********************************
  63. **************************************************************************/
  64. /* Standard Include Files. */
  65. #include <stdint.h>
  66. #include <stdlib.h>
  67. #include <stddef.h>
  68. #include <string.h>
  69. #include <stdio.h>
  70. #include <math.h>
  71. /* BIOS/XDC Include Files. */
  72. #include <xdc/std.h>
  73. #include <xdc/cfg/global.h>
  74. #include <xdc/runtime/IHeap.h>
  75. #include <xdc/runtime/System.h>
  76. #include <xdc/runtime/Error.h>
  77. #include <xdc/runtime/Memory.h>
  78. #include <ti/sysbios/BIOS.h>
  79. #include <ti/sysbios/knl/Task.h>
  80. #include <ti/sysbios/knl/Event.h>
  81. #include <ti/sysbios/knl/Semaphore.h>
  82. #include <ti/sysbios/knl/Clock.h>
  83. #include <ti/sysbios/heaps/HeapBuf.h>
  84. #include <ti/sysbios/heaps/HeapMem.h>
  85. #include <ti/sysbios/knl/Event.h>
  86. #include <ti/sysbios/family/arm/v7a/Pmu.h>
  87. #include <ti/sysbios/family/arm/v7r/vim/Hwi.h>
  88. #include <ti/sysbios/utils/Load.h>
  89. #include <ti/drivers/osal/MemoryP.h>
  90. /* mmWave SDK Include Files: */
  91. #include <ti/common/sys_common.h>
  92. #include <ti/common/mmwave_sdk_version.h>
  93. #include <ti/drivers/soc/soc.h>
  94. #include <ti/drivers/esm/esm.h>
  95. #include <ti/drivers/crc/crc.h>
  96. #include <ti/drivers/gpio/gpio.h>
  97. #include <ti/drivers/mailbox/mailbox.h>
  98. #include <ti/drivers/pinmux/pinmux.h>
  99. #include <ti/control/mmwave/mmwave.h>
  100. #include <ti/control/dpm/dpm.h>
  101. #include <ti/drivers/osal/DebugP.h>
  102. #include <ti/drivers/uart/UART.h>
  103. #include <ti/utils/cli/cli.h>
  104. #include <ti/utils/mathutils/mathutils.h>
  105. /* Demo Include Files */
  106. #include <people_counting/68xx_3D_people_counting/src/common/mmwdemo_rfparser.h>
  107. #include <people_counting/68xx_3D_people_counting/src/common/mmwdemo_adcconfig.h>
  108. #include <people_counting/68xx_3D_people_counting/src/common/pcount3D_config.h>
  109. #include <people_counting/68xx_3D_people_counting/src/common/pcount3D_output.h>
  110. #include <people_counting/68xx_3D_people_counting/src/common/pcount3D_hwres.h>
  111. #include <people_counting/68xx_3D_people_counting/src/mss/pcount3D_mss.h>
  112. /* Profiler Include Files */
  113. #include <ti/utils/cycleprofiler/cycle_profiler.h>
  114. #include <people_counting/68xx_3D_people_counting/src/mss/tracker_output.h>
  115. #include <common/src/dpc/objdetrangehwa/include/objdetrangehwainternal.h>
  116. #include <common/src/dpc/objdetrangehwa/objdetrangehwa.h>
  117. #include <people_counting/68xx_3D_people_counting/src/common/swpform.h>
  118. /**
  119. * @brief Task Priority settings:
  120. * Mmwave task is at higher priority because of potential async messages from BSS
  121. * that need quick action in real-time.
  122. *
  123. * CLI task must be at a lower priority than object detection
  124. * dpm task priority because the dynamic CLI command handling in the objection detection
  125. * dpm task assumes CLI task is held back during this processing. The alternative
  126. * is to use a semaphore between the two tasks.
  127. */
  128. #define MMWDEMO_CLI_TASK_PRIORITY 2
  129. #define MMWDEMO_TRACKERDPU_TASK_PRIORITY 3
  130. #define MMWDEMO_UARTTX_TASK_PRIORITY 4
  131. #define MMWDEMO_DPC_OBJDET_DPM_TASK_PRIORITY 5
  132. #define MMWDEMO_MMWAVE_CTRL_TASK_PRIORITY 6
  133. #if (MMWDEMO_CLI_TASK_PRIORITY >= MMWDEMO_DPC_OBJDET_DPM_TASK_PRIORITY)
  134. #error CLI task priority must be < Object Detection DPM task priority
  135. #endif
  136. #define DPC_OBJDET_R4F_INSTANCEID (0xFEEDFEED)
  137. #define DEBUG(_x) _x
  138. /**
  139. * @brief
  140. * Global Variable for LDO BYPASS config, PLease consult your
  141. * board/EVM user guide before changing the values here
  142. */
  143. rlRfLdoBypassCfg_t gRFLdoBypassCfg =
  144. {
  145. .ldoBypassEnable = 0, /* 1.0V RF supply 1 and 1.0V RF supply 2 */
  146. .supplyMonIrDrop = 0, /* IR drop of 3% */
  147. .ioSupplyIndicator = 0, /* 3.3 V IO supply */
  148. };
  149. /**************************************************************************
  150. *************************** Global Definitions ***************************
  151. **************************************************************************/
  152. /**
  153. * @brief
  154. * Global Variable for tracking information required by the mmw Demo
  155. */
  156. Pcount3DDemo_MSS_MCB gMmwMssMCB;
  157. extern ObjDetObj *gObjDetObj;
  158. /*! TCMB RAM buffer for object detection DPC */
  159. #define MMWDEMO_OBJDET_LOCALRAM_SIZE (8U * 1024U)
  160. uint8_t gDPCTCM[MMWDEMO_OBJDET_LOCALRAM_SIZE];
  161. #pragma DATA_SECTION(gDPCTCM, ".dpcLocalRam");
  162. #pragma DATA_ALIGN(gDPCTCM, 4);
  163. /*! L3 RAM buffer for object detection DPC */
  164. #pragma DATA_SECTION(gMmwL3, ".l3ram");
  165. uint8_t gMmwL3[MMWAVE_MSSUSED_L3RAM_SIZE];
  166. /**************************************************************************
  167. *************************** Extern Definitions ***************************
  168. **************************************************************************/
  169. extern void MmwDemo_CLIInit(uint8_t taskPriority);
  170. /**************************************************************************
  171. ************************* Millimeter Wave Demo Functions prototype *************
  172. **************************************************************************/
  173. /* MMW demo functions for datapath operation */
  174. static void Pcount3DDemo_dataPathOpen(void);
  175. static int32_t Pcount3DDemo_dataPathConfig (void);
  176. static void Pcount3DDemo_dataPathStart (void);
  177. static void Pcount3DDemo_dataPathStop (void);
  178. static void Pcount3DDemo_handleObjectDetResult(DPM_Buffer *ptrResult);
  179. static void Pcount3DDemo_DPC_ObjectDetection_reportFxn
  180. (
  181. DPM_Report reportType,
  182. uint32_t instanceId,
  183. int32_t errCode,
  184. uint32_t arg0,
  185. uint32_t arg1
  186. );
  187. #ifdef TRACKERPROC_EN
  188. static void MmwDemo_trackerDPUTask(UArg arg0, UArg arg1);
  189. #endif
  190. static void MmwDemo_uartTxTask(UArg arg0, UArg arg1);
  191. /*Pcount3DDemo_transmitProcessedOutput
  192. (
  193. UART_Handle uartHandle,
  194. Pcount3DDemo_output_message_UARTpointCloud *result,
  195. uint32_t frameIdx,
  196. uint8_t subFrameIdx,
  197. Pcount3DDemo_output_message_stats *timingInfo
  198. );*/
  199. static int32_t Pcount3DDemo_DPM_ioctl_blocking
  200. (
  201. DPM_Handle handle,
  202. uint32_t cmd,
  203. void* arg,
  204. uint32_t argLen
  205. );
  206. static int32_t Pcount3DDemo_processPendingDynamicCfgCommands(uint8_t subFrameIndx);
  207. static void Pcount3DDemo_initTask(UArg arg0, UArg arg1);
  208. static void Pcount3DDemo_platformInit(Pcount3DDemo_platformCfg *config);
  209. /* Mmwave control functions */
  210. static void Pcount3DDemo_mmWaveCtrlTask(UArg arg0, UArg arg1);
  211. static int32_t Pcount3DDemo_mmWaveCtrlStop (void);
  212. static int32_t Pcount3DDemo_eventCallbackFxn(uint16_t msgId, uint16_t sbId, uint16_t sbLen, uint8_t *payload);
  213. /* external sleep function when in idle (used in .cfg file) */
  214. void Pcount3DDemo_sleep(void);
  215. /* Edma related functions */
  216. static void Pcount3DDemo_edmaInit(Pcount3DDemo_DataPathObj *obj, uint8_t instance);
  217. static void Pcount3DDemo_edmaOpen(Pcount3DDemo_DataPathObj *obj, uint8_t instance);
  218. static void Pcount3DDemo_EDMA_transferControllerErrorCallbackFxn(EDMA_Handle handle,
  219. EDMA_transferControllerErrorInfo_t *errorInfo);
  220. static void Pcount3DDemo_EDMA_errorCallbackFxn(EDMA_Handle handle, EDMA_errorInfo_t *errorInfo);
  221. /**************************************************************************
  222. ************************* Millimeter Wave Demo Functions **********************
  223. **************************************************************************/
  224. /**
  225. * @b Description
  226. * @n
  227. * EDMA driver init
  228. *
  229. * @param[in] obj Pointer to data path object
  230. * @param[in] instance EDMA instance
  231. *
  232. * @retval
  233. * Not Applicable.
  234. */
  235. static void Pcount3DDemo_edmaInit(Pcount3DDemo_DataPathObj *obj, uint8_t instance)
  236. {
  237. int32_t errorCode;
  238. errorCode = EDMA_init(instance);
  239. if (errorCode != EDMA_NO_ERROR)
  240. {
  241. System_printf ("Debug: EDMA instance %d initialization returned error %d\n", errorCode);
  242. Pcount3DDemo_debugAssert (0);
  243. return;
  244. }
  245. memset(&obj->EDMA_errorInfo, 0, sizeof(obj->EDMA_errorInfo));
  246. memset(&obj->EDMA_transferControllerErrorInfo, 0, sizeof(obj->EDMA_transferControllerErrorInfo));
  247. }
  248. /**
  249. * @b Description
  250. * @n
  251. * Call back function for EDMA CC (Channel controller) error as per EDMA API.
  252. * Declare fatal error if happens, the output errorInfo can be examined if code
  253. * gets trapped here.
  254. */
  255. static void Pcount3DDemo_EDMA_errorCallbackFxn(EDMA_Handle handle, EDMA_errorInfo_t *errorInfo)
  256. {
  257. gMmwMssMCB.dataPathObj.EDMA_errorInfo = *errorInfo;
  258. Pcount3DDemo_debugAssert(0);
  259. }
  260. /**
  261. * @b Description
  262. * @n
  263. * Call back function for EDMA transfer controller error as per EDMA API.
  264. * Declare fatal error if happens, the output errorInfo can be examined if code
  265. * gets trapped here.
  266. */
  267. static void Pcount3DDemo_EDMA_transferControllerErrorCallbackFxn
  268. (
  269. EDMA_Handle handle,
  270. EDMA_transferControllerErrorInfo_t *errorInfo
  271. )
  272. {
  273. gMmwMssMCB.dataPathObj.EDMA_transferControllerErrorInfo = *errorInfo;
  274. Pcount3DDemo_debugAssert(0);
  275. }
  276. /**
  277. * @b Description
  278. * @n
  279. * Open EDMA driver instance
  280. *
  281. * @param[in] obj Pointer to data path object
  282. * @param[in] instance EDMA instance
  283. *
  284. * @retval
  285. * Not Applicable.
  286. */
  287. static void Pcount3DDemo_edmaOpen(Pcount3DDemo_DataPathObj *obj, uint8_t instance)
  288. {
  289. int32_t errCode;
  290. EDMA_instanceInfo_t edmaInstanceInfo;
  291. EDMA_errorConfig_t errorConfig;
  292. obj->edmaHandle = EDMA_open(instance, &errCode, &edmaInstanceInfo);
  293. if (obj->edmaHandle == NULL)
  294. {
  295. Pcount3DDemo_debugAssert (0);
  296. return;
  297. }
  298. errorConfig.isConfigAllEventQueues = true;
  299. errorConfig.isConfigAllTransferControllers = true;
  300. errorConfig.isEventQueueThresholdingEnabled = true;
  301. errorConfig.eventQueueThreshold = EDMA_EVENT_QUEUE_THRESHOLD_MAX;
  302. errorConfig.isEnableAllTransferControllerErrors = true;
  303. errorConfig.callbackFxn = Pcount3DDemo_EDMA_errorCallbackFxn;
  304. errorConfig.transferControllerCallbackFxn = Pcount3DDemo_EDMA_transferControllerErrorCallbackFxn;
  305. if ((errCode = EDMA_configErrorMonitoring(obj->edmaHandle, &errorConfig)) != EDMA_NO_ERROR)
  306. {
  307. //System_printf("Error: EDMA_configErrorMonitoring() failed with errorCode = %d\n", errCode);
  308. Pcount3DDemo_debugAssert (0);
  309. return;
  310. }
  311. }
  312. /**
  313. * @b Description
  314. * @n
  315. * Close EDMA driver instance
  316. *
  317. * @param[in] obj Pointer to data path object
  318. *
  319. * @retval
  320. * Not Applicable.
  321. */
  322. void Pcount3DDemo_edmaClose(Pcount3DDemo_DataPathObj *obj)
  323. {
  324. EDMA_close(obj->edmaHandle);
  325. }
  326. /**
  327. * @b Description
  328. * @n
  329. * HWA driver init
  330. *
  331. * @param[in] obj Pointer to data path object
  332. *
  333. * @retval
  334. * Not Applicable.
  335. */
  336. static void Pcount3DDemo_hwaInit(Pcount3DDemo_DataPathObj *obj)
  337. {
  338. /* Initialize the HWA */
  339. HWA_init();
  340. }
  341. /**
  342. * @b Description
  343. * @n
  344. * Open HWA driver instance
  345. *
  346. * @param[in] obj Pointer to data path object
  347. * @param[in] socHandle SOC driver handle
  348. *
  349. * @retval
  350. * Not Applicable.
  351. */
  352. static void Pcount3DDemo_hwaOpen(Pcount3DDemo_DataPathObj *obj, SOC_Handle socHandle)
  353. {
  354. int32_t errCode;
  355. /* Open the HWA Instance */
  356. obj->hwaHandle = HWA_open(0, socHandle, &errCode);
  357. if (obj->hwaHandle == NULL)
  358. {
  359. //System_printf("Error: Unable to open the HWA Instance err:%d\n",errCode);
  360. Pcount3DDemo_debugAssert (0);
  361. return;
  362. }
  363. }
  364. /**
  365. * @b Description
  366. * @n
  367. * Close HWA driver instance
  368. *
  369. * @param[in] obj Pointer to data path object
  370. *
  371. * @retval
  372. * Not Applicable.
  373. */
  374. void Pcount3DDemo_hwaClose(Pcount3DDemo_DataPathObj *obj)
  375. {
  376. int32_t errCode;
  377. /* Close the HWA Instance */
  378. errCode = HWA_close(obj->hwaHandle);
  379. if (errCode != 0)
  380. {
  381. Pcount3DDemo_debugAssert (0);
  382. return;
  383. }
  384. }
  385. /**
  386. * @b Description
  387. * @n
  388. * Send assert information through CLI.
  389. *
  390. * @param[in] expression Expression for evaluation
  391. * @param[in] file C file that caused assertion
  392. * @param[in] line Line number in C fine that caused assertion
  393. *
  394. */
  395. void _Pcount3DDemo_debugAssert(int32_t expression, const char *file, int32_t line)
  396. {
  397. if (!expression) {
  398. CLI_write ("Exception: %s, line %d.\n",file,line);
  399. }
  400. }
  401. /**
  402. * @b Description
  403. * @n
  404. * Utility function to set the pending state of configuration.
  405. *
  406. * @param[in] subFrameCfg Pointer to Sub-frame specific configuration
  407. * @param[in] offset Configuration structure offset that uniquely identifies the
  408. * configuration to set to the pending state.
  409. *
  410. * @retval None
  411. */
  412. static void Pcount3DDemo_setSubFramePendingState(Pcount3DDemo_SubFrameCfg *subFrameCfg, uint32_t offset)
  413. {
  414. switch (offset)
  415. {
  416. case PCOUNT3DDEMO_ADCBUFCFG_OFFSET:
  417. subFrameCfg->isAdcBufCfgPending = 1;
  418. break;
  419. default:
  420. Pcount3DDemo_debugAssert(0);
  421. break;
  422. }
  423. }
  424. /**
  425. * @b Description
  426. * @n
  427. * Resets (clears) all pending static (non-dynamic) configuration
  428. *
  429. */
  430. void Pcount3DDemo_resetStaticCfgPendingState(void)
  431. {
  432. uint8_t indx;
  433. for(indx = 0; indx < gMmwMssMCB.objDetCommonCfg.numSubFrames; indx++)
  434. {
  435. gMmwMssMCB.subFrameCfg[indx].isAdcBufCfgPending = 0;
  436. }
  437. }
  438. /**
  439. * @b Description
  440. * @n
  441. * Utility function to find out if all configuration (common and sub-frame
  442. * specific dynamic config) is in pending state.
  443. *
  444. * @retval 1 if all configuration (common and sub-frame specific dynamic config)
  445. * is in pending state, else return 0
  446. */
  447. uint8_t Pcount3DDemo_isAllCfgInPendingState(void)
  448. {
  449. uint8_t indx, flag = 1;
  450. for(indx = 0; indx < gMmwMssMCB.objDetCommonCfg.numSubFrames; indx++)
  451. {
  452. flag = flag && (gMmwMssMCB.subFrameCfg[indx].isAdcBufCfgPending == 1);
  453. }
  454. return(flag);
  455. }
  456. /**
  457. * @b Description
  458. * @n
  459. * Utility function to find out if all configuration (common and sub-frame
  460. * specific dynamic config) is in non-pending (cleared) state.
  461. *
  462. * @retval 1 if all configuration (common and sub-frame specific dynamic config)
  463. * is in non-pending state, else return 0
  464. */
  465. uint8_t Pcount3DDemo_isAllCfgInNonPendingState(void)
  466. {
  467. uint8_t indx, flag = 1;
  468. for(indx = 0; indx < gMmwMssMCB.objDetCommonCfg.numSubFrames; indx++)
  469. {
  470. flag = flag && (gMmwMssMCB.subFrameCfg[indx].isAdcBufCfgPending == 0);
  471. }
  472. return(flag);
  473. }
  474. /**
  475. * @b Description
  476. * @n
  477. * Utility function to apply configuration to specified sub-frame
  478. *
  479. * @param[in] srcPtr Pointer to configuration
  480. * @param[in] offset Offset of configuration within the parent structure
  481. * @param[in] size Size of configuration
  482. * @param[in] subFrameNum Sub-frame Number (0 based) to apply to, broadcast to
  483. * all sub-frames if special code MMWDEMO_SUBFRAME_NUM_FRAME_LEVEL_CONFIG
  484. *
  485. * @retval
  486. * Success - 0
  487. * @retval
  488. * Error - <0
  489. */
  490. void Pcount3DDemo_CfgUpdate(void *srcPtr, uint32_t offset, uint32_t size, int8_t subFrameNum)
  491. {
  492. /* if subFrameNum undefined, broadcast to all sub-frames */
  493. if(subFrameNum == PCOUNT3DDEMO_SUBFRAME_NUM_FRAME_LEVEL_CONFIG)
  494. {
  495. uint8_t indx;
  496. for(indx = 0; indx < RL_MAX_SUBFRAMES; indx++)
  497. {
  498. memcpy((void *)((uint32_t) &gMmwMssMCB.subFrameCfg[indx] + offset), srcPtr, size);
  499. Pcount3DDemo_setSubFramePendingState(&gMmwMssMCB.subFrameCfg[indx], offset);
  500. }
  501. }
  502. else
  503. {
  504. /* Apply configuration to specific subframe (or to position zero for the legacy case
  505. where there is no advanced frame config) */
  506. memcpy((void *)((uint32_t) &gMmwMssMCB.subFrameCfg[subFrameNum] + offset), srcPtr, size);
  507. Pcount3DDemo_setSubFramePendingState(&gMmwMssMCB.subFrameCfg[subFrameNum], offset);
  508. }
  509. }
  510. /** @brief Transmits detection data over UART
  511. *
  512. * @param[in] uartHandle UART driver handle
  513. * @param[in] result Pointer to result from object detection DPC processing
  514. * @param[in] timingInfo Pointer to timing information provided from core that runs data path
  515. */
  516. void MmwDemo_uartTxTask(UArg arg0, UArg arg1)
  517. /*static void Pcount3DDemo_transmitProcessedOutput
  518. (
  519. UART_Handle uartHandle,
  520. Pcount3DDemo_output_message_UARTpointCloud *result,
  521. uint32_t frameIdx,
  522. uint8_t subFrameIdx,
  523. Pcount3DDemo_output_message_stats *timingInfo
  524. )*/
  525. {
  526. UART_Handle uartHandle;
  527. Pcount3DDemo_output_message_header header;
  528. uint32_t tlvIdx = 0;
  529. uint32_t packetLen, subFrameIdx, frameIdx;
  530. uint16_t *headerPtr;
  531. Pcount3DDemo_output_message_stats *timingInfo;
  532. Pcount3DDemo_output_message_UARTpointCloud *objOut;
  533. uint32_t sum, n, targetListLength=0, targetIndexLength=0, presenceIndLength=0;
  534. volatile uint32_t startTime;
  535. Pcount3DDemo_output_message_tl tl;
  536. /* Clear message header */
  537. memset((void *)&header, 0, sizeof(Pcount3DDemo_output_message_header));
  538. /* Header: */
  539. header.platform = 0xA6843;
  540. header.magicWord[0] = 0x0102;
  541. header.magicWord[1] = 0x0304;
  542. header.magicWord[2] = 0x0506;
  543. header.magicWord[3] = 0x0708;
  544. header.version = MMWAVE_SDK_VERSION_BUILD |
  545. (MMWAVE_SDK_VERSION_BUGFIX << 8) |
  546. (MMWAVE_SDK_VERSION_MINOR << 16) |
  547. (MMWAVE_SDK_VERSION_MAJOR << 24);
  548. /* wait for new message and process all the messages received from the peer */
  549. while(1)
  550. {
  551. uint32_t numTargets, numIndices;
  552. uint8_t *tList;
  553. uint8_t *tIndex;
  554. Semaphore_pend(gMmwMssMCB.uartTxSemHandle, BIOS_WAIT_FOREVER);
  555. startTime = Cycleprofiler_getTimeStamp();
  556. tlvIdx = 0;
  557. uartHandle = gMmwMssMCB.loggingUartHandle;
  558. objOut = &(gMmwMssMCB.pointCloudToUart);
  559. subFrameIdx = gMmwMssMCB.currSubFrameIdx;
  560. timingInfo = &gMmwMssMCB.subFrameStats[subFrameIdx].outputStats;
  561. frameIdx = gMmwMssMCB.frameStatsFromDSP->frameStartIntCounter;
  562. packetLen = sizeof(Pcount3DDemo_output_message_header);
  563. header.chirpProcessingMargin = timingInfo->interChirpProcessingMargin;
  564. header.frameProcessingTimeInUsec = timingInfo->frameProcessingTimeInUsec;
  565. header.trackingProcessingTimeInUsec = gMmwMssMCB.trackerProcessingTimeInUsec;
  566. header.uartSendingTimeInUsec = gMmwMssMCB.uartProcessingTimeInUsec;
  567. numTargets = gMmwMssMCB.numTargets;
  568. numIndices = gMmwMssMCB.numIndices;
  569. tList = (uint8_t*)gMmwMssMCB.trackerOutput.tList[gMmwMssMCB.trackerOutput.currentDescr];
  570. tIndex = (uint8_t*)gMmwMssMCB.trackerOutput.tIndex[gMmwMssMCB.trackerOutput.currentDescr];
  571. if (objOut->header.length > 0)
  572. {
  573. packetLen += objOut->header.length;
  574. tlvIdx++;
  575. }
  576. if (numTargets > 0)
  577. {
  578. targetListLength = sizeof(Pcount3DDemo_output_message_tl) + numTargets*sizeof(trackerProc_Target);
  579. packetLen += targetListLength;
  580. tlvIdx++;
  581. }
  582. if ((numIndices > 0) && (numTargets > 0))
  583. {
  584. targetIndexLength = sizeof(Pcount3DDemo_output_message_tl) + numIndices*sizeof(trackerProc_TargetIndex);
  585. packetLen += targetIndexLength;
  586. tlvIdx++;
  587. }
  588. if(gMmwMssMCB.presenceDetEnabled)
  589. {
  590. presenceIndLength = sizeof(Pcount3DDemo_output_message_tl) + sizeof(uint32_t);;
  591. packetLen += presenceIndLength;
  592. tlvIdx++;
  593. }
  594. header.numTLVs = tlvIdx;
  595. header.totalPacketLen = packetLen;
  596. header.frameNumber = frameIdx;
  597. header.subFrameNumber = subFrameIdx;
  598. header.checkSum = 0;
  599. headerPtr = (uint16_t *)&header;
  600. for(n=0, sum = 0; n < sizeof(Pcount3DDemo_output_message_header)/sizeof(uint16_t); n++)
  601. sum += *headerPtr++;
  602. header.checkSum = ~((sum >> 16) + (sum & 0xFFFF));
  603. /* Send packet header */
  604. UART_write (uartHandle,
  605. (uint8_t*)&header,
  606. sizeof(Pcount3DDemo_output_message_header));
  607. /* Send detected Objects */
  608. if (objOut->header.length > 0)
  609. {
  610. UART_write (uartHandle,
  611. (uint8_t*)objOut,
  612. objOut->header.length);
  613. }
  614. Task_sleep(1);
  615. /*Send Tracker information*/
  616. if (numTargets > 0)
  617. {
  618. tl.type = MMWDEMO_OUTPUT_MSG_TARGET_LIST;
  619. tl.length = targetListLength;
  620. UART_write(uartHandle, (uint8_t*)&tl, sizeof(Pcount3DDemo_output_message_tl));
  621. UART_write(uartHandle, tList, targetListLength-sizeof(Pcount3DDemo_output_message_tl));
  622. GPIO_toggle(gMmwMssMCB.cfg.platformCfg.SensorStatusGPIO);
  623. }
  624. /*Send Tracker Index Information*/
  625. if ((numIndices > 0) && (numTargets > 0))
  626. {
  627. tl.type = MMWDEMO_OUTPUT_MSG_TARGET_INDEX;
  628. tl.length = targetIndexLength;
  629. UART_write(uartHandle, (uint8_t*)&tl, sizeof(Pcount3DDemo_output_message_tl));
  630. UART_write(uartHandle, tIndex, targetIndexLength-sizeof(Pcount3DDemo_output_message_tl));
  631. }
  632. /* Send Presence TLV if presence detect is enabled */
  633. if(gMmwMssMCB.presenceDetEnabled)
  634. {
  635. tl.type = MMWDEMO_OUTPUT_PRESENCE_IND;
  636. tl.length = presenceIndLength;
  637. UART_write(uartHandle, (uint8_t*)&tl, sizeof(Pcount3DDemo_output_message_tl));
  638. UART_write(uartHandle, (uint8_t*)&(gMmwMssMCB.presenceInd), sizeof(uint32_t));
  639. }
  640. gMmwMssMCB.uartProcessingTimeInUsec = (Cycleprofiler_getTimeStamp() - startTime)/R4F_CLOCK_MHZ;
  641. }
  642. }
  643. /**************************************************************************
  644. ******************** Millimeter Wave Demo control path Functions *****************
  645. **************************************************************************/
  646. /**
  647. * @b Description
  648. * @n
  649. * The function is used to trigger the Front end to stop generating chirps.
  650. *
  651. * @retval
  652. * Not Applicable.
  653. */
  654. static int32_t Pcount3DDemo_mmWaveCtrlStop (void)
  655. {
  656. int32_t errCode = 0;
  657. DebugP_log0("App: Issuing MMWave_stop\n");
  658. /* Stop the mmWave module: */
  659. if (MMWave_stop (gMmwMssMCB.ctrlHandle, &errCode) < 0)
  660. {
  661. MMWave_ErrorLevel errorLevel;
  662. int16_t mmWaveErrorCode;
  663. int16_t subsysErrorCode;
  664. /* Error/Warning: Unable to stop the mmWave module */
  665. MMWave_decodeError (errCode, &errorLevel, &mmWaveErrorCode, &subsysErrorCode);
  666. if (errorLevel == MMWave_ErrorLevel_ERROR)
  667. {
  668. /* Error: Display the error message: */
  669. System_printf ("Error: mmWave Stop failed [Error code: %d Subsystem: %d]\n",
  670. mmWaveErrorCode, subsysErrorCode);
  671. /* Not expected */
  672. Pcount3DDemo_debugAssert(0);
  673. }
  674. else
  675. {
  676. /* Warning: This is treated as a successful stop. */
  677. System_printf ("mmWave Stop error ignored [Error code: %d Subsystem: %d]\n",
  678. mmWaveErrorCode, subsysErrorCode);
  679. }
  680. }
  681. return errCode;
  682. }
  683. /**
  684. * @b Description
  685. * @n
  686. * The task is used to provide an execution context for the mmWave
  687. * control task
  688. *
  689. * @retval
  690. * Not Applicable.
  691. */
  692. static void Pcount3DDemo_mmWaveCtrlTask(UArg arg0, UArg arg1)
  693. {
  694. int32_t errCode;
  695. while (1)
  696. {
  697. /* Execute the mmWave control module: */
  698. if (MMWave_execute (gMmwMssMCB.ctrlHandle, &errCode) < 0)
  699. {
  700. //System_printf ("Error: mmWave control execution failed [Error code %d]\n", errCode);
  701. Pcount3DDemo_debugAssert (0);
  702. }
  703. }
  704. }
  705. /**************************************************************************
  706. ******************** Millimeter Wave Demo data path Functions *******************
  707. **************************************************************************/
  708. /**
  709. * @b Description
  710. * @n
  711. * Help function to make DPM_ioctl blocking until response is reported
  712. *
  713. * @retval
  714. * Success -0
  715. * Failed <0
  716. */
  717. static int32_t Pcount3DDemo_DPM_ioctl_blocking
  718. (
  719. DPM_Handle handle,
  720. uint32_t cmd,
  721. void* arg,
  722. uint32_t argLen
  723. )
  724. {
  725. int32_t retVal = 0;
  726. DebugP_log3("Pcount3DDemo_DPM_ioctl_blocking: cmd = %d, *arg = %d, len = %d\n", cmd, *(uint8_t *)arg, argLen);
  727. retVal = DPM_ioctl(handle,
  728. cmd,
  729. arg,
  730. argLen);
  731. if(retVal == 0)
  732. {
  733. /* Wait until ioctl completed */
  734. Semaphore_pend(gMmwMssMCB.DPMioctlSemHandle, BIOS_WAIT_FOREVER);
  735. }
  736. return(retVal);
  737. }
  738. /**
  739. * @b Description
  740. * @n
  741. * Perform Data path driver open
  742. *
  743. * @retval
  744. * Not Applicable.
  745. */
  746. static void Pcount3DDemo_dataPathOpen(void)
  747. {
  748. gMmwMssMCB.adcBufHandle = MmwDemo_ADCBufOpen(gMmwMssMCB.socHandle);
  749. if(gMmwMssMCB.adcBufHandle == NULL)
  750. {
  751. Pcount3DDemo_debugAssert(0);
  752. }
  753. }
  754. /**
  755. * @b Description
  756. * @n
  757. * The function is used to configure the data path based on the chirp profile.
  758. * After this function is executed, the data path processing will ready to go
  759. * when the ADC buffer starts receiving samples corresponding to the chirps.
  760. *
  761. * @retval
  762. * Success - 0
  763. * @retval
  764. * Error - <0
  765. */
  766. static int32_t Pcount3DDemo_dataPathConfig (void)
  767. {
  768. int32_t errCode;
  769. MMWave_CtrlCfg *ptrCtrlCfg;
  770. Pcount3DDemo_DPC_ObjDet_CommonCfg *objDetCommonCfgDSP;
  771. Pcount3DDemo_SubFrameCfg *subFrameCfg;
  772. int8_t subFrameIndx;
  773. MmwDemo_RFParserOutParams RFparserOutParams;
  774. DPC_ObjectDetectionRangeHWA_PreStartCfg objDetPreStartR4fCfg;
  775. DPC_ObjectDetectionRangeHWA_StaticCfg *staticCfgR4F;
  776. DPC_ObjectDetection_PreStartCfg objDetPreStartDspCfg;
  777. DPC_ObjectDetectionRangeHWA_PreStartCommonCfg preStartCommonCfgHWA;
  778. uint8_t radarCubeFormat = DPIF_RADARCUBE_FORMAT_2;
  779. /* Get data path object and control configuration */
  780. ptrCtrlCfg = &gMmwMssMCB.cfg.ctrlCfg;
  781. objDetCommonCfgDSP = &gMmwMssMCB.objDetCommonCfg;
  782. staticCfgR4F = &objDetPreStartR4fCfg.staticCfg;
  783. /* Get RF frequency scale factor */
  784. gMmwMssMCB.rfFreqScaleFactor = SOC_getDeviceRFFreqScaleFactor(gMmwMssMCB.socHandle, &errCode);
  785. if (errCode < 0)
  786. {
  787. System_printf ("Error: Unable to get RF scale factor [Error:%d]\n", errCode);
  788. Pcount3DDemo_debugAssert(0);
  789. }
  790. objDetCommonCfgDSP->numSubFrames = MmwDemo_RFParser_getNumSubFrames(ptrCtrlCfg);
  791. DEBUG(System_printf("App: Issuing Pre-start Common Config IOCTL to R4F\n");)
  792. /* DPC pre-start common config */
  793. DEBUG(System_printf("App: Issuing Pre-start Common Config IOCTL to DSP\n");)
  794. errCode = Pcount3DDemo_DPM_ioctl_blocking (gMmwMssMCB.objDetDpmHandle,
  795. DPC_OBJDET_IOCTL__STATIC_PRE_START_COMMON_CFG,
  796. objDetCommonCfgDSP,
  797. sizeof (Pcount3DDemo_DPC_ObjDet_CommonCfg));
  798. if (errCode < 0)
  799. {
  800. System_printf ("Error: Unable to send DPC_OBJDET_IOCTL__STATIC_PRE_START_COMMON_CFG [Error:%d]\n", errCode);
  801. goto exit;
  802. }
  803. preStartCommonCfgHWA.numSubFrames = objDetCommonCfgDSP->numSubFrames;
  804. errCode = Pcount3DDemo_DPM_ioctl_blocking (gMmwMssMCB.objDetDpmHandle,
  805. DPC_OBJDETRANGEHWA_IOCTL__STATIC_PRE_START_COMMON_CFG,
  806. &preStartCommonCfgHWA,
  807. sizeof (preStartCommonCfgHWA));
  808. if (errCode < 0)
  809. {
  810. System_printf ("Error: Unable to send DPC_OBJDETRANGEHWA_IOCTL__STATIC_PRE_START_COMMON_CFG [Error:%d]\n", errCode);
  811. goto exit;
  812. }
  813. /* Reason for reverse loop is that when sensor is started, the first sub-frame
  814. * will be active and the ADC configuration needs to be done for that sub-frame
  815. * before starting (ADC buf hardware does not have notion of sub-frame, it will
  816. * be reconfigured every sub-frame). This cannot be alternatively done by calling
  817. * the Pcount3DDemo_ADCBufConfig function only for the first sub-frame because this is
  818. * a utility API that computes the rxChanOffset that is part of ADC dataProperty
  819. * which will be used by range DPU and therefore this computation is required for
  820. * all sub-frames.
  821. */
  822. for(subFrameIndx = objDetCommonCfgDSP->numSubFrames -1; subFrameIndx >= 0;
  823. subFrameIndx--)
  824. {
  825. subFrameCfg = &gMmwMssMCB.subFrameCfg[subFrameIndx];
  826. /*****************************************************************************
  827. * Data path :: Algorithm Configuration
  828. *****************************************************************************/
  829. DEBUG(System_printf("App: Calling MmwDemo_RFParser_parseConfig\n");)
  830. /* Parse the profile and chirp configs and get the valid number of TX Antennas */
  831. errCode = MmwDemo_RFParser_parseConfig(&RFparserOutParams, subFrameIndx,
  832. &gMmwMssMCB.cfg.openCfg, ptrCtrlCfg,
  833. &subFrameCfg->adcBufCfg,
  834. gMmwMssMCB.rfFreqScaleFactor,
  835. 0);
  836. if (errCode != 0)
  837. {
  838. System_printf ("Error: MmwDemo_RFParser_parseConfig [Error:%d]\n", errCode);
  839. goto exit;
  840. }
  841. /* The following code is to enable processing for number of doppler chirps that are
  842. * less than 16 (the minimal numDopplerBins supported in doppler DPU DSP).
  843. * In this case, interpolate to detect better with CFAR tuning. E.g. a 2 -pt FFT will
  844. * be problematic in terms of distinguishing direction of motion */
  845. if (RFparserOutParams.numDopplerChirps <= 8)
  846. {
  847. RFparserOutParams.dopplerStep = RFparserOutParams.dopplerStep / (16 / RFparserOutParams.numDopplerBins);
  848. RFparserOutParams.numDopplerBins = 16;
  849. }
  850. /* Workaround for range DPU limitation for FFT size 1024 and 12 virtual antennas case*/
  851. if ((RFparserOutParams.numVirtualAntennas == 12) && (RFparserOutParams.numRangeBins == 1024))
  852. {
  853. RFparserOutParams.numRangeBins = 1022;
  854. }
  855. subFrameCfg->numChirpsPerChirpEvent = RFparserOutParams.numChirpsPerChirpEvent;
  856. subFrameCfg->adcBufChanDataSize = RFparserOutParams.adcBufChanDataSize;
  857. subFrameCfg->numAdcSamples = RFparserOutParams.numAdcSamples;
  858. subFrameCfg->numChirpsPerSubFrame = RFparserOutParams.numChirpsPerFrame;
  859. subFrameCfg->numVirtualAntennas = RFparserOutParams.numVirtualAntennas;
  860. DEBUG(System_printf("App: Calling MmwDemo_ADCBufConfig\n");)
  861. errCode = MmwDemo_ADCBufConfig(gMmwMssMCB.adcBufHandle,
  862. gMmwMssMCB.cfg.openCfg.chCfg.rxChannelEn,
  863. subFrameCfg->numChirpsPerChirpEvent,
  864. subFrameCfg->adcBufChanDataSize,
  865. &subFrameCfg->adcBufCfg,
  866. &staticCfgR4F->ADCBufData.dataProperty.rxChanOffset[0]);
  867. if (errCode < 0)
  868. {
  869. System_printf("Error: ADCBuf config failed with error[%d]\n", errCode);
  870. Pcount3DDemo_debugAssert (0);
  871. }
  872. if (errCode < 0)
  873. {
  874. goto exit;
  875. }
  876. /* DPC pre-start config R4F HWA*/
  877. {
  878. /***********************************************************************
  879. Pre-start preparation for objdetR4FHWA
  880. ***********************************************************************/
  881. objDetPreStartR4fCfg.subFrameNum = subFrameIndx;
  882. /* Fill static configuration */
  883. staticCfgR4F->ADCBufData.data = (void *)SOC_XWR68XX_MSS_ADCBUF_BASE_ADDRESS;
  884. staticCfgR4F->ADCBufData.dataProperty.adcBits = 2; /* 16-bit */
  885. /* only complex format supported */
  886. Pcount3DDemo_debugAssert(subFrameCfg->adcBufCfg.adcFmt == 0);
  887. if (subFrameCfg->adcBufCfg.iqSwapSel == 1)
  888. {
  889. staticCfgR4F->ADCBufData.dataProperty.dataFmt = DPIF_DATAFORMAT_COMPLEX16_IMRE;
  890. }
  891. else
  892. {
  893. staticCfgR4F->ADCBufData.dataProperty.dataFmt = DPIF_DATAFORMAT_COMPLEX16_REIM;
  894. }
  895. if (subFrameCfg->adcBufCfg.chInterleave == 0)
  896. {
  897. staticCfgR4F->ADCBufData.dataProperty.interleave = DPIF_RXCHAN_INTERLEAVE_MODE;
  898. }
  899. else
  900. {
  901. staticCfgR4F->ADCBufData.dataProperty.interleave = DPIF_RXCHAN_NON_INTERLEAVE_MODE;
  902. }
  903. staticCfgR4F->radarCubeFormat = radarCubeFormat;
  904. staticCfgR4F->ADCBufData.dataProperty.numAdcSamples = RFparserOutParams.numAdcSamples;
  905. staticCfgR4F->ADCBufData.dataProperty.numChirpsPerChirpEvent = RFparserOutParams.numChirpsPerChirpEvent;
  906. staticCfgR4F->ADCBufData.dataProperty.numRxAntennas = RFparserOutParams.numRxAntennas;
  907. staticCfgR4F->ADCBufData.dataSize = RFparserOutParams.numRxAntennas * RFparserOutParams.numAdcSamples * sizeof(cmplx16ImRe_t);
  908. staticCfgR4F->numChirpsPerFrame = RFparserOutParams.numChirpsPerFrame;
  909. staticCfgR4F->numDopplerChirps = RFparserOutParams.numDopplerChirps;
  910. staticCfgR4F->numRangeBins = RFparserOutParams.numRangeBins;
  911. staticCfgR4F->numTxAntennas = RFparserOutParams.numTxAntennas;
  912. staticCfgR4F->numVirtualAntennas = RFparserOutParams.numVirtualAntennas;
  913. if (RFparserOutParams.numRangeBins >= 1022)
  914. {
  915. staticCfgR4F->rangeFFTtuning.fftOutputDivShift = 1;
  916. /*scale 2 stages */
  917. staticCfgR4F->rangeFFTtuning.numLastButterflyStagesToScale = 2;
  918. }
  919. else if (RFparserOutParams.numRangeBins == 512)
  920. {
  921. staticCfgR4F->rangeFFTtuning.fftOutputDivShift = 2;
  922. /*scale last stages */
  923. staticCfgR4F->rangeFFTtuning.numLastButterflyStagesToScale = 1;
  924. }
  925. else
  926. {
  927. /*NS: Changed this value to 2 to match ming's version */
  928. //staticCfgR4F->rangeFFTtuning.fftOutputDivShift = 3;
  929. staticCfgR4F->rangeFFTtuning.fftOutputDivShift = 2;
  930. /*no scaling needed as ADC data is 16-bit and we have 8 bits to grow */
  931. staticCfgR4F->rangeFFTtuning.numLastButterflyStagesToScale = 0;
  932. }
  933. /* Fill dynamic configuration for the sub-frame */
  934. objDetPreStartR4fCfg.dynCfg = subFrameCfg->objDetDynCfg.r4fDynCfg;
  935. DebugP_log1("App: Issuing Pre-start Config IOCTL (subFrameIndx = %d)\n", subFrameIndx);
  936. /* send pre-start config to R4F chain, using blocking call here */
  937. errCode = Pcount3DDemo_DPM_ioctl_blocking (gMmwMssMCB.objDetDpmHandle,
  938. DPC_OBJDETRANGEHWA_IOCTL__STATIC_PRE_START_CFG,
  939. &objDetPreStartR4fCfg,
  940. sizeof (DPC_ObjectDetectionRangeHWA_PreStartCfg));
  941. if (errCode < 0)
  942. {
  943. System_printf ("Error: Unable to send DPC_OBJDETRANGEHWA_IOCTL__STATIC_PRE_START_CFG [Error:%d]\n", errCode);
  944. goto exit;
  945. }
  946. DebugP_log0("App: DPC_OBJDETRANGEHWA_IOCTL__STATIC_PRE_START_CFG is processed \n");
  947. }
  948. /* DPC pre-start config DSP*/
  949. DEBUG(System_printf("App: pre-start config for DSP \n");)
  950. {
  951. DPU_radarProcessConfig_t *pParam_s;
  952. /***********************************************************************
  953. Pre-start preparation for objdetdsp
  954. ***********************************************************************/
  955. /* Reset preStart config */
  956. memset((void *)&objDetPreStartDspCfg, 0, sizeof(DPC_ObjectDetection_PreStartCfg));
  957. /* DPC configuration */
  958. objDetPreStartDspCfg.subFrameNum = subFrameIndx;
  959. objDetPreStartDspCfg.dynCfg = subFrameCfg->objDetDynCfg.dspDynCfg;
  960. pParam_s = &objDetPreStartDspCfg.dynCfg.caponChainCfg;
  961. memcpy((void *)pParam_s, &(gMmwMssMCB.subFrameCfg[subFrameIndx].objDetDynCfg.dspDynCfg.caponChainCfg), sizeof(DPU_radarProcessConfig_t));
  962. pParam_s->numRangeBins = RFparserOutParams.numRangeBins;
  963. pParam_s->numTxAntenna = RFparserOutParams.numTxAntennas;
  964. pParam_s->numPhyRxAntenna = RFparserOutParams.numRxAntennas;
  965. pParam_s->numAntenna = pParam_s->numTxAntenna * pParam_s->numPhyRxAntenna;
  966. if (pParam_s->numTxAntenna > 1)
  967. pParam_s->mimoModeFlag = 1;
  968. else
  969. pParam_s->mimoModeFlag = 0;
  970. pParam_s->numAdcSamplePerChirp = RFparserOutParams.numAdcSamples;
  971. pParam_s->dynamicCfarConfig.rangeRes = RFparserOutParams.rangeStep;
  972. pParam_s->staticCfarConfig.rangeRes = pParam_s->dynamicCfarConfig.rangeRes;
  973. pParam_s->numChirpPerFrame = RFparserOutParams.numDopplerChirps ;
  974. gMmwMssMCB.subFrameCfg[subFrameIndx].objDetDynCfg.dspDynCfg.caponChainCfg.numChirpPerFrame = RFparserOutParams.numDopplerChirps ;
  975. pParam_s->framePeriod = RFparserOutParams.framePeriod;
  976. pParam_s->chirpInterval = RFparserOutParams.chirpInterval;
  977. pParam_s->bandwidth = RFparserOutParams.bandwidth;
  978. pParam_s->centerFreq = RFparserOutParams.centerFreq;
  979. gMmwMssMCB.subFrameCfg[subFrameIndx].objDetDynCfg.dspDynCfg.caponChainCfg.chirpInterval = RFparserOutParams.chirpInterval;
  980. gMmwMssMCB.subFrameCfg[subFrameIndx].objDetDynCfg.dspDynCfg.caponChainCfg.framePeriod = RFparserOutParams.framePeriod;
  981. gMmwMssMCB.subFrameCfg[subFrameIndx].objDetDynCfg.dspDynCfg.caponChainCfg.bandwidth = RFparserOutParams.bandwidth;
  982. gMmwMssMCB.subFrameCfg[subFrameIndx].objDetDynCfg.dspDynCfg.caponChainCfg.centerFreq = RFparserOutParams.centerFreq;
  983. pParam_s->dynamicCfarConfig.dopplerRes = RFparserOutParams.dopplerStep;
  984. pParam_s->dynamicCfarConfig.cfarType = RADARDEMO_DETECTIONCFAR_RA_CASOCFAR; //hardcoded, only method can be used in this chain
  985. pParam_s->dynamicCfarConfig.inputType = RADARDEMO_DETECTIONCFAR_INPUTTYPE_SP; //hardcoded, only method can be used in this chain
  986. pParam_s->staticCfarConfig.cfarType = RADARDEMO_DETECTIONCFAR_RA_CASOCFAR; //hardcoded, only method can be used in this chain
  987. pParam_s->staticCfarConfig.inputType = RADARDEMO_DETECTIONCFAR_INPUTTYPE_SP; //hardcoded, only method can be used in this chain
  988. pParam_s->maxNumDetObj = (uint16_t)MAX_RESOLVED_OBJECTS_PER_FRAME;
  989. /* The L3 memory and radarCube memory usage are reported and saved in @ref Pcount3DDemo_DPC_ObjectDetection_reportFxn.
  990. The memory information is configured here and passed to objdetdsp chain.
  991. */
  992. objDetPreStartDspCfg.dynCfg.radarCubeFormat = radarCubeFormat;
  993. if(gMmwMssMCB.dataPathObj.radarCubeMem.addr != 0)
  994. {
  995. /* Update DPC radar cube configuration */
  996. objDetPreStartDspCfg.shareMemCfg.radarCubeMem.addr = gMmwMssMCB.dataPathObj.radarCubeMem.addr;
  997. objDetPreStartDspCfg.shareMemCfg.radarCubeMem.size = gMmwMssMCB.dataPathObj.radarCubeMem.size;
  998. /* Update DPC L3 RAM configuration */
  999. objDetPreStartDspCfg.shareMemCfg.L3Ram.addr = (void *)((uint32_t)(gMmwMssMCB.dataPathObj.radarCubeMem.addr) +
  1000. gMmwMssMCB.dataPathObj.memUsage.L3RamUsage);
  1001. objDetPreStartDspCfg.shareMemCfg.L3Ram.size =gMmwMssMCB.dataPathObj.memUsage.L3RamTotal - gMmwMssMCB.dataPathObj.memUsage.L3RamUsage;
  1002. /* Convert address for DSP core */
  1003. objDetPreStartDspCfg.shareMemCfg.radarCubeMem.addr = (void *) SOC_translateAddress((uint32_t)objDetPreStartDspCfg.shareMemCfg.radarCubeMem.addr,
  1004. SOC_TranslateAddr_Dir_TO_OTHER_CPU,
  1005. &errCode);
  1006. DebugP_assert ((uint32_t)objDetPreStartDspCfg.shareMemCfg.radarCubeMem.addr != SOC_TRANSLATEADDR_INVALID);
  1007. objDetPreStartDspCfg.shareMemCfg.L3Ram.addr = (void *) SOC_translateAddress((uint32_t)objDetPreStartDspCfg.shareMemCfg.L3Ram.addr,
  1008. SOC_TranslateAddr_Dir_TO_OTHER_CPU,
  1009. &errCode);
  1010. DebugP_assert ((uint32_t)objDetPreStartDspCfg.shareMemCfg.L3Ram.addr != SOC_TRANSLATEADDR_INVALID);
  1011. /* Enable shared memory configuration */
  1012. objDetPreStartDspCfg.shareMemCfg.shareMemEnable = true;
  1013. }
  1014. /* send pre-start config */
  1015. DEBUG(System_printf("App: pre-start config ready to be set to DSP \n");)
  1016. errCode = Pcount3DDemo_DPM_ioctl_blocking (gMmwMssMCB.objDetDpmHandle,
  1017. DPC_OBJDET_IOCTL__STATIC_PRE_START_CFG,
  1018. &objDetPreStartDspCfg,
  1019. sizeof (DPC_ObjectDetection_PreStartCfg));
  1020. DebugP_log0("App: DPC_OBJDET_IOCTL__STATIC_PRE_START_CFG is processed \n");
  1021. if (errCode < 0)
  1022. {
  1023. System_printf ("Error: Unable to send DPC_OBJDET_IOCTL__STATIC_PRE_START_CFG [Error:%d]\n", errCode);
  1024. goto exit;
  1025. }
  1026. }
  1027. }
  1028. exit:
  1029. return errCode;
  1030. }
  1031. #ifdef TRACKERPROC_EN
  1032. /**
  1033. * @b Description
  1034. * @n
  1035. * The function is used to configure the tracker DPU.
  1036. *
  1037. * @retval
  1038. * 0 if no error, error code otherwise.
  1039. */
  1040. int32_t MmwDemo_trackerConfig (void)
  1041. {
  1042. int32_t errCode;
  1043. DebugP_log0("App: Issuing Tracker Static Config IOCTL\n");
  1044. /* DPC pre-start common config */
  1045. //errCode = DPM_ioctl (dataPathObj->objDetDpmHandle,
  1046. errCode = DPM_ioctl (gMmwMssMCB.objDetDpmHandle,
  1047. DPC_OBJDETRANGEHWA_IOCTL__STATIC_TRACKER_CFG,
  1048. &(gMmwMssMCB.trackerCfg),
  1049. sizeof (DPC_ObjectDetection_TrackerConfig));
  1050. if (errCode < 0)
  1051. {
  1052. System_printf ("Error: Unable to send DPC_OBJDETRANGEHWA_IOCTL__TRACKER_STATIC_CFG [Error:%d]\n", errCode);
  1053. goto exit;
  1054. }
  1055. exit:
  1056. return errCode;
  1057. }
  1058. #endif
  1059. /**
  1060. * @b Description
  1061. * @n
  1062. * This function is used to start data path to handle chirps from front end.
  1063. *
  1064. * @retval
  1065. * Not Applicable.
  1066. */
  1067. static void Pcount3DDemo_dataPathStart (void)
  1068. {
  1069. int32_t retVal;
  1070. int32_t pointCloudSize;
  1071. DebugP_log0("App: Issuing DPM_start\n");
  1072. pointCloudSize = MAX_RESOLVED_OBJECTS_PER_FRAME * sizeof(DPIF_PointCloudSpherical);
  1073. gMmwMssMCB.pointCloudFromDSP = (DPIF_PointCloudSpherical *)MemoryP_ctrlAlloc(pointCloudSize, sizeof(float));
  1074. gMmwMssMCB.pointCloudSideInfoFromDSP = (DPIF_PointCloudSideInfo *)MemoryP_ctrlAlloc(MAX_RESOLVED_OBJECTS_PER_FRAME * sizeof(DPIF_PointCloudSideInfo), sizeof(int16_t));
  1075. /* Start the DPM Profile: */
  1076. if ((retVal = DPM_start(gMmwMssMCB.objDetDpmHandle)) < 0)
  1077. {
  1078. /* Error: Unable to start the profile */
  1079. System_printf("Error: Unable to start the DPM [Error: %d]\n", retVal);
  1080. Pcount3DDemo_debugAssert(0);
  1081. }
  1082. /* Wait until start completed */
  1083. Semaphore_pend(gMmwMssMCB.DPMstartSemHandle, BIOS_WAIT_FOREVER);
  1084. DebugP_log0("App: DPM_start Done (post Semaphore_pend on reportFxn reporting start)\n");
  1085. }
  1086. /**
  1087. * @b Description
  1088. * @n
  1089. * This function is used to stop data path.
  1090. *
  1091. * @retval
  1092. * Not Applicable.
  1093. */
  1094. static void Pcount3DDemo_dataPathStop (void)
  1095. {
  1096. int32_t retVal;
  1097. int32_t pointCloudSize;
  1098. DebugP_log0("App: Issuing DPM_stop\n");
  1099. pointCloudSize = MAX_RESOLVED_OBJECTS_PER_FRAME * sizeof(Pcount3DDemo_output_message_point);
  1100. MemoryP_ctrlFree(gMmwMssMCB.pointCloudFromDSP, pointCloudSize);
  1101. retVal = DPM_stop (gMmwMssMCB.objDetDpmHandle);
  1102. if (retVal < 0)
  1103. {
  1104. System_printf ("DPM_stop failed[Error code %d]\n", retVal);
  1105. Pcount3DDemo_debugAssert(0);
  1106. }
  1107. }
  1108. /**
  1109. * @b Description
  1110. * @n
  1111. * Registered event function to mmwave which is invoked when an event from the
  1112. * BSS is received.
  1113. *
  1114. * @param[in] msgId
  1115. * Message Identifier
  1116. * @param[in] sbId
  1117. * Subblock identifier
  1118. * @param[in] sbLen
  1119. * Length of the subblock
  1120. * @param[in] payload
  1121. * Pointer to the payload buffer
  1122. *
  1123. * @retval
  1124. * Always return 0
  1125. */
  1126. static int32_t Pcount3DDemo_eventCallbackFxn(uint16_t msgId, uint16_t sbId, uint16_t sbLen, uint8_t *payload)
  1127. {
  1128. uint16_t asyncSB = RL_GET_SBID_FROM_UNIQ_SBID(sbId);
  1129. /* Process the received message: */
  1130. switch (msgId)
  1131. {
  1132. case RL_RF_ASYNC_EVENT_MSG:
  1133. {
  1134. /* Received Asychronous Message: */
  1135. switch (asyncSB)
  1136. {
  1137. case RL_RF_AE_CPUFAULT_SB:
  1138. {
  1139. Pcount3DDemo_debugAssert(0);
  1140. break;
  1141. }
  1142. case RL_RF_AE_ESMFAULT_SB:
  1143. {
  1144. Pcount3DDemo_debugAssert(0);
  1145. break;
  1146. }
  1147. case RL_RF_AE_ANALOG_FAULT_SB:
  1148. {
  1149. Pcount3DDemo_debugAssert(0);
  1150. break;
  1151. }
  1152. case RL_RF_AE_INITCALIBSTATUS_SB:
  1153. {
  1154. rlRfInitComplete_t* ptrRFInitCompleteMessage;
  1155. uint32_t calibrationStatus;
  1156. /* Get the RF-Init completion message: */
  1157. ptrRFInitCompleteMessage = (rlRfInitComplete_t*)payload;
  1158. calibrationStatus = ptrRFInitCompleteMessage->calibStatus & 0xFFFU;
  1159. /* Display the calibration status: */
  1160. CLI_write ("Debug: Init Calibration Status = 0x%x\n", calibrationStatus);
  1161. break;
  1162. }
  1163. case RL_RF_AE_FRAME_TRIGGER_RDY_SB:
  1164. {
  1165. gMmwMssMCB.stats.frameTriggerReady++;
  1166. break;
  1167. }
  1168. case RL_RF_AE_MON_TIMING_FAIL_REPORT_SB:
  1169. {
  1170. gMmwMssMCB.stats.failedTimingReports++;
  1171. break;
  1172. }
  1173. case RL_RF_AE_RUN_TIME_CALIB_REPORT_SB:
  1174. {
  1175. gMmwMssMCB.stats.calibrationReports++;
  1176. break;
  1177. }
  1178. case RL_RF_AE_FRAME_END_SB:
  1179. {
  1180. gMmwMssMCB.stats.sensorStopped++;
  1181. DebugP_log0("App: BSS stop (frame end) received\n");
  1182. Pcount3DDemo_dataPathStop();
  1183. break;
  1184. }
  1185. default:
  1186. {
  1187. System_printf ("Error: Asynchronous Event SB Id %d not handled\n", asyncSB);
  1188. break;
  1189. }
  1190. }
  1191. break;
  1192. }
  1193. /* Async Event from MMWL */
  1194. case RL_MMWL_ASYNC_EVENT_MSG:
  1195. {
  1196. switch (asyncSB)
  1197. {
  1198. case RL_MMWL_AE_MISMATCH_REPORT:
  1199. {
  1200. /* link reports protocol error in the async report from BSS */
  1201. Pcount3DDemo_debugAssert(0);
  1202. break;
  1203. }
  1204. case RL_MMWL_AE_INTERNALERR_REPORT:
  1205. {
  1206. /* link reports internal error during BSS communication */
  1207. Pcount3DDemo_debugAssert(0);
  1208. break;
  1209. }
  1210. }
  1211. break;
  1212. }
  1213. default:
  1214. {
  1215. System_printf ("Error: Asynchronous message %d is NOT handled\n", msgId);
  1216. break;
  1217. }
  1218. }
  1219. return 0;
  1220. }
  1221. /**
  1222. * @b Description
  1223. * @n
  1224. * DPM Registered Report Handler. The DPM Module uses this registered function to notify
  1225. * the application about DPM reports.
  1226. *
  1227. * @param[in] reportType
  1228. * Report Type
  1229. * @param[in] instanceId
  1230. * Instance Identifier which generated the report
  1231. * @param[in] errCode
  1232. * Error code if any.
  1233. * @param[in] arg0
  1234. * Argument 0 interpreted with the report type
  1235. * @param[in] arg1
  1236. * Argument 1 interpreted with the report type
  1237. *
  1238. * @retval
  1239. * Not Applicable.
  1240. */
  1241. static void Pcount3DDemo_DPC_ObjectDetection_reportFxn
  1242. (
  1243. DPM_Report reportType,
  1244. uint32_t instanceId,
  1245. int32_t errCode,
  1246. uint32_t arg0,
  1247. uint32_t arg1
  1248. )
  1249. {
  1250. /* Only errors are logged on the console: */
  1251. if ((errCode != 0) )
  1252. {
  1253. /* Error: Detected log on the console and die all errors are FATAL currently. */
  1254. System_printf ("Error: DPM Report %d received with error:%d arg0:0x%x arg1:0x%x\n",
  1255. reportType, errCode, arg0, arg1);
  1256. DebugP_assert (0);
  1257. }
  1258. /* Processing further is based on the reports received: This is the control of the profile
  1259. * state machine: */
  1260. switch (reportType)
  1261. {
  1262. case DPM_Report_IOCTL:
  1263. {
  1264. /*****************************************************************
  1265. * DPC has been configured without an error:
  1266. * - This is an indication that the profile configuration commands
  1267. * went through without any issues.
  1268. *****************************************************************/
  1269. DebugP_log1("App: DPM Report IOCTL, command = %d\n", arg0);
  1270. if (arg0 == DPC_OBJDETRANGEHWA_IOCTL__STATIC_PRE_START_CFG)
  1271. {
  1272. DPC_ObjectDetectionRangeHWA_PreStartCfg *cfg;
  1273. DPC_ObjectDetectionRangeHWA_preStartCfg_memUsage *memUsage;
  1274. cfg = (DPC_ObjectDetectionRangeHWA_PreStartCfg*)arg1;
  1275. /* Save radar cube memory information, it will be passed to objdetdsp chain for inter-frame processing */
  1276. memcpy((void *)&gMmwMssMCB.dataPathObj.radarCubeMem, (void *)&cfg->radarCubeMem,
  1277. sizeof(DPC_ObjectDetectionRangeHWA_preStartCfg_radarCubeMem));
  1278. /* Get memory usage and print the usage */
  1279. memUsage = &cfg->memUsage;
  1280. /* Save memory usage, it will be passed to objdetdsp chain for inter-frame processing */
  1281. memcpy((void *)&gMmwMssMCB.dataPathObj.memUsage, (void *)memUsage,
  1282. sizeof(DPC_ObjectDetectionRangeHWA_preStartCfg_memUsage));
  1283. System_printf("============ Heap Memory Stats ============\n");
  1284. System_printf("%20s %12s %12s %12s %12s\n", " ", "Size", "Used", "Free", "DPCUsed");
  1285. System_printf("%20s %12d %12d %12d %12d\n", "System Heap(TCMB)",
  1286. memUsage->SystemHeapTotal, memUsage->SystemHeapUsed,
  1287. memUsage->SystemHeapTotal - memUsage->SystemHeapUsed,
  1288. memUsage->SystemHeapDPCUsed);
  1289. System_printf("%20s %12d %12d %12d\n", "L3",
  1290. memUsage->L3RamTotal,
  1291. memUsage->L3RamUsage,
  1292. memUsage->L3RamTotal - memUsage->L3RamUsage);
  1293. System_printf("%20s %12d %12d %12d\n", "localRam(TCMB)",
  1294. memUsage->CoreLocalRamTotal,
  1295. memUsage->CoreLocalRamUsage,
  1296. memUsage->CoreLocalRamTotal - memUsage->CoreLocalRamUsage);
  1297. }
  1298. switch(arg0)
  1299. {
  1300. /* The following ioctls take longer time to finish. It causes DPM to queue IOCTL requests on DSS before
  1301. * they are handled. However DPM has limited pipe queues, hence adding sync points in demo to avoid
  1302. * sending too many such ioctls to DSS at a time.
  1303. * The semaphore blocks CLI task to wait for the response from DSS before sending the next ioctl.
  1304. */
  1305. case DPC_OBJDETRANGEHWA_IOCTL__STATIC_PRE_START_COMMON_CFG:
  1306. case DPC_OBJDET_IOCTL__STATIC_PRE_START_COMMON_CFG:
  1307. case DPC_OBJDET_IOCTL__STATIC_PRE_START_CFG:
  1308. #ifdef TRACKERPROC_EN
  1309. case DPC_OBJDETRANGEHWA_IOCTL__STATIC_TRACKER_CFG:
  1310. #endif
  1311. /* The following ioctl returns memory information needs to be used in configuration follows the ioctl.
  1312. * The semaphore blocks CLI task to wiat for the response from DPC before further execution.
  1313. */
  1314. case DPC_OBJDETRANGEHWA_IOCTL__STATIC_PRE_START_CFG:
  1315. System_printf("DPM IOCTL report msg = %d\n", arg0 );
  1316. Semaphore_post(gMmwMssMCB.DPMioctlSemHandle);
  1317. break;
  1318. default:
  1319. break;
  1320. }
  1321. break;
  1322. }
  1323. case DPM_Report_DPC_STARTED:
  1324. {
  1325. /*****************************************************************
  1326. * DPC has been started without an error:
  1327. * - notify sensor management task that DPC is started.
  1328. *****************************************************************/
  1329. DebugP_log0("App: DPM Report DPC Started\n");
  1330. gMmwMssMCB.stats.dpmStartEvents++;
  1331. /* every sensor start should cause 2 DPM start events due to distributed domain
  1332. Wait for both the events before proceeding with remaining steps */
  1333. if (gMmwMssMCB.stats.dpmStartEvents % 2 == 0)
  1334. {
  1335. Semaphore_post(gMmwMssMCB.DPMstartSemHandle);
  1336. }
  1337. break;
  1338. }
  1339. case DPM_Report_NOTIFY_DPC_RESULT:
  1340. {
  1341. /*****************************************************************
  1342. * datapath has finished frame processing, results are reported
  1343. *****************************************************************/
  1344. DPM_Buffer* ptrResult;
  1345. /* Get the result: */
  1346. ptrResult = (DPM_Buffer*)arg0;
  1347. Pcount3DDemo_handleObjectDetResult(ptrResult);
  1348. break;
  1349. }
  1350. case DPM_Report_DPC_ASSERT:
  1351. {
  1352. DPM_DPCAssert* ptrAssert;
  1353. /*****************************************************************
  1354. * DPC Fault has been detected:
  1355. * - This implies that the DPC has crashed.
  1356. * - The argument0 points to the DPC assertion information
  1357. *****************************************************************/
  1358. ptrAssert = (DPM_DPCAssert*)arg0;
  1359. CLI_write("Obj Det DPC Exception: %s, line %d.\n", ptrAssert->fileName,
  1360. ptrAssert->lineNum);
  1361. break;
  1362. }
  1363. case DPM_Report_DPC_STOPPED:
  1364. {
  1365. /*****************************************************************
  1366. * DPC has been stopped without an error:
  1367. * - This implies that the DPC can either be reconfigured or
  1368. * restarted.
  1369. *****************************************************************/
  1370. DebugP_log0("App: DPM Report DPC Stopped\n");
  1371. gMmwMssMCB.stats.dpmStopEvents++;
  1372. /* every sensor stop should cause 2 DPM stop events due to distributed domain
  1373. Wait for both the events before proceeding with remaining steps */
  1374. if (gMmwMssMCB.stats.dpmStopEvents % 2 == 0)
  1375. {
  1376. Semaphore_post(gMmwMssMCB.DPMstopSemHandle);
  1377. }
  1378. break;
  1379. }
  1380. case DPM_Report_DPC_INFO:
  1381. case DPM_Report_NOTIFY_DPC_RESULT_ACKED:
  1382. {
  1383. /* Currently objDetDsp does not use this feature. */
  1384. break;
  1385. }
  1386. default:
  1387. {
  1388. DebugP_assert (0);
  1389. break;
  1390. }
  1391. }
  1392. return;
  1393. }
  1394. /**
  1395. * @b Description
  1396. * @n
  1397. * Utility function to get next sub-frame index
  1398. *
  1399. * @param[in] currentIndx Current sub-frame index
  1400. * @param[in] numSubFrames Number of sub-frames
  1401. *
  1402. * @retval
  1403. * Index of next sub-frame.
  1404. */
  1405. static uint8_t Pcount3DDemo_getNextSubFrameIndx(uint8_t currentIndx, uint8_t numSubFrames)
  1406. {
  1407. uint8_t nextIndx;
  1408. if (currentIndx == (numSubFrames - 1))
  1409. {
  1410. nextIndx = 0;
  1411. }
  1412. else
  1413. {
  1414. nextIndx = currentIndx + 1;
  1415. }
  1416. return(nextIndx);
  1417. }
  1418. /**
  1419. * @b Description
  1420. * @n
  1421. * Utility function to get previous sub-frame index
  1422. *
  1423. * @param[in] currentIndx Current sub-frame index
  1424. * @param[in] numSubFrames Number of sub-frames
  1425. *
  1426. * @retval
  1427. * Index of previous sub-frame
  1428. */
  1429. /*
  1430. static uint8_t Pcount3DDemo_getPrevSubFrameIndx(uint8_t currentIndx, uint8_t numSubFrames)
  1431. {
  1432. uint8_t prevIndx;
  1433. if (currentIndx == 0)
  1434. {
  1435. prevIndx = numSubFrames - 1;
  1436. }
  1437. else
  1438. {
  1439. prevIndx = currentIndx - 1;
  1440. }
  1441. return(prevIndx);
  1442. }
  1443. */
  1444. /**
  1445. * @b Description
  1446. * @n
  1447. * Processes any pending dynamic configuration commands for the specified
  1448. * sub-frame by fanning out to the respective DPUs using IOCTL interface, and
  1449. * resets (clears) the pending state after processing.
  1450. *
  1451. * @param[in] subFrameIndx Sub-frame index of desired sub-frame to process
  1452. *
  1453. * @retval
  1454. * Success - 0
  1455. * @retval
  1456. * Error - <0
  1457. */
  1458. static int32_t Pcount3DDemo_processPendingDynamicCfgCommands(uint8_t subFrameIndx)
  1459. {
  1460. int32_t retVal =0;
  1461. return(retVal);
  1462. }
  1463. /**
  1464. * @b Description
  1465. * @n
  1466. * Function to handle frame processing results from DPC
  1467. *
  1468. * @param[in] ptrResult Pointer to DPC result
  1469. *
  1470. * @retval
  1471. * Not Applicable.
  1472. */
  1473. static void Pcount3DDemo_handleObjectDetResult
  1474. (
  1475. DPM_Buffer *ptrResult
  1476. )
  1477. {
  1478. int32_t retVal;
  1479. int32_t pntIdx;
  1480. DPC_ObjectDetection_ExecuteResultExportedInfo exportInfo;
  1481. DPC_ObjectDetection_ExecuteResult *dpcResults;
  1482. volatile uint32_t startTime;
  1483. uint8_t nextSubFrameIdx;
  1484. uint8_t numSubFrames;
  1485. uint8_t currSubFrameIdx;
  1486. Pcount3DDemo_SubFrameStats *currSubFrameStats;
  1487. float * heatmapBuff;
  1488. radarProcessOutput * outputFromDSP;
  1489. /*****************************************************************
  1490. * datapath has finished frame processing, results are reported
  1491. *****************************************************************/
  1492. /* Validate DPC results buffer */
  1493. DebugP_assert (ptrResult->size[0] == sizeof(DPC_ObjectDetection_ExecuteResult));
  1494. /* Translate the address: */
  1495. dpcResults = (DPC_ObjectDetection_ExecuteResult *)SOC_translateAddress((uint32_t)ptrResult->ptrBuffer[0],
  1496. SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
  1497. &retVal);
  1498. DebugP_assert ((uint32_t)dpcResults != SOC_TRANSLATEADDR_INVALID);
  1499. /* Translate the address: */
  1500. gMmwMssMCB.frameStatsFromDSP = (DPC_ObjectDetection_Stats *)SOC_translateAddress((uint32_t)ptrResult->ptrBuffer[1],
  1501. SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
  1502. &retVal);
  1503. DebugP_assert ((uint32_t)(gMmwMssMCB.frameStatsFromDSP) != SOC_TRANSLATEADDR_INVALID);
  1504. outputFromDSP = &(dpcResults->objOut);
  1505. heatmapBuff = outputFromDSP->heatMapOut.data;
  1506. heatmapBuff = (float *)SOC_translateAddress((uint32_t)heatmapBuff,
  1507. SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
  1508. &retVal);
  1509. //DebugP_log2("Pcount3DDemo_handleObjectDetResult: heatmap = (float *)0x%x, size = %d \n", (uint32_t)heatmapBuff, outputFromDSP->heatMapOut.dataSize );
  1510. gMmwMssMCB.heatMapOutFromDSP.dataSize = outputFromDSP->heatMapOut.dataSize;
  1511. gMmwMssMCB.heatMapOutFromDSP.data = outputFromDSP->heatMapOut.data;
  1512. //copy to the format for output, and to future tracker
  1513. gMmwMssMCB.pointCloudToUart.header.length = sizeof(Pcount3DDemo_output_message_tl) + sizeof(Pcount3DDemo_output_message_point_unit) + sizeof(Pcount3DDemo_output_message_UARTpoint) * outputFromDSP->pointCloudOut.object_count;
  1514. if ( outputFromDSP->pointCloudOut.object_count == 0)
  1515. gMmwMssMCB.pointCloudToUart.header.length = 0;
  1516. gMmwMssMCB.pointCloudToUart.header.type = MMWDEMO_OUTPUT_MSG_POINT_CLOUD;
  1517. gMmwMssMCB.pointCloudToUart.pointUint.azimuthUnit = 0.01f;
  1518. gMmwMssMCB.pointCloudToUart.pointUint.elevationUnit = 0.01f;
  1519. gMmwMssMCB.pointCloudToUart.pointUint.rangeUnit = 0.00025f;
  1520. gMmwMssMCB.pointCloudToUart.pointUint.dopplerUnit = 0.00028f;
  1521. gMmwMssMCB.pointCloudToUart.pointUint.snrUint = 0.04f;
  1522. gMmwMssMCB.numDetectedPoints = outputFromDSP->pointCloudOut.object_count;
  1523. for (pntIdx = 0; pntIdx < (int32_t)outputFromDSP->pointCloudOut.object_count; pntIdx++ )
  1524. {
  1525. //output to host
  1526. gMmwMssMCB.pointCloudToUart.point[pntIdx].azimuth = (int8_t)round(outputFromDSP->pointCloudOut.pointCloud[pntIdx].azimuthAngle/ gMmwMssMCB.pointCloudToUart.pointUint.azimuthUnit);
  1527. gMmwMssMCB.pointCloudToUart.point[pntIdx].elevation = (int8_t)round((outputFromDSP->pointCloudOut.pointCloud[pntIdx].elevAngle)/ gMmwMssMCB.pointCloudToUart.pointUint.elevationUnit);
  1528. gMmwMssMCB.pointCloudToUart.point[pntIdx].range = (uint16_t)round(outputFromDSP->pointCloudOut.pointCloud[pntIdx].range / gMmwMssMCB.pointCloudToUart.pointUint.rangeUnit);
  1529. gMmwMssMCB.pointCloudToUart.point[pntIdx].doppler = (int16_t)round(outputFromDSP->pointCloudOut.pointCloud[pntIdx].velocity / gMmwMssMCB.pointCloudToUart.pointUint.dopplerUnit);
  1530. gMmwMssMCB.pointCloudToUart.point[pntIdx].snr = (uint16_t)round((float)outputFromDSP->pointCloudOut.snr[pntIdx].snr * 0.125f / gMmwMssMCB.pointCloudToUart.pointUint.snrUint);
  1531. //future tracker input
  1532. gMmwMssMCB.pointCloudFromDSP[pntIdx].azimuthAngle = outputFromDSP->pointCloudOut.pointCloud[pntIdx].azimuthAngle;// - gMmwMssMCB.trackerCfg.trackerDpuCfg.staticCfg.sensorAzimuthTilt;
  1533. gMmwMssMCB.pointCloudFromDSP[pntIdx].elevAngle = outputFromDSP->pointCloudOut.pointCloud[pntIdx].elevAngle;
  1534. gMmwMssMCB.pointCloudFromDSP[pntIdx].range = outputFromDSP->pointCloudOut.pointCloud[pntIdx].range;
  1535. gMmwMssMCB.pointCloudFromDSP[pntIdx].velocity = outputFromDSP->pointCloudOut.pointCloud[pntIdx].velocity;
  1536. gMmwMssMCB.pointCloudSideInfoFromDSP[pntIdx].snr = (float)outputFromDSP->pointCloudOut.snr[pntIdx].snr * 0.125f;
  1537. }
  1538. numSubFrames = gMmwMssMCB.objDetCommonCfg.numSubFrames;
  1539. currSubFrameIdx = dpcResults->subFrameIdx;
  1540. currSubFrameStats = &gMmwMssMCB.subFrameStats[currSubFrameIdx];
  1541. gMmwMssMCB.currSubFrameIdx = currSubFrameIdx;
  1542. /*****************************************************************
  1543. * Transmit results
  1544. *****************************************************************/
  1545. startTime = Cycleprofiler_getTimeStamp();
  1546. currSubFrameStats->outputStats.interChirpProcessingMargin = gMmwMssMCB.subFrameStats[currSubFrameIdx].outputStats.interChirpProcessingMargin;
  1547. currSubFrameStats->outputStats.interFrameProcessingTime = gMmwMssMCB.frameStatsFromDSP->interFrameExecTimeInUsec;
  1548. currSubFrameStats->outputStats.interFrameCPULoad = (uint32_t) (100.f * (float) gMmwMssMCB.frameStatsFromDSP->interFrameExecTimeInUsec / gMmwMssMCB.subFrameCfg[currSubFrameIdx].objDetDynCfg.dspDynCfg.caponChainCfg.framePeriod);
  1549. currSubFrameStats->outputStats.frameProcessingTimeInUsec = gMmwMssMCB.frameStatsFromDSP->activeFrameProcTimeInUsec;
  1550. currSubFrameStats->outputStats.activeFrameCPULoad = (uint32_t) (100.f * (float) gMmwMssMCB.frameStatsFromDSP->activeFrameProcTimeInUsec /
  1551. (gMmwMssMCB.subFrameCfg[currSubFrameIdx].objDetDynCfg.dspDynCfg.caponChainCfg.framePeriod - gMmwMssMCB.subFrameCfg[currSubFrameIdx].objDetDynCfg.dspDynCfg.caponChainCfg.chirpInterval
  1552. * (float)gMmwMssMCB.subFrameCfg[currSubFrameIdx].objDetDynCfg.dspDynCfg.caponChainCfg.numChirpPerFrame) ) ;
  1553. /*****************************************************************
  1554. * Send notification to data path after results are handled --
  1555. * all data are local now, release the memory to DSP
  1556. *****************************************************************/
  1557. /* Indicate result consumed and end of frame/sub-frame processing */
  1558. exportInfo.subFrameIdx = currSubFrameIdx;
  1559. retVal = DPM_ioctl (gMmwMssMCB.objDetDpmHandle,
  1560. DPC_OBJDET_IOCTL__DYNAMIC_EXECUTE_RESULT_EXPORTED,
  1561. &exportInfo,
  1562. sizeof (DPC_ObjectDetection_ExecuteResultExportedInfo));
  1563. if (retVal < 0) {
  1564. System_printf ("Error: DPM DPC_OBJDET_IOCTL__DYNAMIC_EXECUTE_RESULT_EXPORTED failed [Error code %d]\n",
  1565. retVal);
  1566. Pcount3DDemo_debugAssert (0);
  1567. }
  1568. /* Run the tracker DPU */
  1569. #ifdef TRACKERPROC_EN
  1570. /* Run the tracker DPU*/
  1571. Semaphore_post(gMmwMssMCB.trackerDPUSemHandle);
  1572. #endif
  1573. /* Transmit processing results for the frame */
  1574. Semaphore_post(gMmwMssMCB.uartTxSemHandle);
  1575. /*
  1576. Pcount3DDemo_transmitProcessedOutput(gMmwMssMCB.loggingUartHandle,
  1577. &(gMmwMssMCB.pointCloudToUart),
  1578. frameStatsDSS->frameStartIntCounter,
  1579. dpcResults->subFrameIdx,
  1580. &currSubFrameStats->outputStats);*/
  1581. /* Update current frame transmit time */
  1582. currSubFrameStats->outputStats.transmitOutputTime = (Cycleprofiler_getTimeStamp() - startTime)/R4F_CLOCK_MHZ; /* In micro seconds */
  1583. /*****************************************************************
  1584. * Handle dynamic pending configuration
  1585. * For non-advanced frame case:
  1586. * process all pending dynamic config commands.
  1587. * For advanced-frame case:
  1588. * Process next sub-frame related pending dynamic config commands.
  1589. * If the next sub-frame was the first sub-frame of the frame,
  1590. * then process common (sub-frame independent) pending dynamic config
  1591. * commands.
  1592. *****************************************************************/
  1593. startTime = Cycleprofiler_getTimeStamp();
  1594. nextSubFrameIdx = Pcount3DDemo_getNextSubFrameIndx(currSubFrameIdx, numSubFrames);
  1595. retVal = Pcount3DDemo_processPendingDynamicCfgCommands(nextSubFrameIdx);
  1596. if (retVal != 0)
  1597. {
  1598. System_printf ("Error: Executing Pending Dynamic Configuration Commands [Error code %d]\n",
  1599. retVal);
  1600. Pcount3DDemo_debugAssert (0);
  1601. }
  1602. currSubFrameStats->pendingConfigProcTime = (Cycleprofiler_getTimeStamp() - startTime)/R4F_CLOCK_MHZ;
  1603. /*****************************************************************
  1604. * Prepare for subFrame switch
  1605. *****************************************************************/
  1606. if(numSubFrames > 1)
  1607. {
  1608. Pcount3DDemo_SubFrameCfg *nextSubFrameCfg;
  1609. uint16_t dummyRxChanOffset[SYS_COMMON_NUM_RX_CHANNEL];
  1610. startTime = Cycleprofiler_getTimeStamp();
  1611. nextSubFrameCfg = &gMmwMssMCB.subFrameCfg[nextSubFrameIdx];
  1612. /* Configure ADC for next sub-frame */
  1613. retVal = MmwDemo_ADCBufConfig(gMmwMssMCB.adcBufHandle,
  1614. gMmwMssMCB.cfg.openCfg.chCfg.rxChannelEn,
  1615. nextSubFrameCfg->numChirpsPerChirpEvent,
  1616. nextSubFrameCfg->adcBufChanDataSize,
  1617. &nextSubFrameCfg->adcBufCfg,
  1618. &dummyRxChanOffset[0]);
  1619. if(retVal < 0)
  1620. {
  1621. System_printf("Error: ADCBuf config failed with error[%d]\n", retVal);
  1622. Pcount3DDemo_debugAssert (0);
  1623. }
  1624. currSubFrameStats->subFramePreparationTime = (Cycleprofiler_getTimeStamp() - startTime)/R4F_CLOCK_MHZ;
  1625. }
  1626. else
  1627. {
  1628. currSubFrameStats->subFramePreparationTime = 0;
  1629. }
  1630. }
  1631. #ifdef TRACKERPROC_EN
  1632. void MmwDemo_trackerDPUTask(UArg arg0, UArg arg1)
  1633. {
  1634. volatile uint32_t startTime;
  1635. int32_t retVal;
  1636. DPU_TrackerProc_OutParams outTrackerProc;
  1637. //DPC_TrackerResults trackerResults;
  1638. //int32_t errCode;
  1639. while(1)
  1640. {
  1641. Semaphore_pend(gMmwMssMCB.trackerDPUSemHandle, BIOS_WAIT_FOREVER);
  1642. startTime = Cycleprofiler_getTimeStamp();
  1643. retVal = DPU_TrackerProc_process(gObjDetObj->dpuTrackerObj, gMmwMssMCB.numDetectedPoints,
  1644. gMmwMssMCB.pointCloudFromDSP, gMmwMssMCB.pointCloudSideInfoFromDSP, &outTrackerProc);
  1645. DebugP_assert(retVal == 0);
  1646. gMmwMssMCB.trackerOutput.currentDescr = outTrackerProc.currentTargetDesc;
  1647. gMmwMssMCB.numTargets = outTrackerProc.numTargets[outTrackerProc.currentTargetDesc];
  1648. gMmwMssMCB.trackerOutput.tList[gMmwMssMCB.trackerOutput.currentDescr] = ((trackerProcObjType*)gObjDetObj->dpuTrackerObj)->targetDescrHandle->tList[outTrackerProc.currentTargetDesc];
  1649. gMmwMssMCB.numIndices = outTrackerProc.numIndices[outTrackerProc.currentTargetDesc];
  1650. gMmwMssMCB.trackerOutput.tIndex[gMmwMssMCB.trackerOutput.currentDescr] = ((trackerProcObjType*)gObjDetObj->dpuTrackerObj)->targetDescrHandle->tIndex[outTrackerProc.currentTargetDesc];
  1651. gMmwMssMCB.presenceInd = outTrackerProc.presenceInd[outTrackerProc.currentTargetDesc];
  1652. gMmwMssMCB.trackerProcessingTimeInUsec = (float)(Cycleprofiler_getTimeStamp() - startTime)/(float)R4F_CLOCK_MHZ;
  1653. }
  1654. }
  1655. #endif
  1656. /**
  1657. * @b Description
  1658. * @n
  1659. * DPM Execution Task which executes the DPM Instance which manages the
  1660. * HL Profiles executing on the MSS.
  1661. *
  1662. * @retval
  1663. * Not Applicable.
  1664. */
  1665. static void mmwDemo_mssDPMTask(UArg arg0, UArg arg1)
  1666. {
  1667. int32_t errCode;
  1668. DPM_Buffer result;
  1669. while (1)
  1670. {
  1671. /* Execute the DPM module: */
  1672. errCode = DPM_execute (gMmwMssMCB.objDetDpmHandle, &result);
  1673. if (errCode < 0)
  1674. {
  1675. System_printf ("Error: DPM execution failed [Error code %d]\n", errCode);
  1676. }
  1677. }
  1678. }
  1679. /**************************************************************************
  1680. ******************** Millimeter Wave Demo sensor management Functions **********
  1681. **************************************************************************/
  1682. /**
  1683. * @b Description
  1684. * @n
  1685. * mmw demo helper Function to do one time sensor initialization.
  1686. * User need to fill gMmwMssMCB.cfg.openCfg before calling this function
  1687. *
  1688. * @param[in] isFirstTimeOpen If true then issues MMwave_open
  1689. *
  1690. * @retval
  1691. * Success - 0
  1692. * @retval
  1693. * Error - <0
  1694. */
  1695. int32_t Pcount3DDemo_openSensor(bool isFirstTimeOpen)
  1696. {
  1697. int32_t errCode;
  1698. MMWave_ErrorLevel errorLevel;
  1699. int16_t mmWaveErrorCode;
  1700. int16_t subsysErrorCode;
  1701. int32_t retVal;
  1702. /* Open mmWave module, this is only done once */
  1703. if (isFirstTimeOpen == true)
  1704. {
  1705. /*Set LDO bypas configuration */
  1706. System_printf ("Debug: Sending rlRfSetLdoBypassConfig with %d %d %d\n",
  1707. gRFLdoBypassCfg.ldoBypassEnable,
  1708. gRFLdoBypassCfg.supplyMonIrDrop,
  1709. gRFLdoBypassCfg.ioSupplyIndicator);
  1710. retVal = rlRfSetLdoBypassConfig(RL_DEVICE_MAP_INTERNAL_BSS, (rlRfLdoBypassCfg_t*)&gRFLdoBypassCfg);
  1711. if(retVal != 0)
  1712. {
  1713. System_printf("Error: rlRfSetLdoBypassConfig retVal=%d\n", retVal);
  1714. return -1;
  1715. }
  1716. /* Open mmWave module, this is only done once */
  1717. /* Setup the calibration frequency: */
  1718. gMmwMssMCB.cfg.openCfg.freqLimitLow = 600U;
  1719. gMmwMssMCB.cfg.openCfg.freqLimitHigh = 640U;
  1720. /* start/stop async events */
  1721. gMmwMssMCB.cfg.openCfg.disableFrameStartAsyncEvent = false;
  1722. gMmwMssMCB.cfg.openCfg.disableFrameStopAsyncEvent = false;
  1723. /* No custom calibration: */
  1724. gMmwMssMCB.cfg.openCfg.useCustomCalibration = false;
  1725. gMmwMssMCB.cfg.openCfg.customCalibrationEnableMask = 0x0;
  1726. /* calibration monitoring base time unit
  1727. * setting it to one frame duration as the demo doesnt support any
  1728. * monitoring related functionality
  1729. */
  1730. gMmwMssMCB.cfg.openCfg.calibMonTimeUnit = 1;
  1731. /* Open the mmWave module: */
  1732. if (MMWave_open (gMmwMssMCB.ctrlHandle, &gMmwMssMCB.cfg.openCfg, NULL, &errCode) < 0)
  1733. {
  1734. /* Error: decode and Report the error */
  1735. MMWave_decodeError (errCode, &errorLevel, &mmWaveErrorCode, &subsysErrorCode);
  1736. System_printf ("Error: mmWave Open failed [Error code: %d Subsystem: %d]\n",
  1737. mmWaveErrorCode, subsysErrorCode);
  1738. return -1;
  1739. }
  1740. #if 0 // seems to be LVDS related only
  1741. /*Set up HSI clock*/
  1742. if(MmwDemo_mssSetHsiClk() < 0)
  1743. {
  1744. System_printf ("Error: MmwDemo_mssSetHsiClk failed.\n");
  1745. return -1;
  1746. }
  1747. #endif
  1748. /* Open the datapath modules that runs on MSS */
  1749. Pcount3DDemo_dataPathOpen();
  1750. }
  1751. return 0;
  1752. }
  1753. /**
  1754. * @b Description
  1755. * @n
  1756. * MMW demo helper Function to configure sensor. User need to fill gMmwMssMCB.cfg.ctrlCfg and
  1757. * add profiles/chirp to mmWave before calling this function
  1758. *
  1759. * @retval
  1760. * Success - 0
  1761. * @retval
  1762. * Error - <0
  1763. */
  1764. int32_t Pcount3DDemo_configSensor(void)
  1765. {
  1766. int32_t errCode = 0;
  1767. /* Configure the mmWave module: */
  1768. if (MMWave_config (gMmwMssMCB.ctrlHandle, &gMmwMssMCB.cfg.ctrlCfg, &errCode) < 0)
  1769. {
  1770. MMWave_ErrorLevel errorLevel;
  1771. int16_t mmWaveErrorCode;
  1772. int16_t subsysErrorCode;
  1773. /* Error: Report the error */
  1774. MMWave_decodeError (errCode, &errorLevel, &mmWaveErrorCode, &subsysErrorCode);
  1775. System_printf ("Error: mmWave Config failed [Error code: %d Subsystem: %d]\n",
  1776. mmWaveErrorCode, subsysErrorCode);
  1777. }
  1778. else
  1779. {
  1780. errCode = Pcount3DDemo_dataPathConfig();
  1781. if (errCode < 0)
  1782. goto exit;
  1783. #ifdef TRACKERPROC_EN
  1784. errCode = MmwDemo_trackerConfig();
  1785. if (errCode < 0)
  1786. goto exit;
  1787. #endif
  1788. }
  1789. exit:
  1790. return errCode;
  1791. }
  1792. /**
  1793. * @b Description
  1794. * @n
  1795. * mmw demo helper Function to start sensor.
  1796. *
  1797. * @retval
  1798. * Success - 0
  1799. * @retval
  1800. * Error - <0
  1801. */
  1802. int32_t Pcount3DDemo_startSensor(void)
  1803. {
  1804. int32_t errCode;
  1805. MMWave_CalibrationCfg calibrationCfg;
  1806. /*****************************************************************************
  1807. * Data path :: start data path first - this will pend for DPC to ack
  1808. *****************************************************************************/
  1809. Pcount3DDemo_dataPathStart();
  1810. /*****************************************************************************
  1811. * RF :: now start the RF and the real time ticking
  1812. *****************************************************************************/
  1813. /* Initialize the calibration configuration: */
  1814. memset ((void *)&calibrationCfg, 0, sizeof(MMWave_CalibrationCfg));
  1815. /* Populate the calibration configuration: */
  1816. calibrationCfg.dfeDataOutputMode = gMmwMssMCB.cfg.ctrlCfg.dfeDataOutputMode;
  1817. calibrationCfg.u.chirpCalibrationCfg.enableCalibration = false;//true;
  1818. calibrationCfg.u.chirpCalibrationCfg.enablePeriodicity = false;//true;
  1819. calibrationCfg.u.chirpCalibrationCfg.periodicTimeInFrames = 10U;
  1820. DebugP_log0("App: MMWave_start Issued\n");
  1821. System_printf("Starting Sensor (issuing MMWave_start)\n");
  1822. /* Start the mmWave module: The configuration has been applied successfully. */
  1823. if (MMWave_start(gMmwMssMCB.ctrlHandle, &calibrationCfg, &errCode) < 0)
  1824. {
  1825. MMWave_ErrorLevel errorLevel;
  1826. int16_t mmWaveErrorCode;
  1827. int16_t subsysErrorCode;
  1828. /* Error/Warning: Unable to stop the mmWave module */
  1829. MMWave_decodeError (errCode, &errorLevel, &mmWaveErrorCode, &subsysErrorCode);
  1830. System_printf ("Error: mmWave Start failed [mmWave Error: %d Subsys: %d]\n", mmWaveErrorCode, subsysErrorCode);
  1831. return -1;
  1832. }
  1833. /*****************************************************************************
  1834. * The sensor has been started successfully. Switch on the LED
  1835. *****************************************************************************/
  1836. GPIO_write (gMmwMssMCB.cfg.platformCfg.SensorStatusGPIO, 1U);
  1837. gMmwMssMCB.sensorStartCount++;
  1838. return 0;
  1839. }
  1840. /**
  1841. * @b Description
  1842. * @n
  1843. * Epilog processing after sensor has stopped
  1844. *
  1845. * @retval None
  1846. */
  1847. static void Pcount3DDemo_sensorStopEpilog(void)
  1848. {
  1849. Task_Stat stat;
  1850. Hwi_StackInfo stackInfo;
  1851. Bool stackOverflow;
  1852. /* Print task statistics, note data path has completely stopped due to
  1853. * end of frame, so we can do non-real time processing like prints on
  1854. * console */
  1855. System_printf("Data Path Stopped (last frame processing done)\n");
  1856. System_printf("============================================\n");
  1857. System_printf("MSS Task Stack Usage (Note: Task Stack Usage) ==========\n");
  1858. System_printf("%20s %12s %12s %12s\n", "Task Name", "Size", "Used", "Free");
  1859. Task_stat(gMmwMssMCB.taskHandles.initTask, &stat);
  1860. System_printf("%20s %12d %12d %12d\n", "Init",
  1861. stat.stackSize, stat.used, stat.stackSize - stat.used);
  1862. Task_stat(gMmwMssMCB.taskHandles.mmwaveCtrl, &stat);
  1863. System_printf("%20s %12d %12d %12d\n", "Mmwave Control",
  1864. stat.stackSize, stat.used, stat.stackSize - stat.used);
  1865. Task_stat(gMmwMssMCB.taskHandles.objDetDpmTask, &stat);
  1866. System_printf("%20s %12d %12d %12d\n", "ObjDet DPM",
  1867. stat.stackSize, stat.used, stat.stackSize - stat.used);
  1868. System_printf("HWI Stack (same as System Stack) Usage ============\n");
  1869. stackOverflow = Hwi_getStackInfo(&stackInfo, TRUE);
  1870. if (stackOverflow == TRUE)
  1871. {
  1872. System_printf("HWI Stack overflowed\n");
  1873. Pcount3DDemo_debugAssert(0);
  1874. }
  1875. else
  1876. {
  1877. System_printf("%20s %12s %12s %12s\n", " ", "Size", "Used", "Free");
  1878. System_printf("%20s %12d %12d %12d\n", " ",
  1879. stackInfo.hwiStackSize, stackInfo.hwiStackPeak,
  1880. stackInfo.hwiStackSize - stackInfo.hwiStackPeak);
  1881. }
  1882. }
  1883. /**
  1884. * @b Description
  1885. * @n
  1886. * Stops the RF and datapath for the sensor. Blocks until both operation are completed.
  1887. * Prints epilog at the end.
  1888. *
  1889. * @retval None
  1890. */
  1891. void Pcount3DDemo_stopSensor(void)
  1892. {
  1893. /* Stop sensor RF , data path will be stopped after RF stop is completed */
  1894. Pcount3DDemo_mmWaveCtrlStop();
  1895. /* Wait until DPM_stop is completed */
  1896. Semaphore_pend(gMmwMssMCB.DPMstopSemHandle, BIOS_WAIT_FOREVER);
  1897. /* Print epilog */
  1898. Pcount3DDemo_sensorStopEpilog();
  1899. /* The sensor has been stopped successfully. Switch off the LED */
  1900. GPIO_write (gMmwMssMCB.cfg.platformCfg.SensorStatusGPIO, 0U);
  1901. gMmwMssMCB.sensorStopCount++;
  1902. /* print for user */
  1903. System_printf("Sensor has been stopped: startCount: %d stopCount %d\n",
  1904. gMmwMssMCB.sensorStartCount,gMmwMssMCB.sensorStopCount);
  1905. }
  1906. /**
  1907. * @b Description
  1908. * @n
  1909. * Call back function that was registered during config time and is going
  1910. * to be called in DPC processing at the beginning of frame/sub-frame processing,
  1911. * we use this to issue BIOS calls for computing CPU load during inter-frame
  1912. *
  1913. * @param[in] subFrameIndx Sub-frame index of the sub-frame during which processing
  1914. * this function was called.
  1915. *
  1916. * @retval None
  1917. */
  1918. static void Pcount3DDemo_DPC_ObjectDetection_processFrameBeginCallBackFxn(uint8_t subFrameIndx)
  1919. {
  1920. Load_update();
  1921. gMmwMssMCB.subFrameStats[subFrameIndx].outputStats.interFrameCPULoad = Load_getCPULoad();
  1922. }
  1923. /**
  1924. * @b Description
  1925. * @n
  1926. * Call back function that was registered during config time and is going
  1927. * to be called in DPC processing at the beginning of inter-frame/inter-sub-frame processing,
  1928. * we use this to issue BIOS calls for computing CPU load during active frame (chirping)
  1929. *
  1930. * @param[in] subFrameIndx Sub-frame index of the sub-frame during which processing
  1931. * this function was called.
  1932. *
  1933. * @retval None
  1934. */
  1935. static void Pcount3DDemo_DPC_ObjectDetection_processInterFrameCallBackFxn(uint8_t subFrameIndx)
  1936. {
  1937. Load_update();
  1938. gMmwMssMCB.subFrameStats[subFrameIndx].outputStats.activeFrameCPULoad = Load_getCPULoad();
  1939. }
  1940. /**************************************************************************
  1941. ******************** Millimeter Wave Demo init Functions ************************
  1942. **************************************************************************/
  1943. /**
  1944. * @b Description
  1945. * @n
  1946. * Platform specific hardware initialization.
  1947. *
  1948. * @param[in] config Platform initialization configuraiton
  1949. *
  1950. * @retval
  1951. * Not Applicable.
  1952. */
  1953. static void Pcount3DDemo_platformInit(Pcount3DDemo_platformCfg *config)
  1954. {
  1955. /* Setup the PINMUX to bring out the UART-1 */
  1956. Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINN5_PADBE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
  1957. Pinmux_Set_FuncSel(SOC_XWR68XX_PINN5_PADBE, SOC_XWR68XX_PINN5_PADBE_MSS_UARTA_TX);
  1958. Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINN4_PADBD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
  1959. Pinmux_Set_FuncSel(SOC_XWR68XX_PINN4_PADBD, SOC_XWR68XX_PINN4_PADBD_MSS_UARTA_RX);
  1960. /* Setup the PINMUX to bring out the UART-3 */
  1961. Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINF14_PADAJ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
  1962. Pinmux_Set_FuncSel(SOC_XWR68XX_PINF14_PADAJ, SOC_XWR68XX_PINF14_PADAJ_MSS_UARTB_TX);
  1963. /**********************************************************************
  1964. * Setup the PINMUX:
  1965. * - GPIO Output: Configure pin K13 as GPIO_2 output
  1966. **********************************************************************/
  1967. Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINK13_PADAZ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
  1968. Pinmux_Set_FuncSel(SOC_XWR68XX_PINK13_PADAZ, SOC_XWR68XX_PINK13_PADAZ_GPIO_2);
  1969. /**********************************************************************
  1970. * Setup the GPIO:
  1971. * - GPIO Output: Configure pin K13 as GPIO_2 output
  1972. **********************************************************************/
  1973. config->SensorStatusGPIO = SOC_XWR68XX_GPIO_2;
  1974. /* Initialize the DEMO configuration: */
  1975. config->sysClockFrequency = MSS_SYS_VCLK;
  1976. config->loggingBaudRate = 921600;
  1977. config->commandBaudRate = 115200;
  1978. /**********************************************************************
  1979. * Setup the DS3 LED on the EVM connected to GPIO_2
  1980. **********************************************************************/
  1981. GPIO_setConfig (config->SensorStatusGPIO, GPIO_CFG_OUTPUT);
  1982. }
  1983. /**
  1984. * @b Description
  1985. * @n
  1986. * System Initialization Task which initializes the various
  1987. * components in the system.
  1988. *
  1989. * @retval
  1990. * Not Applicable.
  1991. */
  1992. static void Pcount3DDemo_initTask(UArg arg0, UArg arg1)
  1993. {
  1994. int32_t errCode;
  1995. MMWave_InitCfg initCfg;
  1996. UART_Params uartParams;
  1997. Task_Params taskParams;
  1998. Semaphore_Params semParams;
  1999. DPM_InitCfg dpmInitCfg;
  2000. DMA_Params dmaParams;
  2001. DMA_Handle dmaHandle;
  2002. DPC_ObjectDetectionRangeHWA_InitParams objDetInitParams;
  2003. // int32_t i;
  2004. /* Debug Message: */
  2005. System_printf("Debug: Launched the Initialization Task\n");
  2006. /*****************************************************************************
  2007. * Initialize the mmWave SDK components:
  2008. *****************************************************************************/
  2009. /* Initialize the UART */
  2010. UART_init();
  2011. /* Initialize the DMA for UART */
  2012. DMA_init ();
  2013. /* Open the DMA Instance */
  2014. DMA_Params_init(&dmaParams);
  2015. dmaHandle = DMA_open(0, &dmaParams, &errCode);
  2016. if (dmaHandle == NULL)
  2017. {
  2018. printf ("Error: Unable to open the DMA Instance [Error code %d]\n", errCode);
  2019. return;
  2020. }
  2021. /* Initialize the GPIO */
  2022. GPIO_init();
  2023. /* Initialize the Mailbox */
  2024. Mailbox_init(MAILBOX_TYPE_MSS);
  2025. /* Platform specific configuration */
  2026. Pcount3DDemo_platformInit(&gMmwMssMCB.cfg.platformCfg);
  2027. /*****************************************************************************
  2028. * Open the mmWave SDK components:
  2029. *****************************************************************************/
  2030. /* Setup the default UART Parameters */
  2031. UART_Params_init(&uartParams);
  2032. uartParams.clockFrequency = gMmwMssMCB.cfg.platformCfg.sysClockFrequency;
  2033. uartParams.baudRate = gMmwMssMCB.cfg.platformCfg.commandBaudRate;
  2034. uartParams.isPinMuxDone = 1;
  2035. /* Open the UART Instance */
  2036. gMmwMssMCB.commandUartHandle = UART_open(0, &uartParams);
  2037. if (gMmwMssMCB.commandUartHandle == NULL)
  2038. {
  2039. Pcount3DDemo_debugAssert (0);
  2040. return;
  2041. }
  2042. /* Setup the default UART Parameters */
  2043. UART_Params_init(&uartParams);
  2044. uartParams.writeDataMode = UART_DATA_BINARY;
  2045. uartParams.readDataMode = UART_DATA_BINARY;
  2046. uartParams.clockFrequency = gMmwMssMCB.cfg.platformCfg.sysClockFrequency;
  2047. uartParams.baudRate = gMmwMssMCB.cfg.platformCfg.loggingBaudRate;
  2048. uartParams.isPinMuxDone = 1U;
  2049. uartParams.dmaHandle = dmaHandle;
  2050. uartParams.txDMAChannel = UART_DMA_TX_CHANNEL;
  2051. uartParams.rxDMAChannel = UART_DMA_RX_CHANNEL;
  2052. /* Open the Logging UART Instance: */
  2053. gMmwMssMCB.loggingUartHandle = UART_open(1, &uartParams);
  2054. if (gMmwMssMCB.loggingUartHandle == NULL)
  2055. {
  2056. System_printf("Error: Unable to open the Logging UART Instance\n");
  2057. Pcount3DDemo_debugAssert (0);
  2058. return;
  2059. }
  2060. /* Create binary semaphores which is used to signal DPM_start/DPM_stop/DPM_ioctl is done
  2061. * to the sensor management task. The signalling (Semaphore_post) will be done
  2062. * from DPM registered report function (which will execute in the DPM execute task context). */
  2063. Semaphore_Params_init(&semParams);
  2064. semParams.mode = Semaphore_Mode_BINARY;
  2065. gMmwMssMCB.DPMstartSemHandle = Semaphore_create(0, &semParams, NULL);
  2066. gMmwMssMCB.DPMstopSemHandle = Semaphore_create(0, &semParams, NULL);
  2067. gMmwMssMCB.DPMioctlSemHandle = Semaphore_create(0, &semParams, NULL);
  2068. /* Open EDMA driver */
  2069. Pcount3DDemo_edmaInit(&gMmwMssMCB.dataPathObj, DPC_OBJDET_R4F_EDMA_INSTANCE);
  2070. /* Use EDMA instance 0 on MSS */
  2071. Pcount3DDemo_edmaOpen(&gMmwMssMCB.dataPathObj, DPC_OBJDET_R4F_EDMA_INSTANCE);
  2072. Pcount3DDemo_hwaInit(&gMmwMssMCB.dataPathObj);
  2073. Pcount3DDemo_hwaOpen(&gMmwMssMCB.dataPathObj, gMmwMssMCB.socHandle);
  2074. /*****************************************************************************
  2075. * mmWave: Initialization of the high level module
  2076. *****************************************************************************/
  2077. /* Initialize the mmWave control init configuration */
  2078. memset ((void*)&initCfg, 0 , sizeof(MMWave_InitCfg));
  2079. /* Populate the init configuration: */
  2080. initCfg.domain = MMWave_Domain_MSS;
  2081. initCfg.socHandle = gMmwMssMCB.socHandle;
  2082. initCfg.eventFxn = Pcount3DDemo_eventCallbackFxn;
  2083. initCfg.linkCRCCfg.useCRCDriver = 1U;
  2084. initCfg.linkCRCCfg.crcChannel = CRC_Channel_CH1;
  2085. initCfg.cfgMode = MMWave_ConfigurationMode_FULL;
  2086. initCfg.executionMode = MMWave_ExecutionMode_ISOLATION;
  2087. /* Initialize and setup the mmWave Control module */
  2088. gMmwMssMCB.ctrlHandle = MMWave_init (&initCfg, &errCode);
  2089. if (gMmwMssMCB.ctrlHandle == NULL)
  2090. {
  2091. /* Error: Unable to initialize the mmWave control module */
  2092. System_printf ("Error: mmWave Control Initialization failed [Error code %d]\n", errCode);
  2093. Pcount3DDemo_debugAssert (0);
  2094. return;
  2095. }
  2096. System_printf ("Debug: mmWave Control Initialization was successful\n");
  2097. /* Synchronization: This will synchronize the execution of the control module
  2098. * between the domains. This is a prerequiste and always needs to be invoked. */
  2099. if (MMWave_sync (gMmwMssMCB.ctrlHandle, &errCode) < 0)
  2100. {
  2101. /* Error: Unable to synchronize the mmWave control module */
  2102. System_printf ("Error: mmWave Control Synchronization failed [Error code %d]\n", errCode);
  2103. Pcount3DDemo_debugAssert (0);
  2104. return;
  2105. }
  2106. System_printf ("Debug: mmWave Control Synchronization was successful\n");
  2107. /*****************************************************************************
  2108. * Launch the mmWave control execution task
  2109. * - This should have a higher priroity than any other task which uses the
  2110. * mmWave control API
  2111. *****************************************************************************/
  2112. Task_Params_init(&taskParams);
  2113. taskParams.priority = MMWDEMO_MMWAVE_CTRL_TASK_PRIORITY;
  2114. taskParams.stackSize = 2800;
  2115. gMmwMssMCB.taskHandles.mmwaveCtrl = Task_create(Pcount3DDemo_mmWaveCtrlTask, &taskParams, NULL);
  2116. /*****************************************************************************
  2117. * Create a task to do DMA based UART data transfer
  2118. *****************************************************************************/
  2119. /* Create a binary semaphore for application task to pend */
  2120. Semaphore_Params_init(&semParams);
  2121. semParams.mode = Semaphore_Mode_BINARY;
  2122. gMmwMssMCB.uartTxSemHandle = Semaphore_create(0, &semParams, NULL);
  2123. Task_Params_init(&taskParams);
  2124. taskParams.priority = MMWDEMO_UARTTX_TASK_PRIORITY;
  2125. taskParams.stackSize = 800;
  2126. Task_create(MmwDemo_uartTxTask, &taskParams, NULL);
  2127. /*****************************************************************************
  2128. * Initialization of the DPM Module:
  2129. *****************************************************************************/
  2130. memset ((void *)&objDetInitParams, 0, sizeof(DPC_ObjectDetectionRangeHWA_InitParams));
  2131. /* Note this must be after Pcount3DDemo_dataPathOpen() above which opens the hwa */
  2132. objDetInitParams.L3ramCfg.addr = (void *)&gMmwL3[0];
  2133. objDetInitParams.L3ramCfg.size = sizeof(gMmwL3);
  2134. objDetInitParams.CoreLocalRamCfg.addr = &gDPCTCM[0];
  2135. objDetInitParams.CoreLocalRamCfg.size = sizeof(gDPCTCM);
  2136. objDetInitParams.edmaHandle = gMmwMssMCB.dataPathObj.edmaHandle;
  2137. objDetInitParams.hwaHandle = gMmwMssMCB.dataPathObj.hwaHandle;
  2138. /* DPC Call-back config */
  2139. objDetInitParams.processCallBackFxn.processInterFrameBeginCallBackFxn =
  2140. Pcount3DDemo_DPC_ObjectDetection_processInterFrameCallBackFxn;
  2141. objDetInitParams.processCallBackFxn.processFrameBeginCallBackFxn =
  2142. Pcount3DDemo_DPC_ObjectDetection_processFrameBeginCallBackFxn;
  2143. /* Setup the configuration: */
  2144. memset ((void *)&dpmInitCfg, 0, sizeof(DPM_InitCfg));
  2145. dpmInitCfg.socHandle = gMmwMssMCB.socHandle;
  2146. dpmInitCfg.ptrProcChainCfg = &gDPC_ObjDetRangeHWACfg;;
  2147. dpmInitCfg.instanceId = DPC_OBJDET_R4F_INSTANCEID;
  2148. dpmInitCfg.domain = DPM_Domain_DISTRIBUTED;
  2149. dpmInitCfg.reportFxn = Pcount3DDemo_DPC_ObjectDetection_reportFxn;
  2150. dpmInitCfg.arg = &objDetInitParams;
  2151. dpmInitCfg.argSize = sizeof(DPC_ObjectDetectionRangeHWA_InitParams);
  2152. /* Initialize the DPM Module: */
  2153. gMmwMssMCB.objDetDpmHandle = DPM_init (&dpmInitCfg, &errCode);
  2154. if (gMmwMssMCB.objDetDpmHandle == NULL)
  2155. {
  2156. System_printf ("Error: Unable to initialize the DPM Module [Error: %d]\n", errCode);
  2157. Pcount3DDemo_debugAssert (0);
  2158. return;
  2159. }
  2160. /* Synchronization: This will synchronize the execution of the datapath module
  2161. * between the domains. This is a prerequiste and always needs to be invoked. */
  2162. while (1)
  2163. {
  2164. int32_t syncStatus;
  2165. /* Get the synchronization status: */
  2166. syncStatus = DPM_synch (gMmwMssMCB.objDetDpmHandle, &errCode);
  2167. if (syncStatus < 0)
  2168. {
  2169. /* Error: Unable to synchronize the framework */
  2170. System_printf ("Error: DPM Synchronization failed [Error code %d]\n", errCode);
  2171. Pcount3DDemo_debugAssert (0);
  2172. return;
  2173. }
  2174. if (syncStatus == 1)
  2175. {
  2176. /* Synchronization acheived: */
  2177. break;
  2178. }
  2179. /* Sleep and poll again: */
  2180. Task_sleep(1);
  2181. }
  2182. #ifdef TRACKERPROC_EN
  2183. /*****************************************************************************
  2184. * Create a task to run tracker DPU at lower priority than HWA DPC
  2185. *****************************************************************************/
  2186. /* Create a binary semaphore for application task to pend */
  2187. Semaphore_Params_init(&semParams);
  2188. semParams.mode = Semaphore_Mode_BINARY;
  2189. gMmwMssMCB.trackerDPUSemHandle = Semaphore_create(0, &semParams, NULL);
  2190. Task_Params_init(&taskParams);
  2191. taskParams.priority = MMWDEMO_TRACKERDPU_TASK_PRIORITY;
  2192. taskParams.stackSize = 7*1024;
  2193. Task_create(MmwDemo_trackerDPUTask, &taskParams, NULL);
  2194. #endif
  2195. /* Launch the DPM Task */
  2196. Task_Params_init(&taskParams);
  2197. taskParams.priority = MMWDEMO_DPC_OBJDET_DPM_TASK_PRIORITY;
  2198. taskParams.stackSize = 7*1024;
  2199. gMmwMssMCB.taskHandles.objDetDpmTask = Task_create(mmwDemo_mssDPMTask, &taskParams, NULL);
  2200. /*****************************************************************************
  2201. * Initialize the Profiler
  2202. *****************************************************************************/
  2203. Cycleprofiler_init();
  2204. /*****************************************************************************
  2205. * Initialize the CLI Module:
  2206. *****************************************************************************/
  2207. Pcount3DDemo_CLIInit(MMWDEMO_CLI_TASK_PRIORITY);
  2208. return;
  2209. }
  2210. /**
  2211. * @b Description
  2212. * @n
  2213. * Function to sleep the R4F using WFI (Wait For Interrupt) instruction.
  2214. * When R4F has no work left to do,
  2215. * the BIOS will be in Idle thread and will call this function. The R4F will
  2216. * wake-up on any interrupt (e.g chirp interrupt).
  2217. *
  2218. * @retval
  2219. * Not Applicable.
  2220. */
  2221. void Pcount3DDemo_sleep(void)
  2222. {
  2223. /* issue WFI (Wait For Interrupt) instruction */
  2224. asm(" WFI ");
  2225. }
  2226. /**
  2227. * @b Description
  2228. * @n
  2229. * Entry point into the Millimeter Wave Demo
  2230. *
  2231. * @retval
  2232. * Not Applicable.
  2233. */
  2234. int main (void)
  2235. {
  2236. Task_Params taskParams;
  2237. int32_t errCode;
  2238. SOC_Handle socHandle;
  2239. SOC_Cfg socCfg;
  2240. /* Initialize the ESM: Dont clear errors as TI RTOS does it */
  2241. ESM_init(0U);
  2242. /* Initialize the SOC confiugration: */
  2243. memset ((void *)&socCfg, 0, sizeof(SOC_Cfg));
  2244. /* Populate the SOC configuration: */
  2245. socCfg.clockCfg = SOC_SysClock_INIT;
  2246. socCfg.mpuCfg = SOC_MPUCfg_CONFIG;
  2247. socCfg.dssCfg = SOC_DSSCfg_UNHALT;
  2248. /* Initialize the SOC Module: This is done as soon as the application is started
  2249. * to ensure that the MPU is correctly configured. */
  2250. socHandle = SOC_init (&socCfg, &errCode);
  2251. if (socHandle == NULL)
  2252. {
  2253. System_printf ("Error: SOC Module Initialization failed [Error code %d]\n", errCode);
  2254. Pcount3DDemo_debugAssert (0);
  2255. return -1;
  2256. }
  2257. /* Initialize and populate the demo MCB */
  2258. memset ((void*)&gMmwMssMCB, 0, sizeof(Pcount3DDemo_MSS_MCB));
  2259. gMmwMssMCB.socHandle = socHandle;
  2260. /* Debug Message: */
  2261. System_printf ("**********************************************\n");
  2262. System_printf ("Debug: Launching the MMW Demo on MSS\n");
  2263. System_printf ("**********************************************\n");
  2264. /* Initialize the Task Parameters. */
  2265. Task_Params_init(&taskParams);
  2266. gMmwMssMCB.taskHandles.initTask = Task_create(Pcount3DDemo_initTask, &taskParams, NULL);
  2267. /* Start BIOS */
  2268. BIOS_start();
  2269. return 0;
  2270. }