Skip to content

Commit 9d05514

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 9d05514

File tree

1 file changed

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

1 file changed

+21
-7
lines changed

applications/serial_lte_modem/src/main.c

+21-7
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 *)
@@ -242,10 +250,7 @@ static void power_pin_callback_enable_poweroff(const struct device *dev,
242250
LOG_DBG("Enabling the poweroff interrupt shortly...");
243251
gpio_remove_callback(dev, gpio_callback);
244252

245-
/* Enable the poweroff interrupt after a small delay
246-
* so that it doesn't fire right away (which it does if enabled here).
247-
*/
248-
k_work_schedule(&work, K_MSEC(1));
253+
configure_power_pin_interrupt(power_pin_callback_poweroff, GPIO_INT_EDGE_RISING);
249254
}
250255

251256
static void power_pin_callback_wakeup(const struct device *dev,
@@ -276,12 +281,21 @@ static void power_pin_callback_wakeup(const struct device *dev,
276281
return;
277282
}
278283

284+
atomic_set(&callback_running, false);
285+
}
286+
287+
static void power_pin_callback_wakeup(const struct device *dev,
288+
struct gpio_callback *gpio_callback, uint32_t)
289+
{
290+
static K_WORK_DEFINE(work, power_pin_callback_wakeup_work_fn);
291+
292+
LOG_INF("Resuming from idle shortly...");
279293
gpio_remove_callback(dev, gpio_callback);
280294

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

284-
atomic_set(&callback_running, false);
298+
k_work_submit(&work);
285299
}
286300

287301
void slm_enter_idle(void)

0 commit comments

Comments
 (0)