This repository was archived by the owner on Feb 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.c
More file actions
1495 lines (1301 loc) · 50.5 KB
/
main.c
File metadata and controls
1495 lines (1301 loc) · 50.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file main.c
*
* @brief
* This is the main file which implements the millimeter wave Demo
*
* \par
* NOTE:
* (C) Copyright 2016 Texas Instruments, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************
*************************** Include Files ********************************
**************************************************************************/
/* Standard Include Files. */
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
/* BIOS/XDC Include Files. */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/IHeap.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/Memory.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/heaps/HeapBuf.h>
#include <ti/sysbios/heaps/HeapMem.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/family/arm/v7a/Pmu.h>
#include <ti/sysbios/family/arm/v7r/vim/Hwi.h>
#include <ti/sysbios/utils/Load.h>
/* mmWave SDK Include Files: */
#include <ti/common/sys_common.h>
#include <ti/common/mmwave_sdk_version.h>
#include <ti/drivers/soc/soc.h>
#include <ti/drivers/esm/esm.h>
#include <ti/drivers/crc/crc.h>
#include <ti/drivers/gpio/gpio.h>
#include <ti/drivers/mailbox/mailbox.h>
#include <ti/control/mmwave/mmwave.h>
#include <ti/drivers/osal/DebugP.h>
#include <ti/drivers/uart/UART.h>
#include <ti/utils/cli/cli.h>
#include <ti/demo/io_interface/mmw_output.h>
#include "config_edma_util.h"
#include "config_hwa_util.h"
/* Demo Include Files */
#include "mmw.h"
#include "data_path.h"
#include <ti/demo/io_interface/mmw_config.h>
#include <ti/demo/utils/mmwDemo_monitor.h>
/* These address offsets are in bytes, when configure address offset in hardware,
these values will be converted to number of 128bits */
#define MMW_DEMO_CQ_SIGIMG_ADDR_OFFSET 0U
#define MMW_DEMO_CQ_RXSAT_ADDR_OFFSET 0x400U
extern mmwHwaBuf_t gMmwHwaMemBuf[MMW_HWA_NUM_MEM_BUFS];
extern uint32_t log2Approx(uint32_t x);
/*! L3 RAM buffer */
uint8_t gMmwL3[SOC_XWR14XX_MSS_L3RAM_SIZE];
#pragma DATA_SECTION(gMmwL3, ".l3ram");
/* Data memory for CQ:Rx Saturation - 16 bit CQ format */
rlRfRxSaturationCqData_t gCQRxSatMonMemory;
/* Data memory for CQ:Signal & Image band monitor - 16 bit CQ format */
rlRfSigImgPowerCqData_t gCQRxSigImgMemory;
/*! L3 heap for convenience of partitioning L3 RAM */
MmwDemoMemPool_t gMmwL3heap =
{
&gMmwL3[0],
SOC_XWR14XX_MSS_L3RAM_SIZE,
0
};
/**************************************************************************
*************************** Global Definitions ***************************
**************************************************************************/
/**
* @brief
* Global Variable for tracking information required by the mmw Demo
*/
MmwDemo_MCB gMmwMCB;
/**************************************************************************
*************************** Extern Definitions ***************************
**************************************************************************/
extern void MmwDemo_CLIInit (void);
/**************************************************************************
************************* Millimeter Wave Demo Functions **********************
**************************************************************************/
void MmwDemo_mmWaveCtrlTask(UArg arg0, UArg arg1);
void MmwDemo_dataPathInit(MmwDemo_DataPathObj *obj);
void MmwDemo_dataPathConfig(void);
void MmwDemo_dataPathOpen(MmwDemo_DataPathObj *obj);
void MmwDemo_dataPathStop (MmwDemo_DataPathObj *obj);
void MmwDemo_transmitProcessedOutput(UART_Handle uartHandle,
MmwDemo_DataPathObj *obj);
void MmwDemo_initTask(UArg arg0, UArg arg1);
void MmwDemo_dataPathTask(UArg arg0, UArg arg1);
int32_t MmwDemo_eventCallbackFxn(uint16_t msgId, uint16_t sbId, uint16_t sbLen, uint8_t *payload);
/* external sleep function when in idle (used in .cfg file) */
void MmwDemo_sleep(void);
/**
* @b Description
* @n
* Send assert information through CLI.
*/
void _MmwDemo_debugAssert(int32_t expression, const char *file, int32_t line)
{
if (!expression) {
CLI_write ("Exception: %s, line %d.\n",file,line);
}
}
/**
* @b Description
* @n
* Get a handle for ADCBuf.
*/
void MmwDemo_ADCBufOpen(MmwDemo_DataPathObj *obj)
{
ADCBuf_Params ADCBufparams;
/*****************************************************************************
* Start ADCBUF driver:
*****************************************************************************/
/* ADCBUF Params initialize */
ADCBuf_Params_init(&ADCBufparams);
ADCBufparams.chirpThreshold = 1;
ADCBufparams.continousMode = 0;
/* Open ADCBUF driver */
obj->adcbufHandle = ADCBuf_open(0, &ADCBufparams);
if (obj->adcbufHandle == NULL)
{
//System_printf("Error: Unable to open the ADCBUF driver\n");
MmwDemo_debugAssert (0);
return;
}
//System_printf("Debug: ADCBUF Instance(0) %p has been opened successfully\n", obj->adcbufHandle);
}
/**
* @b Description
* @n
* Configures ADCBuf and returns the number of RxAntennas
*/
int32_t MmwDemo_ADCBufConfig(MmwDemo_DataPathObj *dataPathObj)
{
ADCBuf_dataFormat dataFormat;
ADCBuf_RxChanConf rxChanConf;
uint8_t channel;
int32_t retVal = 0;
uint8_t numBytePerSample = 0;
MmwDemo_ADCBufCfg* ptrAdcbufCfg;
uint32_t chirpThreshold;
uint32_t rxChanMask = 0xF;
ptrAdcbufCfg = &dataPathObj->cliCfg->adcBufCfg;
/* Check if ADC configuration is supported:*/
/* ADC out bits: must be 16 Bits */
MmwDemo_debugAssert(gMmwMCB.cfg.openCfg.adcOutCfg.fmt.b2AdcBits == 2);
/* ADC data format: must be complex */
/*adcCfg command*/
if((gMmwMCB.cfg.openCfg.adcOutCfg.fmt.b2AdcOutFmt != 1) &&
(gMmwMCB.cfg.openCfg.adcOutCfg.fmt.b2AdcOutFmt != 2))
{
MmwDemo_debugAssert(0);
}
/*adcbufCfg command*/
MmwDemo_debugAssert(ptrAdcbufCfg->adcFmt == 0);
/* ADC channel interleave mode: must be interleaved */
MmwDemo_debugAssert(ptrAdcbufCfg->chInterleave == 0);
/*****************************************************************************
* Disable all ADCBuf channels
*****************************************************************************/
if ((retVal = ADCBuf_control(dataPathObj->adcbufHandle, ADCBufMMWave_CMD_CHANNEL_DISABLE, (void *)&rxChanMask)) < 0)
{
//System_printf("Error: Disable ADCBuf channels failed with [Error=%d]\n", retVal);
MmwDemo_debugAssert (0);
goto exit;
}
/* Complex dataFormat has 4 bytes */
numBytePerSample = 4;
/* Configure ADC buffer data format */
dataFormat.adcOutFormat = ptrAdcbufCfg->adcFmt;
dataFormat.sampleInterleave = ptrAdcbufCfg->iqSwapSel;
dataFormat.channelInterleave = ptrAdcbufCfg->chInterleave;
/* Debug Message: */
/*System_printf("Debug: Start ADCBuf driver dataFormat=%d, sampleSwap=%d, interleave=%d, chirpThreshold=%d\n",
dataFormat.adcOutFormat, dataFormat.sampleInterleave, dataFormat.channelInterleave,
ptrAdcbufCfg->chirpThreshold);*/
retVal = ADCBuf_control(dataPathObj->adcbufHandle, ADCBufMMWave_CMD_CONF_DATA_FORMAT, (void *)&dataFormat);
if (retVal < 0)
{
MmwDemo_debugAssert (0);
goto exit;
}
memset((void*)&rxChanConf, 0, sizeof(ADCBuf_RxChanConf));
/* Enable Rx Channel indicated in channel configuration */
for (channel = 0; channel < SYS_COMMON_NUM_RX_CHANNEL; channel++)
{
if(gMmwMCB.cfg.openCfg.chCfg.rxChannelEn & (0x1<<channel))
{
/* Populate the receive channel configuration: */
rxChanConf.channel = channel;
retVal = ADCBuf_control(dataPathObj->adcbufHandle, ADCBufMMWave_CMD_CHANNEL_ENABLE, (void *)&rxChanConf);
if (retVal < 0)
{
MmwDemo_debugAssert (0);
goto exit;
}
rxChanConf.offset += dataPathObj->numAdcSamples * numBytePerSample;
}
}
chirpThreshold = ptrAdcbufCfg->chirpThreshold;
/* Set the chirp threshold: */
retVal = ADCBuf_control(dataPathObj->adcbufHandle, ADCBufMMWave_CMD_SET_CHIRP_THRESHHOLD,
(void *)&chirpThreshold);
if(retVal < 0)
{
MmwDemo_debugAssert (0);
}
exit:
return retVal;
}
/**
* @b Description
* @n
* EDMA transfer completion callback for CQ transfers
*
* @param[in] arg Transfer completion callback argument
* @param[in] transferCompletionCode Transfer completion code
*
* @retval
* None
*/
void MmwDemo_EDMA_CQTransferCompletionCallbackFxn(uintptr_t arg,
uint8_t transferCompletionCode)
{
MmwDemo_DataPathObj *obj = (MmwDemo_DataPathObj *)arg;
switch (transferCompletionCode)
{
case MMW_EDMA_RXSAT_TRANSFER_COMPLETION:
/* Chained EDMA channels complete on 2nd EDMA channel */
if(obj->datapathCQ.anaMonCfg->sigImgMonEn)
{
obj->datapathCQ.sigImgBandEdmaCnt++;
MmwDemo_debugAssert(*(uint8_t *)obj->datapathCQ.sigImgData <= obj->datapathCQ.sigImgMonCfg->numSlices);
}
if(obj->datapathCQ.anaMonCfg->rxSatMonEn)
{
obj->datapathCQ.rxSatEdmaCnt++;
MmwDemo_debugAssert(*(uint8_t *)obj->datapathCQ.rxSatData <= obj->datapathCQ.rxSatMonCfg->numSlices);
}
break;
default:
MmwDemo_debugAssert(0);
break;
}
}
/**
* @b Description
* @n
* Configures all CQ EDMA channels and param sets used in data path processing
* @param[in] obj Pointer to data path object
*
* @retval
* -1 if error, 0 for no error
*/
int32_t MmwDemo_dataPathConfigCQEdma(MmwDemo_DataPathObj *obj)
{
uint32_t eventQueue;
int32_t retVal = 0;
uint16_t aCnt;
/*****************************************************
* EDMA configuration for getting CQ data from CQ buffer
* to Datapath CQ storage
*****************************************************/
/* Use event queue 1 for CQ because when event queue 0 is used for CQ
and LVDS streaming is enabled (LVDS streaming uses event queue 0)
then there is data corruption on the saved CQ data that is EDMAed below.
Problem being investigated.*/
eventQueue = 1U;
/*
EDMA configurations for 2 chained EDMA channels:
sigImgMonEn = 1, rxSatMonEn = 1,
acnt: sigImgMonTotalSize, satMonTotalSize
sigImgMonEn = 1, rxSatMonEn = 0,
acnt: sigImgMonTotalSize, 0
sigImgMonEn = 0, rxSatMonEn = 1,
acnt: 0, satMonTotalSize
*/
if(obj->datapathCQ.anaMonCfg->sigImgMonEn)
{
aCnt = obj->datapathCQ.sigImgMonTotalSize;
}
else
{
/* This becomes a dummy paRAM set */
aCnt = 0;
}
/* Configure EDMA channel for sigImg monitor */
retVal = EDMAutil_configSyncAwithChaining(obj->edmaHandle,
(uint8_t *)(SOC_translateAddress((uint32_t)obj->datapathCQ.sigImgMonAddr,SOC_TranslateAddr_Dir_TO_EDMA,NULL)),
(uint8_t *)(SOC_translateAddress((uint32_t)obj->datapathCQ.sigImgData,SOC_TranslateAddr_Dir_TO_EDMA,NULL)),
EDMA_TPCC0_REQ_DFE_CHIRP_AVAIL,
MMW_EDMA_CH_RX_SATURATION_MON,
true,
EDMA_TPCC0_REQ_DFE_CHIRP_AVAIL,
aCnt,
1,
0,
0,
eventQueue,
false, /*isFinalTransferInterruptEnabled */
true, /* isFinalChainingEnabled */
NULL,
(uintptr_t) NULL);
if (retVal != EDMA_NO_ERROR)
{
return -1;
}
if(obj->datapathCQ.anaMonCfg->rxSatMonEn)
{
aCnt = obj->datapathCQ.satMonTotalSize;
}
else
{
/* This becomes a dummy paRAM set */
aCnt = 0;
}
/* Configure EDMA channel for RX saturation monitor */
retVal = EDMAutil_configSyncAwithChaining(obj->edmaHandle,
(uint8_t *)(SOC_translateAddress((uint32_t)obj->datapathCQ.satMonAddr,SOC_TranslateAddr_Dir_TO_EDMA,NULL)),
(uint8_t *)(SOC_translateAddress((uint32_t)obj->datapathCQ.rxSatData,SOC_TranslateAddr_Dir_TO_EDMA,NULL)),
MMW_EDMA_CH_RX_SATURATION_MON,
MMW_EDMA_CH_RX_SATURATION_MON,
false,
MMW_EDMA_CH_RX_SATURATION_MON,
aCnt,
1,
0,
0,
eventQueue,
true, /*isFinalTransferInterruptEnabled */
false, /* isFinalChainingEnabled */
MmwDemo_EDMA_CQTransferCompletionCallbackFxn,
(uintptr_t) obj);
if (retVal != EDMA_NO_ERROR)
{
return -1;
}
return 0;
}
/**
* @b Description
* @n
* Function to configure CQ.
* @param[in] ptrDataPathObj Pointer to data path object.
*
* @retval
* 0 if no error, else error (there will be system prints for these).
*/
int32_t MmwDemo_dataPathConfigCQ(MmwDemo_DataPathObj * ptrDataPathObj)
{
ADCBuf_CQConf cqConfig;
rlRxSatMonConf_t* ptrSatMonCfg;
rlSigImgMonConf_t* ptrSigImgMonCfg;
MmwDemo_AnaMonitorCfg* ptrAnaMonitorCfg;
int32_t retVal;
/* Get analog monitor configuration */
ptrAnaMonitorCfg = &ptrDataPathObj->cliCommonCfg->anaMonCfg;
/* Config mmwaveLink to enable Saturation monitor - CQ2 */
ptrSatMonCfg = &ptrDataPathObj->cliCommonCfg->cqSatMonCfg[ptrDataPathObj->validProfileIdx];
if (ptrAnaMonitorCfg->rxSatMonEn)
{
retVal = mmwDemo_cfgRxSaturationMonitor(ptrSatMonCfg);
if(retVal < 0)
{
System_printf ("Error: rlRfRxIfSatMonConfig returns error = %d\n", retVal);
MmwDemo_debugAssert(0);
}
}
/* Config mmwaveLink to enable Signal Image band monitor - CQ1 */
ptrSigImgMonCfg = &ptrDataPathObj->cliCommonCfg->cqSigImgMonCfg[ptrDataPathObj->validProfileIdx];
if (ptrAnaMonitorCfg->sigImgMonEn)
{
retVal = mmwDemo_cfgRxSigImgMonitor(ptrSigImgMonCfg);
if(retVal < 0)
{
System_printf ("Error: rlRfRxIfSatMonConfig returns error = %d\n", retVal);
MmwDemo_debugAssert(0);
}
}
/* Config CQ */
if ((ptrAnaMonitorCfg->rxSatMonEn) || (ptrAnaMonitorCfg->sigImgMonEn))
{
/* CQ driver config */
memset((void *)&cqConfig, 0, sizeof(ADCBuf_CQConf));
cqConfig.cqDataWidth = 0; /* 16bit for mmw demo */
/* CQ1 starts from the beginning of the buffer, address should be 16 bytes aligned */
cqConfig.cq1AddrOffset = MMW_DEMO_CQ_SIGIMG_ADDR_OFFSET;
cqConfig.cq2AddrOffset = MMW_DEMO_CQ_RXSAT_ADDR_OFFSET; /* address should be 16 bytes aligned. */
retVal = ADCBuf_control(ptrDataPathObj->adcbufHandle, ADCBufMMWave_CMD_CONF_CQ, (void *)&cqConfig);
if (retVal < 0)
{
System_printf ("Error: Unable to configure CQ, errorCode[%d]\n", retVal);
return -1;
}
}
/* Save config pointer */
ptrDataPathObj->datapathCQ.rxSatMonCfg = ptrSatMonCfg;
ptrDataPathObj->datapathCQ.sigImgMonCfg = ptrSigImgMonCfg;
ptrDataPathObj->datapathCQ.anaMonCfg= ptrAnaMonitorCfg;
if (ptrAnaMonitorCfg->sigImgMonEn)
{
/* Save CQ-Signal & Image band energy info in datapath object */
ptrDataPathObj->datapathCQ.sigImgMonAddr = ADCBUF_MMWave_getCQBufAddr(ptrDataPathObj->adcbufHandle,
ADCBufMMWave_CQType_CQ1,
&retVal);
MmwDemo_debugAssert (ptrDataPathObj->datapathCQ.sigImgMonAddr != NULL);
/* This is for 16bit format in mmw demo */
ptrDataPathObj->datapathCQ.sigImgMonTotalSize = (ptrSigImgMonCfg->numSlices + 1U) * 2U;
/* Allocate data memory */
ptrDataPathObj->datapathCQ.sigImgData = &gCQRxSigImgMemory;
}
if (ptrAnaMonitorCfg->rxSatMonEn)
{
/* Save CQ-Rx Saturation info in datapath object */
ptrDataPathObj->datapathCQ.satMonAddr =
ADCBUF_MMWave_getCQBufAddr(ptrDataPathObj->adcbufHandle,
ADCBufMMWave_CQType_CQ2,
&retVal);
MmwDemo_debugAssert (ptrDataPathObj->datapathCQ.satMonAddr != NULL);
/* This is for 16bit format in mmw demo */
ptrDataPathObj->datapathCQ.satMonTotalSize = ptrSatMonCfg->numSlices + 1U;
/* Allocate data memory */
ptrDataPathObj->datapathCQ.rxSatData = &gCQRxSatMonMemory;
}
/* EDMA configuration for CQ */
if ((ptrAnaMonitorCfg->rxSatMonEn) || (ptrAnaMonitorCfg->sigImgMonEn))
{
retVal = MmwDemo_dataPathConfigCQEdma(ptrDataPathObj);
if(retVal < 0)
{
return -1;
}
}
return 0;
}
/**
* @b Description
* @n
* parses Profile, Chirp and Frame config and extracts parameters
* needed for processing chain configuration
*/
bool MmwDemo_parseProfileAndChirpConfig(MmwDemo_DataPathObj *dataPathObj)
{
uint16_t frameChirpStartIdx;
uint16_t frameChirpEndIdx;
int16_t frameTotalChirps;
int32_t errCode;
uint32_t profileLoopIdx, chirpLoopIdx;
bool foundValidProfile = false;
uint16_t channelTxEn = gMmwMCB.cfg.openCfg.chCfg.txChannelEn;
uint8_t channel;
uint8_t numRxAntennas = 0;
/* Find number of enabled channels */
for (channel = 0; channel < SYS_COMMON_NUM_RX_CHANNEL; channel++)
{
if(gMmwMCB.cfg.openCfg.chCfg.rxChannelEn & (0x1<<channel))
{
/* Track the number of receive channels: */
numRxAntennas++;
}
}
dataPathObj->numRxAntennas = numRxAntennas;
/* read frameCfg chirp start/stop*/
frameChirpStartIdx = gMmwMCB.cfg.ctrlCfg.u.frameCfg.frameCfg.chirpStartIdx;
frameChirpEndIdx = gMmwMCB.cfg.ctrlCfg.u.frameCfg.frameCfg.chirpEndIdx;
frameTotalChirps = frameChirpEndIdx - frameChirpStartIdx + 1;
/* loop for profiles and find if it has valid chirps */
/* we support only one profile in this processing chain */
for (profileLoopIdx=0;
((profileLoopIdx<MMWAVE_MAX_PROFILE)&&(foundValidProfile==false));
profileLoopIdx++)
{
uint32_t mmWaveNumChirps = 0;
bool validProfileHasElevation=false;
bool validProfileHasOneTxPerChirp=false;
uint16_t validProfileTxEn = 0;
uint16_t validChirpTxEnBits[32]={0};
MMWave_ProfileHandle profileHandle;
profileHandle = gMmwMCB.cfg.ctrlCfg.u.frameCfg.profileHandle[profileLoopIdx];
if (profileHandle == NULL)
continue; /* skip this profile */
/* get numChirps for this profile; skip error checking */
MMWave_getNumChirps(profileHandle,&mmWaveNumChirps,&errCode);
/* loop for chirps and find if it has valid chirps for the frame
looping around for all chirps in a profile, in case
there are duplicate chirps
*/
for (chirpLoopIdx=1;chirpLoopIdx<=mmWaveNumChirps;chirpLoopIdx++)
{
MMWave_ChirpHandle chirpHandle;
/* get handle and read ChirpCfg */
if (MMWave_getChirpHandle(profileHandle,chirpLoopIdx,&chirpHandle,&errCode)==0)
{
rlChirpCfg_t chirpCfg;
if (MMWave_getChirpCfg(chirpHandle,&chirpCfg,&errCode)==0)
{
uint16_t chirpTxEn = chirpCfg.txEnable;
/* do chirps fall in range and has valid antenna enabled */
if ((chirpCfg.chirpStartIdx >= frameChirpStartIdx) &&
(chirpCfg.chirpEndIdx <= frameChirpEndIdx) &&
((chirpTxEn & channelTxEn) > 0))
{
uint16_t idx = 0;
for (idx=(chirpCfg.chirpStartIdx-frameChirpStartIdx);idx<=(chirpCfg.chirpEndIdx-frameChirpStartIdx);idx++)
{
validChirpTxEnBits[idx] = chirpTxEn;
foundValidProfile = true;
}
}
}
}
}
/* now loop through unique chirps and check if we found all of the ones
needed for the frame and then determine the azimuth/elevation antenna
configuration
*/
if (foundValidProfile) {
int16_t nonElevFirstChirpIdx = -1;
for (chirpLoopIdx=0;chirpLoopIdx<frameTotalChirps;chirpLoopIdx++)
{
bool validChirpHasElevation=false;
bool validChirpHasOneTxPerChirp=false;
uint16_t chirpTxEn = validChirpTxEnBits[chirpLoopIdx];
if (chirpTxEn == 0) {
/* this profile doesnt have all the needed chirps */
foundValidProfile = false;
break;
}
/* check if this is an elevation TX chirp */
validChirpHasElevation = (chirpTxEn==0x2);
validProfileHasElevation |= validChirpHasElevation;
/* if not, then check the MIMO config */
if (!validChirpHasElevation)
{
validChirpHasOneTxPerChirp = ((chirpTxEn==0x1) || (chirpTxEn==0x4));
/* if this is the first chirp without elevation, record the chirp's
MIMO config as profile's MIMO config. We dont handle intermix
at this point */
if (nonElevFirstChirpIdx==-1) {
validProfileHasOneTxPerChirp = validChirpHasOneTxPerChirp;
nonElevFirstChirpIdx = chirpLoopIdx;
}
/* check the chirp's MIMO config against Profile's MIMO config */
if (validChirpHasOneTxPerChirp != validProfileHasOneTxPerChirp)
{
/* this profile doesnt have all chirps with same MIMO config */
foundValidProfile = false;
break;
}
}
/* save the antennas actually enabled in this profile */
validProfileTxEn |= chirpTxEn;
}
}
/* found valid chirps for the frame; mark this profile valid */
if (foundValidProfile==true) {
rlProfileCfg_t profileCfg;
uint32_t numTxAntAzim = 0;
uint32_t numTxAntElev = 0;
dataPathObj->validProfileIdx = profileLoopIdx;
dataPathObj->numTxAntennas = 0;
if (validProfileHasElevation)
{
numTxAntElev = 1;
}
if (!validProfileHasOneTxPerChirp)
{
numTxAntAzim=1;
}
else
{
if (validProfileTxEn & 0x1)
{
numTxAntAzim++;
}
if (validProfileTxEn & 0x4)
{
numTxAntAzim++;
}
}
/*System_printf("Azimuth Tx: %d (MIMO:%d), Elev Tx:%d\n",
numTxAntAzim,validProfileHasMIMO,numTxAntElev);*/
dataPathObj->numTxAntennas = numTxAntAzim + numTxAntElev;
dataPathObj->numVirtualAntAzim = numTxAntAzim * dataPathObj->numRxAntennas;
dataPathObj->numVirtualAntElev = numTxAntElev * dataPathObj->numRxAntennas;
dataPathObj->numVirtualAntennas = dataPathObj->numVirtualAntAzim + dataPathObj->numVirtualAntElev;
/* Sanity Check: Ensure that the number of antennas is within system limits */
MmwDemo_debugAssert (dataPathObj->numVirtualAntennas > 0);
MmwDemo_debugAssert (dataPathObj->numVirtualAntennas <= (SYS_COMMON_NUM_TX_ANTENNAS * SYS_COMMON_NUM_RX_CHANNEL));
/* Get the profile configuration: */
if (MMWave_getProfileCfg(profileHandle,&profileCfg, &errCode) < 0)
{
MmwDemo_debugAssert(0);
return false;
}
#ifndef MMW_ENABLE_NEGATIVE_FREQ_SLOPE
/* Check frequency slope */
if (profileCfg.freqSlopeConst < 0)
{
System_printf("Frequency slope must be positive\n");
MmwDemo_debugAssert(0);
}
#endif
dataPathObj->numAdcSamples = profileCfg.numAdcSamples;
dataPathObj->numRangeBins = MmwDemo_pow2roundup(dataPathObj->numAdcSamples);
dataPathObj->numChirpsPerFrame = frameTotalChirps *
gMmwMCB.cfg.ctrlCfg.u.frameCfg.frameCfg.numLoops;
dataPathObj->numDopplerBins = dataPathObj->numChirpsPerFrame/dataPathObj->numTxAntennas;
dataPathObj->numRangeBinsPerTransfer = MMW_NUM_RANGE_BINS_PER_TRANSFER;
dataPathObj->rangeResolution = MMWDEMO_SPEED_OF_LIGHT_IN_METERS_PER_SEC * profileCfg.digOutSampleRate * 1e3 /
(2 * profileCfg.freqSlopeConst * ((3.6*1e3*900)/(1U << 26)) * 1e12 * dataPathObj->numRangeBins);
dataPathObj->xyzOutputQFormat = (uint32_t) ceil(log10(16./fabs(dataPathObj->rangeResolution))/log10(2));
dataPathObj->dataPathMode = DATA_PATH_WITH_ADCBUF;
dataPathObj->frameStartIntCounter = 0;
dataPathObj->interFrameProcToken = 0;
}
}
return foundValidProfile;
}
/** @brief Transmits detection data over UART
*
* The following data is transmitted:
* 1. Header (size = 32bytes), including "Magic word", (size = 8 bytes)
* and icluding the number of TLV items
* TLV Items:
* 3. If logMagRange flag is set, rangeProfile,
* size = number of range bins * sizeof(uint16_t)
* 7. If rangeAzimuthHeatMap flag is set, the zero Doppler column of the
* range cubed matrix, size = number of Rx Azimuth virtual antennas *
* number of chirps per frame * sizeof(uint32_t)
* 8. If rangeDopplerHeatMap flag is set, the log magnitude range-Doppler matrix,
* size = number of range bins * number of Doppler bins * sizeof(uint16_t)
* @param[in] uartHandle UART driver handle
* @param[in] obj Pointer data path object MmwDemo_DataPathObj
*/
void MmwDemo_transmitProcessedOutput(UART_Handle uartHandle,
MmwDemo_DataPathObj *obj)
{
MmwDemo_output_message_header header;
MmwDemo_GuiMonSel *pGuiMonSel;
uint32_t tlvIdx = 0;
uint32_t i;
uint32_t numPaddingBytes;
uint32_t packetLen;
uint8_t padding[MMWDEMO_OUTPUT_MSG_SEGMENT_LEN];
MmwDemo_output_message_tl tl[MMWDEMO_OUTPUT_MSG_MAX];
if (obj->frameStartIntCounter > 1) {
// Only send the first frame.
return;
}
/* Get Gui Monitor configuration */
pGuiMonSel = &gMmwMCB.cliCfg.guiMonSel;
/* Clear message header */
memset((void *)&header, 0, sizeof(MmwDemo_output_message_header));
/* Header: */
header.platform = 0xA1443;
header.magicWord[0] = 0x0102;
header.magicWord[1] = 0x0304;
header.magicWord[2] = 0x0506;
header.magicWord[3] = 0x0708;
header.numDetectedObj = 0;
header.version = MMWAVE_SDK_VERSION_BUILD | //DEBUG_VERSION
(MMWAVE_SDK_VERSION_BUGFIX << 8) |
(MMWAVE_SDK_VERSION_MINOR << 16) |
(MMWAVE_SDK_VERSION_MAJOR << 24);
packetLen = sizeof(MmwDemo_output_message_header);
if (pGuiMonSel->logMagRange)
{
tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_RANGE_PROFILE;
tl[tlvIdx].length = sizeof(uint16_t) * obj->numRangeBins;
packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
tlvIdx++;
}
if (pGuiMonSel->rangeAzimuthHeatMap)
{
tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_AZIMUT_STATIC_HEAT_MAP;
tl[tlvIdx].length = obj->numRangeBins * obj->numVirtualAntAzim * sizeof(uint32_t);
packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
tlvIdx++;
}
if (pGuiMonSel->rangeDopplerHeatMap)
{
tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_RANGE_DOPPLER_HEAT_MAP;
tl[tlvIdx].length = obj->numRangeBins * obj->numDopplerBins * sizeof(uint16_t);
packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
tlvIdx++;
}
header.numTLVs = tlvIdx;
/* Round up packet length to multiple of MMWDEMO_OUTPUT_MSG_SEGMENT_LEN */
header.totalPacketLen = MMWDEMO_OUTPUT_MSG_SEGMENT_LEN *
((packetLen + (MMWDEMO_OUTPUT_MSG_SEGMENT_LEN-1))/MMWDEMO_OUTPUT_MSG_SEGMENT_LEN);
header.timeCpuCycles = Pmu_getCount(0);
header.frameNumber = obj->frameStartIntCounter;
UART_writePolling (uartHandle,
(uint8_t*)&header,
sizeof(MmwDemo_output_message_header));
tlvIdx = 0;
/* Send Range profile */
if (pGuiMonSel->logMagRange)
{
UART_writePolling (uartHandle,
(uint8_t*)&tl[tlvIdx],
sizeof(MmwDemo_output_message_tl));
for(i = 0; i < obj->numRangeBins; i++)
{
UART_writePolling (uartHandle,
(uint8_t*)&obj->rangeDopplerLogMagMatrix[i*obj->numDopplerBins],
sizeof(uint16_t));
}
tlvIdx++;
}
/* Send data for static azimuth heatmap */
if (pGuiMonSel->rangeAzimuthHeatMap)
{
UART_writePolling (uartHandle,
(uint8_t*)&tl[tlvIdx],
sizeof(MmwDemo_output_message_tl));
UART_writePolling (uartHandle,
(uint8_t *) obj->azimuthStaticHeatMap,
obj->numRangeBins * obj->numVirtualAntAzim * sizeof(uint32_t));
tlvIdx++;
}
/* Send data for range/Doppler heatmap */
if (pGuiMonSel->rangeDopplerHeatMap == 1)
{
UART_writePolling (uartHandle,
(uint8_t*)&tl[tlvIdx],
sizeof(MmwDemo_output_message_tl));
UART_writePolling (uartHandle,
(uint8_t*)obj->rangeDopplerLogMagMatrix,
tl[tlvIdx].length);
tlvIdx++;
}
/* Send radarCube */
{
/* numRangeBins * numDopplerBins * numTxAntennas * numRxAntennas * 4 */
size_t radarCubeSize = obj->numRangeBins * obj->numDopplerBins * obj->numTxAntennas * obj->numRxAntennas * 4;
size_t transmitSize = radarCubeSize;
UART_writePolling(uartHandle,
(uint8_t*)obj->radarCube,
transmitSize);
}
/* Send padding bytes */
numPaddingBytes = MMWDEMO_OUTPUT_MSG_SEGMENT_LEN - (packetLen & (MMWDEMO_OUTPUT_MSG_SEGMENT_LEN-1));
if (numPaddingBytes<MMWDEMO_OUTPUT_MSG_SEGMENT_LEN)
{
UART_writePolling (uartHandle,
(uint8_t*)padding,
numPaddingBytes);
}
}
/**
* @b Description
* @n
* The function is used to trigger the Front end to start generating chirps.
*
* @retval
* Not Applicable.
*/
int32_t MmwDemo_dataPathStart (void)
{
MMWave_CalibrationCfg calibrationCfg;
int32_t errCode = 0;
MmwDemo_DataPathObj *dataPathObj = &gMmwMCB.dataPathObj;
dataPathObj->frameStartIntCounter = 0;
dataPathObj->interFrameProcToken = 0;
/* Initialize the calibration configuration: */
memset ((void *)&calibrationCfg, 0, sizeof(MMWave_CalibrationCfg));
/* Populate the calibration configuration: */
calibrationCfg.dfeDataOutputMode = MMWave_DFEDataOutputMode_FRAME;
calibrationCfg.u.chirpCalibrationCfg.enableCalibration = true;
calibrationCfg.u.chirpCalibrationCfg.enablePeriodicity = true;
calibrationCfg.u.chirpCalibrationCfg.periodicTimeInFrames = 10U;
/* Start the mmWave module: The configuration has been applied successfully. */
if (MMWave_start (gMmwMCB.ctrlHandle, &calibrationCfg, &errCode) < 0)
{
/* Error: Unable to start the mmWave control */
//System_printf ("Error: mmWave Control Start failed [Error code %d]\n", errCode);
MmwDemo_debugAssert (0);
}
else
{
/* Update data path stop status */
dataPathObj->datapathStopped = false;
}
return errCode;
}
/**
* @b Description
* @n
* The function is used to configure the data path based on the chirp profile.
* After this function is executed, the data path processing will ready to go
* when the ADC buffer starts receiving samples corresponding to the chirps.
*
* @retval
* Not Applicable.
*/
void MmwDemo_dataPathConfig (void)
{
int32_t retVal = 0;
MmwDemo_DataPathObj *dataPathObj = &gMmwMCB.dataPathObj;
/* Configure ADCBuf Config and get the valid number of RX antennas
do this first as we need the numRxAntennas in MmwDemo_parseProfileAndChirpConfig
to get the Virtual Antennas */
/* Parse the profile and chirp configs and get the valid number of TX Antennas */
if (MmwDemo_parseProfileAndChirpConfig(dataPathObj) == true)
{
retVal = mmwDemo_cfgAnalogMonitor(&dataPathObj->cliCommonCfg->anaMonCfg);
if (retVal != 0)
{
System_printf ("Error: rlRfAnaMonConfig returns error = %d\n", retVal);
MmwDemo_debugAssert(0);
}
if (MmwDemo_ADCBufConfig(dataPathObj) < 0)
{
//System_printf("Error: ADCBuf config failed \n");
MmwDemo_debugAssert (0);
}
/* Configure CQ */
MmwDemo_dataPathConfigCQ(dataPathObj);
/* Now we are ready to allocate and config the data buffers */
MmwDemo_dataPathCfgBuffers(dataPathObj, &gMmwL3heap);
/* Configure one-time EDMA and HWA parameters */
MmwDemo_dataPathConfigCommon(dataPathObj);
/* Config HWA for 1D processing and keep it ready for immediate processingh
as soon as Front End starts generating chirps */
MmwDemo_config1D_HWA(dataPathObj);
MmwDemo_dataPathTrigger1D(dataPathObj);
}
else
{
/* no valid profile found - assert! */
MmwDemo_debugAssert(0);