Преглед изворни кода

OS/ThreadX: enable threadx idle task when the _tx_thread_execute_ptr is NULL

Signed-off-by: Huaqi Fang <578567190@qq.com>
Huaqi Fang пре 1 година
родитељ
комит
d00a7e36af
1 измењених фајлова са 16 додато и 0 уклоњено
  1. 16 0
      OS/ThreadX/ports/nuclei/port.c

+ 16 - 0
OS/ThreadX/ports/nuclei/port.c

@@ -68,6 +68,22 @@ void PortThreadSwitch(void)
 #ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
     _tx_execution_thread_exit();
 #endif
+    /*
+     * ThreadX don't have idle task, so _tx_thread_execute_ptr could be NULL
+     * If it is NULL, it means it should goto idle state, and wait for interrupt
+     */
+    if (!_tx_thread_execute_ptr) {
+        /* mcause must be saved and restore if interrupt nested */
+        rv_csr_t mcause = __RV_CSR_READ(CSR_MCAUSE);
+        ECLIC_SetLevelIRQ(SysTimer_IRQn, KERNEL_INTERRUPT_PRIORITY + 1);
+        __enable_irq();
+        while (!_tx_thread_execute_ptr) {
+            __WFI();
+        }
+        __disable_irq();
+        ECLIC_SetLevelIRQ(SysTimer_IRQn, KERNEL_INTERRUPT_PRIORITY);
+        __RV_CSR_WRITE(CSR_MCAUSE, mcause);
+    }
     /* Determine if the time-slice is active.  */
     if (_tx_timer_time_slice) {
         /* Preserve current remaining time-slice for the thread and clear the current time-slice.  */