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.

radarProcess.c 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*!
  2. * \file radarProcess.c
  3. *
  4. * \brief radar signal processing chain.
  5. *
  6. * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
  7. *
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * Neither the name of Texas Instruments Incorporated nor the names of
  22. * its contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. */
  38. #include <common/src/dpu/capon3d/include/radarProcess_internal.h>
  39. #include <math.h>
  40. #include <common/src/dpu/capon3d/modules/utilities/cycle_measure.h>
  41. #include <common/src/dpu/capon3d/modules/utilities/radarOsal_malloc.h>
  42. #include <common/src/dpu/capon3d/modules/utilities/radar_c674x.h>
  43. #if (defined SOC_XWR16XX) || (defined SOC_XWR68XX)
  44. #include <xdc/runtime/System.h>
  45. #endif
  46. #define ONEOVERFACTORIAL3 (1.f/6.f)
  47. #define ONEOVERFACTORIAL5 (1.f/230.f)
  48. #define ONEOVERFACTORIAL7 (1.f/5040.f)
  49. #define MAXANT (12)
  50. #define MAXWIN1DSize (128)
  51. //user input configuration parameters
  52. /***************************************************************************
  53. *************************** External API Functions ************************
  54. **************************************************************************/
  55. /**
  56. * @b Description
  57. * @n
  58. * The function is radarProcess DPU init function. It allocates memory to store
  59. * its internal data object and returns a handle if it executes successfully.
  60. *
  61. * @param[in] initParams radarProcess initialization parameters.
  62. * @param[in] errCode Pointer to errCode generates from the API
  63. *
  64. *
  65. * @retval
  66. * Success - valid radarProcess handle
  67. * @retval
  68. * Error - NULL
  69. */
  70. DPU_radarProcess_Handle DPU_radarProcess_init
  71. (
  72. DPU_radarProcessConfig_t * initParams,
  73. DPU_ProcessErrorCodes * errCode
  74. )
  75. {
  76. radarProcessInstance_t * inst;
  77. int32_t i;
  78. int32_t itemp, perRngbinHeatmapLen;
  79. DPU_ProcessErrorCodes errorCode = PROCESS_OK;
  80. inst = (radarProcessInstance_t *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, sizeof(radarProcessInstance_t), 8);
  81. itemp = initParams->numChirpPerFrame;
  82. if ((1 << (30 - _norm(itemp))) == itemp)
  83. inst->DopplerFFTSize = itemp;
  84. else
  85. inst->DopplerFFTSize = 1 << (31 - _norm(itemp));
  86. inst->dopplerOversampleFactor = 1;
  87. inst->scaleDopCfarOutCFAR = 1;
  88. inst->nRxAnt = initParams->numAntenna;
  89. inst->numChirpsPerFrame = initParams->numChirpPerFrame;
  90. itemp = initParams->numAdcSamplePerChirp;
  91. if ((1 << (30 - _norm(itemp))) == itemp)
  92. inst->numRangeBins = itemp;
  93. else
  94. inst->numRangeBins = 1 << (31 - _norm(itemp));
  95. initParams->numRangeBins = inst->numRangeBins;
  96. //update the interbin resolution for range and Doppler
  97. initParams->dynamicCfarConfig.rangeRes = divsp_i(initParams->dynamicCfarConfig.rangeRes * (float)initParams->numAdcSamplePerChirp, (float)inst->numRangeBins);
  98. inst->rangeRes = initParams->dynamicCfarConfig.rangeRes;
  99. initParams->dynamicCfarConfig.dopplerRes= divsp_i(initParams->dynamicCfarConfig.dopplerRes * (float)initParams->numChirpPerFrame, (float)inst->DopplerFFTSize);
  100. inst->dopplerRes = initParams->dynamicCfarConfig.dopplerRes;
  101. /* rearrange phase compensation coeff from OOB to be able to use in 2D capon chain */
  102. {
  103. cplxf_t * tempCmpVec;
  104. float tempRe, tempIm, tempP, invsqrt, errorLimit;
  105. int32_t compFlag;
  106. tempCmpVec = (cplxf_t *)&(initParams->doaConfig.phaseCompVect[0]);
  107. //check whether we need to compensate
  108. compFlag = 0;
  109. errorLimit = 0.0001f;
  110. for (i = 0; i < initParams->numAntenna; i++)
  111. {
  112. if (((_fabs(tempCmpVec[i].real) - 1.f) > errorLimit) || (_fabs(tempCmpVec[i].imag) > errorLimit))
  113. compFlag = 1;
  114. }
  115. if (compFlag)
  116. {
  117. for (i = 0; i < initParams->numAntenna; i++)
  118. {
  119. tempRe = tempCmpVec[i].real;
  120. tempIm = tempCmpVec[i].imag;
  121. tempP = tempRe * tempRe + tempIm * tempIm;
  122. invsqrt = _rsqrsp(tempP);
  123. invsqrt = invsqrt * (1.5f - 0.5f * tempP * invsqrt * invsqrt);
  124. invsqrt = invsqrt * (1.5f - 0.5f * tempP * invsqrt * invsqrt);
  125. tempCmpVec[i].real = tempRe * invsqrt * (float)(initParams->doaConfig.phaseRot[i]);
  126. tempCmpVec[i].imag = -tempIm * invsqrt * (float)(initParams->doaConfig.phaseRot[i]);
  127. }
  128. }
  129. }
  130. inst->perRangeBinMax = (float *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, inst->numRangeBins * sizeof(float), 8);
  131. /* 2D Capon DoA init and config */
  132. {
  133. int32_t heatmapSize, maxNumAngleEst;
  134. initParams->doaConfig.numInputRangeBins = inst->numRangeBins;
  135. initParams->doaConfig.numInputChirps = initParams->numChirpPerFrame;
  136. initParams->doaConfig.dopperFFTSize = inst->DopplerFFTSize;
  137. initParams->doaConfig.nRxAnt = inst->nRxAnt;
  138. inst->aoaInstance = (void *) RADARDEMO_aoaEst2DCaponBF_create(&initParams->doaConfig, &inst->aoaBFErrorCode);
  139. if (inst->aoaBFErrorCode > RADARDEMO_AOACAPONBF_NO_ERROR)
  140. {
  141. errorCode = PROCESS_ERROR_DOAPROC_INIT_FAILED;
  142. }
  143. inst->numDynAngleBin = initParams->doaConfig.numRAangleBin;
  144. inst->aoaInput = (RADARDEMO_aoaEst2DCaponBF_input *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, sizeof(RADARDEMO_aoaEst2DCaponBF_input), 1);
  145. inst->aoaOutput = (RADARDEMO_aoaEst2DCaponBF_output *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, sizeof(RADARDEMO_aoaEst2DCaponBF_output), 1);
  146. heatmapSize = (int32_t)ceil(divsp_i ((float)initParams->doaConfig.numAzimBins, (float)initParams->doaConfig.staticEstCfg.staticAzimStepDeciFactor))
  147. * (int32_t)ceil(divsp_i ((float)initParams->doaConfig.numElevBins, (float)initParams->doaConfig.staticEstCfg.staticElevStepDeciFactor))
  148. * initParams->doaConfig.numInputRangeBins;
  149. if (heatmapSize < initParams->doaConfig.numRAangleBin * initParams->doaConfig.numInputRangeBins)
  150. heatmapSize = initParams->doaConfig.numRAangleBin * initParams->doaConfig.numInputRangeBins;
  151. if ( heatmapSize < initParams->doaConfig.numAzimBins * initParams->doaConfig.numElevBins)
  152. heatmapSize = initParams->doaConfig.numAzimBins * initParams->doaConfig.numElevBins;
  153. inst->localHeatmap = (float *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_DDR_CACHED, 0, heatmapSize *sizeof(float), 8);
  154. initParams->heatMapMemSize = heatmapSize;
  155. inst->heatMapMemSize = heatmapSize;
  156. if (initParams->doaConfig.rangeAngleCfg.detectionMethod <= 1)
  157. maxNumAngleEst = initParams->doaConfig.angle2DEst.azimElevAngleEstCfg.maxNpeak2Search * (initParams->doaConfig.angle2DEst.azimElevAngleEstCfg.peakExpSamples * 2 + 1) * (initParams->doaConfig.angle2DEst.azimElevAngleEstCfg.peakExpSamples * 2 + 1);
  158. else
  159. maxNumAngleEst = (initParams->doaConfig.angle2DEst.azimElevZoominCfg.peakExpSamples * 2 + 1) * (initParams->doaConfig.angle2DEst.azimElevZoominCfg.peakExpSamples * 2 + 1);
  160. inst->aoaOutput->azimEst = (float *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, maxNumAngleEst * sizeof(float), 1);
  161. inst->aoaOutput->elevEst = (float *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, maxNumAngleEst * sizeof(float), 1);
  162. inst->aoaOutput->peakPow = (float *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, maxNumAngleEst * sizeof(float), 1);
  163. inst->aoaOutput->bwFilter = (cplxf_t *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, maxNumAngleEst * initParams->doaConfig.nRxAnt * sizeof(cplxf_t), 8);
  164. //inst->aoaOutput->malValPerRngBin = (float *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL2, 0, initParams->doaConfig.numInputRangeBins * sizeof(float), 1);
  165. inst->aoaOutput->static_information = (cplxf_t *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_DDR_CACHED, 0, initParams->doaConfig.numInputRangeBins * initParams->doaConfig.nRxAnt * sizeof(cplxf_t), 8);
  166. inst->aoaOutput->malValPerRngBin = inst->perRangeBinMax;
  167. inst->aoaOutput->invRnMatrices = (cplxf_t *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL2, 0, initParams->doaConfig.numInputRangeBins * (initParams->doaConfig.nRxAnt >> 1) * (initParams->doaConfig.nRxAnt + 1) * sizeof(cplxf_t), 8);
  168. if (initParams->doaConfig.rangeAngleCfg.dopplerEstMethod == 1)
  169. {
  170. inst->aoaOutput->dopplerIdx = (uint16_t *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, maxNumAngleEst * MAX_DOPCFAR_DET * sizeof(uint16_t), 1);
  171. inst->aoaOutput->dopplerDetSNR = (float *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, maxNumAngleEst * MAX_DOPCFAR_DET * sizeof(float), 1);
  172. }
  173. else
  174. {
  175. inst->aoaOutput->dopplerIdx = (uint16_t *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, maxNumAngleEst * sizeof(uint16_t), 1);
  176. }
  177. #ifdef CAPON2DMODULEDEBUG
  178. inst->aoaOutput->cyclesLog = (RADARDEMO_aoaEst2DCaponBF_moduleCycles *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_DDR_CACHED, 0, sizeof(RADARDEMO_aoaEst2DCaponBF_moduleCycles), 8);
  179. memset(inst->aoaOutput->cyclesLog, 0, sizeof(RADARDEMO_aoaEst2DCaponBF_moduleCycles));
  180. #endif
  181. if ((inst->aoaOutput == NULL) || (inst->aoaInput == NULL))
  182. {
  183. errorCode = PROCESS_ERROR_DOAPROC_INOUTALLOC_FAILED;
  184. }
  185. }
  186. /* dynamic Detection CFAR init and config */
  187. {
  188. inst->cfarRangeSkipLeft = initParams->dynamicCfarConfig.leftSkipSize;
  189. inst->cfarRangeSkipRight = initParams->dynamicCfarConfig.rightSkipSize;
  190. initParams->dynamicCfarConfig.fft2DSize = initParams->doaConfig.numRAangleBin;
  191. initParams->dynamicCfarConfig.fft1DSize = inst->numRangeBins;
  192. initParams->dynamicCfarConfig.maxNumDetObj = MAX_DYNAMIC_CFAR_PNTS;
  193. initParams->dynamicCfarConfig.angleDim1 = initParams->doaConfig.numAzimBins; // not used, hardcoded to 0
  194. initParams->dynamicCfarConfig.angleDim2 = initParams->doaConfig.numElevBins; // not used, hardcoded to 0
  195. inst->dynamicCFARInstance = (void *) RADARDEMO_detectionCFAR_create(&initParams->dynamicCfarConfig, &inst->cfarErrorCode);
  196. if (inst->cfarErrorCode > RADARDEMO_DETECTIONCFAR_NO_ERROR)
  197. {
  198. errorCode = PROCESS_ERROR_CFARPROC_INIT_FAILED;
  199. }
  200. inst->maxNumDetObj = initParams->maxNumDetObj;
  201. inst->detectionCFAROutput = (RADARDEMO_detectionCFAR_output *) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, sizeof(RADARDEMO_detectionCFAR_output), 1);
  202. inst->detectionCFAROutput->rangeInd = (uint16_t *) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, initParams->dynamicCfarConfig.maxNumDetObj * sizeof(uint16_t), 1);
  203. inst->detectionCFAROutput->dopplerInd = (uint16_t *) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, initParams->dynamicCfarConfig.maxNumDetObj * sizeof(uint16_t), 1);
  204. inst->detectionCFAROutput->snrEst = (float *) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, initParams->dynamicCfarConfig.maxNumDetObj * sizeof(float), 1);
  205. inst->detectionCFAROutput->noise = (float *) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, initParams->dynamicCfarConfig.maxNumDetObj * sizeof(float), 1);
  206. inst->detectionCFARInput = (RADARDEMO_detectionCFAR_input *) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, sizeof(RADARDEMO_detectionCFAR_input), 1);
  207. inst->dynamicHeatmapPtr = (float **) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL2, 0, initParams->dynamicCfarConfig.fft2DSize * sizeof(float *), 1);
  208. inst->dynamicSideLobeThr = initParams->dynamicSideLobeThr;
  209. inst->dynamicSideLobeThr = initParams->dynamicSideLobeThr;
  210. for (i = 0; i < (int32_t)initParams->dynamicCfarConfig.fft2DSize; i++ )
  211. {
  212. inst->dynamicHeatmapPtr[i] = (float *) &inst->localHeatmap[i * initParams->dynamicCfarConfig.fft1DSize];
  213. }
  214. if ( (inst->detectionCFAROutput == NULL)
  215. || (inst->detectionCFAROutput->rangeInd == NULL)
  216. || (inst->detectionCFAROutput->dopplerInd == NULL)
  217. || (inst->detectionCFAROutput->snrEst == NULL)
  218. || (inst->detectionCFAROutput->noise == NULL))
  219. {
  220. errorCode = PROCESS_ERROR_CFARPROC_INOUTALLOC_FAILED;
  221. }
  222. }
  223. inst->staticProcEnabled = initParams->doaConfig.staticEstCfg.staticProcEnabled;
  224. perRngbinHeatmapLen = inst->numDynAngleBin;
  225. /* static Detection CFAR init and config */
  226. if (inst->staticProcEnabled)
  227. {
  228. inst->numStaticAngleBin = (int32_t)(ceil(divsp_i ((float)initParams->doaConfig.numAzimBins, (float)initParams->doaConfig.staticEstCfg.staticAzimStepDeciFactor))
  229. * ceil(divsp_i ((float)initParams->doaConfig.numElevBins, (float)initParams->doaConfig.staticEstCfg.staticElevStepDeciFactor)));
  230. perRngbinHeatmapLen = inst->numStaticAngleBin;
  231. if ( perRngbinHeatmapLen < inst->numStaticAngleBin )
  232. perRngbinHeatmapLen = inst->numStaticAngleBin;
  233. initParams->staticCfarConfig.fft2DSize = inst->numStaticAngleBin;
  234. initParams->staticCfarConfig.fft1DSize = inst->numRangeBins;
  235. initParams->staticCfarConfig.maxNumDetObj = MAX_STATIC_CFAR_PNTS;
  236. initParams->staticCfarConfig.angleDim2 = (uint32_t)ceil(divsp_i ((float)initParams->doaConfig.numAzimBins, (float)initParams->doaConfig.staticEstCfg.staticAzimStepDeciFactor));
  237. initParams->staticCfarConfig.angleDim1 = (uint32_t)ceil(divsp_i ((float)initParams->doaConfig.numElevBins, (float)initParams->doaConfig.staticEstCfg.staticElevStepDeciFactor));
  238. initParams->staticCfarConfig.leftSkipSize = inst->cfarRangeSkipLeft; //set the skip range bins the same as the dynamic scene
  239. initParams->staticCfarConfig.rightSkipSize = inst->cfarRangeSkipRight; //set the skip range bins the same as the dynamic scene
  240. inst->staticCFARInstance = (void *) RADARDEMO_detectionCFAR_create(&initParams->staticCfarConfig, &inst->cfarErrorCode);
  241. if (inst->cfarErrorCode > RADARDEMO_DETECTIONCFAR_NO_ERROR)
  242. {
  243. errorCode = PROCESS_ERROR_CFARPROC_INIT_FAILED;
  244. }
  245. inst->staticSideLobeThr = initParams->staticSideLobeThr;
  246. inst->staticHeatmapPtr = (float **) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL1, 0, initParams->dynamicCfarConfig.fft2DSize * sizeof(float *), 1);
  247. for (i = 0; i < (int32_t)initParams->staticCfarConfig.fft2DSize; i++ )
  248. {
  249. inst->staticHeatmapPtr[i] = (float *) &inst->localHeatmap[i * initParams->staticCfarConfig.fft1DSize];
  250. }
  251. }
  252. inst->tempHeatMapOut = (float *) radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_LL2, 0, perRngbinHeatmapLen * sizeof(float), 8);
  253. inst->framePeriod = initParams->framePeriod;
  254. inst->mimoModeFlag = (uint8_t)initParams->mimoModeFlag;
  255. initParams->heatMapMem = inst->localHeatmap;
  256. inst->benchmarkPtr = (radarProcessBenchmarkObj *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_DDR_CACHED, 0, sizeof(radarProcessBenchmarkObj), 1);
  257. inst->benchmarkPtr->bufferLen = 20;
  258. inst->benchmarkPtr->bufferIdx = 0;
  259. inst->benchmarkPtr->buffer = (radarProcessBenchmarkElem *)radarOsal_memAlloc(RADARMEMOSAL_HEAPTYPE_DDR_CACHED, 0, inst->benchmarkPtr->bufferLen * sizeof(radarProcessBenchmarkElem), 1);
  260. #ifdef CAPON2DMODULEDEBUG
  261. inst->benchmarkPtr->aoaCyclesLog = inst->aoaOutput->cyclesLog;
  262. #endif
  263. memset(inst->benchmarkPtr->buffer, 0, inst->benchmarkPtr->bufferLen * sizeof(radarProcessBenchmarkElem));
  264. if ((inst->localHeatmap == NULL) ||(inst->benchmarkPtr == NULL) || (inst->benchmarkPtr->buffer == NULL))
  265. errorCode = PROCESS_ERROR_INIT_MEMALLOC_FAILED;
  266. initParams->benchmarkPtr = inst->benchmarkPtr;
  267. *errCode = errorCode;
  268. #ifndef CCS
  269. System_printf("DPU_radarProcess_init - process handle: (radarProcessInstance_t *)0x%x\n", (uint32_t)inst);
  270. System_printf("DPU_radarProcess_init - dynamic CFAR handle: (RADARDEMO_detectionCFAR_handle *)0x%x\n", (uint32_t)(inst->dynamicCFARInstance));
  271. System_printf("DPU_radarProcess_init - staic CFAR handle: (RADARDEMO_detectionCFAR_handle *)0x%x\n", (uint32_t)(inst->staticCFARInstance));
  272. System_printf("DPU_radarProcess_init - 2D capon handle: (RADARDEMO_aoaEst2DCaponBF_handle *)0x%x\n", (uint32_t)(inst->aoaInstance));
  273. System_printf("DPU_radarProcess_init - benchmark obj: (radarProcessBenchmarkObj *)0x%x\n", (uint32_t)(inst->benchmarkPtr));
  274. System_printf("DPU_radarProcess_init - heatmap: (float *)0x%x\n", (uint32_t)(inst->localHeatmap));
  275. #else
  276. printf("DPU_radarProcess_init - process handle: (radarProcessInstance_t *)0x%x\n", (uint32_t)inst);
  277. printf("DPU_radarProcess_init - dynamic CFAR handle: (RADARDEMO_detectionCFAR_handle *)0x%x\n", (uint32_t)(inst->dynamicCFARInstance));
  278. printf("DPU_radarProcess_init - staic CFAR handle: (RADARDEMO_detectionCFAR_handle *)0x%x\n", (uint32_t)(inst->staticCFARInstance));
  279. printf("DPU_radarProcess_init - 2D capon handle: (RADARDEMO_aoaEst2DCaponBF_handle *)0x%x\n", (uint32_t)(inst->aoaInstance));
  280. printf("DPU_radarProcess_init - benchmark obj: (radarProcessBenchmarkObj *)0x%x\n", (uint32_t)(inst->benchmarkPtr));
  281. printf("DPU_radarProcess_init - heatmap: (float *)0x%x\n", (uint32_t)(inst->localHeatmap));
  282. #endif
  283. return (void *) inst;
  284. }
  285. /**
  286. * @b Description
  287. * @n
  288. * The function is radarProcess DPU config function. Currently not used.
  289. *
  290. * @param[in] handle radarProcess handle.
  291. * @param[in] sampleProcCfg radarProcess configurations.
  292. * @param[in] errCode Pointer to errCode generates from the API
  293. *
  294. * \ingroup DPU_SAMPLEPROC_EXTERNAL_FUNCTION
  295. *
  296. * @retval
  297. * Success =0
  298. * @retval
  299. * Error <0
  300. */
  301. int32_t DPU_radarProcess_config
  302. (
  303. DPU_radarProcess_Handle hndle,
  304. DPU_radarProcessConfig_t * initParams,
  305. DPU_ProcessErrorCodes * errCode
  306. )
  307. {
  308. int32_t retVal = 0;
  309. return (retVal);
  310. }
  311. /**
  312. * @b Description
  313. * @n
  314. * The function is radarProcess DPU process function. It runs from the data path
  315. * processing chain, with configuration and buffers assiged at config time.
  316. *
  317. * @param[in] handle radarProcess handle.
  318. * @param[in] pDataIn Input buffer for the processing -- range FFT output in radar cube
  319. * @param[out] pDataOut 3D point cloud data
  320. * @param[out] errCode Pointer to errCode generates from the API
  321. *
  322. * @retval
  323. * Success =0
  324. * @retval
  325. * Error <0
  326. */
  327. int32_t DPU_radarProcess_process (void *handle, cplx16_t * pDataIn, void * pDataOut, int32_t *errCode)
  328. {
  329. radarProcessInstance_t * processInst = (radarProcessInstance_t *)handle;
  330. #ifdef _TMS320C6X
  331. int32_t t1;
  332. #endif
  333. int32_t i, cOutNumDectected, numDynamicPnts;
  334. //RADARDEMO_aoaEst2DCaponBF_errorCode aoaBFErrorCode;
  335. radarProcessOutput *resultsPtr = (radarProcessOutput *) pDataOut;
  336. radarProcessOutputToTracker * output = &resultsPtr->pointCloudOut;
  337. DPIF_DetMatrix * heatmap = &resultsPtr->heatMapOut;
  338. ////////////////////////////////////////////////////////////////////////////////////////////
  339. /////////////////// Calling modules -- Dynamic processing ////////////////////////
  340. ////////////////////////////////////////////////////////////////////////////////////////////
  341. { //range-angle heatmap generation for dynamic scene processing
  342. processInst->aoaInput->fallBackToConvBFFlag = 0; //capon only
  343. processInst->aoaInput->processingStepSelector = 0; //BF part
  344. processInst->aoaInput->clutterRemovalFlag = 1; //clutter removal always on
  345. processInst->aoaInput->nChirps = processInst->numChirpsPerFrame;
  346. processInst->aoaInput->lastRB2Process = 0;
  347. #ifdef _TMS320C6X
  348. t1 = TSCL;
  349. #endif
  350. #ifdef CAPON2DMODULEDEBUG
  351. processInst->aoaOutput->cyclesLog->uniqueRngCnt = 0;
  352. processInst->aoaOutput->cyclesLog->dopDetCnt = 0;
  353. processInst->aoaOutput->cyclesLog->raDetCnt = 0;
  354. #endif
  355. for ( i = processInst->cfarRangeSkipLeft; i < processInst->numRangeBins - processInst->cfarRangeSkipRight; i++)
  356. {
  357. processInst->aoaInput->rangeIndx = i;
  358. processInst->aoaInput->inputRangeProcOutSamples = &pDataIn[i * processInst->nRxAnt * processInst->aoaInput->nChirps];
  359. processInst->aoaOutput->rangeAzimuthHeatMap = processInst->tempHeatMapOut;
  360. //has to be set to indicate the last rb to process, so that buffer init will be done correctly inside module, only needed for dynamic processing.
  361. if ( i == (processInst->numRangeBins - processInst->cfarRangeSkipRight - 1))
  362. processInst->aoaInput->lastRB2Process = 1;
  363. processInst->aoaBFErrorCode = RADARDEMO_aoaEst2DCaponBF_run(
  364. processInst->aoaInstance,
  365. processInst->aoaInput,
  366. processInst->aoaOutput);
  367. //transpose and store
  368. copyTranspose((uint32_t *)&processInst->tempHeatMapOut[0], (uint32_t *)&processInst->localHeatmap[i], processInst->numDynAngleBin, 0, processInst->numRangeBins, 1);
  369. }
  370. #ifdef _TMS320C6X
  371. processInst->benchmarkPtr->bufferIdx++;
  372. if (processInst->benchmarkPtr->bufferIdx >= processInst->benchmarkPtr->bufferLen)
  373. processInst->benchmarkPtr->bufferIdx = 0;
  374. processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx].dynHeatmpGenCycles = TSCL - t1;
  375. #endif
  376. }
  377. { //Dynamic CFAR
  378. #ifdef _TMS320C6X
  379. t1 = TSCL;
  380. #endif
  381. processInst->detectionCFARInput->azMaxPerRangeBin = processInst->perRangeBinMax;
  382. processInst->detectionCFARInput->sidelobeThr = processInst->dynamicSideLobeThr;
  383. processInst->detectionCFARInput->enableSecondPass = 1;
  384. processInst->detectionCFARInput->enable_neighbour_check = 1;
  385. processInst->detectionCFARInput->heatmapInput = processInst->dynamicHeatmapPtr;
  386. // Detection
  387. processInst->cfarErrorCode = RADARDEMO_detectionCFAR_run(
  388. processInst->dynamicCFARInstance,
  389. processInst->detectionCFARInput,
  390. processInst->detectionCFAROutput);
  391. #ifdef _TMS320C6X
  392. processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx].dynCfarDetectionCycles = TSCL - t1;
  393. #endif
  394. }
  395. #ifdef CCS
  396. printf("CFAR pnt: %d\t", processInst->detectionCFAROutput->numObjDetected);
  397. #endif
  398. cOutNumDectected = 0;
  399. { // angle and doppler estimation, per detected range-angle points -- for dynamic scene processing
  400. int32_t angleCount, dopplerCount, detIdx;
  401. int32_t dopplerIdx;
  402. processInst->aoaInput->processingStepSelector = 1;
  403. #ifdef _TMS320C6X
  404. t1 = TSCL;
  405. #endif
  406. processInst->aoaInput->nChirps = processInst->numChirpsPerFrame;
  407. processInst->aoaOutput->rangeAzimuthHeatMap = processInst->localHeatmap;
  408. for (detIdx = 0; detIdx < (int32_t)processInst->detectionCFAROutput->numObjDetected; detIdx++)
  409. {
  410. if (cOutNumDectected > DOA_OUTPUT_MAXPOINTS) break;
  411. processInst->aoaInput->rangeIndx = processInst->detectionCFAROutput->rangeInd[detIdx];
  412. processInst->aoaInput->angleIndx = processInst->detectionCFAROutput->dopplerInd[detIdx];
  413. processInst->aoaInput->inputRangeProcOutSamples = &pDataIn[processInst->aoaInput->rangeIndx * processInst->nRxAnt * processInst->aoaInput->nChirps];
  414. processInst->aoaInput->noise = processInst->detectionCFAROutput->noise[detIdx];
  415. processInst->aoaBFErrorCode = RADARDEMO_aoaEst2DCaponBF_run(
  416. processInst->aoaInstance,
  417. processInst->aoaInput,
  418. processInst->aoaOutput);
  419. dopplerCount = 0;
  420. for ( angleCount = 0; angleCount < processInst->aoaOutput->numAngleEst; angleCount++ )
  421. {
  422. if (cOutNumDectected > DOA_OUTPUT_MAXPOINTS) break;
  423. for ( i = 0; i < processInst->aoaOutput->numDopplerIdx; i++ )
  424. {
  425. output->pointCloud[cOutNumDectected].range = (float)processInst->aoaInput->rangeIndx * processInst->rangeRes;
  426. output->pointCloud[cOutNumDectected].azimuthAngle = processInst->aoaOutput->azimEst[angleCount];
  427. output->pointCloud[cOutNumDectected].elevAngle = processInst->aoaOutput->elevEst[angleCount];
  428. dopplerIdx = (int32_t)processInst->aoaOutput->dopplerIdx[dopplerCount++];
  429. if ( dopplerIdx > (processInst->DopplerFFTSize >> 1))
  430. dopplerIdx -= processInst->DopplerFFTSize;
  431. output->pointCloud[cOutNumDectected].velocity = (float)dopplerIdx * processInst->dopplerRes;
  432. if (processInst->aoaOutput->numAngleEst == 1)
  433. output->snr[cOutNumDectected].snr = (int16_t)((float)processInst->detectionCFAROutput->snrEst[detIdx] * 8.f);
  434. else
  435. output->snr[cOutNumDectected].snr = (int16_t)(divsp_i ((float)processInst->aoaOutput->peakPow[angleCount], processInst->aoaInput->noise) * 8.f);
  436. cOutNumDectected++;
  437. if (cOutNumDectected > DOA_OUTPUT_MAXPOINTS) break;
  438. }
  439. }
  440. }
  441. numDynamicPnts = cOutNumDectected;
  442. #ifdef _TMS320C6X
  443. processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx].dynAngleDopEstCycles = TSCL - t1;
  444. processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx].dynNumDetPnts = numDynamicPnts;
  445. #endif
  446. }
  447. #ifdef CCS
  448. printf("dyn pnt: %d\t", numDynamicPnts);
  449. #endif
  450. /////////////////// end of Dynamic processing ////////////////////////////////////
  451. ////////////////////////////////////////////////////////////////////////////////////////////
  452. /////////////////// Calling modules -- Static processing ////////////////////////
  453. ////////////////////////////////////////////////////////////////////////////////////////////
  454. if ((processInst->staticProcEnabled) && (cOutNumDectected < DOA_OUTPUT_MAXPOINTS))
  455. { //range-angle heatmap generation for Static scene processing
  456. processInst->aoaInput->processingStepSelector = 0; //BF part
  457. #ifdef _TMS320C6X
  458. t1 = TSCL;
  459. #endif
  460. for ( i = 0; i < processInst->numRangeBins; i++)
  461. {
  462. processInst->aoaInput->rangeIndx = i;
  463. processInst->aoaOutput->rangeAzimuthHeatMap = processInst->tempHeatMapOut;
  464. processInst->aoaBFErrorCode = RADARDEMO_aoaEst2DCaponBF_static_run(
  465. processInst->aoaInstance,
  466. processInst->aoaInput,
  467. processInst->aoaOutput);
  468. copyTranspose((uint32_t *)&processInst->tempHeatMapOut[0], (uint32_t *)&processInst->localHeatmap[i], processInst->numStaticAngleBin, 0, processInst->numRangeBins, 1);
  469. }
  470. #ifdef _TMS320C6X
  471. processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx].staticHeatmpGenCycles = TSCL - t1;
  472. #endif
  473. }
  474. if (processInst->staticProcEnabled)
  475. { // test CFAR -- for Static scene processing
  476. #ifdef _TMS320C6X
  477. t1 = TSCL;
  478. #endif
  479. processInst->detectionCFARInput->azMaxPerRangeBin = processInst->perRangeBinMax;
  480. processInst->detectionCFARInput->sidelobeThr = processInst->staticSideLobeThr;
  481. processInst->detectionCFARInput->enableSecondPass = 0;
  482. processInst->detectionCFARInput->enable_neighbour_check = 1;
  483. processInst->detectionCFARInput->heatmapInput = processInst->staticHeatmapPtr;
  484. // Detection
  485. processInst->cfarErrorCode = RADARDEMO_detectionCFAR_run(
  486. processInst->staticCFARInstance,
  487. processInst->detectionCFARInput,
  488. processInst->detectionCFAROutput);
  489. #ifdef _TMS320C6X
  490. processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx].staticCfarDetectionCycles = TSCL - t1;
  491. #endif
  492. }
  493. if (processInst->staticProcEnabled)
  494. { // angle interpolation per detected range-angle points -- for Static scene processing
  495. int32_t detIdx, angleIdx;
  496. #ifdef _TMS320C6X
  497. t1 = TSCL;
  498. #endif
  499. processInst->aoaInput->processingStepSelector = 1;
  500. processInst->aoaOutput->rangeAzimuthHeatMap = &processInst->localHeatmap[0];
  501. processInst->aoaInput->nChirps = processInst->numChirpsPerFrame;
  502. processInst->aoaOutput->rangeAzimuthHeatMap = processInst->localHeatmap;
  503. for (detIdx = 0; detIdx < (int32_t)processInst->detectionCFAROutput->numObjDetected; detIdx++)
  504. {
  505. if (cOutNumDectected > DOA_OUTPUT_MAXPOINTS) break;
  506. processInst->aoaInput->rangeIndx = processInst->detectionCFAROutput->rangeInd[detIdx];
  507. processInst->aoaInput->angleIndx = processInst->detectionCFAROutput->dopplerInd[detIdx];
  508. processInst->aoaInput->inputRangeProcOutSamples = &pDataIn[processInst->aoaInput->rangeIndx * processInst->nRxAnt * processInst->aoaInput->nChirps];
  509. processInst->aoaInput->noise = processInst->detectionCFAROutput->noise[detIdx];
  510. processInst->aoaBFErrorCode = RADARDEMO_aoaEst2DCaponBF_static_run(
  511. processInst->aoaInstance,
  512. processInst->aoaInput,
  513. processInst->aoaOutput);
  514. for ( angleIdx = 0; angleIdx < processInst->aoaOutput->numAngleEst; angleIdx++ )
  515. {
  516. output->pointCloud[cOutNumDectected].range = (float)processInst->aoaInput->rangeIndx * processInst->rangeRes;
  517. output->pointCloud[cOutNumDectected].azimuthAngle = -processInst->aoaOutput->azimEst[angleIdx];
  518. output->pointCloud[cOutNumDectected].elevAngle = processInst->aoaOutput->elevEst[angleIdx];
  519. output->pointCloud[cOutNumDectected].velocity = 0.f;
  520. output->snr[cOutNumDectected].snr = (int16_t)(divsp_i ((float)processInst->aoaOutput->peakPow[angleIdx], processInst->aoaInput->noise) * 8.f);
  521. cOutNumDectected++;
  522. if (cOutNumDectected > DOA_OUTPUT_MAXPOINTS) break;
  523. }
  524. }
  525. #ifdef _TMS320C6X
  526. processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx].staticAngleEstCycles = TSCL - t1;
  527. processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx].staticNumDetPnts = cOutNumDectected - numDynamicPnts;
  528. #endif
  529. }
  530. #ifdef CCS
  531. printf("static pnt: %d\t", cOutNumDectected - numDynamicPnts);
  532. #endif
  533. #ifdef _TMS320C6X
  534. resultsPtr->benchmarkOut = &processInst->benchmarkPtr->buffer[processInst->benchmarkPtr->bufferIdx];
  535. #endif
  536. heatmap->datafmt = 0;
  537. heatmap->dataSize = processInst->heatMapMemSize;
  538. heatmap->data = (void *)processInst->localHeatmap;
  539. output->object_count = cOutNumDectected;
  540. *errCode = (int32_t)processInst->aoaBFErrorCode;
  541. return(-processInst->aoaBFErrorCode);
  542. }
  543. /**
  544. * @b Description
  545. * @n
  546. * The function is radarProcess DPU control function. Currently not used.
  547. *
  548. * @param[in] handle radarProcess handle.
  549. *
  550. * @retval
  551. * Success =0
  552. * @retval
  553. * Error <0
  554. */
  555. int32_t DPU_radarProcess_control
  556. (
  557. DPU_radarProcess_Handle handle
  558. )
  559. {
  560. int32_t retVal = 0;
  561. return (retVal);
  562. }
  563. /**
  564. * @b Description
  565. * @n
  566. * The function is radarProcess DPU deinit function. It release resources used for the DPU.
  567. *
  568. * @param[in] handle radarProcess handle.
  569. * @param[in] errCode Pointer to errCode generates from the API
  570. *
  571. *
  572. * @retval
  573. * Success =0
  574. * @retval
  575. * Error <0
  576. */
  577. int32_t DPU_radarProcess_deinit
  578. (
  579. DPU_radarProcess_Handle handle,
  580. int32_t *errCode
  581. )
  582. {
  583. radarProcessInstance_t * processInst = (radarProcessInstance_t *)handle;
  584. RADARDEMO_aoaEst2DCaponBF_delete(processInst->aoaInstance);
  585. RADARDEMO_detectionCFAR_delete(processInst->dynamicCFARInstance);
  586. if (processInst->staticProcEnabled)
  587. RADARDEMO_detectionCFAR_delete(processInst->staticCFARInstance);
  588. //
  589. radarOsal_memFree(processInst, sizeof(radarProcessInstance_t));
  590. return 0;
  591. }