From b476eccf69aafcbb555d903c3d544a0807d5b7ab Mon Sep 17 00:00:00 2001 From: Mateusz Lubecki Date: Mon, 21 Oct 2024 20:49:49 +0200 Subject: [PATCH] some delay after power button is pressed for gsm modem --- src/main.c | 2 +- src/pwr_save.c | 15 --------------- system/include/drivers/max31865.h | 1 + system/include/gsm/sim800_state_t.h | 1 + system/src/drivers/max31865.c | 7 +++++++ system/src/gsm/sim800c.c | 16 ++++++++++------ 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/main.c b/src/main.c index b213e3f..45dd0ca 100644 --- a/src/main.c +++ b/src/main.c @@ -1529,7 +1529,7 @@ int main(int argc, char* argv[]){ // this sleep is used by @link{pwr_save_after_stop2_rtc_wakeup_it} to // go to the intermediate sleep in L4 powersave mode, when xxx seconds // long sleep is divided into 'PWR_SAVE_STOP2_CYCLE_LENGHT_SEC' to - // serwice IWDG in between + // service IWDG in between system_clock_configure_auto_wakeup_l4(PWR_SAVE_STOP2_CYCLE_LENGHT_SEC); pwr_save_enter_stop2(); diff --git a/src/pwr_save.c b/src/pwr_save.c index a8e711a..53b0a35 100644 --- a/src/pwr_save.c +++ b/src/pwr_save.c @@ -257,16 +257,6 @@ void pwr_save_enter_stop2(void) { */ void pwr_save_after_stop2_rtc_wakeup_it(void) { - // if yes set curent state - rte_main_woken_up = RTE_MAIN_WOKEN_UP_AFTER_LAST_SLEEP; - -// // check if this is an intermediate wakeup from STOP2 -// pwr_save_check_stop2_cycles(); -// -// system_clock_configure_l4(); -// -// pwr_save_exit_after_last_stop2_cycle(); - // reload internal watchdog main_reload_internal_wdg(); @@ -277,11 +267,6 @@ void pwr_save_after_stop2_rtc_wakeup_it(void) { if (pwr_save_number_of_sleep_cycles > 0) { backup_reg_set_monitor(15); -// // go back to sleep -// // configure how long micro should sleep -// system_clock_configure_auto_wakeup_l4(PWR_SAVE_STOP2_CYCLE_LENGHT_SEC); -// -// pwr_save_enter_stop2(); rte_main_woken_up = RTE_MAIN_GO_TO_INTERMEDIATE_SLEEP; } else { diff --git a/system/include/drivers/max31865.h b/system/include/drivers/max31865.h index 23fad9e..df4f659 100644 --- a/system/include/drivers/max31865.h +++ b/system/include/drivers/max31865.h @@ -30,5 +30,6 @@ void max31865_pool(void); int32_t max31865_get_pt100_result(); int32_t max31865_get_result(uint32_t RTDnominal); max31865_qf_t max31865_get_qf(void); +void max31865_set_state_after_wkup(void); #endif /* INCLUDE_DRIVERS_MAX31865_H_ */ diff --git a/system/include/gsm/sim800_state_t.h b/system/include/gsm/sim800_state_t.h index 03d1903..e7df43d 100644 --- a/system/include/gsm/sim800_state_t.h +++ b/system/include/gsm/sim800_state_t.h @@ -12,6 +12,7 @@ typedef enum gsm_sim800_state_t { SIM800_UNKNOWN, SIM800_POWERED_OFF, SIM800_POWERING_ON, + SIM800_WAITING_FOR_POWERUP, SIM800_NOT_YET_COMM, SIM800_HANDSHAKING, SIM800_INITIALIZING, diff --git a/system/src/drivers/max31865.c b/system/src/drivers/max31865.c index 6898d33..9f53184 100644 --- a/system/src/drivers/max31865.c +++ b/system/src/drivers/max31865.c @@ -501,3 +501,10 @@ int32_t max31865_get_result(uint32_t RTDnominal) { max31865_qf_t max31865_get_qf(void) { return max31865_quality_factor; } + +void max31865_set_state_after_wkup(void) { + max31865_current_state = MAX_SHUTDOWN; + + max31865_shutdown_ticks = MAX31865_INTERVAL - 1; +} + diff --git a/system/src/gsm/sim800c.c b/system/src/gsm/sim800c.c index e9dc6e0..870b96a 100644 --- a/system/src/gsm/sim800c.c +++ b/system/src/gsm/sim800c.c @@ -363,16 +363,20 @@ void gsm_sim800_initialization_pool(srl_context_t * srl_context, gsm_sim800_stat else if (*state == SIM800_POWERING_ON) { gsm_sim800_press_pwr_button(); + *state = SIM800_WAITING_FOR_POWERUP; + + } + else if (*state == SIM800_WAITING_FOR_POWERUP) { + // depress power button + gsm_sim800_depress_pwr_button(); + + // give GSM module some time for its bootup to complete *state = SIM800_NOT_YET_COMM; } else if (*state == SIM800_NOT_YET_COMM) { - - // depress power button - gsm_sim800_depress_pwr_button(); - - // configure rx timeout - srl_switch_timeout(srl_context, 1, 0); + // configure rx timeout - give some more time + srl_switch_timeout(srl_context, 1, 3000u); // send handshake srl_send_data(srl_context, (const uint8_t*) AUTOBAUD_STRING, SRL_MODE_ZERO, strlen(AUTOBAUD_STRING), SRL_INTERNAL);