summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-05-30 00:52:22 +0700
committerhathach <[email protected]>2026-05-30 00:52:22 +0700
commita64eb336c4a8d3f9c160aa30b81033e3ad7227d8 (patch)
tree5ff9c3a1a2f5a33e920980e672b53ea0bf0fd093 /examples
parentfc933e341df29e2ab6fa62508d45a92c65a621fb (diff)
dynamic_switch: hoist while(1) out for OS_NONE
Sonar flagged the loop body as executing only once on OS_NONE because the OS_NONE branch returns inside the first iteration (main() drives the task again). Make the while(1) conditional on RTOS so the OS_NONE build is a straight-line function with no misleading loop. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/dual/dynamic_switch/src/main.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/examples/dual/dynamic_switch/src/main.c b/examples/dual/dynamic_switch/src/main.c
index e8e0deb53..ac5126e56 100644
--- a/examples/dual/dynamic_switch/src/main.c
+++ b/examples/dual/dynamic_switch/src/main.c
@@ -281,7 +281,9 @@ void usb_mode_switch(void) {
void cdc_task(void *param) {
(void) param;
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
while (1) {
+#endif
// Only touch device-CDC APIs while we're in device mode. After
// usb_mode_switch() sets current_role to INVALID and tusb_deinit() runs,
// calling tud_cdc_write_flush() here would hit a deinit'd device stack.
@@ -295,13 +297,10 @@ void cdc_task(void *param) {
}
tud_cdc_write_flush();
}
-
#if CFG_TUSB_OS == OPT_OS_FREERTOS
vTaskDelay(pdMS_TO_TICKS(10));
-#else
- return; // main loop will call us again
-#endif
}
+#endif
}
//--------------------------------------------------------------------+
@@ -369,7 +368,9 @@ void tuh_umount_cb(uint8_t daddr) {
void print_devinfo_task(void *param) {
(void) param;
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
while (1) {
+#endif
if (current_role == TUSB_ROLE_HOST) {
for (uint8_t daddr = 1; daddr < TU_ARRAY_SIZE(need_devinfo); daddr++) {
if (need_devinfo[daddr]) {
@@ -378,13 +379,10 @@ void print_devinfo_task(void *param) {
}
}
}
-
#if CFG_TUSB_OS == OPT_OS_FREERTOS
vTaskDelay(pdMS_TO_TICKS(10));
-#else
- return;
-#endif
}
+#endif
}
static void print_one_device(uint8_t daddr) {