diff --git a/applications/serial_lte_modem/src/main.c b/applications/serial_lte_modem/src/main.c index 03edcb586..c8b6033d2 100644 --- a/applications/serial_lte_modem/src/main.c +++ b/applications/serial_lte_modem/src/main.c @@ -38,6 +38,9 @@ static bool full_idle_mode; /* global variable used across different files */ struct k_work_q slm_work_q; +/* define semaphore */ +K_SEM_DEFINE(semWake, 0, 1); + /* global variable defined in different files */ extern uint8_t fota_type; extern uint8_t fota_stage; @@ -54,15 +57,22 @@ void nrf_modem_recoverable_error_handler(uint32_t err) { LOG_ERR("Modem library recoverable error: %u", err); } - +#define USE_SEM_WAKE static void exit_idle(struct k_work *work) { int err; LOG_INF("Exit idle, full mode: %d", full_idle_mode); + +#ifdef USE_SEM_WAKE + if(k_sem_take(&semWake, K_NO_WAIT ) == 0 ) + return; +#endif gpio_pin_interrupt_configure(gpio_dev, CONFIG_SLM_INTERFACE_PIN, GPIO_INT_DISABLE); gpio_remove_callback(gpio_dev, &gpio_cb); + + /* Do the same as nrf_gpio_cfg_default() */ gpio_pin_configure(gpio_dev, CONFIG_SLM_INTERFACE_PIN, GPIO_INPUT); @@ -79,6 +89,9 @@ static void exit_idle(struct k_work *work) LOG_ERR("Failed to wake up uart: %d", err); } } +#ifdef USE_SEM_WAKE + k_sem_give(&semWake); +#endif } static void gpio_callback(const struct device *dev,