-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Reset/ncsdk 36564 to main #26163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Reset/ncsdk 36564 to main #26163
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||
| * Copyright (c) 2025 Nordic Semiconductor ASA | ||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||
| * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #include <zcbor_common.h> | ||||||||||||||||||||||||||||||||||
| #include <zcbor_encode.h> | ||||||||||||||||||||||||||||||||||
| #include <zephyr/mgmt/mcumgr/mgmt/callbacks.h> | ||||||||||||||||||||||||||||||||||
| #include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h> | ||||||||||||||||||||||||||||||||||
| #include <zephyr/logging/log.h> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #ifdef CONFIG_BT | ||||||||||||||||||||||||||||||||||
| #include <zephyr/bluetooth/bluetooth.h> | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| #ifdef CONFIG_MPSL | ||||||||||||||||||||||||||||||||||
| #include <mpsl.h> | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| LOG_MODULE_REGISTER(os_mgmt_reboot_bt, CONFIG_MCUMGR_GRP_OS_LOG_LEVEL); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #ifdef CONFIG_MULTITHREADING | ||||||||||||||||||||||||||||||||||
| static void bt_disable_work_handler(struct k_work *work); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| static K_WORK_DELAYABLE_DEFINE(bt_disable_work, bt_disable_work_handler); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| static void bt_disable_work_handler(struct k_work *work) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| ARG_UNUSED(work); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #ifdef CONFIG_BT | ||||||||||||||||||||||||||||||||||
| int err_rc = bt_disable(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (err_rc) { | ||||||||||||||||||||||||||||||||||
| LOG_ERR("BT disable failed before reboot: %d", err_rc); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| #ifdef CONFIG_MPSL | ||||||||||||||||||||||||||||||||||
| mpsl_uninit(); | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| static enum mgmt_cb_return reboot_bt_hook(uint32_t event, enum mgmt_cb_return prev_status, | ||||||||||||||||||||||||||||||||||
| int32_t *rc, uint16_t *group, bool *abort_more, | ||||||||||||||||||||||||||||||||||
| void *data, size_t data_size) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| struct os_mgmt_reset_data *reboot_data = (struct os_mgmt_reset_data *)data; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (event != MGMT_EVT_OP_OS_MGMT_RESET || data_size != sizeof(*reboot_data)) { | ||||||||||||||||||||||||||||||||||
| *rc = MGMT_ERR_EUNKNOWN; | ||||||||||||||||||||||||||||||||||
| return MGMT_CB_ERROR_RC; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| #ifdef CONFIG_MULTITHREADING | ||||||||||||||||||||||||||||||||||
| /* disable bluetooth from the system workqueue thread. */ | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| /* disable bluetooth from the system workqueue thread. */ | |
| /* disable bluetooth from the system workqueue thread. */ | |
| /* | |
| * Schedule Bluetooth disable at half the reset timeout. | |
| * This ensures Bluetooth is disabled well before the actual reset occurs, | |
| * allowing time for clean shutdown and resource release. | |
| */ |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add parentheses around the division operation: K_MSEC((CONFIG_MCUMGR_GRP_OS_RESET_MS/2)). This improves readability and prevents potential issues with macro expansion.
| k_work_schedule(&bt_disable_work, K_MSEC(CONFIG_MCUMGR_GRP_OS_RESET_MS/2)); | |
| k_work_schedule(&bt_disable_work, K_MSEC((CONFIG_MCUMGR_GRP_OS_RESET_MS/2))); |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The variable name cmd_reboot_bt_info_cb is misleading as it suggests an info callback, but this handles the reboot hook. Consider renaming to reboot_bt_hook_cb or os_mgmt_reboot_bt_cb for clarity.
| static struct mgmt_callback cmd_reboot_bt_info_cb = { | |
| .callback = reboot_bt_hook, | |
| .event_id = MGMT_EVT_OP_OS_MGMT_RESET, | |
| }; | |
| static int os_mgmt_register_reboot_bt(void) | |
| { | |
| mgmt_callback_register(&cmd_reboot_bt_info_cb); | |
| static struct mgmt_callback reboot_bt_hook_cb = { | |
| .callback = reboot_bt_hook, | |
| .event_id = MGMT_EVT_OP_OS_MGMT_RESET, | |
| }; | |
| static int os_mgmt_register_reboot_bt(void) | |
| { | |
| mgmt_callback_register(&reboot_bt_hook_cb); |
Uh oh!
There was an error while loading. Please reload this page.