Jelajahi Sumber

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 <jsun@bouffalolab.com>
SunJ 6 hari lalu
induk
melakukan
1de6b93045
1 mengubah file dengan 13 tambahan dan 4 penghapusan
  1. 13 4
      osal/usb_osal_nuttx.c

+ 13 - 4
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, &param) == 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, &param) == 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, &param) == 0);
 }
 
 usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)