Просмотр исходного кода

change: 在不影响移芯平台的条件下, 让luat_rtos.h兼容tick周期不是1000HZ的平台

Wendal Chen 1 год назад
Родитель
Сommit
f004c8c465

+ 20 - 0
components/rtos/freertos/luat_common_freertos.c

@@ -44,6 +44,26 @@ uint64_t GetSysTickMS(void)
 }
 #endif
 
+#if defined(CHIP_EC618) || defined(CHIP_EC716) || defined(CHIP_EC718)
+#else
+int luat_rtos_ms2tick(int ms) {
+	if (configTICK_RATE_HZ == 1000) {
+		return ms;
+	}
+	if (ms == LUAT_WAIT_FOREVER) {
+		return LUAT_WAIT_FOREVER;
+	}
+    if (ms <= 0) {
+        return 0;
+	}
+    if ((configTICK_RATE_HZ) == 500) {
+        return (ms + 1) / 2;
+	}
+    return ms;
+}
+#endif
+
+
 void *create_event_task(TaskFun_t task_fun, void *param, uint32_t stack_bytes, uint8_t priority, uint16_t event_max_cnt, const char *task_name)
 {
 	priority = configMAX_PRIORITIES * priority / 100;

+ 1 - 1
components/rtos/freertos/luat_rtos_freertos_mutex.c

@@ -31,7 +31,7 @@ int luat_rtos_mutex_create(luat_rtos_mutex_t *mutex_handle)
 int luat_rtos_mutex_lock(luat_rtos_mutex_t mutex_handle, uint32_t timeout)
 {
 	if (!mutex_handle) return -1;
-	if (pdFALSE == xSemaphoreTakeRecursive(mutex_handle, timeout))
+	if (pdFALSE == xSemaphoreTakeRecursive(mutex_handle, luat_rtos_ms2tick(timeout)))
 		return -1;
 	return 0;
 }

+ 2 - 2
components/rtos/freertos/luat_rtos_freertos_queue.c

@@ -44,7 +44,7 @@ int luat_rtos_queue_send(luat_rtos_queue_t queue_handle, void *item, uint32_t it
 	}
 	else
 	{
-		if (xQueueSend(queue_handle, item, timeout) != pdPASS)
+		if (xQueueSend(queue_handle, item, luat_rtos_ms2tick(timeout)) != pdPASS)
 			return -1;
 	}
 	return 0;
@@ -64,7 +64,7 @@ int luat_rtos_queue_recv(luat_rtos_queue_t queue_handle, void *item, uint32_t it
 	}
 	else
 	{
-		if (xQueueReceive(queue_handle, item, timeout) != pdPASS)
+		if (xQueueReceive(queue_handle, item, luat_rtos_ms2tick(timeout)) != pdPASS)
 			return -1;
 	}
 	return 0;

+ 1 - 1
components/rtos/freertos/luat_rtos_freertos_semaphore.c

@@ -49,7 +49,7 @@ int luat_rtos_semaphore_delete(luat_rtos_semaphore_t semaphore_handle)
 int luat_rtos_semaphore_take(luat_rtos_semaphore_t semaphore_handle, uint32_t timeout)
 {
 	if (!semaphore_handle) return -1;
-	if (pdTRUE == xSemaphoreTake(semaphore_handle, timeout))
+	if (pdTRUE == xSemaphoreTake(semaphore_handle, luat_rtos_ms2tick(timeout)))
 		return 0;
 	return -1;
 }

+ 3 - 3
components/rtos/freertos/luat_rtos_freertos_timer.c

@@ -82,7 +82,7 @@ int luat_start_rtos_timer(void *timer, uint32_t ms, uint8_t is_repeat)
     if (luat_rtos_get_ipsr())
     {
 		BaseType_t pxHigherPriorityTaskWoken;
-		if ((xTimerChangePeriodFromISR(htimer->timer, ms, &pxHigherPriorityTaskWoken) != pdPASS))
+		if ((xTimerChangePeriodFromISR(htimer->timer, luat_rtos_ms2tick(ms), &pxHigherPriorityTaskWoken) != pdPASS))
 			return -1;
 		portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
 		return 0;
@@ -163,14 +163,14 @@ int luat_rtos_timer_start(luat_rtos_timer_t timer_handle, uint32_t timeout, uint
     if (luat_rtos_get_ipsr())
     {
 		BaseType_t pxHigherPriorityTaskWoken;
-		if ((xTimerChangePeriodFromISR(htimer->timer, timeout, &pxHigherPriorityTaskWoken) != pdPASS))
+		if ((xTimerChangePeriodFromISR(htimer->timer, luat_rtos_ms2tick(timeout), &pxHigherPriorityTaskWoken) != pdPASS))
 			return -1;
 		portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
 		return 0;
     }
     else
     {
-		if (xTimerChangePeriod(htimer->timer, timeout, 0) != pdPASS)
+		if (xTimerChangePeriod(htimer->timer, luat_rtos_ms2tick(timeout), 0) != pdPASS)
 			return -1;
     }
 	return 0;

+ 6 - 0
luat/include/luat_rtos.h

@@ -492,6 +492,12 @@ void luat_rtos_exit_critical(uint32_t critical);
  * @return uint32_t 0不是中断,1是中断
  */
 uint32_t luat_rtos_get_ipsr(void);
+
+#if defined(CHIP_EC618) || defined(CHIP_EC716) || defined(CHIP_EC718)
+#define luat_rtos_ms2tick(ms) (ms)
+#else
+int luat_rtos_ms2tick(int ms);
+#endif
 /*------------------------------------------------ critical   end----------------------------------------------- */
 /** @}*/
 /** @}*/