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
/
sensor_mgmt.c
1365 lines (1201 loc) · 42.2 KB
/
sensor_mgmt.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 sensor_mgmt.c
*
* @brief
* The file implements the sensor management. Sensors can be started
* or stopped by either the GPIO Switch or through the CLI.
*
* \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>
/* mmWave SDK Include Files: */
#include <ti/common/sys_common.h>
#include <ti/drivers/soc/soc.h>
#include <ti/drivers/esm/esm.h>
#include <ti/drivers/gpio/gpio.h>
#include <ti/drivers/crc/crc.h>
#include <ti/drivers/uart/UART.h>
#include <ti/drivers/mailbox/mailbox.h>
#include <ti/control/mmwave/mmwave.h>
#include <ti/drivers/osal/DebugP.h>
#include <ti/utils/cli/cli.h>
#include <ti/utils/hsiheader/hsiheader.h>
/* Demo Include Files */
#include "mmw.h"
#include "data_path.h"
/**************************************************************************
******************** Sensor Mgmt Local Definitions ***********************
**************************************************************************/
/**************************************************************************
******************** Sensor Mgmt Events Definitions ***********************
**************************************************************************/
/**
* @brief Sensor Start Event
*/
#define MMWDEMO_CLI_SENSORSTART_EVT Event_Id_00
/**
* @brief Sensor Stop Event
*/
#define MMWDEMO_CLI_SENSORSTOP_EVT Event_Id_01
/**
* @brief Sensor Start Event without reconfig
*/
#define MMWDEMO_CLI_FRAMESTART_EVT Event_Id_02
/**
* @brief Sensor start completed event
*/
#define MMWDEMO_START_COMPLETED_EVT Event_Id_03
/**
* @brief Sensor stop completed event
*/
#define MMWDEMO_STOP_COMPLETED_EVT Event_Id_04
/**
* @brief Sensor start failed event
*/
#define MMWDEMO_START_FAILED_EVT Event_Id_05
/**
* @brief Sensor start key event
*/
#define MMWDEMO_KEY_PRESS_EVT Event_Id_06
/**
* @brief Sensor BSS stop event
*/
#define MMWDEMO_BSS_STOP_EVT Event_Id_07
/**
* @brief Sensor Datapath stop event
*/
#define MMWDEMO_DATAPATH_STOP_EVT Event_Id_08
/**************************************************************************
******************** Sensor Mgmt Stop Status Definitions ***********************
**************************************************************************/
/**
* @brief Sensor Stop status bit for Data path - Bit 0
*/
#define MMWDEMO_DATAPATH_STOP_STATUS 1U
/**
* @brief Sensor Stop status bit for BSS - Bit 1
*/
#define MMWDEMO_BSS_STOP_STATUS 2U
/**
* @brief Sensor Stop status bit for Data path - Bit 2
*/
#define MMWDEMO_CTRLPATH_STOP_STATUS 4U
/**
* @brief Sensor Stop status bits for all components
*/
#define MMWDEMO_ALLCOMP_STOP_STATUS (MMWDEMO_DATAPATH_STOP_STATUS | \
MMWDEMO_BSS_STOP_STATUS | \
MMWDEMO_CTRLPATH_STOP_STATUS)
/**************************************************************************
******************** Sensor Mgmt Local Structures ************************
**************************************************************************/
/**
* @brief
* Millimeter Wave Demo Sensor State
*
* @details
* The enumeration is used to define the sensor states used in mmwDemo
*/
typedef enum MmwDemo_SensorState_e
{
/**
* @brief mmwDemo Sensor INIT state.
* This is the inital state after sensor is initialized.
*/
MmwDemo_SensorState_INIT = 0,
/**
* @brief mmwDemo Sensor START state.
* This is the state after sensor is started through mmwave_start()
*/
MmwDemo_SensorState_START,
/**
* @brief mmwDemo Sensor STOP PEDNING state.
* This is the state after sensor is stopped through mmwave_stop(),
* and waiting for all modules(such as datapath, Bss etc) to reach
* full stop state.
*/
MmwDemo_SensorState_STOP_PENDING,
/**
* @brief mmwDemo Sensor STOP state.
* This is the state that radar sensor including all its componets reach
* stop state.
*/
MmwDemo_SensorState_STOP,
/**
* @brief mmwDemo Sensor maximum supported state.
*/
MmwDemo_SensorState_MAX
}MmwDemo_SensorState;
/**
* @brief
* Millimeter Wave Demo Sensor Event
*
* @details
* The enumeration is used to define the sensor events used in mmwDemo
*/
typedef enum MmwDemo_SensorEvent_e
{
/**
* @brief mmwDemo Sensor start event
*/
MmwDemo_SensorEvent_START = 0,
/**
* @brief mmwDemo Sensor stop event
*/
MmwDemo_SensorEvent_STOP,
/**
* @brief mmwDemo Sensor frame start event
*/
MmwDemo_SensorEvent_FRAME_START,
/**
* @brief mmwDemo key press event
*/
MmwDemo_SensorEvent_KEY_PRESS,
/**
* @brief mmwDemo BSS stop event
*/
MmwDemo_SensorEvent_BSS_STOP,
/**
* @brief mmwDemo data path stop event
*/
MmwDemo_SensorEvent_DATAPATH_STOP,
/**
* @brief mmwDemo maximum event
*/
MmwDemo_SensorEvent_MAX
}MmwDemo_SensorEvent;
/* Sensor management State Machine Function definition */
typedef void (*MmwDemo_sensorSMFunc)(MmwDemo_SensorEvent event);
/**
* @brief
* Millimeter Wave Demo Session Management MCB
*
* @details
* The structure is used to hold all the relevant information for the
* Millimeter Wave demo session management module
*/
typedef struct MmwDemo_SensorMgmtMCB_t
{
/**
* @brief Sensor Management Task Handle:
*/
Task_Handle sensorMgmtTaskHandle;
/**
* @brief Sensor Management Event Handle:
*/
Event_Handle sensorMgmtEventHandle;
/**
* @brief Sensor Management Event Notify Handle:
*/
Event_Handle eventHandleNotify;
/**
* @brief Tracks the status of the sensor
*/
bool isSensorOpened;
/**
* @brief Tracks the status of the sensor
*/
bool isSensorStarted;
/**
* @brief Tracks the number of sensor start
*/
uint32_t sensorStartCount;
/**
* @brief Tracks the number of sensor sop
*/
uint32_t sensorStopCount;
/**
* @brief Tracks the sensor stop status from different components
*/
uint32_t sensorStopStatus;
/**
* @brief Tracks the key press event, it is used to determine if there
* is a need to post CLI event need
*/
uint32_t keyPressEvent;
/**
* @brief Tracks the current sensor state
*/
MmwDemo_SensorState state;
}MmwDemo_SensorMgmtMCB;
/**************************************************************************
************************ Sensor Mgmt Globals *****************************
**************************************************************************/
/**
* @brief Global variable which is used to keep relevant information used
* by the Session Management module.
*/
MmwDemo_SensorMgmtMCB gMmwSessionMgmtMCB;
/**************************************************************************
************************ Sensor Mgmt Functions ***************************
**************************************************************************/
/**
* @b Description
* @n
* mmw demo helper Function to do sensor Open
* Function to Setup the HSI Clock. Required for LVDS streaming.
*
* @retval
* 0 - Success.
* <0 - Failed with errors
*/
/*LVDS feature is unverified code. Conflicts with data path processing and should not be used.*/
int32_t MmwDemo_setHsiClk(void)
{
rlDevHsiClk_t hsiClkgs;
int32_t retVal;
/*************************************************************************************
* Setup the HSI Clock through the mmWave Link:
*************************************************************************************/
memset ((void*)&hsiClkgs, 0, sizeof(rlDevHsiClk_t));
/* Setup the HSI Clock as per the Radar Interface Document:
* - This is set to 600Mhz DDR Mode */
hsiClkgs.hsiClk = 0x9;
/* Setup the HSI in the radar link: */
retVal = rlDeviceSetHsiClk(RL_DEVICE_MAP_CASCADED_1, &hsiClkgs);
if (retVal != RL_RET_CODE_OK)
{
/* Error: Unable to set the HSI clock */
//System_printf ("Error: Setting up the HSI Clock Failed [Error %d]\n", retVal);
return -1;
}
/* The delay below is needed only if the DCA1000EVM is being used to capture the data traces.
This is needed because the DCA1000EVM FPGA needs the delay to lock to the
bit clock before they can start capturing the data correctly. */
Task_sleep(HSI_DCA_MIN_DELAY_MSEC);
return 0;
}
/**
* @b Description
* @n
*
* @retval
* open Status: true - open successfully
* false - open failed
*/
static bool MmwDemo_doSensorOpen(void)
{
bool startStatus = true;
int32_t errCode;
/* Open mmWave module, this is only done once */
if (gMmwSessionMgmtMCB.isSensorOpened == false)
{
/* Get the open configuration: */
CLI_getMMWaveExtensionOpenConfig (&gMmwMCB.cfg.openCfg);
/* Setup the calibration frequency: */
gMmwMCB.cfg.openCfg.freqLimitLow = 760U;
gMmwMCB.cfg.openCfg.freqLimitHigh = 810U;
/* start/stop async events */
gMmwMCB.cfg.openCfg.disableFrameStartAsyncEvent = false;
gMmwMCB.cfg.openCfg.disableFrameStopAsyncEvent = false;
/* Open the mmWave module: */
if (MMWave_open (gMmwMCB.ctrlHandle, &gMmwMCB.cfg.openCfg, &errCode) < 0)
{
System_printf ("Error: mmWave Open failed %d\n", errCode);
/* Post event that start failed */
startStatus = false;
}
else
{
startStatus = true;
/*Set up HSI clock*/
if(MmwDemo_setHsiClk() < 0)
{
MmwDemo_debugAssert(0);
}
/* mmWave module has been opened. */
gMmwSessionMgmtMCB.isSensorOpened = true;
}
}
else
{
/* openCfg related configurations like chCfg, lowPowerMode, adcCfg
* are only used on the first sensor start. If they are different
* on a subsequent sensor start, then generate a fatal error
* so the user does not think that the new (changed) configuration
* takes effect, the board needs to be reboot for the new
* configuration to be applied.
*/
MMWave_OpenCfg openCfg;
CLI_getMMWaveExtensionOpenConfig (&openCfg);
/* initialize to same as in "if" part where open is done
* to allow memory compare of structures to be used.
* Note that even if structures may have holes, the memory
* compare is o.k because CLI always stores the configurations
* in the same global CLI structure which is copied over to the
* one supplied by the application through the
* CLI_getMMWaveExtensionOpenConfig API. Not using memcmp will
* require individual field comparisons which is probably
* more code size and cumbersome.
*/
openCfg.freqLimitLow = 760U;
openCfg.freqLimitHigh = 810U;
/* start/stop async events */
openCfg.disableFrameStartAsyncEvent = false;
openCfg.disableFrameStopAsyncEvent = false;
/* Compare openCfg */
if(memcmp((void *)&gMmwMCB.cfg.openCfg, (void *)&openCfg,
sizeof(MMWave_OpenCfg)) != 0)
{
startStatus = false;
/* Post event that start failed */
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_START_FAILED_EVT);
MmwDemo_debugAssert(0);
}
else
{
startStatus = true;
}
}
return startStatus;
}
/**
* @b Description
* @n
* mmw demo helper Function to do sensor Start
*
*
* @retval
* start Status: true - start successfully
* false - start failed
*/
static bool MmwDemo_doSensorStart(void)
{
bool startStatus = true;
int32_t errCode;
if (gMmwSessionMgmtMCB.isSensorStarted == false)
{
gMmwSessionMgmtMCB.sensorStartCount++;
/* Get the configuration from the CLI mmWave Extension */
CLI_getMMWaveExtensionConfig (&gMmwMCB.cfg.ctrlCfg);
/* Configure the mmWave module: */
if (MMWave_config (gMmwMCB.ctrlHandle, &gMmwMCB.cfg.ctrlCfg, &errCode) < 0)
{
MMWave_ErrorLevel errorLevel;
int16_t mmWaveErrorCode;
int16_t subsysErrorCode;
/* Error: Report the error */
MMWave_decodeError (errCode, &errorLevel, &mmWaveErrorCode, &subsysErrorCode);
System_printf ("Error: mmWave Config failed [Error code: %d Subsystem: %d]\n",
mmWaveErrorCode, subsysErrorCode);
/* Post event that start failed */
startStatus = false;
}
else
{
/* Setup the data path: */
MmwDemo_dataPathConfig ();
if (MmwDemo_dataPathStart()==0)
{
/* The sensor has been started successfully. Switch on the LED */
GPIO_write (SOC_XWR14XX_GPIO_2, 1U);
/* Sensor has been started successfully: */
gMmwSessionMgmtMCB.isSensorStarted = true;
gMmwSessionMgmtMCB.sensorStopStatus = 0U;
/* Post event that start is done */
startStatus = true;
}
else
{
/* Post event that start failed */
startStatus = false;
}
}
}
else
{
/* Not expected */
MmwDemo_debugAssert(0);
}
return startStatus;
}
/**
* @b Description
* @n
* mmw demo helper Function to do sensor frame Start
*
*
* @retval
* start Status: true - start successfully
* false - start failed
*/
static bool MmwDemo_doSensorFrameStart(void)
{
bool startStatus = true;
/* These events trigger sensor start without re-config */
if (gMmwSessionMgmtMCB.isSensorStarted == false)
{
gMmwSessionMgmtMCB.sensorStartCount++;
if (MmwDemo_dataPathStart()==0)
{
/* The sensor has been started successfully. Switch on the LED */
GPIO_write (SOC_XWR14XX_GPIO_2, 1U);
/* Sensor has been started successfully: */
gMmwSessionMgmtMCB.isSensorStarted = true;
gMmwSessionMgmtMCB.sensorStopStatus = 0U;
/* Post event that start is done */
startStatus = true;
}
else
{
/* Post event that start failed */
startStatus = false;
}
}
else
{
/* Not expected */
MmwDemo_debugAssert(0);
}
return startStatus;
}
/**
* @b Description
* @n
* mmw demo helper Function to trigger sensor Stop
*
* @retval
* start Status: true - start successfully
* false - start failed
*/
static bool MmwDemo_doSensorStop(void)
{
bool stopStatus = true;
int32_t errCode;
if (gMmwSessionMgmtMCB.isSensorStarted == true)
{
/* Stop the mmWave module: */
if (MMWave_stop (gMmwMCB.ctrlHandle, &errCode) < 0)
{
MMWave_ErrorLevel errorLevel;
int16_t mmWaveErrorCode;
int16_t subsysErrorCode;
/* Error/Warning: Unable to stop the mmWave module */
MMWave_decodeError (errCode, &errorLevel, &mmWaveErrorCode, &subsysErrorCode);
if (errorLevel == MMWave_ErrorLevel_ERROR)
{
/* Error: Display the error message: */
System_printf ("Error: mmWave Stop failed [Error code: %d Subsystem: %d]\n",
mmWaveErrorCode, subsysErrorCode);
/* Set the status of the stop. */
stopStatus = false;
/* Not expected */
MmwDemo_debugAssert(0);
}
else
{
/* Warning: This is treated as a successful stop. */
System_printf ("mmWave Stop error ignored [Error code: %d Subsystem: %d]\n",
mmWaveErrorCode, subsysErrorCode);
stopStatus = true;
}
}
else
{
stopStatus = true;
}
}
else
{
/* Not expected */
MmwDemo_debugAssert(0);
}
if(stopStatus == true)
{
gMmwSessionMgmtMCB.sensorStopStatus |= MMWDEMO_CTRLPATH_STOP_STATUS;
/* Sensor stopped, Notify data path to handle sensor stop */
MmwDemo_dataPathStop(&gMmwMCB.dataPathObj);
}
return stopStatus;
}
/**
* @b Description
* @n
* mmw demo helper Function to finish sensor Stop when stop is done successfully
*
* @retval
* start Status: true - start successfully
* false - start failed
*/
static void MmwDemo_finishSensorStop(void)
{
/* The sensor has been stopped successfully. Switch off the LED */
GPIO_write (SOC_XWR14XX_GPIO_2, 0U);
/* Sensor has been stopped successfully: */
gMmwSessionMgmtMCB.isSensorStarted = false;
gMmwSessionMgmtMCB.sensorStopCount++;
/* print for user */
System_printf("Sensor has been stopped: start:%d stop%d\n",
gMmwSessionMgmtMCB.sensorStartCount,gMmwSessionMgmtMCB.sensorStopCount);
}
/**
* @b Description
* @n
* This function implements the sensor state machine in INIT state
*
* @param[in] event mmwDemo event sent to sensor state machine
*
* @retval
* Not applicable
*/
void MmwDemo_sensorStateInit(MmwDemo_SensorEvent event)
{
bool startStatus = true;
switch(event)
{
case MmwDemo_SensorEvent_START:
/* Sensor Open */
startStatus = MmwDemo_doSensorOpen();
/* Sensor Start */
if (startStatus == true)
{
startStatus = MmwDemo_doSensorStart();
}
/* Post events to CLI/key switch task with start results */
if(startStatus == true)
{
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_START;
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_START_COMPLETED_EVT);
}
else
{
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_START_FAILED_EVT);
/* mmwave open or start failed, remain in the INIT state */
}
break;
case MmwDemo_SensorEvent_FRAME_START:
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_START_COMPLETED_EVT);
break;
case MmwDemo_SensorEvent_STOP:
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_STOP_COMPLETED_EVT);
break;
case MmwDemo_SensorEvent_KEY_PRESS:
case MmwDemo_SensorEvent_BSS_STOP:
case MmwDemo_SensorEvent_DATAPATH_STOP:
/* These events will be ignored in INIT state */
break;
default:
/* Not expected */
MmwDemo_debugAssert(0);
break;
}
}
/**
* @b Description
* @n
* This function implements the sensor state machine in START state
*
* @param[in] event mmwDemo event sent to sensor state machine
*
* @retval
* Not applicable
*/
void MmwDemo_sensorStateStart(MmwDemo_SensorEvent event)
{
bool stopStatus = true;
switch(event)
{
case MmwDemo_SensorEvent_STOP:
case MmwDemo_SensorEvent_KEY_PRESS:
/* These events trigger the stop process */
stopStatus = MmwDemo_doSensorStop();
if (stopStatus == true)
{
/* Change sensor state to wait for ALL Components stop done */
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_STOP_PENDING;
}
else
{
/* Sensor Stop error, do assertion */
MmwDemo_debugAssert(0);
}
break;
case MmwDemo_SensorEvent_START:
case MmwDemo_SensorEvent_FRAME_START:
/* Ignore duplicate command */
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_START_COMPLETED_EVT);
break;
case MmwDemo_SensorEvent_BSS_STOP:
/* Finite frame loop configuration, BSS stop comes first */
gMmwSessionMgmtMCB.sensorStopStatus |= MMWDEMO_BSS_STOP_STATUS;
if(gMmwSessionMgmtMCB.sensorStopStatus == MMWDEMO_ALLCOMP_STOP_STATUS)
{
/* Not expected events */
MmwDemo_debugAssert(0);
}
else
{
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_STOP_PENDING;
}
break;
case MmwDemo_SensorEvent_DATAPATH_STOP:
/* Not expected events */
MmwDemo_debugAssert(0);
break;
default:
/* Not expected events */
MmwDemo_debugAssert(0);
break;
}
}
/**
* @b Description
* @n
* This function implements the sensor state machine in STOP Pending state
*
* @param[in] event mmwDemo event sent to sensor state machine
*
* @retval
* Not applicable
*/
void MmwDemo_sensorStateStopPending(MmwDemo_SensorEvent event)
{
bool stopStatus = true;
bool postEvent = false;
switch(event)
{
case MmwDemo_SensorEvent_STOP:
case MmwDemo_SensorEvent_KEY_PRESS:
if(gMmwSessionMgmtMCB.sensorStopStatus == 0)
{
/* Ignore duplicated events from CLI/key press */
}
else
{
/* For finite loop frame configuration, BSS done comes first, always waiting for sensor stop from CLI */
/* Start sensor stop on control path */
stopStatus = MmwDemo_doSensorStop();
if (stopStatus == true)
{
gMmwSessionMgmtMCB.sensorStopStatus |= MMWDEMO_CTRLPATH_STOP_STATUS;
if(gMmwSessionMgmtMCB.sensorStopStatus == MMWDEMO_ALLCOMP_STOP_STATUS)
{
/* All componets stopped, move to STOP state */
MmwDemo_finishSensorStop();
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_STOP;
postEvent = true;
}
else
{
/* Stay in the same stae, waiting for data path event */
}
}
else
{
/* Not expected */
MmwDemo_debugAssert(0);
}
}
break;
case MmwDemo_SensorEvent_START:
case MmwDemo_SensorEvent_FRAME_START:
/* This events can come for finite frame loop configuration, unblock CLI */
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_START_COMPLETED_EVT);
break;
case MmwDemo_SensorEvent_DATAPATH_STOP:
gMmwSessionMgmtMCB.sensorStopStatus |= MMWDEMO_DATAPATH_STOP_STATUS;
if(gMmwSessionMgmtMCB.sensorStopStatus == MMWDEMO_ALLCOMP_STOP_STATUS)
{
/* All componets stopped, move to STOP state */
MmwDemo_finishSensorStop();
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_STOP;
postEvent = true;
}
else
{
/* Stay in the same state, waiting for all componets stopped */
}
break;
case MmwDemo_SensorEvent_BSS_STOP:
gMmwSessionMgmtMCB.sensorStopStatus |= MMWDEMO_BSS_STOP_STATUS;
if(gMmwSessionMgmtMCB.sensorStopStatus == MMWDEMO_ALLCOMP_STOP_STATUS)
{
/* All componets stopped, move to STOP state */
MmwDemo_finishSensorStop();
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_STOP;
postEvent = true;
}
else
{
/* Stay in the same state, waiting for all componets stopped */
}
break;
default:
/* Not expected events */
MmwDemo_debugAssert(0);
break;
}
/* Post CLI event if the request comes from CLI */
if ((postEvent == true) & (gMmwSessionMgmtMCB.keyPressEvent == 0))
{
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_STOP_COMPLETED_EVT);
}
}
/**
* @b Description
* @n
* This function implements the sensor state machine in STOP state
*
* @param[in] event mmwDemo event sent to sensor state machine
*
* @retval
* Not applicable
*/
void MmwDemo_sensorStateStop(MmwDemo_SensorEvent event)
{
bool startStatus = true;
bool postEvent = false;
switch(event)
{
case MmwDemo_SensorEvent_START:
/* These events trigger sensor start process */
/* Sensor Open */
startStatus = MmwDemo_doSensorOpen();
if(startStatus == true)
{
startStatus = MmwDemo_doSensorStart();
}
postEvent = true;
if(startStatus == true)
{
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_START;
}
else
{
/* Start failed, remain in the same state */
}
break;
case MmwDemo_SensorEvent_KEY_PRESS:
/* These events trigger sensor start without re-config */
postEvent = false;
startStatus = MmwDemo_doSensorFrameStart();
if(startStatus == true)
{
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_START;
}
else
{
/* Start failed, remain in the same state */
}
break;
case MmwDemo_SensorEvent_FRAME_START:
/* These events trigger sensor start without re-config */
postEvent = true;
startStatus = MmwDemo_doSensorFrameStart();
if(startStatus == true)
{
gMmwSessionMgmtMCB.state = MmwDemo_SensorState_START;
}
else
{
/* Start failed, remain in the same state */
}
break;
case MmwDemo_SensorEvent_STOP:
/* Event should be ignored, post event to unblock CLI*/
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_STOP_COMPLETED_EVT);
break;
case MmwDemo_SensorEvent_BSS_STOP:
case MmwDemo_SensorEvent_DATAPATH_STOP:
/* Ignore these events in STOP state */
break;
default:
/* Not expected events */
MmwDemo_debugAssert(0);
break;
}
/* Post complete/fail event to CLI */
if ((postEvent == true) & (gMmwSessionMgmtMCB.keyPressEvent == 0))
{
if(startStatus == true)
{
Event_post(gMmwSessionMgmtMCB.eventHandleNotify, MMWDEMO_START_COMPLETED_EVT);
}
else
{