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.

pcount3D_mss.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /**
  2. * @file pcount3D_mss.h
  3. *
  4. * @brief
  5. * This is the main header file for the 3D people counting demo
  6. *
  7. * \par
  8. * NOTE:
  9. * (C) Copyright 2016 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. #ifndef MMW_MSS_H
  40. #define MMW_MSS_H
  41. #include <ti/sysbios/knl/Semaphore.h>
  42. #include <ti/sysbios/knl/Task.h>
  43. #include <ti/common/mmwave_error.h>
  44. #include <ti/drivers/osal/DebugP.h>
  45. #include <ti/drivers/soc/soc.h>
  46. #include <ti/drivers/uart/UART.h>
  47. #include <ti/drivers/gpio/gpio.h>
  48. #include <ti/drivers/mailbox/mailbox.h>
  49. #include <people_counting/68xx_3D_people_counting/src/common/mmwdemo_adcconfig.h>
  50. //#include <ti/demo/utils/mmwdemo_monitor.h>
  51. #include <common/src/dpc/objdetrangehwa/objdetrangehwa.h>
  52. #include <people_counting/68xx_3D_people_counting/src/common/pcount3D_output.h>
  53. #include <people_counting/68xx_3D_people_counting/src/common/pcount3D_config.h>
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. /*! @brief For advanced frame config, below define means the configuration given is
  58. * global at frame level and therefore it is broadcast to all sub-frames.
  59. */
  60. #define PCOUNT3DDEMO_SUBFRAME_NUM_FRAME_LEVEL_CONFIG (-1)
  61. /**
  62. * @defgroup configStoreOffsets Offsets for storing CLI configuration
  63. * @brief Offsets of config fields within the parent structures, note these offsets will be
  64. * unique and hence can be used to differentiate the commands for processing purposes.
  65. * @{
  66. */
  67. #define PCOUNT3DDEMO_ADCBUFCFG_OFFSET (offsetof(Pcount3DDemo_SubFrameCfg, adcBufCfg))
  68. #define PCOUNT3DDEMO_SUBFRAME_DSPDYNCFG_OFFSET (offsetof(Pcount3DDemo_SubFrameCfg, objDetDynCfg) + \
  69. offsetof(Pcount3DDemo_DPC_ObjDet_DynCfg, dspDynCfg))
  70. #define PCOUNT3DDEMO_SUBFRAME_R4FDYNCFG_OFFSET (offsetof(Pcount3DDemo_SubFrameCfg, objDetDynCfg) + \
  71. offsetof(Pcount3DDemo_DPC_ObjDet_DynCfg, r4fDynCfg))
  72. #define PCOUNT3DDEMO_CALIBDCRANGESIG_OFFSET (PCOUNT3DDEMO_SUBFRAME_R4FDYNCFG_OFFSET + \
  73. offsetof(DPC_ObjectDetectionRangeHWA_DynCfg, calibDcRangeSigCfg))
  74. #define PCOUNT3DDEMO_CAPONCHAINCFG_OFFSET (PCOUNT3DDEMO_SUBFRAME_DSPDYNCFG_OFFSET + \
  75. offsetof(DPC_ObjectDetection_DynCfg, caponChainCfg))
  76. #define PCOUNT3DDEMO_DYNRACFARCFG_OFFSET (PCOUNT3DDEMO_CAPONCHAINCFG_OFFSET + \
  77. offsetof(caponChainCfg, dynamicCfarConfig))
  78. #define PCOUNT3DDEMO_STATICRACFARCFG_OFFSET (PCOUNT3DDEMO_CAPONCHAINCFG_OFFSET + \
  79. offsetof(caponChainCfg, staticCfarConfig))
  80. #define PCOUNT3DDEMO_DOACAPONCFG_OFFSET (PCOUNT3DDEMO_CAPONCHAINCFG_OFFSET + \
  81. offsetof(caponChainCfg, doaConfig))
  82. #define PCOUNT3DDEMO_DOACAPONRACFG_OFFSET (PCOUNT3DDEMO_DOACAPONCFG_OFFSET + \
  83. offsetof(doaConfig, rangeAngleCfg))
  84. #define PCOUNT3DDEMO_DOA2DESTCFG_OFFSET (PCOUNT3DDEMO_DOACAPONCFG_OFFSET + \
  85. offsetof(doaConfig, angle2DEst))
  86. #define PCOUNT3DDEMO_DOAFOVCFG_OFFSET (PCOUNT3DDEMO_DOACAPONCFG_OFFSET + \
  87. offsetof(doaConfig, fovCfg))
  88. #define PCOUNT3DDEMO_STATICANGESTCFG_OFFSET (PCOUNT3DDEMO_DOACAPONCFG_OFFSET + \
  89. offsetof(doaConfig, staticEstCfg))
  90. #define PCOUNT3DDEMO_DOPCFARCFG_OFFSET (PCOUNT3DDEMO_DOACAPONCFG_OFFSET + \
  91. offsetof(doaConfig, dopCfarCfg))
  92. /** @}*/ /* configStoreOffsets */
  93. /**
  94. * @brief
  95. * 3D people counting Demo Sensor State
  96. *
  97. * @details
  98. * The enumeration is used to define the sensor states used in 3D people counting Demo
  99. */
  100. typedef enum Pcount3DDemo_SensorState_e
  101. {
  102. /*! @brief Inital state after sensor is initialized.
  103. */
  104. Pcount3DDemo_SensorState_INIT = 0,
  105. /*! @brief Indicates sensor is started */
  106. Pcount3DDemo_SensorState_STARTED,
  107. /*! @brief State after sensor has completely stopped */
  108. Pcount3DDemo_SensorState_STOPPED
  109. }Pcount3DDemo_SensorState;
  110. /**
  111. * @brief
  112. * 3D people counting Demo statistics
  113. *
  114. * @details
  115. * The structure is used to hold the statistics information for the
  116. * 3D people counting Demo
  117. */
  118. typedef struct Pcount3DDemo_MSS_Stats_t
  119. {
  120. /*! @brief Counter which tracks the number of frame trigger events from BSS */
  121. uint64_t frameTriggerReady;
  122. /*! @brief Counter which tracks the number of failed calibration reports
  123. * The event is triggered by an asynchronous event from the BSS */
  124. uint32_t failedTimingReports;
  125. /*! @brief Counter which tracks the number of calibration reports received
  126. * The event is triggered by an asynchronous event from the BSS */
  127. uint32_t calibrationReports;
  128. /*! @brief Counter which tracks the number of sensor stop events received
  129. * The event is triggered by an asynchronous event from the BSS */
  130. uint32_t sensorStopped;
  131. /*! @brief Counter which tracks the number of dpm stop events received
  132. * The event is triggered by DPM_Report_DPC_STOPPED from DPM */
  133. uint32_t dpmStopEvents;
  134. /*! @brief Counter which tracks the number of dpm start events received
  135. * The event is triggered by DPM_Report_DPC_STARTED from DPM */
  136. uint32_t dpmStartEvents;
  137. }Pcount3DDemo_MSS_Stats;
  138. /**
  139. * @brief
  140. * 3D people counting Demo Data Path Information.
  141. *
  142. * @details
  143. * The structure is used to hold all the relevant information for
  144. * the data path.
  145. */
  146. typedef struct Pcount3DDemo_SubFrameCfg_t
  147. {
  148. /*! @brief ADC buffer configuration storage */
  149. MmwDemo_ADCBufCfg adcBufCfg;
  150. /*! @brief Flag indicating if @ref adcBufCfg is pending processing. */
  151. uint8_t isAdcBufCfgPending : 1;
  152. /*! @brief Dynamic configuration storage for object detection DPC */
  153. Pcount3DDemo_DPC_ObjDet_DynCfg objDetDynCfg;
  154. /*! @brief ADCBUF will generate chirp interrupt event every this many chirps - chirpthreshold */
  155. uint8_t numChirpsPerChirpEvent;
  156. /*! @brief Number of bytes per RX channel, it is aligned to 16 bytes as required by ADCBuf driver */
  157. uint32_t adcBufChanDataSize;
  158. /*! @brief Number of ADC samples */
  159. uint16_t numAdcSamples;
  160. /*! @brief Number of chirps per sub-frame */
  161. uint16_t numChirpsPerSubFrame;
  162. /*! @brief Number of virtual antennas */
  163. uint8_t numVirtualAntennas;
  164. } Pcount3DDemo_SubFrameCfg;
  165. /*!
  166. * @brief
  167. * Structure holds message stats information from data path.
  168. *
  169. * @details
  170. * The structure holds stats information. This is a payload of the TLV message item
  171. * that holds stats information.
  172. */
  173. typedef struct Pcount3DDemo_SubFrameStats_t
  174. {
  175. /*! @brief Frame processing stats */
  176. Pcount3DDemo_output_message_stats outputStats;
  177. /*! @brief Dynamic CLI configuration time in usec */
  178. uint32_t pendingConfigProcTime;
  179. /*! @brief SubFrame Preparation time on MSS in usec */
  180. uint32_t subFramePreparationTime;
  181. } Pcount3DDemo_SubFrameStats;
  182. /**
  183. * @brief Task handles storage structure
  184. */
  185. typedef struct Pcount3DDemo_TaskHandles_t
  186. {
  187. /*! @brief MMWAVE Control Task Handle */
  188. Task_Handle mmwaveCtrl;
  189. /*! @brief ObjectDetection DPC related dpmTask */
  190. Task_Handle objDetDpmTask;
  191. /*! @brief Demo init task */
  192. Task_Handle initTask;
  193. } Pcount3DDemo_taskHandles;
  194. typedef struct Pcount3DDemo_DataPathObj_t
  195. {
  196. /*! @brief Handle to hardware accelerator driver. */
  197. HWA_Handle hwaHandle;
  198. /*! @brief Handle of the EDMA driver. */
  199. EDMA_Handle edmaHandle;
  200. /*! @brief Radar cube memory information from range DPC */
  201. DPC_ObjectDetectionRangeHWA_preStartCfg_radarCubeMem radarCubeMem;
  202. /*! @brief Memory usage after the preStartCfg range DPC is applied */
  203. DPC_ObjectDetectionRangeHWA_preStartCfg_memUsage memUsage;
  204. /*! @brief EDMA error Information when there are errors like missing events */
  205. EDMA_errorInfo_t EDMA_errorInfo;
  206. /*! @brief EDMA transfer controller error information. */
  207. EDMA_transferControllerErrorInfo_t EDMA_transferControllerErrorInfo;
  208. } Pcount3DDemo_DataPathObj;
  209. /**
  210. * @brief
  211. * 3D people counting Demo MCB
  212. *
  213. * @details
  214. * The structure is used to hold all the relevant information for the
  215. * 3D people counting Demo
  216. */
  217. typedef struct Pcount3DDemo_MSS_MCB_t
  218. {
  219. /*! @brief Configuration which is used to execute the demo */
  220. Pcount3DDemo_Cfg cfg;
  221. /*! * @brief Handle to the SOC Module */
  222. SOC_Handle socHandle;
  223. /*! @brief UART Logging Handle */
  224. UART_Handle loggingUartHandle;
  225. /*! @brief UART Command Rx/Tx Handle */
  226. UART_Handle commandUartHandle;
  227. /*! @brief This is the mmWave control handle which is used
  228. * to configure the BSS. */
  229. MMWave_Handle ctrlHandle;
  230. /*! @brief ADCBuf driver handle */
  231. ADCBuf_Handle adcBufHandle;
  232. /*! @brief DSP chain DPM Handle */
  233. DPM_Handle objDetDpmHandle;
  234. /*! @brief Object Detection DPC common configuration */
  235. Pcount3DDemo_DPC_ObjDet_CommonCfg objDetCommonCfg;
  236. /*! @brief Data path object */
  237. Pcount3DDemo_DataPathObj dataPathObj;
  238. /*! @brief Tracker DPU Static Configuration */
  239. DPC_ObjectDetection_TrackerConfig trackerCfg;
  240. /*! @brief Object Detection DPC subFrame configuration */
  241. Pcount3DDemo_SubFrameCfg subFrameCfg[RL_MAX_SUBFRAMES];
  242. /*! @brief sub-frame stats */
  243. Pcount3DDemo_SubFrameStats subFrameStats[RL_MAX_SUBFRAMES];
  244. /*! @brief Demo Stats */
  245. Pcount3DDemo_MSS_Stats stats;
  246. Pcount3DDemo_output_message_UARTpointCloud pointCloudToUart;
  247. DPIF_DetMatrix heatMapOutFromDSP;
  248. DPIF_PointCloudSpherical *pointCloudFromDSP;
  249. DPIF_PointCloudSideInfo *pointCloudSideInfoFromDSP;
  250. DPC_ObjectDetection_Stats *frameStatsFromDSP;
  251. uint32_t currSubFrameIdx;
  252. trackerProc_TargetDescrHandle trackerOutput;
  253. uint8_t numTargets;
  254. uint16_t numIndices;
  255. bool presenceDetEnabled;
  256. uint32_t presenceInd;
  257. uint16_t numDetectedPoints;
  258. uint32_t trackerProcessingTimeInUsec;
  259. uint32_t uartProcessingTimeInUsec;
  260. /*! @brief Task handle storage */
  261. Pcount3DDemo_taskHandles taskHandles;
  262. /*! @brief RF frequency scale factor, = 2.7 for 60GHz device, = 3.6 for 76GHz device */
  263. double rfFreqScaleFactor;
  264. /*! @brief Semaphore handle to signal DPM started from DPM report function */
  265. Semaphore_Handle DPMstartSemHandle;
  266. /*! @brief Semaphore handle to signal DPM stopped from DPM report function. */
  267. Semaphore_Handle DPMstopSemHandle;
  268. /*! @brief Semaphore handle to signal DPM ioctl from DPM report function. */
  269. Semaphore_Handle DPMioctlSemHandle;
  270. /*! @brief Semaphore handle to run UART DMA task. */
  271. Semaphore_Handle uartTxSemHandle;
  272. /*! @brief Semaphore handle to trigger tracker DPU. */
  273. Semaphore_Handle trackerDPUSemHandle;
  274. /*! @brief Sensor state */
  275. Pcount3DDemo_SensorState sensorState;
  276. /*! @brief Tracks the number of sensor start */
  277. uint32_t sensorStartCount;
  278. /*! @brief Tracks the number of sensor sop */
  279. uint32_t sensorStopCount;
  280. } Pcount3DDemo_MSS_MCB;
  281. /**************************************************************************
  282. *************************** Extern Definitions ***************************
  283. **************************************************************************/
  284. /* Functions to handle the actions need to move the sensor state */
  285. extern int32_t Pcount3DDemo_openSensor(bool isFirstTimeOpen);
  286. extern int32_t Pcount3DDemo_configSensor(void);
  287. extern int32_t Pcount3DDemo_startSensor(void);
  288. extern void Pcount3DDemo_stopSensor(void);
  289. /* functions to manage the dynamic configuration */
  290. extern uint8_t Pcount3DDemo_isAllCfgInPendingState(void);
  291. extern uint8_t Pcount3DDemo_isAllCfgInNonPendingState(void);
  292. extern void Pcount3DDemo_resetStaticCfgPendingState(void);
  293. extern void Pcount3DDemo_CfgUpdate(void *srcPtr, uint32_t offset, uint32_t size, int8_t subFrameNum);
  294. extern void Pcount3DDemo_CLIInit (uint8_t taskPriority);
  295. /* Debug Functions */
  296. extern void _Pcount3DDemo_debugAssert(int32_t expression, const char *file, int32_t line);
  297. #define Pcount3DDemo_debugAssert(expression) { \
  298. _Pcount3DDemo_debugAssert(expression, \
  299. __FILE__, __LINE__); \
  300. DebugP_assert(expression); \
  301. }
  302. #ifdef __cplusplus
  303. }
  304. #endif
  305. #endif /* MMW_MSS_H */