Skip to content

Commit

Permalink
mgmt: mcumgr: use delayed workqueue for reset
Browse files Browse the repository at this point in the history
Same behaviour, less code, smaller code size.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
  • Loading branch information
nixward authored and carlescufi committed Jan 15, 2024
1 parent 70c7ac7 commit 00cfab6
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ LOG_MODULE_REGISTER(mcumgr_os_grp, CONFIG_MCUMGR_GRP_OS_LOG_LEVEL);

#ifdef CONFIG_REBOOT
static void os_mgmt_reset_work_handler(struct k_work *work);
static void os_mgmt_reset_cb(struct k_timer *timer);

K_WORK_DEFINE(os_mgmt_reset_work, os_mgmt_reset_work_handler);
static K_TIMER_DEFINE(os_mgmt_reset_timer, os_mgmt_reset_cb, NULL);
K_WORK_DELAYABLE_DEFINE(os_mgmt_reset_work, os_mgmt_reset_work_handler);
#endif

/* This is passed to zcbor_map_start/end_endcode as a number of
Expand Down Expand Up @@ -358,13 +356,9 @@ static int os_mgmt_taskstat_read(struct smp_streamer *ctxt)
*/
static void os_mgmt_reset_work_handler(struct k_work *work)
{
sys_reboot(SYS_REBOOT_WARM);
}
ARG_UNUSED(work);

static void os_mgmt_reset_cb(struct k_timer *timer)
{
/* Reboot the system from the system workqueue thread. */
k_work_submit(&os_mgmt_reset_work);
sys_reboot(SYS_REBOOT_WARM);
}

static int os_mgmt_reset(struct smp_streamer *ctxt)
Expand Down Expand Up @@ -404,8 +398,9 @@ static int os_mgmt_reset(struct smp_streamer *ctxt)
}
#endif

k_timer_start(&os_mgmt_reset_timer, K_MSEC(CONFIG_MCUMGR_GRP_OS_RESET_MS),
K_NO_WAIT);
/* Reboot the system from the system workqueue thread. */
k_work_schedule(&os_mgmt_reset_work, K_MSEC(CONFIG_MCUMGR_GRP_OS_RESET_MS));

return 0;
}
#endif
Expand Down

0 comments on commit 00cfab6

Please sign in to comment.