|
6 | 6 |
|
7 | 7 | #include <zcbor_common.h> |
8 | 8 | #include <zcbor_encode.h> |
9 | | -#include <pm_config.h> |
10 | 9 | #include <zephyr/mgmt/mcumgr/mgmt/callbacks.h> |
11 | 10 | #include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h> |
12 | 11 | #include <zephyr/logging/log.h> |
|
20 | 19 |
|
21 | 20 | LOG_MODULE_REGISTER(os_mgmt_reboot_bt, CONFIG_MCUMGR_GRP_OS_LOG_LEVEL); |
22 | 21 |
|
| 22 | +#ifdef CONFIG_MULTITHREADING |
| 23 | +static void bt_disable_work_handler(struct k_work *work); |
| 24 | + |
| 25 | +static K_WORK_DELAYABLE_DEFINE(bt_disable_work, bt_disable_work_handler); |
| 26 | + |
| 27 | +static void bt_disable_work_handler(struct k_work *work) |
| 28 | +{ |
| 29 | + ARG_UNUSED(work); |
| 30 | + |
| 31 | +#ifdef CONFIG_BT |
| 32 | + int err_rc = bt_disable(); |
| 33 | + |
| 34 | + if (err_rc) { |
| 35 | + LOG_ERR("BT disable failed before reboot: %d", err_rc); |
| 36 | + } |
| 37 | +#endif |
| 38 | +#ifdef CONFIG_MPSL |
| 39 | + mpsl_uninit(); |
| 40 | +#endif |
| 41 | +} |
| 42 | +#endif |
| 43 | + |
23 | 44 | static enum mgmt_cb_return reboot_bt_hook(uint32_t event, enum mgmt_cb_return prev_status, |
24 | 45 | int32_t *rc, uint16_t *group, bool *abort_more, |
25 | 46 | void *data, size_t data_size) |
26 | 47 | { |
27 | | - int err_rc; |
28 | 48 | struct os_mgmt_reset_data *reboot_data = (struct os_mgmt_reset_data *)data; |
29 | 49 |
|
30 | 50 | if (event != MGMT_EVT_OP_OS_MGMT_RESET || data_size != sizeof(*reboot_data)) { |
31 | 51 | *rc = MGMT_ERR_EUNKNOWN; |
32 | 52 | return MGMT_CB_ERROR_RC; |
33 | 53 | } |
34 | | - |
| 54 | +#ifdef CONFIG_MULTITHREADING |
| 55 | + /* disable bluetooth from the system workqueue thread. */ |
| 56 | + k_work_schedule(&bt_disable_work, K_MSEC(CONFIG_MCUMGR_GRP_OS_RESET_MS/2)); |
| 57 | +#else |
35 | 58 | #ifdef CONFIG_BT |
36 | | - err_rc = bt_disable(); |
| 59 | + int err_rc = bt_disable(); |
| 60 | + |
37 | 61 | if (err_rc) { |
38 | 62 | LOG_ERR("BT disable failed before reboot: %d", err_rc); |
39 | 63 | } |
40 | 64 | #endif |
41 | 65 | #ifdef CONFIG_MPSL |
42 | 66 | mpsl_uninit(); |
| 67 | +#endif |
43 | 68 | #endif |
44 | 69 |
|
45 | 70 | return MGMT_CB_OK; |
|
0 commit comments