Mercurial > public > ostc4
comparison Small_CPU/Src/baseCPU2.c @ 662:1b995079c045 Betatest
PSCR Mode
author | heinrichs weikamp |
---|---|
date | Tue, 14 Dec 2021 15:36:10 +0100 |
parents | 9513a92b293b |
children | 12d029f38430 |
comparison
equal
deleted
inserted
replaced
661:87bee7cc77b3 | 662:1b995079c045 |
---|---|
140 #include "batteryGasGauge.h" | 140 #include "batteryGasGauge.h" |
141 #include "batteryCharger.h" | 141 #include "batteryCharger.h" |
142 #include "scheduler.h" | 142 #include "scheduler.h" |
143 #include "tm_stm32f4_otp.h" | 143 #include "tm_stm32f4_otp.h" |
144 #include "externalInterface.h" | 144 #include "externalInterface.h" |
145 #include "uart.h" | |
145 | 146 |
146 // From Common/Inc: | 147 // From Common/Inc: |
147 #include "calc_crush.h" | 148 #include "calc_crush.h" |
148 #include "decom.h" | 149 #include "decom.h" |
149 #include "FirmwareData.h" | 150 #include "FirmwareData.h" |
171 | 172 |
172 /* 4 bytes with trailing 0 */ | 173 /* 4 bytes with trailing 0 */ |
173 .signature = "mh", | 174 .signature = "mh", |
174 | 175 |
175 .release_year = 21, | 176 .release_year = 21, |
176 .release_month = 4, | 177 .release_month = 3, |
177 .release_day = 26, | 178 .release_day = 30, |
178 .release_sub = 0, | 179 .release_sub = 0, |
179 | 180 |
180 /* max 48 with trailing 0 */ | 181 /* max 48 with trailing 0 */ |
181 //release_info ="12345678901234567890123456789012345678901" | 182 //release_info ="12345678901234567890123456789012345678901" |
182 .release_info = "stable Nov'19", | 183 .release_info = "stable Nov'19", |
227 #define WIRELSS_FALLING_IRQn EXTI2_IRQn | 228 #define WIRELSS_FALLING_IRQn EXTI2_IRQn |
228 | 229 |
229 #define WIRELSS_POWER_GPIO_PIN GPIO_PIN_12 | 230 #define WIRELSS_POWER_GPIO_PIN GPIO_PIN_12 |
230 #define WIRELSS_POWER_GPIO_PORT GPIOB | 231 #define WIRELSS_POWER_GPIO_PORT GPIOB |
231 #define WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() | 232 #define WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() |
233 | |
234 | |
235 #define LED_CONTROL_PIN GPIO_PIN_3 /* PortC */ | |
236 #define MAINCPU_CONTROL_PIN GPIO_PIN_0 /* PortC */ | |
232 | 237 |
233 /* Private macro -------------------------------------------------------------*/ | 238 /* Private macro -------------------------------------------------------------*/ |
234 | 239 |
235 /* Private variables ---------------------------------------------------------*/ | 240 /* Private variables ---------------------------------------------------------*/ |
236 uint32_t global_test_time_counter = 0; | 241 uint32_t global_test_time_counter = 0; |
351 } | 356 } |
352 init_battery_gas_gauge(); | 357 init_battery_gas_gauge(); |
353 HAL_Delay(10); | 358 HAL_Delay(10); |
354 battery_gas_gauge_get_data(); | 359 battery_gas_gauge_get_data(); |
355 | 360 |
361 global.lifeData.battery_voltage = get_voltage(); | |
362 global.lifeData.battery_charge = get_charge(); | |
363 copyBatteryData(); | |
364 | |
356 MX_SPI3_Init(); | 365 MX_SPI3_Init(); |
357 | 366 |
358 if(coldstart != 0xA5) /* Not reading a 0xA5 means the memory cells has not been initialized before => cold start */ | 367 if(coldstart != 0xA5) /* Not reading a 0xA5 means the memory cells has not been initialized before => cold start */ |
359 { | 368 { |
360 coldstart = 0xA5; | 369 coldstart = 0xA5; |
361 battery_gas_gauge_set(0); | 370 |
371 set_charge_state(Charger_ColdStart); | |
372 | |
362 global.dataSendToMaster.power_on_reset = 1; | 373 global.dataSendToMaster.power_on_reset = 1; |
363 global.deviceDataSendToMaster.power_on_reset = 1; | 374 global.deviceDataSendToMaster.power_on_reset = 1; |
364 | 375 |
365 if (!scheduleSetButtonResponsiveness()) | 376 if (!scheduleSetButtonResponsiveness()) |
366 { | 377 { |
371 scheduleSetButtonResponsiveness(); // init | 382 scheduleSetButtonResponsiveness(); // init |
372 HAL_Delay(1); | 383 HAL_Delay(1); |
373 } | 384 } |
374 } | 385 } |
375 } | 386 } |
376 | 387 else |
377 global.lifeData.battery_voltage = get_voltage(); | 388 { |
378 global.lifeData.battery_charge = get_charge(); | 389 set_charge_state(Charger_NotConnected); |
379 copyBatteryData(); | 390 } |
380 | 391 |
381 ADCx_Init(); | 392 ADCx_Init(); |
382 GPIO_Power_MainCPU_Init(); | 393 GPIO_Power_MainCPU_Init(); |
394 | |
395 externalInterface_InitPower33(); | |
396 | |
383 global.mode = MODE_POWERUP; | 397 global.mode = MODE_POWERUP; |
384 #else | 398 #else |
385 init_pressure(); | 399 init_pressure(); |
386 init_surface_ring(0); | 400 init_surface_ring(0); |
387 | 401 |
406 GPIO_Power_MainCPU_ON(); | 420 GPIO_Power_MainCPU_ON(); |
407 } | 421 } |
408 SPI_synchronize_with_Master(); | 422 SPI_synchronize_with_Master(); |
409 MX_DMA_Init(); | 423 MX_DMA_Init(); |
410 MX_SPI1_Init(); | 424 MX_SPI1_Init(); |
425 MX_USART1_UART_Init(); | |
411 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ | 426 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ |
412 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); | 427 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
413 EXTI_Test_Button_Init(); | 428 EXTI_Test_Button_Init(); |
414 global.mode = MODE_SURFACE; | 429 global.mode = MODE_SURFACE; |
415 break; | 430 break; |
476 GPIO_Power_MainCPU_OFF(); | 491 GPIO_Power_MainCPU_OFF(); |
477 EXTI_Test_Button_DeInit(); | 492 EXTI_Test_Button_DeInit(); |
478 EXTI_Wakeup_Button_Init(); | 493 EXTI_Wakeup_Button_Init(); |
479 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); | 494 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); |
480 */ | 495 */ |
496 | |
481 EXTI_Test_Button_DeInit(); | 497 EXTI_Test_Button_DeInit(); |
498 externalInterface_SwitchPower33(false); | |
482 if (hasExternalClock()) | 499 if (hasExternalClock()) |
483 SystemClock_Config_HSI(); | 500 SystemClock_Config_HSI(); |
484 sleep_prepare(); | 501 sleep_prepare(); |
485 | 502 |
486 GPIO_LED_Init(); | 503 GPIO_LED_Init(); |
497 accelerator_init(); | 514 accelerator_init(); |
498 SPI_synchronize_with_Master(); | 515 SPI_synchronize_with_Master(); |
499 MX_DMA_Init(); | 516 MX_DMA_Init(); |
500 MX_SPI1_Init(); | 517 MX_SPI1_Init(); |
501 SPI_Start_single_TxRx_with_Master(); | 518 SPI_Start_single_TxRx_with_Master(); |
519 | |
520 if(externalInterface_isEnabledPower33()) | |
521 { | |
522 externalInterface_SwitchPower33(true); | |
523 } | |
502 | 524 |
503 // EXTILine0_Button_DeInit(); not now, later after testing | 525 // EXTILine0_Button_DeInit(); not now, later after testing |
504 break; | 526 break; |
505 } | 527 } |
506 | 528 |
791 | 813 |
792 static void GPIO_LED_Init(void) { | 814 static void GPIO_LED_Init(void) { |
793 GPIO_InitTypeDef GPIO_InitStructure; | 815 GPIO_InitTypeDef GPIO_InitStructure; |
794 | 816 |
795 __GPIOC_CLK_ENABLE(); | 817 __GPIOC_CLK_ENABLE(); |
796 GPIO_InitStructure.Pin = GPIO_PIN_3; | 818 GPIO_InitStructure.Pin = LED_CONTROL_PIN; |
797 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | 819 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
798 GPIO_InitStructure.Pull = GPIO_PULLUP; | 820 GPIO_InitStructure.Pull = GPIO_PULLUP; |
799 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | 821 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; |
800 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | 822 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); |
801 } | 823 } |
803 void GPIO_new_DEBUG_Init(void) { | 825 void GPIO_new_DEBUG_Init(void) { |
804 #ifdef DEBUG_PIN_ACTIVE | 826 #ifdef DEBUG_PIN_ACTIVE |
805 GPIO_InitTypeDef GPIO_InitStructure; | 827 GPIO_InitTypeDef GPIO_InitStructure; |
806 | 828 |
807 __GPIOC_CLK_ENABLE(); | 829 __GPIOC_CLK_ENABLE(); |
808 GPIO_InitStructure.Pin = GPIO_PIN_3; | 830 GPIO_InitStructure.Pin = LED_CONTROL_PIN; |
809 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | 831 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
810 GPIO_InitStructure.Pull = GPIO_PULLUP; | 832 GPIO_InitStructure.Pull = GPIO_PULLUP; |
811 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | 833 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; |
812 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | 834 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); |
813 #endif | 835 #endif |
814 } | 836 } |
815 | 837 |
816 void GPIO_new_DEBUG_LOW(void) { | 838 void GPIO_new_DEBUG_LOW(void) { |
817 #ifdef DEBUG_PIN_ACTIVE | 839 #ifdef DEBUG_PIN_ACTIVE |
818 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); | 840 HAL_GPIO_WritePin(GPIOC,LED_CONTROL_PIN,GPIO_PIN_RESET); |
819 #endif | 841 #endif |
820 } | 842 } |
821 | 843 |
822 void GPIO_new_DEBUG_HIGH(void) { | 844 void GPIO_new_DEBUG_HIGH(void) { |
823 #ifdef DEBUG_PIN_ACTIVE | 845 #ifdef DEBUG_PIN_ACTIVE |
824 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); | 846 HAL_GPIO_WritePin(GPIOC,LED_CONTROL_PIN,GPIO_PIN_SET); |
825 #endif | 847 #endif |
826 } | 848 } |
827 | 849 |
828 static void GPIO_Power_MainCPU_Init(void) { | 850 static void GPIO_Power_MainCPU_Init(void) { |
829 GPIO_InitTypeDef GPIO_InitStructure; | 851 GPIO_InitTypeDef GPIO_InitStructure; |
830 __GPIOC_CLK_ENABLE(); | 852 __GPIOC_CLK_ENABLE(); |
831 GPIO_InitStructure.Pin = GPIO_PIN_0; | 853 GPIO_InitStructure.Pin = MAINCPU_CONTROL_PIN; |
832 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | 854 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
833 GPIO_InitStructure.Pull = GPIO_PULLUP; | 855 GPIO_InitStructure.Pull = GPIO_PULLUP; |
834 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | 856 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; |
835 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | 857 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); |
836 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); | 858 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET); |
837 } | 859 } |
838 | 860 |
839 static void GPIO_Power_MainCPU_ON(void) { | 861 static void GPIO_Power_MainCPU_ON(void) { |
840 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); | 862 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_RESET); |
841 } | 863 } |
842 | 864 |
843 static void GPIO_Power_MainCPU_OFF(void) { | 865 static void GPIO_Power_MainCPU_OFF(void) { |
844 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_SET); | 866 HAL_GPIO_WritePin( GPIOC, MAINCPU_CONTROL_PIN, GPIO_PIN_SET); |
845 } | 867 } |
846 | 868 |
847 /** | 869 /** |
848 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | 870 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode |
849 * @param None | 871 * @param None |
936 | 958 |
937 } | 959 } |
938 | 960 |
939 void sleep_prepare(void) { | 961 void sleep_prepare(void) { |
940 EXTI_Wakeup_Button_Init(); | 962 EXTI_Wakeup_Button_Init(); |
941 /* | 963 |
942 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
943 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
944 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
945 */ | |
946 compass_sleep(); | 964 compass_sleep(); |
947 HAL_Delay(100); | 965 HAL_Delay(100); |
948 accelerator_sleep(); | 966 accelerator_sleep(); |
949 HAL_Delay(100); | 967 HAL_Delay(100); |
950 | 968 |
970 #endif | 988 #endif |
971 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); | 989 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
972 | 990 |
973 GPIO_InitStruct.Pin = | 991 GPIO_InitStruct.Pin = |
974 GPIO_PIN_All | 992 GPIO_PIN_All |
975 ^ ( GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_14 | 993 ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | CHARGE_IN_PIN | EXT33V_CONTROL_PIN | LED_CONTROL_PIN); /* power off & charger in & charge out & OSC32 & ext33Volt */ |
976 | GPIO_PIN_15); /* power off & charger in & charge out & OSC32*/ | 994 |
977 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); | 995 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); |
978 | 996 |
979 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | 997 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); |
980 #ifdef DEBUGMODE | 998 #ifdef DEBUGMODE |
981 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ | 999 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ |