-
Notifications
You must be signed in to change notification settings - Fork 1
/
gnssapp.c
2189 lines (1798 loc) · 72.1 KB
/
gnssapp.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: gnssapp.c
PROJECT: STA8090 GPS application
SW PACKAGE: STA8090 GPS library and application
------------------------------------------------------------------------------
DESCRIPTION: Module to run and test STA8090 GPS library
------------------------------------------------------------------------------
COPYRIGHT: (c) 2005 STMicroelectronics, (S2S - SWD) Napoli (ITALY)
------------------------------------------------------------------------------
Created by : Fulvio boggia
on : 2007.07.25
*****************************************************************************/
/*****************************************************************************
includes
*****************************************************************************/
// general
#include "macros.h"
#include "fixpoint.h"
#include "clibs.h"
// LLD for STA8090
#include "lld_gpio.h"
// OS related
#include "gpOS.h"
// GNSS library related
#include "gnss_const.h"
#include "gnss_defs.h"
#include "gnss_api.h"
#include "gnss_debug.h"
#include "gpsconfig.h"
// GNSS MSG related
#include "gnss_msg.h"
#include "gnss_msg_queue.h"
#if defined( NVM_NOR ) || defined( NVM_SQI )
#include "gps_nvm_swap_mgr.h"
#endif
#include "gps_nvm.h"
#include "platform.h"
#include "sw_config.h"
#include "frontend.h"
#include "gnssapp.h"
#include "gnssapp_plugins.h"
// Services related
#include "svc_mcu.h"
#include "svc_adc.h"
#include "svc_ssp.h"
#include "svc_i2c.h"
#include "svc_gpio.h"
#include "svc_pwr.h"
#include "svc_fsw.h"
#include "svc_can.h"
// Modules related
#include "in_out.h"
#include "gnss_events.h"
#include "nmea.h"
#if defined( STBIN_LINKED )
#include "stbin.h"
#endif
#if defined( SDLOG_LINKED )
#include "sdlog.h"
#endif
#if defined( SW_CONFIG_PRIVATE_BLOCK )
#include "sm_sensors_api.h"
#include "sw_config_private.h"
#endif
#if defined( DR_CODE_LINKED )
#include "dr_api.h"
#endif
#if defined( FREERTOS )
#include "FR_timei.h"
#endif
#include "lvd_mgmt.h"
#include "antenna_sensing.h"
#include "shutdn_ctrl.h"
/*****************************************************************************
external declarations
*****************************************************************************/
/*****************************************************************************
defines and macros (scope: module-local)
*****************************************************************************/
/**< Version ID for NVM data */
#define NVM_VID_GLONASS 0x1U
#define NVM_VID_GALILEO 0x2U
#define NVM_VID_COMPASS 0x4U
#if defined( ST_AGPS )
#define NVM_VID_STAGPS 0x10U
#else
#define NVM_VID_STAGPS 0x0U
#endif
#if defined(DR_CODE_LINKED)
#define NVM_VID_DR 0x20U
#else
#define NVM_VID_DR 0x0U
#endif
/**< version for backup data */
#define NVM_VERSION_ID (0x84100000U | NVM_VID_DR | NVM_VID_STAGPS | NVM_VID_COMPASS | NVM_VID_GALILEO | NVM_VID_GLONASS)
/**< suffix for all versions */
#define GNSSAPP_VERSION_SUFFIX MCR_MACROTOSTRING(VERSION_SUFFIX)
/**< product versions */
#define GNSSAPP_VERSION_STRING MCR_MACROTOSTRING(VERSION_SDK) GNSSAPP_VERSION_SUFFIX
#if defined( VERSION_BINARY )
#define BINIMG_VERSION_STRING MCR_MACROTOSTRING(VERSION_BINARY) GNSSAPP_VERSION_SUFFIX
#endif
#define GNSSAPP_VERSION_SIZE (32U)
/* NVM memory sizes
* Note: they are sized to 128kB for flash devices as they need to be aligned to the highest possible sector
* size available on the market.
*/
#if defined( NVM_NOR)
#define NVM_MEM_SIZE (1 * 128 * 1024) /**< NVM region size in NOR configuration*/
#elif defined( NVM_SQI)
#define NVM_MEM_SIZE (1 * 128 * 1024) /**< NVM region size in SQI configuration*/
#else
#define NVM_MEM_SIZE (32 * 1024) /**< NVM region size in backup configuration */
#endif
/* SAT list size: different lists in the GNSS lib are sized according to the number of potential tracked satellites */
/* The following constant cannot exceed 64, and should be sized according to the number of constellation supported by the build */
#define GNSSLIB_SAT_LIST_SIZE VISIBLE_MAX_NUM_OF_SATS
#define GNSSAPP_MTU_CLOCK 24552U
#define DEFAULT_AMQ_MSG_SIZE 2U
/*****************************************************************************
typedefs and structures (scope: module-local)
*****************************************************************************/
typedef struct gnssapp_handler_s
{
gpOS_partition_t * fast_part;
gnss_debug_writeout_t debug_output;
gnss_debug_inout_t debug_input;
nmea_inout_t nmea_input;
nmea_inout_t nmea_output;
nmea_inout_t rtcm_input;
#if defined( SDLOG_LINKED )
sdlog_file_t * debug_file_hdlr;
sdlog_file_t * nmea_file_hdlr;
#endif
} gnssapp_handler_t;
typedef struct gnssapp_lowpow_s
{
gnss_app_lowpow_standby_type_t Standby; /**< Standby activated */
gnss_low_power_cyclic_mode_t cyclic; /**< backup of low power config */
gnss_low_power_periodic_mode_t periodic; /**< backup of low power config */
}gnssapp_lowpow_t;
typedef enum
{
GNSSAPP_LOW_POWER_INIT,
GNSSAPP_LOW_POWER_UPDATE
}gnss_app_lowpow_setup_type_t;
/*****************************************************************************
global variable definitions (scope: module-exported)
*****************************************************************************/
// Version string
const tChar gnssapp_ver[GNSSAPP_VERSION_SIZE] = MCR_VERSION_STRING( "GPSAPP", GNSSAPP_VERSION_STRING );
#if defined( VERSION_BINARY )
const tChar gnssapp_binimg_ver[GNSSAPP_VERSION_SIZE] = MCR_VERSION_STRING( "BINIMG", BINIMG_VERSION_STRING );
#endif
tUInt spm;
tUInt spm_configuration;
/*****************************************************************************
global variable definitions (scope: module-local)
*****************************************************************************/
static gnssapp_handler_t *gnssapp_handler;
static gnssapp_startup_time_t gnssapp_startup_time;
static gpOS_semaphore_t *gnssapp_startup_time_sem;
static tUInt tcxo_config_selector = 0U;
extern tU8 adc_chan_to_read[8];
extern boolean_t adc_chan_read_mode_ON;
#pragma arm section zidata = "SRAM_STDBY_DATA"
SRAM_STDBY_DATA static gnssapp_lowpow_t gnssapp_lowpow; /**< gnssapp low power backup */
#pragma arm section zidata
/*****************************************************************************
function prototypes (scope: module-local)
*****************************************************************************/
gpOS_error_t gnssapp_gnss_service_start( gpOS_partition_t *);
gpOS_error_t gnssapp_gnss_amq_init( gpOS_partition_t *, boolean_t , tUInt );
gpOS_error_t gnssapp_gnss_lib_start( gpOS_partition_t *);
static tVoid gnssapp_low_power_setup( gnss_app_lowpow_setup_type_t, gnss_app_lowpow_standby_type_t, gnss_low_power_cyclic_mode_t *, gnss_low_power_periodic_mode_t *);
/*****************************************************************************
function implementations (scope: module-local)
*****************************************************************************/
/********************************************//**
* \brief Initialize NVM module
*
* \param tVoid
* \return gpOS_FAILURE if it fails
*
***********************************************/
gpOS_error_t gnssapp_nvm_start( gpOS_partition_t *part )
{
tUInt nvm_primary_addr, nvm_secondary_addr;
tUInt nvm_memory_size = NVM_MEM_SIZE;
// Check if any plugins needs more NVM memory and update size
gnssapp_plugins_get_nvm_size( &nvm_memory_size );
// Initialize NVM or backup RAM memory
platform_gnss_get_nvm_config( &nvm_primary_addr, &nvm_secondary_addr, nvm_memory_size);
if ( nvm_open_p( part, NVM_VERSION_ID, ( nvm_address_t )nvm_primary_addr, ( nvm_address_t )nvm_secondary_addr, nvm_memory_size, gnss_flash_erase_priority ) == NVM_ERROR )
{
return ( gpOS_FAILURE );
}
return gpOS_SUCCESS;
}
/********************************************//**
* \brief
*
* \param tVoid
* \return gpOS_error_t
*
***********************************************/
static gpOS_error_t gnssapp_swconfig_setup( gpOS_partition_t *part )
{
tUInt gpio_cfg0, gpio_mode_AFSLA;
tUInt gpio_cfg1, gpio_mode_AFSLB;
tUInt gpio_set_to_high_mask;
tUInt gpio_set_to_low_mask;
tU8 cpu_clock_speed;
tUInt pwr_high_low_cfg = 0;
/**< Start sw config module */
sw_config_init();
sw_config_get_param( CURRENT_CONFIG_DATA, TCXO_CONFIG_SELECTOR_ID, &tcxo_config_selector );
if(tcxo_config_selector == 10) // to be better implemneted
{
FE_def_write_data(5,0x4D);
FE_def_write_data(6,0xB6);
FE_def_write_data(7,0x93);
platform_mcu_setspeed( PLATFORM_MCU_SPEED_48MHZ);
}
else if(tcxo_config_selector == 11) // to be better implemneted
{
FE_def_write_data(5,0x19);
FE_def_write_data(6,0xB0);
FE_def_write_data(7,0x87);
platform_mcu_setspeed( PLATFORM_MCU_SPEED_55MHZ);
}
if ( gnss_set_tcxo_config( tcxo_config_selector ) == GNSS_ERROR )
{
return gpOS_FAILURE;
}
svc_fsw_setextfreq( TRACKER_CPU_TICKS_PER_SECOND);
sw_config_get_param( CURRENT_CONFIG_DATA, LOW_POWER_CFG_PARAMS_6_ID, &pwr_high_low_cfg);
platform_set_pwr_high_low_configs(pwr_high_low_cfg);
sw_config_get_param( CURRENT_CONFIG_DATA, CPU_CLOCK_SPEED, &cpu_clock_speed);
platform_set_cpu_clock_speed( (cpu_clock_speed & 0xF), ((cpu_clock_speed >> 4) & 0x3));
/**< GPIO configuration parameters */
sw_config_get_param( CURRENT_CONFIG_DATA, GPIO_PORT0_CFG0_ID, &gpio_cfg0 );
sw_config_get_param( CURRENT_CONFIG_DATA, GPIO_PORT0_CFG1_ID, &gpio_cfg1 );
sw_config_get_param( CURRENT_CONFIG_DATA, GPIO_PORT0_MODE_AFSLA_ID, &gpio_mode_AFSLA);
sw_config_get_param( CURRENT_CONFIG_DATA, GPIO_PORT0_MODE_AFSLB_ID, &gpio_mode_AFSLB);
gpio_set_to_high_mask = gpio_cfg0 & gpio_cfg1;
gpio_set_to_low_mask = ~gpio_cfg0 & ~gpio_cfg1;
if ( ( gpio_set_to_high_mask | gpio_set_to_low_mask ) != 0 )
{
tUInt mode_none_mask=0, mode_A_mask=0, mode_B_mask=0, mode_C_mask=0;
mode_none_mask = ~(gpio_mode_AFSLA | gpio_mode_AFSLB);
mode_A_mask = gpio_mode_AFSLA & ~(gpio_mode_AFSLB);
mode_B_mask = ~(gpio_mode_AFSLA) & gpio_mode_AFSLB;
mode_C_mask = gpio_mode_AFSLA & gpio_mode_AFSLB;
LLD_GPIO_SetControlMode((LLD_GPIO_idTy)GPIO0_REG_START_ADDR,(LLD_GPIO_PinTy)((gpio_set_to_high_mask | gpio_set_to_low_mask) & mode_none_mask),LLD_GPIO_ALTERNATE_NONE);
LLD_GPIO_SetControlMode((LLD_GPIO_idTy)GPIO0_REG_START_ADDR,(LLD_GPIO_PinTy)((gpio_set_to_high_mask | gpio_set_to_low_mask) & mode_A_mask),LLD_GPIO_ALTERNATE_MODE_A);
LLD_GPIO_SetControlMode((LLD_GPIO_idTy)GPIO0_REG_START_ADDR,(LLD_GPIO_PinTy)((gpio_set_to_high_mask | gpio_set_to_low_mask) & mode_B_mask),LLD_GPIO_ALTERNATE_MODE_B);
LLD_GPIO_SetControlMode((LLD_GPIO_idTy)GPIO0_REG_START_ADDR,(LLD_GPIO_PinTy)((gpio_set_to_high_mask | gpio_set_to_low_mask) & mode_C_mask),LLD_GPIO_ALTERNATE_MODE_C);
LLD_GPIO_SetDirectionOutput((LLD_GPIO_idTy)GPIO0_REG_START_ADDR,(LLD_GPIO_PinTy)(gpio_set_to_high_mask | gpio_set_to_low_mask));
LLD_GPIO_SetStateHigh((LLD_GPIO_idTy)GPIO0_REG_START_ADDR,(LLD_GPIO_PinTy)gpio_set_to_high_mask);
LLD_GPIO_SetStateLow((LLD_GPIO_idTy)GPIO0_REG_START_ADDR,(LLD_GPIO_PinTy)gpio_set_to_low_mask);
{
tUInt i2C_gpio_set_to_high_mask, i2C_gpio_set_to_low_mask;
tUInt i2c_gpio_AltFunc_mask;
i2c_gpio_AltFunc_mask = LLD_GPIO_GetMask(LLD_GPIO_AF_I2C);
i2C_gpio_set_to_high_mask = gpio_set_to_high_mask & i2c_gpio_AltFunc_mask;
i2C_gpio_set_to_low_mask = gpio_set_to_low_mask & i2c_gpio_AltFunc_mask;
if ( (tUInt)( i2C_gpio_set_to_high_mask | i2C_gpio_set_to_low_mask ) != 0x0U )
{
i2c_gpio_sw_config_used = TRUE;
}
}
}
sw_config_get_param( CURRENT_CONFIG_DATA, GPIO_PORT1_CFG0_ID, &gpio_cfg0 );
sw_config_get_param( CURRENT_CONFIG_DATA, GPIO_PORT1_CFG1_ID, &gpio_cfg1 );
sw_config_get_param( CURRENT_CONFIG_DATA, GPIO_PORT1_MODE_AFSLA_ID, &gpio_mode_AFSLA);
sw_config_get_param( CURRENT_CONFIG_DATA, GPIO_PORT1_MODE_AFSLB_ID, &gpio_mode_AFSLB);
gpio_set_to_high_mask = gpio_cfg0 & gpio_cfg1;
gpio_set_to_low_mask = ~gpio_cfg0 & ~gpio_cfg1;
if ( ( gpio_set_to_high_mask | gpio_set_to_low_mask ) != 0 )
{
tUInt mode_none_mask=0, mode_A_mask=0, mode_B_mask=0, mode_C_mask=0;
mode_none_mask = ~(gpio_mode_AFSLA | gpio_mode_AFSLB);
mode_A_mask = gpio_mode_AFSLA & ~(gpio_mode_AFSLB);
mode_B_mask = ~(gpio_mode_AFSLA) & gpio_mode_AFSLB;
mode_C_mask = gpio_mode_AFSLA & gpio_mode_AFSLB;
LLD_GPIO_SetControlMode((LLD_GPIO_idTy)GPIO1_REG_START_ADDR,(LLD_GPIO_PinTy)((gpio_set_to_high_mask | gpio_set_to_low_mask) & mode_none_mask),LLD_GPIO_ALTERNATE_NONE);
LLD_GPIO_SetControlMode((LLD_GPIO_idTy)GPIO1_REG_START_ADDR,(LLD_GPIO_PinTy)((gpio_set_to_high_mask | gpio_set_to_low_mask) & mode_A_mask),LLD_GPIO_ALTERNATE_MODE_A);
LLD_GPIO_SetControlMode((LLD_GPIO_idTy)GPIO1_REG_START_ADDR,(LLD_GPIO_PinTy)((gpio_set_to_high_mask | gpio_set_to_low_mask) & mode_B_mask),LLD_GPIO_ALTERNATE_MODE_B);
LLD_GPIO_SetControlMode((LLD_GPIO_idTy)GPIO1_REG_START_ADDR,(LLD_GPIO_PinTy)((gpio_set_to_high_mask | gpio_set_to_low_mask) & mode_C_mask),LLD_GPIO_ALTERNATE_MODE_C);
LLD_GPIO_SetDirectionOutput( (LLD_GPIO_idTy)GPIO1_REG_START_ADDR, ( LLD_GPIO_PinTy )( gpio_set_to_high_mask | gpio_set_to_low_mask ) );
LLD_GPIO_SetStateHigh( (LLD_GPIO_idTy)GPIO1_REG_START_ADDR, ( LLD_GPIO_PinTy )gpio_set_to_high_mask );
LLD_GPIO_SetStateLow( (LLD_GPIO_idTy)GPIO1_REG_START_ADDR, ( LLD_GPIO_PinTy )gpio_set_to_low_mask );
}
return gpOS_SUCCESS;
}
/********************************************//**
* \brief
*
* \param tVoid
* \return gpOS_error_t
*
***********************************************/
gpOS_error_t gnssapp_gnss_debug_start( gpOS_partition_t *part )
{
gnss_debug_mode_t gnss_debug_mode = GNSS_DEBUG_ON;
sw_config_get_param( CURRENT_CONFIG_DATA, GPS_DEBUG_MODE_ID, &gnss_debug_mode );
gnss_debug_mode &= GNSS_DEBUG_MASK;
if ( gnss_debug_init( part, gnss_debug_mode, gnssapp_handler->debug_output ) == gpOS_FAILURE )
{
return ( gpOS_FAILURE );
}
#if defined( __ARMCC_VERSION)
GPS_DEBUG_MSG( ( "\r\n\r\n\r\nARM C/C++ Compiler version: %d\r\n", __ARMCC_VERSION ) );
#endif
#if defined( __GNUC__)
GPS_DEBUG_MSG( ( "\r\n\r\n\r\nGNU C/C++ Compiler version: %d%d%d\r\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ ) );
#endif
GPS_DEBUG_MSG( ( "%s\r\n%s\r\n", gnssapp_version(), gpOS_version() ) );
//sw_config_print();
return ( gpOS_SUCCESS );
}
/********************************************//**
* \brief Start GPS Services
*
* \param tVoid
* \return gpOS_error_t
*
***********************************************/
gpOS_error_t gnssapp_gnss_service_start( gpOS_partition_t *gps_part)
{
gpOS_error_t error = gpOS_SUCCESS;
/* Init SSP service for frontend */
if( svc_ssp_init( gps_part, PLATFORM_BUSCLK_ID_MCLK) == gpOS_FAILURE)
{
error = gpOS_FAILURE;
}
/* Init I2C service */
if( svc_i2c_init( gps_part, PLATFORM_BUSCLK_ID_MCLK) == gpOS_FAILURE)
{
error = gpOS_FAILURE;
}
#if defined( DR_CODE_LINKED )
/* Init CAN service */
if( svc_can_init(NULL,PLATFORM_BUSCLK_ID_CAN_CLK) == gpOS_FAILURE)
{
error = gpOS_FAILURE;
}
#endif // defined( DR_CODE_LINKED )
/* Init GPIO service */
if( svc_gpio_init( gps_part) == gpOS_FAILURE)
{
error = gpOS_FAILURE;
}
return error;
}
/********************************************//**
* \brief Initialize the Advanced Message Queue
*
* \param gpOS_partition_t *gps_part
* \param boolean_t sensors_presence indicates if sensors are present in the config
* \param boolean_t sens_buf_size indicates the buffer size defined in the config for sensors
* \return gpOS_error_t
*
***********************************************/
gpOS_error_t gnssapp_gnss_amq_init( gpOS_partition_t *part, boolean_t sensors_presence, tUInt sens_buf_size)
{
gpOS_error_t return_error = gpOS_SUCCESS;
if ( ( sensors_presence == TRUE) || ( sens_buf_size != 0x0U ) )
{
if( sens_buf_size == 0x0U )
{
/* use the default msg queue length */
if (gnss_msg_queue_init(part, &gnss_msg_queue, MSG_QUEUE_LEN) == GNSS_ERROR)
{
ERROR_MSG( "[main]: AMQ Init failed\r\n" );
return_error = gpOS_FAILURE;
}
}
else
{
/* initialize the msg queue length with the sensor buf msg number. AMQ will receive sensors data + nav msgs. Nav msg size is minor */
if (gnss_msg_queue_init(part, &gnss_msg_queue, (tU16)(sens_buf_size * 64U)) == GNSS_ERROR)
{
ERROR_MSG( "[main]: AMQ Init failed\r\n" );
return_error = gpOS_FAILURE;
}
}
}
/* If sensors are not enabled*/
else
{
/* amq size is minimum */
if (gnss_msg_queue_init(part, &gnss_msg_queue, (tU16)((sizeof( nav_message_t )+sizeof(gnss_msg_header_t))*DEFAULT_AMQ_MSG_SIZE )) == GNSS_ERROR)
{
ERROR_MSG( "[main]: AMQ Init failed\r\n" );
return_error = gpOS_FAILURE;
}
}
return return_error;
}
/********************************************//**
* \brief Start GPS libraries
*
* \param tVoid
* \return gpOS_error_t
*
***********************************************/
gpOS_error_t gnssapp_gnss_lib_start( gpOS_partition_t *gps_part )
{
gnss_sat_type_mask_t orbit_list_selection = 0;
gnss_sat_type_mask_t constellation_usage_selection = 0;
gnss_error_t err = GNSS_NO_ERROR;
gpOS_error_t ret = gpOS_SUCCESS;
tU8 pps_clock = 32;
// Initialize frontend default values if needed
{
tU32 cnt;
for ( cnt = 0; cnt < 25; cnt++ )
{
tU8 addr, data, func;
err = sw_config_get_param( CURRENT_CONFIG_DATA, FE_A0_ID + (cnt * 2), &addr );
err = sw_config_get_param( CURRENT_CONFIG_DATA, FE_D0_ID + (cnt * 2), &data );
if ( addr != DEFAULT_NOT_USED_FE_REGISTER )
{
func = ( addr >> 6 ) & 0x3;
addr = addr & 0x3F;
if ( func > 0 )
{
tUInt read_data;
FE_def_read_data( addr, &read_data );
switch ( func )
{
case 1:
data = read_data | data;
break;
case 2:
data = read_data & data;
break;
default:
/* Should never go there*/
break;
}
}
FE_def_write_data( addr, data );
}
}
}
/**< Initialize gnss section */
// Configure orbit lists for tracking and positioning
if( sw_config_get_software_switch_status( GPS_ON_OFF_SWITCH )!= FALSE )
{
MCR_SETBIT( orbit_list_selection, GNSS_SAT_TYPE_GPS );
}
if( sw_config_get_software_switch_status( GPS_USE_ON_OFF_SWITCH )!= FALSE )
{
MCR_SETBIT( constellation_usage_selection, GNSS_SAT_TYPE_GPS );
}
if( sw_config_get_software_switch_status( QZSS_ON_OFF_SWITCH ) != FALSE)
{
MCR_SETBIT( orbit_list_selection, GNSS_SAT_TYPE_QZSS_L1_CA );
}
if( sw_config_get_software_switch_status( QZSS_USE_ON_OFF_SWITCH )!= FALSE )
{
MCR_SETBIT( constellation_usage_selection, GNSS_SAT_TYPE_QZSS_L1_CA );
}
if( sw_config_get_software_switch_status( GLONASS_ON_OFF_SWITCH )!= FALSE )
{
MCR_SETBIT( orbit_list_selection, GNSS_SAT_TYPE_GLONASS );
}
if( sw_config_get_software_switch_status( GLONASS_USE_ON_OFF_SWITCH )!= FALSE )
{
MCR_SETBIT( constellation_usage_selection, GNSS_SAT_TYPE_GLONASS );
}
if (( boolean_t )sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, GALILEO_ON_OFF_SWITCH )!= FALSE)
{
MCR_SETBIT( orbit_list_selection, GNSS_SAT_TYPE_GALILEO );
}
if(( boolean_t )sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, GALILEO_USE_ON_OFF_SWITCH )!= FALSE)
{
MCR_SETBIT( constellation_usage_selection, GNSS_SAT_TYPE_GALILEO );
}
if (( boolean_t )sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, COMPASS_ON_OFF_SWITCH )!= FALSE)
{
MCR_SETBIT( orbit_list_selection, GNSS_SAT_TYPE_COMPASS );
}
if(( boolean_t )sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, COMPASS_USE_ON_OFF_SWITCH )!= FALSE)
{
MCR_SETBIT( constellation_usage_selection, GNSS_SAT_TYPE_COMPASS );
}
// Configure frontend registers based on SW config data
err = sw_config_get_param( CURRENT_CONFIG_DATA, PPS_CLOCK_SETTING_ID, &pps_clock );
platform_gnss_set_pps_clock( pps_clock );
if ( platform_gnss_init() == gpOS_FAILURE )
{
return ( gpOS_FAILURE );
}
gnssapp_startup_time.gnss_lib_set_timer_clock = gpOS_time_now();
{
tInt min_week_n = 0, max_week_n = 0, utc_delta_time_default = 0;
gnss_fix_config_t fix_config;
err = sw_config_get_param( CURRENT_CONFIG_DATA, GPS_MIN_MAX_WEEK_NUMBER_ID, &min_week_n );
max_week_n = ( min_week_n >> 16 ) & 0xFFFF;
min_week_n = min_week_n & 0xFFFF;
gnss_set_min_max_week_number( min_week_n, max_week_n );
err = sw_config_get_param( CURRENT_CONFIG_DATA, GPS_UTC_DEFAULT_SETTING_ID , &utc_delta_time_default );
gnss_set_gps_utc_delta_time_default( utc_delta_time_default );
gnss_get_fix_config( &fix_config );
fix_config.few_sats_pos_estimation_enable = ( boolean_t )sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, FEW_SATS_POS_EST_ON_OFF_SWITCH );
gnss_set_fix_config( &fix_config );
}
if(sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, EXT_RTC_OSCI_ON_OFF_SWITCH ) != FALSE)
{
LLD_PRCC_SetOscillator(FALSE);
}
else
{
/* Internal oscillator is used to generate the RTC clock.*/
}
if(sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, RTC_USAGE_DISABLING_ON_OFF_SWITCH ) != FALSE)
{
/**< Turn off RTC and initialise */
gnss_time_t gnss_time;
/* calculate the gps week and time of week */
/* year month day, hour, mins ,secs */
//gnss_date_time_to_gnss_time( 2009, 06, 12, 13, 30, 00, &gnss_time);
/* Initialize the RTC to off and tell it GPS time at a CPU time */
gnss_time.week_n = 0;
gnss_time.tow = 0.0;
gnss_init_rtc( RTC_SWITCH_OFF, &gnss_time, gpOS_time_now(), 0xFFFFFFFFU );
}
/*}}} */
/**< Init GNSS event mechanism */
if ( gnss_events_init_p( gps_part ) == gpOS_FAILURE )
{
return ( gpOS_FAILURE );
}
gnss_set_sat_list_size(GNSSLIB_SAT_LIST_SIZE);
/**< Setup GPS engine */
if( gnss_init_p( (gpOS_partition_t *)gps_part, orbit_list_selection, constellation_usage_selection) == GNSS_ERROR )
{
ERROR_MSG( "[main]: ERROR gnss_init failed\r\n" );
return ( gpOS_FAILURE );
}
else
{
tInt trk_threshold = 0;
tDouble fix_rate = 0.0;
tUInt mask_angle = 0;
tUInt wls_params = 0;
//if (nmea_msg_list_check(NMEA_msg_list, NAV_NMEA_M) == TRUE)
if (sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, NAVM_SUPPORT_ON_OFF_SWITCH ) != 0)
{
//gnss_error_t gnss_nav_dump_init( gpOS_partition_t *part);
if( gnss_nav_dump_init( gps_part) == GNSS_ERROR)
{
ERROR_MSG(("GNSS_ERROR subframe dump init failed\r\n"));
return ( gpOS_FAILURE );
}
}
err = sw_config_get_param( CURRENT_CONFIG_DATA, GPS_MASK_ANGLE_ID, &mask_angle );
err = sw_config_get_param( CURRENT_CONFIG_DATA, GPS_FIX_RATE_ID, &fix_rate );
gnss_set_elevation_mask_angle( ( tDouble )mask_angle );
gnss_set_fix_rate( fix_rate );
err = sw_config_get_param( CURRENT_CONFIG_DATA, GPS_MASK_ANGLE_POSITIONING_ID, &mask_angle );
gnss_set_elevation_mask_angle_positioning( ( tDouble )mask_angle );
err = sw_config_get_param( CURRENT_CONFIG_DATA, WLS_CFG_PARAMS_1_ID, &wls_params);
if((wls_params & 0x1) != 0)
{
tDouble par1, par2;
par1 = (tDouble)((wls_params >> 8) & 0xFF) / 10;
par2 = (tDouble)((wls_params >> 16) & 0xFF) / 10;
gnss_set_wls_runtime(TRUE,par1,par2);
}
{
tInt notch_filter_cfg = 0;
err = sw_config_get_param( CURRENT_CONFIG_DATA, NOTCH_FILTER_CFG_ID, ¬ch_filter_cfg );
if ( MCR_ISBITSET( notch_filter_cfg, GNSS_SAT_TYPE_GPS ) )
{
gnss_notch_filter_enable( GNSS_SAT_TYPE_GPS, 0, 1 );
}
if ( MCR_ISBITSET( notch_filter_cfg, GNSS_SAT_TYPE_GLONASS ) )
{
gnss_notch_filter_enable( GNSS_SAT_TYPE_GLONASS, 0, 1 );
}
if ( MCR_ISBITSET( notch_filter_cfg >> 2, GNSS_SAT_TYPE_GPS ) )
{
gnss_notch_filter_enable( GNSS_SAT_TYPE_GPS, 0, 2 );
}
if ( MCR_ISBITSET( notch_filter_cfg >> 2, GNSS_SAT_TYPE_GLONASS ) )
{
gnss_notch_filter_enable( GNSS_SAT_TYPE_GLONASS, 0, 2 );
}
}
if ( sw_config_get_software_switch_status( ACQ_2_5_PPM_TCXO_SWITCH ) != FALSE )
{
gnss_init_2_5_ppm_support( TRUE );
GPS_DEBUG_MSG( ( "2.5 ppm ACQ TCXO error support\r\n" ) );
}
{
tUInt gnss_integrity_check_cfg = 0U;
err = sw_config_get_param( CURRENT_CONFIG_DATA, GNSS_INTEGRITY_CHECK_CFG_ID, &gnss_integrity_check_cfg );
gnss_init_integrity_check_cfg( gnss_integrity_check_cfg );
GPS_DEBUG_MSG( ( "GNSS Integrity support %d\r\n",gnss_integrity_check_cfg) );
}
if( sw_config_get_software_switch_status( HIGH_DYNAMICS_ON_OFF_SWITCH )!=FALSE )
{
if(gnss_init_high_dynamics_mode(1) == GNSS_ERROR)
{
GPS_DEBUG_MSG(("gnss_init_high_dynamics_mode: ERROR\r\n"));
}
}
else
{
tUInt dyn_params = 0;
tUInt param;
err = sw_config_get_param( CURRENT_CONFIG_DATA, DYNAMIC_MODE_CFG_PARAMS_ID, &dyn_params);
if((dyn_params & 0xFU) == 4U)
{
dynamic_mng_data_t data;
param = ((dyn_params >> 24U) & 0xFFU);
data.hd_acc_th = (tDouble)param;
data.hd_acc_th = data.hd_acc_th / 10.0;
param = ((dyn_params >> 16U) & 0xFFU);
data.ld_acc_th = (tDouble)param;
data.ld_acc_th = data.ld_acc_th / 100.0;
param = ((dyn_params >> 8U) & 0xFFU);
data.hd_hysteresis_s = (tChar)param;
param= ((dyn_params >> 4U) & 0xFU);
data.ld_stabilization_s = (tChar)param;
gnss_set_dynamic_mng_params(TRUE,&data);
}
else
{
param = (dyn_params & 0xFU);
if(gnss_init_high_dynamics_mode((tInt)param) == GNSS_ERROR)
{
GPS_DEBUG_MSG(("gnss_init_high_dynamics_mode: ERROR\r\n"));
}
}
}
if ( sw_config_get_param( CURRENT_CONFIG_DATA, GPS_TRACKING_TH_ID, &trk_threshold ) == GNSS_NO_ERROR )
{
gnss_init_tracking_threshold( trk_threshold );
}
if ( sw_config_get_software_switch_status( QZSS_SLOW_ACQUISITION_MODE_SWITCH ) != FALSE )
{
gnss_acquisition_set_operational_mode( GNSS_SAT_TYPE_QZSS_L1_CA, 1 );
}
{
tUInt dsp_config_options = 0U;
err = sw_config_get_param( CURRENT_CONFIG_DATA, DSP_CONFIG_OPTIONS_ID, &dsp_config_options);
gnss_set_multipath_mitigation_mode((tInt)(dsp_config_options & 0x3));
gnss_set_tcxo_jump_detection_mode((tInt)((dsp_config_options & 0x4)>>2));
}
{
tUInt param1, param2;
gnss_lms_config_t lms_cfg;
err = sw_config_get_param( CURRENT_CONFIG_DATA, LMS_ALGO_CFG_PARAMS_1_ID, ¶m1 );
err = sw_config_get_param( CURRENT_CONFIG_DATA, LMS_ALGO_CFG_PARAMS_2_ID, ¶m2 );
gnss_lms_get_config( &lms_cfg );
lms_cfg.enable_2D_fixes = (boolean_t)( ( param1 >> 0U ) & 0x1U );
lms_cfg.check_residual_hdop_product = (boolean_t)( ( param1 >> 1U ) & 0x1U );
lms_cfg.lock_glonass_path_delay = (boolean_t)( ( param1 >> 2U ) & 0x1U );
lms_cfg.position_residual_thr = ( tDouble )( ( param1 >> 8U ) & 0xFFU );
lms_cfg.position_residual_thr_after_raim = ( tDouble )( ( param1 >> 16U ) & 0xFFU );
lms_cfg.min_sat_gnss_fix = ( ( param2 >> 0U ) & 0xFFU );
lms_cfg.min_sat_single_const_fix = ( ( param2 >> 8U ) & 0xFFU );
lms_cfg.glonass_path_delay_init_value = ( tDouble )( ( tShort )( ( param2 >> 16U ) & 0xFFFFU ) ) / 10;
gnss_lms_set_config( &lms_cfg );
}
// restore previous parameter after standby return
if( (svc_pwr_StartupMode() != SVC_PWR_STARTUP_POWER_ON) )
{
GPS_DEBUG_MSG(( "[gnssapp pwr] low power mode reload backup\r\n"));
gnssapp_low_power_setup(GNSSAPP_LOW_POWER_INIT, gnssapp_lowpow.Standby, &gnssapp_lowpow.cyclic, &gnssapp_lowpow.periodic );
}
else
{
if(sw_config_get_software_switch_status( LOW_POWER_ON_OFF_SWITCH )!=FALSE)
{
gnss_low_power_cyclic_mode_t cyclic;
gnss_low_power_periodic_mode_t periodic;
gnss_app_lowpow_standby_type_t Standby;
tUInt param1,param4,param5;
GPS_DEBUG_MSG(( "[gnssapp pwr] low power mode reload NVM\r\n"));
err = sw_config_get_param( CURRENT_CONFIG_DATA, LOW_POWER_CFG_PARAMS_1_ID, ¶m1);
err = sw_config_get_param( CURRENT_CONFIG_DATA, LOW_POWER_CFG_PARAMS_4_ID, ¶m4);
err = sw_config_get_param( CURRENT_CONFIG_DATA, LOW_POWER_CFG_PARAMS_5_ID, ¶m5);
/* Adaptive and Cyclic config bits */
cyclic.reduced_type = (boolean_t)((param1 ) & 0x01U);
cyclic.duty_cycle_on_off = (boolean_t)((param1 >> 1U) & 0x01U);
/* 2 bits left */
/* Adaptive and Cyclic settings */
cyclic.ehpe_threshold = (tU8) ((param1 >> 4U) & 0xFFU);
cyclic.N_sats_reduced = (tU8) ((param1 >> 12U) & 0xFFU);
cyclic.duty_cycle_fixperiod = (tShort)((param1 >> 20U) & 0xFFFU);
/* ConsteLLation applicable */
cyclic.const_mask_init = constellation_usage_selection;
/* Periodic config bits */
periodic.NoFixTimeout = (tU8) ((param5 ) & 0xFFU);
periodic.NoFixOffTime = (tU16) ((param5 >> 8U) & 0xFFFU);
periodic.periodic_mode = (boolean_t)((param4 ) & 0x01U);
periodic.EPH_refresh = (tU8)((param4 >> 2U) & 0x01U);
periodic.RTC_refresh = (tU8)((param4 >> 3U) & 0x01U);
periodic.wakeup_pin_en = (tU8)((param4 >> 4U) & 0x01U);
/* 3 bits left */
/* Periodic settings */
periodic.fix_period = (tU32)((param4 >> 8U) & 0x1FFFFU);
periodic.fix_on_time = (tU8) ((param4 >> 25U) & 0x7FU);
if(((param4 >> 1U) & 0x01U) == 0x01U)
{
Standby = GNSSAPP_LOW_POWER_STANDBY_ENABLE;
}
else
{
Standby = GNSSAPP_LOW_POWER_STANDBY_DISABLE;
}
gnssapp_low_power_setup(GNSSAPP_LOW_POWER_INIT, Standby, &cyclic, &periodic );
if( svc_pwr_get_standby_allowed() == TRUE )
{
GPS_DEBUG_MSG(( "[gnssapp pwr] NVM standby mode activated\r\n"));
}
}
else
{
gnssapp_low_power_setup(GNSSAPP_LOW_POWER_INIT, GNSSAPP_LOW_POWER_STANDBY_DISABLE, NULL, NULL );
}
}
if(sw_config_get_software_switch_status_by_id(APP_ON_OFF_2_ID,GNSS_FAST_CN0_MODE_ON_OFF_SWITCH) != FALSE)
{
gnss_set_fast_CN0_mode(TRUE);
}
else
{
gnss_set_fast_CN0_mode(FALSE);
}
if (sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, RTC_USAGE_DISABLING_ON_OFF_SWITCH) == 0U)
{
if(sw_config_get_software_switch_status_by_id( APP_ON_OFF_2_ID, RTC_CALIBRATION_ON_OFF_SWITCH) != 0U)
{
gnss_set_rtc_calibration_mode(TRUE);
}
else
{
gnss_set_rtc_calibration_mode(FALSE);
}
}
}
#if 0
/**< Invalidate NVM data to do a cold start */
gnss_clear_all_almanacs();
gnss_clear_all_ephems();
gnss_test_invalidate_user_pos();
gnss_test_invalidate_rtc();
#endif
#if 0
/**< Force setting of NCO frequency and bandwidth */
gnss_set_centre_freq( startup_nco_center );
gnss_set_freq_range( startup_nco_max, startup_nco_min );
#endif
/**< Starts GPS engine */
gnss_set_diff_mode( DIFF_MODE_AUTO );
gnss_diff_set_source_type( diff_source );
/*PPS CLOCK SETTING STEP2*/
gnss_pps_set_clock_speed( pps_clock ); //this call must be placed before the gnss_start() call
/* Pulse Per Second Initialization and Configuration*/
if( sw_config_get_software_switch_status( PPS_ON_OFF_SWITCH ) != FALSE)
{
tDouble pps_correction = 0.0, gps_pps_correction = 0.0, glonass_pps_correction = 0.0, compass_pps_correction = 0.0, galileo_pps_correction = 0.0;
tDouble pps_pulse_duration = 5E-1;
boolean_t pps_inverted_polarity = FALSE;
gnss_pps_enable_control( TRUE );
err = sw_config_get_param( CURRENT_CONFIG_DATA, RF_TIME_CORRECTION_ID, &pps_correction );
err = sw_config_get_param( CURRENT_CONFIG_DATA, PPS_PULSE_DURATION_ID, &pps_pulse_duration );
pps_inverted_polarity = (boolean_t)sw_config_get_software_switch_status( PPS_INVERTED_POLARITY_ON_OFF_SWITCH );
gnss_pps_init( (gpOS_partition_t *)gps_part, pps_correction, pps_pulse_duration, pps_inverted_polarity );
err = sw_config_get_param( CURRENT_CONFIG_DATA, GPS_RF_TIME_CORRECTION_ID, &gps_pps_correction );
err = sw_config_get_param( CURRENT_CONFIG_DATA, GLONASS_RF_TIME_CORRECTION_ID, &glonass_pps_correction );
err = sw_config_get_param( CURRENT_CONFIG_DATA, COMPASS_RF_TIME_CORRECTION_ID, &compass_pps_correction );
err = sw_config_get_param( CURRENT_CONFIG_DATA, GALILEO_RF_TIME_CORRECTION_ID, &galileo_pps_correction );
gnss_pps_set_rf_compensation( GNSS_SAT_TYPE_GPS, gps_pps_correction );
gnss_pps_set_rf_compensation( GNSS_SAT_TYPE_GLONASS, glonass_pps_correction );
gnss_pps_set_rf_compensation( GNSS_SAT_TYPE_COMPASS, compass_pps_correction );
gnss_pps_set_rf_compensation( GNSS_SAT_TYPE_GALILEO, galileo_pps_correction );
{
tU8 hw_cfg;
err = sw_config_get_param( CURRENT_CONFIG_DATA, HARDWARE_CONFIGURATION_ID, &hw_cfg );
if ( hw_cfg == HW_SAL_CFG )
{
LLD_GPIO_SetControlMode( (LLD_GPIO_idTy)GPIO0_REG_START_ADDR, LLD_GPIO_PIN1, LLD_GPIO_ALTERNATE_MODE_B );
}
}
if( sw_config_get_software_switch_status( POSITION_HOLD_ON_OFF_SWITCH ) != FALSE)
{
tDouble lat, lon, height;
err = sw_config_get_param( CURRENT_CONFIG_DATA, POSITION_HOLD_LAT_ID, &lat );
err = sw_config_get_param( CURRENT_CONFIG_DATA, POSITION_HOLD_LON_ID, &lon );
err = sw_config_get_param( CURRENT_CONFIG_DATA, POSITION_HOLD_HEIGHT_ID, &height );
gnss_pps_set_position_hold_llh_pos( lat, lon, height );
gnss_pps_set_position_hold_status( TRUE );
}
if(sw_config_get_software_switch_status( TIMING_TRAIM_ON_OFF_SWITCH )!= FALSE)
{
tDouble traim_alarm = 15E-9;
err = sw_config_get_param( CURRENT_CONFIG_DATA, TIMING_TRAIM_ALARM_ID, &traim_alarm );
gnss_pps_enable_traim( traim_alarm );
}