This repository has been archived by the owner on Feb 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
data_path.c
1360 lines (1219 loc) · 47 KB
/
data_path.c
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 data_path.c
*
* @brief
* Implements Data path processing functionality.
*
* \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/HeapMin.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>
#define DebugP_ASSERT_ENABLED 1
#include <ti/drivers/osal/DebugP.h>
#include <assert.h>
#include <ti/common/sys_common.h>
#include <ti/drivers/osal/SemaphoreP.h>
#include <ti/drivers/edma/edma.h>
#include <ti/drivers/esm/esm.h>
#include <ti/drivers/soc/soc.h>
#include "config_edma_util.h"
#include "config_hwa_util.h"
#include "data_path.h"
#include "mmw.h"
int32_t MmwDemo_config2D_EDMA(MmwDemo_DataPathObj *obj);
void MmwDemo_config2D_HWA(MmwDemo_DataPathObj *obj);
void MmwDemo_dataPathTrigger2D(MmwDemo_DataPathObj *obj);
void MmwDemo_dataPathWait2D(MmwDemo_DataPathObj *obj);
int32_t MmwDemo_config1D_EDMA(MmwDemo_DataPathObj *obj);
void MmwDemo_EDMA_transferCompletionCallbackFxn(uintptr_t arg,
uint8_t transferCompletionCode);
void MmwDemo_dataPathHwaDoneIsrCallback(void * arg);
#pragma DATA_SECTION(gMmwHwaMemBuf, ".hwaBufs");
/*! HWA memory buffer to produce the M0,M1,M2,M3 partition addresses
and link to the HWA section in the linker command file. */
mmwHwaBuf_t gMmwHwaMemBuf[MMW_HWA_NUM_MEM_BUFS];
/**
* @b Description
* @n
* Function to generate a single FFT window sample.
*
* @param[out] win Pointer to output calculated window sample.
* @param[in] winIndx Index of window to generate sample at.
* @param[in] phi Pre-calculated constant by caller as (2*pi/(window length - 1)).
* @param[in] winType Type of window, one of @ref MMW_WIN_BLACKMAN, @ref MMW_WIN_HANNING,
* or @ref MMW_WIN_RECT.
* @retval none.
*/
static inline MmwDemo_genWindow(uint32_t *win, uint32_t winIndx, float phi, uint32_t winType)
{
if(winType == MMW_WIN_BLACKMAN)
{
//Blackman window
float a0 = 0.42;
float a1 = 0.5;
float a2 = 0.08;
*win = (uint32_t) ((ONE_Q17 * (a0 - a1*cos(phi * winIndx) +
a2*cos(2 * phi * winIndx))) + 0.5); //in Q17
if(*win >= ONE_Q17)
{
*win = ONE_Q17 - 1;
}
}
else if(winType == MMW_WIN_HANNING)
{
//Hanning window
*win = (uint32_t) ((ONE_Q17 * 0.5* (1 - cos(phi * winIndx))) + 0.5); //in Q17
if(*win >= ONE_Q17)
{
*win = ONE_Q17 - 1;
}
}
else if(winType == MMW_WIN_RECT)
{
//Rectangular window
*win = (uint32_t) (ONE_Q17/16); //in Q17
}
}
/**
* @b Description
* @n
* EDMA transfer completion call back function as per EDMA API.
* Depending on the programmed transfer completion codes,
* posts the corresponding done/completion semaphore.
* Per current design, a single semaphore could have been used as the
* 1D and 2D stages are sequential, this code gives some flexibility
* if some design change in future.
*/
void MmwDemo_EDMA_transferCompletionCallbackFxn(uintptr_t arg,
uint8_t transferCompletionCode)
{
MmwDemo_DataPathObj *obj = (MmwDemo_DataPathObj *)arg;
switch (transferCompletionCode)
{
case MMWDEMO_EDMA_TRANSFER_COMPLETION_CODE_1D_DONE:
Semaphore_post(obj->EDMA_1Ddone_semHandle);
break;
case MMWDEMO_EDMA_TRANSFER_COMPLETION_CODE_2D_DONE:
Semaphore_post(obj->EDMA_2Ddone_semHandle);
break;
default:
MmwDemo_debugAssert(0);
break;
}
}
/**
* @b Description
* @n
* HWA processing completion call back function as per HWA API.
* Depending on the programmed transfer completion codes,
* posts HWA done semaphore.
*/
void MmwDemo_dataPathHwaDoneIsrCallback(void * arg)
{
Semaphore_Handle semHandle;
if (arg != NULL) {
semHandle = (Semaphore_Handle)arg;
Semaphore_post(semHandle);
}
}
/**
* @b Description
* @n
* Configures all 2D processing related EDMA configuration.
*
* @param[in] obj Pointer to data path object
* @retval EDMA error code, see EDMA API.
*/
int32_t MmwDemo_config2D_EDMA(MmwDemo_DataPathObj *obj)
{
int32_t errorCode = EDMA_NO_ERROR;
EDMA_Handle handle = obj->edmaHandle;
HWA_SrcDMAConfig dmaConfig;
uint32_t sizeOfAbsTransfer = obj->numDopplerBins * obj->numRangeBinsPerTransfer;
uint32_t sizeOfAbsTransferBytes = sizeOfAbsTransfer * sizeof(uint16_t);
uint32_t sizeOfComplexTransfer = obj->numDopplerBins * obj->numVirtualAntennas * obj->numRangeBinsPerTransfer;
uint32_t sizeOfComplexTransferBytes = sizeOfComplexTransfer * sizeof(uint32_t);
/**************PROGRAM DMA'S FOR PING**************************************/
if(obj->datapathChainSel == DATA_PATH_CHAIN_SEPARATE_LOGMAG)
{
/*************************************************************************
* PROGRAM DMA channel to transfer 2D FFT data from accelerator output
buffer (ping) to L3
*************************************************************************/
errorCode = EDMAutil_configHwaContiguous(handle,
MMW_EDMA_2D_PING_CH_ID, //chId,
true, //isEventTriggered
MMW_EDMA_2D_PING_SHADOW_LINK_CH_ID1, //linkChId,
MMW_EDMA_2D_PING_CHAIN_CH_ID1, //chainChId,
(uint32_t*)SOC_translateAddress((uint32_t)MMW_HWA_2D_OUT_PING,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //*pSrcAddress,
(uint32_t*)SOC_translateAddress((uint32_t)obj->radarCube,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //*pDestAddress,
sizeOfComplexTransferBytes, // numBytes,
obj->numRangeBins /(2*obj->numRangeBinsPerTransfer), //numBlocks,
0, //srcIncrBytes,
sizeOfComplexTransferBytes * 2, //dstIncrBytes,
true, //isIntermediateChainingEnabled,
true, //isFinalChainingEnabled,
false, //isTransferCompletionEnabled
NULL, //transferCompletionCallbackFxn
NULL);
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
/***************************************************************************
* PROGRAM DMA channel to transfer 2D abs data from accelerator output
* buffer (ping) to L3
**************************************************************************/
errorCode = EDMAutil_configHwaContiguous(handle,
MMW_EDMA_2D_PING_CHAIN_CH_ID1, //chId,
false, //isEventTriggered
MMW_EDMA_2D_PING_SHADOW_LINK_CH_ID2, //linkChId,
MMW_EDMA_2D_PING_CHAIN_CH_ID2, //chainChId,
(uint32_t*)(SOC_translateAddress((uint32_t)MMW_HWA_2D_OUT_PING,
SOC_TranslateAddr_Dir_TO_EDMA,NULL)+ sizeOfComplexTransferBytes), //*pSrcAddress,
(uint32_t*) SOC_translateAddress((uint32_t)obj->rangeDopplerLogMagMatrix,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //*pDestAddress,
sizeOfAbsTransferBytes, // numBytes,
obj->numRangeBins/(2*obj->numRangeBinsPerTransfer), //numBlocks,
0, //srcIncrBytes,
sizeOfAbsTransferBytes * 2, //dstIncrBytes,
true, //isIntermediateChainingEnabled,
false, //isFinalChainingEnabled,
false, //isTransferCompletionEnabled
NULL, //transferCompletionCallbackFxn
NULL);
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
}
else
{
/***************************************************************************
* PROGRAM DMA channel to transfer 2D abs data from accelerator output
* buffer (ping) to L3
**************************************************************************/
errorCode = EDMAutil_configHwaContiguous(handle,
MMW_EDMA_2D_PING_CH_ID, //chId,
true, //isEventTriggered
MMW_EDMA_2D_PING_SHADOW_LINK_CH_ID1, //linkChId,
MMW_EDMA_2D_PING_CHAIN_CH_ID2, //chainChId,
(uint32_t*)(SOC_translateAddress((uint32_t)MMW_HWA_2D_OUT_PING,
SOC_TranslateAddr_Dir_TO_EDMA,NULL)+ sizeOfComplexTransferBytes), //*pSrcAddress,
(uint32_t*) SOC_translateAddress((uint32_t)obj->rangeDopplerLogMagMatrix,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //*pDestAddress,
sizeOfAbsTransferBytes, // numBytes,
obj->numRangeBins/(2*obj->numRangeBinsPerTransfer), //numBlocks,
0, //srcIncrBytes,
sizeOfAbsTransferBytes * 2, //dstIncrBytes,
true, //isIntermediateChainingEnabled,
false, //isFinalChainingEnabled,
false, //isTransferCompletionEnabled
NULL, //transferCompletionCallbackFxn
NULL);
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
}
/******************************************************************************************
* PROGRAM DMA channel to transfer data from L3 to accelerator input buffer (ping)
******************************************************************************************/
errorCode = EDMAutil_configHwaContiguous(handle,
MMW_EDMA_2D_PING_CHAIN_CH_ID2, //chId,
false, //isEventTriggered
MMW_EDMA_2D_PING_SHADOW_LINK_CH_ID3, //linkChId,
MMW_EDMA_2D_PING_CHAIN_CH_ID3, //chainChId,
(uint32_t*)SOC_translateAddress((uint32_t)obj->radarCube,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //*pSrcAddress,
(uint32_t*)SOC_translateAddress((uint32_t)MMW_HWA_2D_INP_PING,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //*pDestAddress,
sizeOfComplexTransferBytes, // numBytes,
obj->numRangeBins/(2*obj->numRangeBinsPerTransfer), //numBlocks,
sizeOfComplexTransferBytes * 2, //srcIncrBytes,
0, //dstIncrBytes,
true, //isIntermediateChainingEnabled,
true, //isFinalChainingEnabled,
false, //isTransferCompletionEnabled;
NULL, //transferCompletionCallbackFxn
NULL);
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
HWA_getDMAconfig(obj->hwaHandle, MMW_HWA_DMA_TRIGGER_SOURCE_2D_PING, &dmaConfig);
errorCode = EDMAutil_configHwaOneHotSignature(handle,
MMW_EDMA_2D_PING_CHAIN_CH_ID3, //chId,
false, //isEventTriggered
(uint32_t*)SOC_translateAddress((uint32_t)dmaConfig.srcAddr,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //pSrcAddress
(uint32_t*)SOC_translateAddress((uint32_t)dmaConfig.destAddr,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //pDestAddress
dmaConfig.aCnt,
dmaConfig.bCnt,
dmaConfig.cCnt,
MMW_EDMA_2D_PING_SHADOW_LINK_CH_ID4); //linkChId
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
/**************PROGRAM DMA'S FOR PONG********************************************************/
if(obj->datapathChainSel == DATA_PATH_CHAIN_SEPARATE_LOGMAG)
{
/******************************************************************************************
* PROGRAM DMA channel to transfer 2D FFT data from accelerator output buffer (pong) to L3
******************************************************************************************/
errorCode = EDMAutil_configHwaContiguous(handle,
MMW_EDMA_2D_PONG_CH_ID, //chId,
true, //isEventTriggered
MMW_EDMA_2D_PONG_SHADOW_LINK_CH_ID1, //linkChId,
MMW_EDMA_2D_PONG_CHAIN_CH_ID1, //chainChId,
(uint32_t*)(SOC_translateAddress((uint32_t)MMW_HWA_2D_OUT_PONG,SOC_TranslateAddr_Dir_TO_EDMA,NULL)), //*pSrcAddress,
(uint32_t*)SOC_translateAddress((uint32_t)(obj->radarCube + sizeOfComplexTransfer),SOC_TranslateAddr_Dir_TO_EDMA,NULL),
sizeOfComplexTransferBytes, // numBytes,
obj->numRangeBins/(2*obj->numRangeBinsPerTransfer), //numBlocks,
0, //srcIncrBytes,
sizeOfComplexTransferBytes * 2, //dstIncrBytes,
true, //isIntermediateChainingEnabled,
true, //isFinalChainingEnabled,
false, //isTransferCompletionEnabled;
NULL, //transferCompletionCallbackFxn
NULL);
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
/******************************************************************************************
* PROGRAM DMA channel to transfer 2D abs data from accelerator output buffer (pong) to L3
******************************************************************************************/
errorCode = EDMAutil_configHwaContiguous(handle,
MMW_EDMA_2D_PONG_CHAIN_CH_ID1, //chId,
false, //isEventTriggered
MMW_EDMA_2D_PONG_SHADOW_LINK_CH_ID2, //linkChId,
MMW_EDMA_2D_PONG_CHAIN_CH_ID2, //chainChId,
(uint32_t*)(SOC_translateAddress((uint32_t)MMW_HWA_2D_OUT_PONG,
SOC_TranslateAddr_Dir_TO_EDMA,NULL)+ sizeOfComplexTransferBytes),//*pSrcAddress,
(uint32_t*)(SOC_translateAddress((uint32_t)(obj->rangeDopplerLogMagMatrix + sizeOfAbsTransfer),
SOC_TranslateAddr_Dir_TO_EDMA,NULL)), //*pDestAddress,
sizeOfAbsTransferBytes, //numBytes,
obj->numRangeBins/(2*obj->numRangeBinsPerTransfer), //numBlocks,
0, //srcIncrBytes,
sizeOfAbsTransferBytes * 2, //dstIncrBytes,
true, //isIntermediateChainingEnabled,
false, //isFinalChainingEnabled,
true, //isTransferCompletionEnabled;
MmwDemo_EDMA_transferCompletionCallbackFxn, //transferCompletionCallbackFxn
(uintptr_t)obj);
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
}
else
{
/******************************************************************************************
* PROGRAM DMA channel to transfer 2D abs data from accelerator output buffer (pong) to L3
******************************************************************************************/
errorCode = EDMAutil_configHwaContiguous(handle,
MMW_EDMA_2D_PONG_CH_ID, //chId,
true, //isEventTriggered
MMW_EDMA_2D_PONG_SHADOW_LINK_CH_ID1, //linkChId,
MMW_EDMA_2D_PONG_CHAIN_CH_ID2, //chainChId,
(uint32_t*)(SOC_translateAddress((uint32_t)MMW_HWA_2D_OUT_PONG,
SOC_TranslateAddr_Dir_TO_EDMA,NULL)+ sizeOfComplexTransferBytes),//*pSrcAddress,
(uint32_t*)(SOC_translateAddress((uint32_t)(obj->rangeDopplerLogMagMatrix + sizeOfAbsTransfer),
SOC_TranslateAddr_Dir_TO_EDMA,NULL)), //*pDestAddress,
sizeOfAbsTransferBytes, //numBytes,
obj->numRangeBins/(2*obj->numRangeBinsPerTransfer), //numBlocks,
0, //srcIncrBytes,
sizeOfAbsTransferBytes * 2, //dstIncrBytes,
true, //isIntermediateChainingEnabled,
false, //isFinalChainingEnabled,
true, //isTransferCompletionEnabled;
MmwDemo_EDMA_transferCompletionCallbackFxn, //transferCompletionCallbackFxn
(uintptr_t)obj);
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
}
/******************************************************************************************
* PROGRAM DMA channel to transfer data from L3 to accelerator input buffer (pong)
******************************************************************************************/
errorCode = EDMAutil_configHwaContiguous(handle,
MMW_EDMA_2D_PONG_CHAIN_CH_ID2, //chId,
false, //isEventTriggered
MMW_EDMA_2D_PONG_SHADOW_LINK_CH_ID3, //linkChId,
MMW_EDMA_2D_PONG_CHAIN_CH_ID3, //chainChId,
(uint32_t*)SOC_translateAddress((uint32_t)(obj->radarCube + sizeOfComplexTransfer),SOC_TranslateAddr_Dir_TO_EDMA,NULL), //*pSrcAddress,
(uint32_t*)SOC_translateAddress((uint32_t)MMW_HWA_2D_INP_PONG,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //*pDestAddress,
sizeOfComplexTransferBytes, //numBytes,
obj->numRangeBins/(2*obj->numRangeBinsPerTransfer), //numBlocks,
sizeOfComplexTransferBytes * 2, //srcIncrBytes,
0, //dstIncrBytes,
true, //isIntermediateChainingEnabled,
true, //isFinalChainingEnabled,
false, //isTransferCompletionEnabled;
NULL, //transferCompletionCallbackFxn
NULL);
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
HWA_getDMAconfig(obj->hwaHandle, MMW_HWA_DMA_TRIGGER_SOURCE_2D_PONG, &dmaConfig);
errorCode = EDMAutil_configHwaOneHotSignature(handle,
MMW_EDMA_2D_PONG_CHAIN_CH_ID3, //chId,
false, //isEventTriggered
(uint32_t*)SOC_translateAddress(dmaConfig.srcAddr,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //pSrcAddress
(uint32_t*)SOC_translateAddress(dmaConfig.destAddr,SOC_TranslateAddr_Dir_TO_EDMA,NULL), //pDestAddress
dmaConfig.aCnt,
dmaConfig.bCnt,
dmaConfig.cCnt,
MMW_EDMA_2D_PONG_SHADOW_LINK_CH_ID4); //linkChId
if (errorCode != EDMA_NO_ERROR)
{
goto exit;
}
exit:
return(errorCode);
}
/**
* @b Description
* @n
* Common configuration of data path processing, required to be done only
* once. Configures all of EDMA and window RAM of HWA.
* @param[in] obj Pointer to data path obj.
* @retval none.
*/
void MmwDemo_dataPathConfigCommon(MmwDemo_DataPathObj *obj)
{
int32_t errCode;
uint32_t fftWindow;
uint32_t winLen, winIndx, hwaRamOffset;
float phi;
HWA_CommonConfig hwaCommonConfig;
MmwDemo_config1D_EDMA(obj);
MmwDemo_config2D_EDMA(obj);
/**********************************************/
/* Disable HWA and reset to known state */
/**********************************************/
/* Disable the HWA */
errCode = HWA_enable(obj->hwaHandle,0);
if (errCode != 0)
{
//System_printf("Error: MmwDemo_dataPathConfigCommon:HWA_enable(0) returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
/* Reset the internal state of the HWA */
errCode = HWA_reset(obj->hwaHandle);
if (errCode != 0)
{
//System_printf("Error: MmwDemo_dataPathConfigCommon:HWA_reset returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
/***********************/
/* CONFIG WINDOW RAM */
/***********************/
/* if windowing is enabled, load the window coefficients in RAM */
//1D-FFT window
hwaRamOffset = 0;
winLen = obj->numAdcSamples;
phi = 2 * PI_ / ((float) winLen - 1);
for(winIndx = 0; winIndx < winLen; winIndx++)
{
MmwDemo_genWindow(&fftWindow, winIndx, phi, MMW_WIN_BLACKMAN);
errCode = HWA_configRam(obj->hwaHandle,
HWA_RAM_TYPE_WINDOW_RAM,
(uint8_t *)&fftWindow,
sizeof(uint32_t), //size in bytes
hwaRamOffset); //offset in bytes
if (errCode != 0)
{
//System_printf("Error: HWA_configRam returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
hwaRamOffset += sizeof(uint32_t);
}
winLen = obj->numDopplerBins;
phi = 2 * PI_ / ((float) winLen - 1);
for(winIndx = 0; winIndx < winLen; winIndx++)
{
MmwDemo_genWindow(&fftWindow, winIndx, phi, MMW_WIN_HANNING);
errCode = HWA_configRam(obj->hwaHandle,
HWA_RAM_TYPE_WINDOW_RAM,
(uint8_t *)&fftWindow,
sizeof(uint32_t), //size in bytes
hwaRamOffset); //offset in bytes
if (errCode != 0)
{
//System_printf("Error: HWA_configRam returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
hwaRamOffset += sizeof(uint32_t);
}
/**********************************************/
/* ENABLE NUMLOOPS DONE INTERRUPT FROM HWA */
/**********************************************/
errCode = HWA_enableDoneInterrupt(obj->hwaHandle,
MmwDemo_dataPathHwaDoneIsrCallback,
obj->HWA_done_semHandle);
if (errCode != 0)
{
//System_printf("Error: HWA_enableDoneInterrupt returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
/***********************************************/
/* ENABLE FFT Twiddle coefficient dithering */
/***********************************************/
/* Config Common Registers */
hwaCommonConfig.configMask = HWA_COMMONCONFIG_MASK_TWIDDITHERENABLE |
HWA_COMMONCONFIG_MASK_LFSRSEED;
hwaCommonConfig.fftConfig.twidDitherEnable = HWA_FEATURE_BIT_ENABLE;
hwaCommonConfig.fftConfig.lfsrSeed = 0x1234567; /*Some non-zero value*/
errCode = HWA_configCommon(obj->hwaHandle,&hwaCommonConfig);
if (errCode != 0)
{
//System_printf("Error: HWA_configCommon returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
}
/**
* @b Description
* @n
* Init HWA.
*/
void MmwDemo_hwaInit(MmwDemo_DataPathObj *obj)
{
/* Initialize the HWA */
HWA_init();
}
/**
* @b Description
* @n
* Init EDMA.
*/
void MmwDemo_edmaInit(MmwDemo_DataPathObj *obj)
{
uint8_t edmaNumInstances, inst;
Semaphore_Params semParams;
int32_t errorCode;
edmaNumInstances = EDMA_getNumInstances();
for (inst = 0; inst < edmaNumInstances; inst++)
{
errorCode = EDMA_init(inst);
if (errorCode != EDMA_NO_ERROR)
{
//System_printf ("Debug: EDMA instance %d initialization returned error %d\n", errorCode);
MmwDemo_debugAssert (0);
return;
}
//System_printf ("Debug: EDMA instance %d has been initialized\n", inst);
}
memset(&obj->EDMA_errorInfo, 0, sizeof(obj->EDMA_errorInfo));
memset(&obj->EDMA_transferControllerErrorInfo, 0, sizeof(obj->EDMA_transferControllerErrorInfo));
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
obj->EDMA_1Ddone_semHandle = Semaphore_create(0, &semParams, NULL);
/* Enable Done Interrupt */
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
obj->HWA_done_semHandle = Semaphore_create(0, &semParams, NULL);
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
obj->EDMA_2Ddone_semHandle = Semaphore_create(0, &semParams, NULL);
}
/**
* @b Description
* @n
* Call back function for EDMA CC (Channel controller) error as per EDMA API.
* Declare fatal error if happens, the output errorInfo can be examined if code
* gets trapped here.
*/
void MmwDemo_EDMA_errorCallbackFxn(EDMA_Handle handle, EDMA_errorInfo_t *errorInfo)
{
MmwDemo_debugAssert(0);
}
/**
* @b Description
* @n
* Call back function for EDMA transfer controller error as per EDMA API.
* Declare fatal error if happens, the output errorInfo can be examined if code
* gets trapped here.
*/
void MmwDemo_EDMA_transferControllerErrorCallbackFxn(EDMA_Handle handle,
EDMA_transferControllerErrorInfo_t *errorInfo)
{
MmwDemo_debugAssert(0);
}
/**
* @b Description
* @n
* Open HWA instance.
*/
void MmwDemo_hwaOpen(MmwDemo_DataPathObj *obj, SOC_Handle socHandle)
{
int32_t errCode;
/* Open the HWA Instance */
obj->hwaHandle = HWA_open(0, socHandle, &errCode);
if (obj->hwaHandle == NULL)
{
//System_printf("Error: Unable to open the HWA Instance err:%d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
//System_printf("Debug: HWA Instance %p has been opened successfully\n", obj->hwaHandle);
}
/**
* @b Description
* @n
* Close HWA instance.
*/
void MmwDemo_hwaClose(MmwDemo_DataPathObj *obj)
{
int32_t errCode;
/* Close the HWA Instance */
errCode = HWA_close(obj->hwaHandle);
if (errCode != 0)
{
//System_printf("Error: Unable to close the HWA Instance err:%d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
//System_printf("Debug: HWA Instance %p has been closed successfully\n", obj->hwaHandle);
}
/**
* @b Description
* @n
* Open EDMA.
*/
void MmwDemo_edmaOpen(MmwDemo_DataPathObj *obj)
{
int32_t errCode;
EDMA_instanceInfo_t edmaInstanceInfo;
EDMA_errorConfig_t errorConfig;
obj->edmaHandle = EDMA_open(0, &errCode, &edmaInstanceInfo);
if (obj->edmaHandle == NULL)
{
//System_printf("Error: Unable to open the EDMA Instance err:%d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
//System_printf("Debug: EDMA Instance %p has been opened successfully\n", obj->edmaHandle);
errorConfig.isConfigAllEventQueues = true;
errorConfig.isConfigAllTransferControllers = true;
errorConfig.isEventQueueThresholdingEnabled = true;
errorConfig.eventQueueThreshold = EDMA_EVENT_QUEUE_THRESHOLD_MAX;
errorConfig.isEnableAllTransferControllerErrors = true;
errorConfig.callbackFxn = MmwDemo_EDMA_errorCallbackFxn;
errorConfig.transferControllerCallbackFxn = MmwDemo_EDMA_transferControllerErrorCallbackFxn;
if ((errCode = EDMA_configErrorMonitoring(obj->edmaHandle, &errorConfig)) != EDMA_NO_ERROR)
{
//System_printf("Error: EDMA_configErrorMonitoring() failed with errorCode = %d\n", errCode);
MmwDemo_debugAssert (0);
return;
}
}
/**
* @b Description
* @n
* Close EDMA.
*/
void MmwDemo_edmaClose(MmwDemo_DataPathObj *obj)
{
EDMA_close(obj->edmaHandle);
}
/**
* @b Description
* @n
* Configure HWA for 2D processing.
*
* @param[in] obj Pointer to data path obj.
* @retval none.
*/
void MmwDemo_config2D_HWA(MmwDemo_DataPathObj *obj)
{
int32_t errCode;
HWA_CommonConfig hwaCommonConfig;
/* Disable the HWA */
errCode = HWA_enable(obj->hwaHandle,0);
if (errCode != 0)
{
//System_printf("Error: HWA_enable(1) returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
/***************************************/
/* Doppler FFT chain */
/***************************************/
HWAutil_configDopplerFFT(obj->hwaHandle,
HWAUTIL_NUM_PARAM_SETS_1D, // paramSetStartIdx,
obj->numDopplerBins, // dopplerFftSize,
obj->numVirtualAntennas, // numVirtualAnt,
obj->numRangeBinsPerTransfer, // numRangeBinsPerIter,
obj->numAdcSamples + MMW_HWA_WINDOWRAM_1D_OFFSET, // windowOffsetBytes
MMW_HWA_DMA_TRIGGER_SOURCE_2D_PING,
MMW_HWA_DMA_TRIGGER_SOURCE_2D_PONG,
MMW_HWA_DMA_DEST_CHANNEL_2D_PING,
MMW_HWA_DMA_DEST_CHANNEL_2D_PONG,
ADDR_TRANSLATE_CPU_TO_HWA(MMW_HWA_2D_INP_PING), //hwaMemSourcePingOffset
ADDR_TRANSLATE_CPU_TO_HWA(MMW_HWA_2D_INP_PONG), //hwaMemSourcePongOffset
ADDR_TRANSLATE_CPU_TO_HWA(MMW_HWA_2D_OUT_PING), //hwaMemDestPingOffset
ADDR_TRANSLATE_CPU_TO_HWA(MMW_HWA_2D_OUT_PONG),
obj->datapathChainSel); //hwaMemDestPongOffset
/***********************/
/* HWA COMMON CONFIG */
/***********************/
/* Config Common Registers */
hwaCommonConfig.configMask =
HWA_COMMONCONFIG_MASK_NUMLOOPS |
HWA_COMMONCONFIG_MASK_PARAMSTARTIDX |
HWA_COMMONCONFIG_MASK_PARAMSTOPIDX |
HWA_COMMONCONFIG_MASK_FFT1DENABLE |
HWA_COMMONCONFIG_MASK_INTERFERENCETHRESHOLD;
hwaCommonConfig.numLoops = obj->numRangeBins/(2*obj->numRangeBinsPerTransfer);
hwaCommonConfig.paramStartIdx = HWAUTIL_NUM_PARAM_SETS_1D; //TODO //only one paramset used here so start and stop index are the same
hwaCommonConfig.paramStopIdx = HWAUTIL_NUM_PARAM_SETS_1D + HWAUTIL_NUM_PARAM_SETS_2D-1;//TODO
hwaCommonConfig.fftConfig.fft1DEnable = HWA_FEATURE_BIT_DISABLE;
hwaCommonConfig.fftConfig.interferenceThreshold = 0xFFFFFF;
errCode = HWA_configCommon(obj->hwaHandle,&hwaCommonConfig);
if (errCode != 0)
{
//System_printf("Error: HWA_configCommon returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
}
/**
* @b Description
* @n
* Trigger 2D processing.
*
* @param[in] obj Pointer to data path obj.
* @retval none.
*/
void MmwDemo_dataPathTrigger2D(MmwDemo_DataPathObj *obj)
{
int32_t errCode;
/* Enable the HWA */
errCode = HWA_enable(obj->hwaHandle,1); // set 1 to enable
if (errCode != 0)
{
//System_printf("Error: HWA_enable(1) returned %d\n",errCode);
MmwDemo_debugAssert (0);
return;
}
EDMA_startTransfer(obj->edmaHandle, MMW_EDMA_2D_PING_CHAIN_CH_ID2, EDMA3_CHANNEL_TYPE_DMA);
EDMA_startTransfer(obj->edmaHandle, MMW_EDMA_2D_PONG_CHAIN_CH_ID2, EDMA3_CHANNEL_TYPE_DMA);
}
/**
* @b Description
* @n
* Waits for 2D processing to finish. This is a blocking function.
*
* @param[in] obj Pointer to data path object
*
* @retval
* NONE
*/
void MmwDemo_dataPathWait2D(MmwDemo_DataPathObj *obj)
{
Bool status;
/* wait for the all paramSets done interrupt */
status = Semaphore_pend(obj->HWA_done_semHandle, BIOS_WAIT_FOREVER);
if (status != TRUE)
{
//System_printf("Error: Semaphore_pend returned %d\n",status);
MmwDemo_debugAssert (0);
return;
}
status = Semaphore_pend(obj->EDMA_2Ddone_semHandle, BIOS_WAIT_FOREVER);
if (status != TRUE)
{
//System_printf("Error: Semaphore_pend returned %d\n",status);
MmwDemo_debugAssert (0);
return;
}
}
#define SOC_MAX_NUM_RX_ANTENNAS 4
#define SOC_MAX_NUM_TX_ANTENNAS 3
/**
* @b Description
* @n
* Initializes data path object with supplied cli config pointer. The cli config
* points to permanent storage outside of data path object that data path object can refer
* to anytime during the lifetime of data path object.
* Data path default values that are not required to come through CLI commands are also
* set in this function.
*/
void MmwDemo_dataPathObjInit(MmwDemo_DataPathObj *obj,
MmwDemo_CliCfg_t *cliCfg,
MmwDemo_CliCommonCfg_t *cliCommonCfg)
{
memset(obj, 0, sizeof(MmwDemo_DataPathObj));
obj->cliCfg = cliCfg;
obj->cliCommonCfg = cliCommonCfg;
/* Default datapath chain selection */
obj->datapathChainSel = DATA_PATH_CHAIN_COMBINED_LOGMAG;
}
/**
* @b Description
* @n
* Allocate buffers needed for data path.
*/
void MmwDemo_dataPathCfgBuffers(MmwDemo_DataPathObj *obj, MmwDemoMemPool_t *pool)
{
MmwDemo_memPoolReset(pool);
obj->radarCube = (uint32_t *) MmwDemo_memPoolAlloc(pool, obj->numRangeBins *
obj->numDopplerBins * obj->numVirtualAntennas * sizeof(uint32_t));
if (obj->radarCube == NULL)
{
MmwDemo_debugAssert(0);
}
obj->rangeDopplerLogMagMatrix = (uint16_t *) MmwDemo_memPoolAlloc(pool, obj->numRangeBins *
obj->numDopplerBins * sizeof(uint16_t));
if (obj->rangeDopplerLogMagMatrix == NULL)
{
MmwDemo_debugAssert(0);
}
if (obj->cliCfg->guiMonSel.rangeAzimuthHeatMap)
{
obj->azimuthStaticHeatMap = (cmplx16ImRe_t *) MmwDemo_memPoolAlloc(pool,
obj->numRangeBins * obj->numVirtualAntAzim * sizeof(cmplx16ImRe_t));
if (obj->azimuthStaticHeatMap == NULL)
{
MmwDemo_debugAssert(0);
}
}
if (obj->dcRangeSigMean == NULL)
{
obj->dcRangeSigMean = (cmplx32ImRe_t *) Memory_alloc (NULL,
DC_RANGE_SIGNATURE_COMP_MAX_BIN_SIZE * SOC_MAX_NUM_TX_ANTENNAS * SOC_MAX_NUM_RX_ANTENNAS * sizeof(cmplx32ImRe_t),
(uint8_t) MMWDEMO_MEMORY_ALLOC_DOUBLE_WORD_ALIGN,
NULL);
}
}
/**
* @b Description
* @n
* Utility function for reseting memory pool.
*
* @param[in] pool Handle to pool structure.
*
* @retval
* none.
*/
void MmwDemo_memPoolReset(MmwDemoMemPool_t *pool)
{
pool->indx = 0;
}
/**
* @b Description
* @n
* Utility function for allocating from a static memory pool.
*
* @pre It is assumed that no allocation from l3 will need better than 32-bit
* alignment (structures with 64-bit prohibited) and so for simplicity,
* size is assumed to be multiple of 4 bytes
*
* @param[in] pool Handle to pool structure.
* @param[in] size Size in bytes to be allocated.
*
* @retval
* pointer to beginning of allocated block. NULL indicates could notice
* allocate.
*/
uint8_t *MmwDemo_memPoolAlloc(MmwDemoMemPool_t *pool, uint32_t size)
{
uint8_t *ptr = NULL;
if ((size % 4) != 0)
{
return(ptr);
}
if ((pool->indx + size) <= pool->size)
{
ptr = pool->base + pool->indx;
pool->indx += size;
}
return(ptr);
}
/**