Skip to content

Commit 54da31a

Browse files
committed
applications: serial_lte_modem: Fix asserts when pressing power pin
Asserts were enabled with PR #20040. This has caused an assert to occur when pressing power pin, because GPIO callback (power_pin_callback_wakeup) called slm_at_host_power_on, which called k_sleep(), which has an assert that it's not called from interrupt context. Added most of the wake up operation into a worker. Jira: LRCS-70 Signed-off-by: Tommi Rantanen <tommi.rantanen@nordicsemi.no>
1 parent 52966b0 commit 54da31a

File tree

1 file changed

+21
-4
lines changed
  • applications/serial_lte_modem/src

1 file changed

+21
-4
lines changed

applications/serial_lte_modem/src/main.c

+21-4
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,22 @@ static int configure_power_pin_interrupt(gpio_callback_handler_t handler, gpio_f
149149
return err;
150150
}
151151

152-
LOG_DBG("Configured interrupt (0x%x) on power pin (%u).", flags, pin);
152+
LOG_DBG("Configured interrupt (0x%x) on power pin (%u) with handler (%p).",
153+
flags, pin, handler);
153154
return 0;
154155
}
155156

157+
static void slm_enter_sleep_work_fn(struct k_work *)
158+
{
159+
slm_enter_sleep();
160+
}
161+
156162
static void power_pin_callback_poweroff(const struct device *, struct gpio_callback *, uint32_t)
157163
{
164+
static K_WORK_DEFINE(work, slm_enter_sleep_work_fn);
165+
158166
LOG_INF("Power off triggered.");
159-
slm_enter_sleep();
167+
k_work_submit(&work);
160168
}
161169

162170
static void poweroff_interrupt_enabler(struct k_work *)
@@ -245,7 +253,7 @@ static void power_pin_callback_enable_poweroff(const struct device *dev,
245253
/* Enable the poweroff interrupt after a small delay
246254
* so that it doesn't fire right away (which it does if enabled here).
247255
*/
248-
k_work_schedule(&work, K_MSEC(1));
256+
poweroff_interrupt_enabler(NULL);
249257
}
250258

251259
static void power_pin_callback_wakeup(const struct device *dev,
@@ -276,12 +284,21 @@ static void power_pin_callback_wakeup(const struct device *dev,
276284
return;
277285
}
278286

287+
atomic_set(&callback_running, false);
288+
}
289+
290+
static void power_pin_callback_wakeup(const struct device *dev,
291+
struct gpio_callback *gpio_callback, uint32_t)
292+
{
293+
static K_WORK_DEFINE(work, power_pin_callback_wakeup_work_fn);
294+
295+
LOG_INF("Resuming from idle shortly...");
279296
gpio_remove_callback(dev, gpio_callback);
280297

281298
/* Enable the poweroff interrupt only when the pin will be back to a nonactive state. */
282299
configure_power_pin_interrupt(power_pin_callback_enable_poweroff, GPIO_INT_EDGE_RISING);
283300

284-
atomic_set(&callback_running, false);
301+
k_work_submit(&work);
285302
}
286303

287304
void slm_enter_idle(void)

0 commit comments

Comments
 (0)