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 111KB

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