From 0c47b42a014e66458bd0848bb19de069e6933f1b Mon Sep 17 00:00:00 2001 From: lyon1998 Date: Tue, 2 May 2023 22:16:41 +0800 Subject: [PATCH 1/2] add_files --- package/ESP32/pika_hal_ESP32_UART.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/package/ESP32/pika_hal_ESP32_UART.c b/package/ESP32/pika_hal_ESP32_UART.c index 47ad83d09..e7b54b685 100644 --- a/package/ESP32/pika_hal_ESP32_UART.c +++ b/package/ESP32/pika_hal_ESP32_UART.c @@ -3,7 +3,10 @@ #include "dataStrs.h" #include "driver/uart.h" #include "pika_hal_ESP32_common.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +extern volatile PikaMemInfo g_PikaMemInfo; typedef struct platform_data_UART { uart_port_t uartPort; uart_config_t uart_conf; @@ -12,8 +15,11 @@ typedef struct platform_data_UART { gpio_num_t rx_port; gpio_num_t rts_port; gpio_num_t cts_port; + PIKA_BOOL event_thread_started; } platform_data_UART; +static SemaphoreHandle_t g_event_lock = NULL; + int pika_hal_platform_UART_open(pika_dev* dev, char* name) { /* UARTX */ if (name[0] != 'U' || name[1] != 'A' || name[2] != 'R' || name[3] != 'T') { @@ -79,7 +85,10 @@ static void uart_event_task(void* pvParameters) { data events than other types of events. If we take too much time on data event, the queue might be full.*/ case UART_DATA: + pika_assert(g_event_lock != NULL); + xSemaphoreTake(g_event_lock, portMAX_DELAY); cfg->event_callback(dev, event.type); + xSemaphoreGive(g_event_lock); break; // Others default: @@ -87,6 +96,7 @@ static void uart_event_task(void* pvParameters) { } } } + g_PikaMemInfo.heapUsed -= PIKA_THREAD_STACK_SIZE; vTaskDelete(NULL); } @@ -220,6 +230,11 @@ int pika_hal_platform_UART_ioctl_config(pika_dev* dev, uart->cts_port = UART_PIN_NO_CHANGE; } + if (dev->is_enabled){ + pika_debug("UART%d: uart is enabled, reconfig\r\n", uart->uartPort); + uart_param_config(uart->uartPort, &uart->uart_conf); + } + /* support event callback */ if (dev->is_enabled == PIKA_TRUE && NULL != cfg->event_callback && PIKA_HAL_EVENT_CALLBACK_ENA_ENABLE == cfg->event_callback_ena) { @@ -241,8 +256,16 @@ int pika_hal_platform_UART_ioctl_config(pika_dev* dev, cfg->event_callback_filter); return -1; } - /* start irq task thread */ - xTaskCreate(uart_event_task, "uart_event_task", 8192, dev, 12, NULL); + if (uart->event_thread_started == PIKA_FALSE){ + /* start irq task thread */ + pika_debug("Starting uart event task:%p\r\n", dev); + if (NULL == g_event_lock){ + g_event_lock = xSemaphoreCreateMutex(); + } + g_PikaMemInfo.heapUsed += PIKA_THREAD_STACK_SIZE; + xTaskCreate(uart_event_task, "uart_event_task", PIKA_THREAD_STACK_SIZE, dev, 12, NULL); + uart->event_thread_started = PIKA_TRUE; + } } return 0; } From 040d1c0efc3400ff8791f4d3f42f75f111867f69 Mon Sep 17 00:00:00 2001 From: lyon1998 Date: Tue, 2 May 2023 22:16:41 +0800 Subject: [PATCH 2/2] update_toml --- packages.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages.toml b/packages.toml index b79b35a90..7f4ec17b5 100644 --- a/packages.toml +++ b/packages.toml @@ -399,7 +399,8 @@ releases = [ "v0.1.0 ee7e38e9422970bba86f5cd7774db8654edd38dc", "v0.2.0 93591e92863f5e192dc89aed6666fd9dab4f7a82", "v0.3.0 8202a1ab52f15f70cd93abb0d409aa03da8170b0", - "v0.3.1 918464a8567f84c87ddda68de99f3d032ee812e0" + "v0.3.1 918464a8567f84c87ddda68de99f3d032ee812e0", + "v0.4.0 0c47b42a014e66458bd0848bb19de069e6933f1b" ] [[packages]]