From af556f4f03949bf44e02ba02683596a10859bd65 Mon Sep 17 00:00:00 2001 From: SunJ Date: Tue, 13 Jan 2026 17:31:29 +0800 Subject: [PATCH] refactor(osal): replace NuttX internal APIs with POSIX APIs Replace nxsched_self() and nxsched_set_priority() with standard POSIX sched_getparam() and sched_setparam() in usb_osal_thread_schedule_other(). This improves portability and follows POSIX standards for thread priority management. Change-Id: I2e637268f77e200fbdee3e7713cba1b115976696 Signed-off-by: SunJ --- osal/usb_osal_nuttx.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/osal/usb_osal_nuttx.c b/osal/usb_osal_nuttx.c index 49911573..1a44fb48 100644 --- a/osal/usb_osal_nuttx.c +++ b/osal/usb_osal_nuttx.c @@ -65,14 +65,23 @@ void usb_osal_thread_delete(usb_osal_thread_t thread) void usb_osal_thread_schedule_other(void) { - struct tcb_s *tcb = nxsched_self(); - const int old_priority = tcb->sched_priority; + struct sched_param param; + int old_priority; - nxsched_set_priority(tcb, SCHED_PRIORITY_MIN); + /* Get current priority (pid=0 means current task) */ + assert(sched_getparam(0, ¶m) == 0); + old_priority = param.sched_priority; + /* Set to minimum priority to yield CPU to other tasks */ + param.sched_priority = SCHED_PRIORITY_MIN; + assert(sched_setparam(0, ¶m) == 0); + + /* Yield CPU to other tasks */ sched_yield(); - nxsched_set_priority(tcb, old_priority); + /* Restore original priority */ + param.sched_priority = old_priority; + assert(sched_setparam(0, ¶m) == 0); } usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)