Mercurial > public > ostc4
comparison Small_CPU/Src/baseCPU2.c @ 936:3029f0332f4f Evo_2_23
GNSS introduced power saving mode:
In the previous implementation the modul always did a cold start. In the new one the power saving functions of the module are activated. The module will be switched to intervall mode while entering sleep. If the computer remains in sleep for a long time then the GNSS modul will be switchen of completly.
author | Ideenmodellierer |
---|---|
date | Sun, 08 Dec 2024 22:03:07 +0100 |
parents | effadaa3a1f7 |
children | df87dbfc9c21 |
comparison
equal
deleted
inserted
replaced
935:f2494a708f52 | 936:3029f0332f4f |
---|---|
133 #include "dma.h" | 133 #include "dma.h" |
134 #include "i2c.h" | 134 #include "i2c.h" |
135 #include "spi.h" | 135 #include "spi.h" |
136 #include "rtc.h" | 136 #include "rtc.h" |
137 #include "adc.h" | 137 #include "adc.h" |
138 #include "gpio.h" | |
138 #include "compass.h" | 139 #include "compass.h" |
139 #include "pressure.h" | 140 #include "pressure.h" |
140 #include "batteryGasGauge.h" | 141 #include "batteryGasGauge.h" |
141 #include "batteryCharger.h" | 142 #include "batteryCharger.h" |
142 #include "scheduler.h" | 143 #include "scheduler.h" |
143 #include "tm_stm32f4_otp.h" | 144 #include "tm_stm32f4_otp.h" |
144 #include "externalInterface.h" | 145 #include "externalInterface.h" |
145 #include "uart.h" | 146 #include "uart.h" |
146 #include "uart_Internal.h" | 147 #include "uart_Internal.h" |
148 #include "uartProtocol_GNSS.h" | |
147 #include "GNSS.h" | 149 #include "GNSS.h" |
148 | 150 |
149 | 151 |
150 // From Common/Inc: | 152 // From Common/Inc: |
151 #include "calc_crush.h" | 153 #include "calc_crush.h" |
213 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 | 215 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 |
214 #define BUTTON_OSTC_GPIO_PORT GPIOA | 216 #define BUTTON_OSTC_GPIO_PORT GPIOA |
215 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | 217 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() |
216 #define BUTTON_OSTC_IRQn EXTI0_IRQn | 218 #define BUTTON_OSTC_IRQn EXTI0_IRQn |
217 | 219 |
218 #define VIBRATION_CONTROL_PIN GPIO_PIN_3 /* PortA */ | |
219 #define LED_CONTROL_PIN_RED GPIO_PIN_2 /* PortA */ | |
220 #define LED_CONTROL_PIN_GREEN GPIO_PIN_1 /* PortA */ | |
221 #define MAINCPU_CONTROL_PIN GPIO_PIN_0 /* PortC */ | |
222 #define GPS_POWER_CONTROL_PIN GPIO_PIN_15 /* PortB */ | |
223 #define GPS_BCKP_CONTROL_PIN GPIO_PIN_14 /* PortB */ | |
224 | 220 |
225 /* Private macro -------------------------------------------------------------*/ | 221 /* Private macro -------------------------------------------------------------*/ |
226 | 222 |
227 /* Private variables ---------------------------------------------------------*/ | 223 /* Private variables ---------------------------------------------------------*/ |
228 uint32_t global_test_time_counter = 0; | 224 uint32_t global_test_time_counter = 0; |
230 | 226 |
231 /* Private function prototypes -----------------------------------------------*/ | 227 /* Private function prototypes -----------------------------------------------*/ |
232 static void EXTI_Wakeup_Button_Init(void); | 228 static void EXTI_Wakeup_Button_Init(void); |
233 static void EXTI_Wakeup_Button_DeInit(void); | 229 static void EXTI_Wakeup_Button_DeInit(void); |
234 | 230 |
235 static void GPIO_LEDs_VIBRATION_Init(void); | |
236 static void GPIO_Power_MainCPU_Init(void); | |
237 static void GPIO_Power_MainCPU_ON(void); | |
238 static void GPIO_Power_MainCPU_OFF(void); | |
239 #ifdef ENABLE_GPIO_V2 | |
240 static void GPIO_LED_RED_OFF(void); | |
241 static void GPIO_LED_RED_ON(void); | |
242 static void GPIO_LED_GREEN_OFF(void); | |
243 static void GPIO_LED_GREEN_ON(void); | |
244 static void GPIO_VIBRATION_OFF(void); | |
245 static void GPIO_VIBRATION_ON(void); | |
246 static void GPIO_GPS_OFF(void); | |
247 static void GPIO_GPS_ON(void); | |
248 static void GPIO_GPS_BCKP_OFF(void); | |
249 static void GPIO_GPS_BCKP_ON(void); | |
250 #endif | |
251 #ifdef DEBUG_I2C_LINES | 231 #ifdef DEBUG_I2C_LINES |
252 void GPIO_test_I2C_lines(void); | 232 void GPIO_test_I2C_lines(void); |
253 #endif | 233 #endif |
254 | 234 |
255 void sleep_prepare(void); | 235 void sleep_prepare(void); |
292 uint8_t measurementindex = 0; | 272 uint8_t measurementindex = 0; |
293 uint8_t lastsecond = 0xFF; | 273 uint8_t lastsecond = 0xFF; |
294 #endif | 274 #endif |
295 | 275 |
296 uint8_t extInterfaceActive = 0; | 276 uint8_t extInterfaceActive = 0; |
277 #if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2 | |
278 uint32_t shutdownTick = 0; | |
279 #endif | |
297 | 280 |
298 HAL_Init(); | 281 HAL_Init(); |
299 SystemClock_Config(); | 282 SystemClock_Config(); |
300 | 283 |
301 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); | 284 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
452 #ifdef ENABLE_GNSS_SUPPORT | 435 #ifdef ENABLE_GNSS_SUPPORT |
453 GNSS_Init(&GNSS_Handle, &huart1); | 436 GNSS_Init(&GNSS_Handle, &huart1); |
454 #endif | 437 #endif |
455 #endif | 438 #endif |
456 | 439 |
457 /* | |
458 * Demo code from SimpleMethod | |
459 * called 1/second | |
460 while (1) { | |
461 | |
462 if ((HAL_GetTick() - Timer) > 1000) { | |
463 GNSS_GetUniqID(&GNSS_Handle); | |
464 GNSS_ParseBuffer(&GNSS_Handle); | |
465 HAL_Delay(250); | |
466 GNSS_GetPVTData(&GNSS_Handle); | |
467 GNSS_ParseBuffer(&GNSS_Handle); | |
468 printf("Day: %d-%d-%d \r\n", GNSS_Handle.day, GNSS_Handle.month,GNSS_Handle.year); | |
469 printf("Time: %d:%d:%d \r\n", GNSS_Handle.hour, GNSS_Handle.min,GNSS_Handle.sec); | |
470 printf("Status of fix: %d \r\n", GNSS_Handle.fixType); | |
471 printf("Latitude: %f \r\n", GNSS_Handle.fLat); | |
472 printf("Longitude: %f \r\n",(float) GNSS_Handle.lon / 10000000.0); | |
473 printf("Height above ellipsoid: %d \r\n", GNSS_Handle.height); | |
474 printf("Height above mean sea level: %d \r\n", GNSS_Handle.hMSL); | |
475 printf("Ground Speed (2-D): %d \r\n", GNSS_Handle.gSpeed); | |
476 printf("Unique ID: %04X %04X %04X %04X %04X \n\r", | |
477 GNSS_Handle.uniqueID[0], GNSS_Handle.uniqueID[1], | |
478 GNSS_Handle.uniqueID[2], GNSS_Handle.uniqueID[3], | |
479 GNSS_Handle.uniqueID[4], GNSS_Handle.uniqueID[5]); | |
480 Timer = HAL_GetTick(); | |
481 } | |
482 */ | |
483 | |
484 global.mode = MODE_SURFACE; | 440 global.mode = MODE_SURFACE; |
485 break; | 441 break; |
486 | 442 |
487 case MODE_CALIB: | 443 case MODE_CALIB: |
488 scheduleCompassCalibrationMode(); | 444 scheduleCompassCalibrationMode(); |
531 backup.seconds_since_last_dive = 0; | 487 backup.seconds_since_last_dive = 0; |
532 break; | 488 break; |
533 | 489 |
534 case MODE_SHUTDOWN: | 490 case MODE_SHUTDOWN: |
535 HAL_Delay(200); | 491 HAL_Delay(200); |
492 | |
493 MX_SPI3_Init(); | |
494 | |
495 #if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2 | |
496 if(shutdownTick == 0) | |
497 { | |
498 shutdownTick = HAL_GetTick(); | |
499 uartGnss_ReqPowerDown(1); | |
500 } | |
501 #ifdef ENABLE_GNSS_SUPPORT | |
502 externalInterface_HandleUART(); | |
503 #else | |
504 UART6_HandleUART(); | |
505 #endif | |
506 if((uartGnss_GetState() == UART_GNSS_INACTIVE) || (time_elapsed_ms(shutdownTick,HAL_GetTick()) > 5000)) | |
507 { | |
508 global.mode = MODE_SLEEP; | |
509 } | |
510 #else | |
536 global.mode = MODE_SLEEP; | 511 global.mode = MODE_SLEEP; |
537 MX_SPI3_Init(); | 512 #endif |
513 | |
514 | |
538 break; | 515 break; |
539 | 516 |
540 case MODE_SLEEP: | 517 case MODE_SLEEP: |
541 extInterfaceActive = externalInterface_isEnabledPower33(); | 518 extInterfaceActive = externalInterface_isEnabledPower33(); |
542 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); | 519 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); |
807 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | 784 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); |
808 HAL_Delay(10); | 785 HAL_Delay(10); |
809 } | 786 } |
810 */ | 787 */ |
811 | 788 |
812 static void GPIO_LEDs_VIBRATION_Init(void) { | |
813 GPIO_InitTypeDef GPIO_InitStructure; | |
814 | |
815 __GPIOA_CLK_ENABLE(); | |
816 GPIO_InitStructure.Pin = LED_CONTROL_PIN_RED; | |
817 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
818 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
819 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
820 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); | |
821 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET); | |
822 | |
823 GPIO_InitStructure.Pin = LED_CONTROL_PIN_GREEN; | |
824 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
825 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
826 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
827 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); | |
828 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET); | |
829 | |
830 GPIO_InitStructure.Pin = VIBRATION_CONTROL_PIN; | |
831 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
832 GPIO_InitStructure.Pull = GPIO_PULLDOWN; | |
833 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
834 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); | |
835 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET); | |
836 | |
837 __GPIOB_CLK_ENABLE(); | |
838 GPIO_InitStructure.Pin = GPS_POWER_CONTROL_PIN; | |
839 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
840 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
841 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
842 HAL_GPIO_Init( GPIOB, &GPIO_InitStructure); | |
843 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET); | |
844 | |
845 GPIO_InitStructure.Pin = GPS_BCKP_CONTROL_PIN; | |
846 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
847 GPIO_InitStructure.Pull = GPIO_PULLDOWN; | |
848 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
849 HAL_GPIO_Init( GPIOB, &GPIO_InitStructure); | |
850 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_RESET); | |
851 } | |
852 | |
853 void GPIO_new_DEBUG_Init(void) { | 789 void GPIO_new_DEBUG_Init(void) { |
854 #ifdef DEBUG_PIN_ACTIVE | 790 #ifdef DEBUG_PIN_ACTIVE |
855 GPIO_InitTypeDef GPIO_InitStructure; | 791 GPIO_InitTypeDef GPIO_InitStructure; |
856 | 792 |
857 __GPIOC_CLK_ENABLE(); | 793 __GPIOC_CLK_ENABLE(); |
872 void GPIO_new_DEBUG_HIGH(void) { | 808 void GPIO_new_DEBUG_HIGH(void) { |
873 #ifdef DEBUG_PIN_ACTIVE | 809 #ifdef DEBUG_PIN_ACTIVE |
874 HAL_GPIO_WritePin(GPIOC,LED_CONTROL_PIN,GPIO_PIN_SET); | 810 HAL_GPIO_WritePin(GPIOC,LED_CONTROL_PIN,GPIO_PIN_SET); |
875 #endif | 811 #endif |
876 } | 812 } |
877 | |
878 static void GPIO_Power_MainCPU_Init(void) { | |
879 GPIO_InitTypeDef GPIO_InitStructure; | |
880 __GPIOC_CLK_ENABLE(); | |
881 GPIO_InitStructure.Pin = MAINCPU_CONTROL_PIN; | |
882 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
883 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
884 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
885 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | |
886 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET); | |
887 } | |
888 | |
889 static void GPIO_Power_MainCPU_ON(void) { | |
890 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET); | |
891 } | |
892 | |
893 static void GPIO_Power_MainCPU_OFF(void) { | |
894 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_SET); | |
895 } | |
896 | |
897 #ifdef ENABLE_GPIO_V2 | |
898 static void GPIO_LED_GREEN_ON(void) { | |
899 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_RESET); | |
900 } | |
901 | |
902 static void GPIO_LED_GREEN_OFF(void) { | |
903 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_GREEN, GPIO_PIN_SET); | |
904 } | |
905 | |
906 static void GPIO_LED_RED_ON(void) { | |
907 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_RESET); | |
908 } | |
909 | |
910 static void GPIO_LED_RED_OFF(void) { | |
911 HAL_GPIO_WritePin( GPIOA, LED_CONTROL_PIN_RED, GPIO_PIN_SET); | |
912 } | |
913 | |
914 static void GPIO_VIBRATION_ON(void) { | |
915 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_SET); | |
916 } | |
917 | |
918 static void GPIO_VIBRATION_OFF(void) { | |
919 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET); | |
920 } | |
921 | |
922 static void GPIO_GPS_ON(void) { | |
923 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_RESET); | |
924 } | |
925 | |
926 static void GPIO_GPS_OFF(void) { | |
927 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET); | |
928 } | |
929 | |
930 static void GPIO_GPS_BCKP_ON(void) { | |
931 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_SET); | |
932 } | |
933 | |
934 static void GPIO_GPS_BCKP_OFF(void) { | |
935 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_RESET); | |
936 } | |
937 #endif | |
938 | 813 |
939 /** | 814 /** |
940 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | 815 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode |
941 * @param None | 816 * @param None |
942 * @retval None | 817 * @retval None |
1021 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | 896 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); |
1022 #ifdef DEBUGMODE | 897 #ifdef DEBUGMODE |
1023 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ | 898 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ |
1024 #endif | 899 #endif |
1025 | 900 |
901 /* | |
1026 GPIO_InitStruct.Pin = GPIO_PIN_All ^ (GPS_POWER_CONTROL_PIN | GPS_BCKP_CONTROL_PIN); | 902 GPIO_InitStruct.Pin = GPIO_PIN_All ^ (GPS_POWER_CONTROL_PIN | GPS_BCKP_CONTROL_PIN); |
1027 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); | 903 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
1028 | 904 */ |
1029 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | EXT33V_CONTROL_PIN); /* power off & charger in & charge out & OSC32 & ext33Volt */ | 905 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | EXT33V_CONTROL_PIN); /* power off & charger in & charge out & OSC32 & ext33Volt */ |
1030 | 906 |
1031 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); | 907 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); |
1032 | 908 |
1033 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | VIBRATION_CONTROL_PIN | LED_CONTROL_PIN_RED | LED_CONTROL_PIN_GREEN); | 909 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | VIBRATION_CONTROL_PIN | LED_CONTROL_PIN_RED | LED_CONTROL_PIN_GREEN); |
1043 #ifdef ENABLE_GPIO_V2 | 919 #ifdef ENABLE_GPIO_V2 |
1044 GPIO_LED_GREEN_OFF(); | 920 GPIO_LED_GREEN_OFF(); |
1045 GPIO_LED_RED_OFF(); | 921 GPIO_LED_RED_OFF(); |
1046 GPIO_VIBRATION_OFF(); | 922 GPIO_VIBRATION_OFF(); |
1047 GPIO_GPS_BCKP_ON(); // mH : costs 100µA in sleep - beware | 923 GPIO_GPS_BCKP_ON(); // mH : costs 100µA in sleep - beware |
1048 GPIO_GPS_OFF(); | 924 /* GPIO_GPS_OFF(); will be done in transition slleep => deep sleep */ |
1049 | 925 |
1050 MX_USART6_UART_DeInit(); | 926 MX_USART6_UART_DeInit(); |
1051 #endif | 927 #endif |
1052 #ifndef DEBUGMODE | 928 #ifndef DEBUGMODE |
1053 __HAL_RCC_GPIOB_CLK_DISABLE(); | 929 __HAL_RCC_GPIOB_CLK_DISABLE(); |