소스 검색

add:添加luat_rtos_get_ipsr函数

Dozingfiretruck 3 년 전
부모
커밋
19224a6171

+ 8 - 8
components/rtos/freertos/luat_common_freertos.c

@@ -2,18 +2,18 @@
 #include "luat_rtos.h"
 #include "luat_mcu.h"
 #include "luat_malloc.h"
-
 #include "common.h"
 #include "c_common.h"
 
+#if (defined(CONFIG_IDF_CMAKE))
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "freertos/queue.h"
-#include "freertos/semphr.h"
-
-#define LUAT_LOG_TAG "rtos"
-#include "luat_log.h"
-
+#else
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+#endif
 
 typedef struct
 {
@@ -106,7 +106,7 @@ int send_event_to_task(void *task_handle, OS_EVENT *event, uint32_t event_id, ui
 	}
 
 	BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-	if (xPortInIsrContext())
+	if (luat_rtos_get_ipsr())
 	{
 		result = xQueueSendToBackFromISR(handle->queue, &Event, &xHigherPriorityTaskWoken);
 		if (xHigherPriorityTaskWoken)
@@ -132,7 +132,7 @@ int get_event_from_task(void *task_handle, uint32_t target_event_id, OS_EVENT *e
 	{
 		return -1;
 	}
-	if (xPortInIsrContext())
+	if (luat_rtos_get_ipsr())
 	{
 		return -ERROR_PERMISSION_DENIED;
 	}

+ 5 - 4
components/rtos/freertos/luat_rtos_freertos_mutex.c

@@ -1,12 +1,13 @@
 #include "luat_base.h"
 #include "luat_rtos.h"
-#include "luat_malloc.h"
 
+#if (defined(CONFIG_IDF_CMAKE))
 #include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
 #include "freertos/semphr.h"
-#include "freertos/timers.h"
+#else
+#include "FreeRTOS.h"
+#include "semphr.h"
+#endif
 
 int luat_rtos_mutex_create(luat_rtos_mutex_t *mutex_handle)
 {

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

@@ -1,13 +1,13 @@
 #include "luat_base.h"
 #include "luat_rtos.h"
 
+#if (defined(CONFIG_IDF_CMAKE))
 #include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
 #include "freertos/queue.h"
-#include "freertos/semphr.h"
-
-#define LUAT_LOG_TAG "rtos"
-#include "luat_log.h"
+#else
+#include "FreeRTOS.h"
+#include "queue.h"
+#endif
 
 int luat_rtos_queue_create(luat_rtos_queue_t *queue_handle, uint32_t item_count, uint32_t item_size)
 {
@@ -26,7 +26,7 @@ int luat_rtos_queue_delete(luat_rtos_queue_t queue_handle)
 int luat_rtos_queue_send(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout)
 {
 	if (!queue_handle || !item) return -1;
-	if (xPortInIsrContext())
+	if (luat_rtos_get_ipsr())
 	{
 		BaseType_t pxHigherPriorityTaskWoken;
 		if (xQueueSendFromISR(queue_handle, item, &pxHigherPriorityTaskWoken) != pdPASS)
@@ -47,7 +47,7 @@ int luat_rtos_queue_recv(luat_rtos_queue_t queue_handle, void *item, uint32_t it
 	if (!queue_handle || !item)
 		return -1;
 	BaseType_t yield = pdFALSE;
-	if (xPortInIsrContext())
+	if (luat_rtos_get_ipsr())
 	{
 		if (xQueueReceiveFromISR(queue_handle, item, &yield) != pdPASS)
 			return -1;

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

@@ -1,13 +1,13 @@
 #include "luat_base.h"
 #include "luat_rtos.h"
-#include "luat_malloc.h"
 
+#if (defined(CONFIG_IDF_CMAKE))
 #include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
 #include "freertos/semphr.h"
-#include "freertos/timers.h"
-
+#else
+#include "FreeRTOS.h"
+#include "semphr.h"
+#endif
 
 int luat_rtos_semaphore_create(luat_rtos_semaphore_t *semaphore_handle, uint32_t init_count)
 {
@@ -49,7 +49,7 @@ int luat_rtos_semaphore_take(luat_rtos_semaphore_t semaphore_handle, uint32_t ti
 int luat_rtos_semaphore_release(luat_rtos_semaphore_t semaphore_handle)
 {
 	if (!semaphore_handle) return -1;
-	if (xPortInIsrContext())
+	if (luat_rtos_get_ipsr())
 	{
 		BaseType_t yield = pdFALSE;
 		if (pdTRUE == xSemaphoreGiveFromISR(semaphore_handle, &yield))

+ 6 - 3
components/rtos/freertos/luat_rtos_freertos_task.c

@@ -1,13 +1,16 @@
 #include "luat_base.h"
 #include "luat_rtos.h"
-
 #include "common.h"
 
+#if (defined(CONFIG_IDF_CMAKE))
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "freertos/queue.h"
-#include "freertos/semphr.h"
-#include "freertos/timers.h"
+#else
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+#endif
 
 typedef struct
 {

+ 10 - 8
components/rtos/freertos/luat_rtos_freertos_timer.c

@@ -2,11 +2,13 @@
 #include "luat_rtos.h"
 #include "luat_malloc.h"
 
+#if (defined(CONFIG_IDF_CMAKE))
 #include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
-#include "freertos/semphr.h"
 #include "freertos/timers.h"
+#else
+#include "FreeRTOS.h"
+#include "timers.h"
+#endif
 
 typedef struct
 {
@@ -55,7 +57,7 @@ int luat_start_rtos_timer(void *timer, uint32_t ms, uint8_t is_repeat)
 
     if (xTimerIsTimerActive (htimer->timer))
 	{
-        if (xPortInIsrContext())
+        if (luat_rtos_get_ipsr())
         {
     		BaseType_t pxHigherPriorityTaskWoken;
     		if ((xTimerStopFromISR(htimer->timer, &pxHigherPriorityTaskWoken) != pdPASS))
@@ -70,7 +72,7 @@ int luat_start_rtos_timer(void *timer, uint32_t ms, uint8_t is_repeat)
         }
     }
     htimer->is_repeat = is_repeat;
-    if (xPortInIsrContext())
+    if (luat_rtos_get_ipsr())
     {
 		BaseType_t pxHigherPriorityTaskWoken;
 		if ((xTimerChangePeriodFromISR(htimer->timer, ms, &pxHigherPriorityTaskWoken) != pdPASS))
@@ -91,7 +93,7 @@ void luat_stop_rtos_timer(void *timer)
 	luat_rtos_user_timer_t *htimer = (luat_rtos_user_timer_t *)timer;
     if (xTimerIsTimerActive (htimer->timer))
 	{
-        if (xPortInIsrContext())
+        if (luat_rtos_get_ipsr())
         {
     		BaseType_t pxHigherPriorityTaskWoken;
     		if ((xTimerStopFromISR(htimer->timer, &pxHigherPriorityTaskWoken) != pdPASS))
@@ -134,7 +136,7 @@ int luat_rtos_timer_start(luat_rtos_timer_t timer_handle, uint32_t timeout, uint
 
     if (xTimerIsTimerActive (htimer->timer))
 	{
-        if (xPortInIsrContext())
+        if (luat_rtos_get_ipsr())
         {
     		BaseType_t pxHigherPriorityTaskWoken;
     		if ((xTimerStopFromISR(htimer->timer, &pxHigherPriorityTaskWoken) != pdPASS))
@@ -151,7 +153,7 @@ int luat_rtos_timer_start(luat_rtos_timer_t timer_handle, uint32_t timeout, uint
     htimer->is_repeat = repeat;
     htimer->call_back = callback_fun;
     htimer->user_param = user_param;
-    if (xPortInIsrContext())
+    if (luat_rtos_get_ipsr())
     {
 		BaseType_t pxHigherPriorityTaskWoken;
 		if ((xTimerChangePeriodFromISR(htimer->timer, timeout, &pxHigherPriorityTaskWoken) != pdPASS))

+ 3 - 0
luat/include/luat_rtos.h

@@ -359,6 +359,9 @@ uint32_t luat_rtos_entry_critical(void);
  */
 void luat_rtos_exit_critical(uint32_t critical);
 /*------------------------------------------------ critical   end----------------------------------------------- */
+
+uint32_t luat_rtos_get_ipsr(void);
+
 /** @}*/
 /** @}*/
 #endif