Parcourir la source

fix: 修复在需要超时参数的函数中osWaitForever的预期异常
- 添加对 osWaitForever 参数的特殊处理,将 osWaitForever 转换为 RT_WAITING_FOREVER,以适应底层 RT-Thread API 的要求
- 对rt_mq_send改为使用rt_mq_send_wait提供超时时间参数传入

wdfk-prog il y a 7 mois
Parent
commit
e0bf895ab2
1 fichiers modifiés avec 38 ajouts et 1 suppressions
  1. 38 1
      cmsis_rtthread.c

+ 38 - 1
cmsis_rtthread.c

@@ -1435,6 +1435,11 @@ uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t optio
         rt_options |= RT_EVENT_FLAG_CLEAR;
         rt_options |= RT_EVENT_FLAG_CLEAR;
     }
     }
 
 
+    if(timeout == osWaitForever)
+    {
+        timeout = RT_WAITING_FOREVER;
+    }
+
     result = rt_event_recv(&(event_cb->event), flags, (rt_uint8_t)rt_options, timeout, &rt_recv);
     result = rt_event_recv(&(event_cb->event), flags, (rt_uint8_t)rt_options, timeout, &rt_recv);
 
 
     if (RT_EOK == result)
     if (RT_EOK == result)
@@ -1562,6 +1567,11 @@ osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
     }
     }
     rt_exit_critical();
     rt_exit_critical();
 
 
+    if(timeout == osWaitForever)
+    {
+        timeout = RT_WAITING_FOREVER;
+    }
+
     result = rt_mutex_take(&(mutex_cb->mutex), timeout);
     result = rt_mutex_take(&(mutex_cb->mutex), timeout);
 
 
     if (RT_EOK == result)
     if (RT_EOK == result)
@@ -1713,6 +1723,11 @@ osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout)
         return osErrorParameter;
         return osErrorParameter;
     }
     }
 
 
+    if(timeout == osWaitForever)
+    {
+        timeout = RT_WAITING_FOREVER;
+    }
+
     result = rt_sem_take(&(sem_cb->sem), timeout);
     result = rt_sem_take(&(sem_cb->sem), timeout);
 
 
     if (RT_EOK == result)
     if (RT_EOK == result)
@@ -1892,6 +1907,11 @@ void *osMemoryPoolAlloc(osMemoryPoolId_t mp_id, uint32_t timeout)
         return RT_NULL;
         return RT_NULL;
     }
     }
 
 
+    if(timeout == osWaitForever)
+    {
+        timeout = RT_WAITING_FOREVER;
+    }
+
     return rt_mp_alloc(&(mempool_cb->mp), timeout);
     return rt_mp_alloc(&(mempool_cb->mp), timeout);
 }
 }
 
 
@@ -2117,7 +2137,12 @@ osStatus_t osMessageQueuePut(osMessageQueueId_t mq_id, const void *msg_ptr, uint
         return osErrorParameter;
         return osErrorParameter;
     }
     }
 
 
-    result = rt_mq_send(&(mq_cb->mq), (void *)msg_ptr, mq_cb->init_msg_size);
+    if(timeout == osWaitForever)
+    {
+        timeout = RT_WAITING_FOREVER;
+    }
+
+    result = rt_mq_send_wait(&(mq_cb->mq), (void *)msg_ptr, mq_cb->init_msg_size, timeout);
 
 
     if (RT_EOK == result)
     if (RT_EOK == result)
         return osOK;
         return osOK;
@@ -2144,6 +2169,12 @@ osStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *m
     {
     {
         return osErrorParameter;
         return osErrorParameter;
     }
     }
+
+    if(timeout == osWaitForever)
+    {
+        timeout = RT_WAITING_FOREVER;
+    }
+
     result = rt_mq_recv(&(mq_cb->mq), msg_ptr, mq_cb->init_msg_size, timeout);
     result = rt_mq_recv(&(mq_cb->mq), msg_ptr, mq_cb->init_msg_size, timeout);
 
 
     if (result > 0)
     if (result > 0)
@@ -2166,6 +2197,12 @@ osStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *m
     {
     {
         return osErrorParameter;
         return osErrorParameter;
     }
     }
+
+    if(timeout == osWaitForever)
+    {
+        timeout = RT_WAITING_FOREVER;
+    }
+
     result = rt_mq_recv(&(mq_cb->mq), msg_ptr, mq_cb->init_msg_size, timeout);
     result = rt_mq_recv(&(mq_cb->mq), msg_ptr, mq_cb->init_msg_size, timeout);
 
 
     if (RT_EOK == result)
     if (RT_EOK == result)