Harden cleanup and reduce internal RAM use. Phase 8C nearly validated
and somewhat stable.
This commit is contained in:
+31
-4
@@ -7,6 +7,7 @@
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/uart.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
@@ -17,8 +18,10 @@
|
||||
|
||||
#define SERIAL_UART_RX_RING_SIZE 8192
|
||||
#define SERIAL_UART_EVENT_QUEUE_SIZE 64
|
||||
#define SERIAL_RX_STREAM_SIZE 16384
|
||||
#define SERIAL_TX_STREAM_SIZE 8192
|
||||
#define SERIAL_RX_STREAM_SIZE 16384U
|
||||
#define SERIAL_TX_STREAM_SIZE 8192U
|
||||
#define SERIAL_RX_STREAM_STORAGE_SIZE (SERIAL_RX_STREAM_SIZE + 1U)
|
||||
#define SERIAL_TX_STREAM_STORAGE_SIZE (SERIAL_TX_STREAM_SIZE + 1U)
|
||||
#define SERIAL_IO_CHUNK_SIZE 256
|
||||
#define SERIAL_TASK_STACK_SIZE 4096
|
||||
#define SERIAL_TASK_PRIORITY 10
|
||||
@@ -32,6 +35,10 @@ static SemaphoreHandle_t s_state_mutex;
|
||||
static SemaphoreHandle_t s_task_stopped;
|
||||
static StreamBufferHandle_t s_rx_stream;
|
||||
static StreamBufferHandle_t s_tx_stream;
|
||||
static StaticStreamBuffer_t s_rx_stream_control;
|
||||
static StaticStreamBuffer_t s_tx_stream_control;
|
||||
static uint8_t *s_rx_stream_storage;
|
||||
static uint8_t *s_tx_stream_storage;
|
||||
static QueueHandle_t s_uart_event_queue;
|
||||
static TaskHandle_t s_event_task;
|
||||
static portMUX_TYPE s_counter_lock = portMUX_INITIALIZER_UNLOCKED;
|
||||
@@ -472,8 +479,24 @@ esp_err_t serial_service_init(const serial_config_t *initial_config)
|
||||
|
||||
s_state_mutex = xSemaphoreCreateMutex();
|
||||
s_task_stopped = xSemaphoreCreateBinary();
|
||||
s_rx_stream = xStreamBufferCreate(SERIAL_RX_STREAM_SIZE, 1);
|
||||
s_tx_stream = xStreamBufferCreate(SERIAL_TX_STREAM_SIZE, 1);
|
||||
s_rx_stream_storage = heap_caps_calloc_prefer(
|
||||
1U, SERIAL_RX_STREAM_STORAGE_SIZE, 2,
|
||||
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT,
|
||||
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
s_tx_stream_storage = heap_caps_calloc_prefer(
|
||||
1U, SERIAL_TX_STREAM_STORAGE_SIZE, 2,
|
||||
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT,
|
||||
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
if (s_rx_stream_storage != NULL) {
|
||||
s_rx_stream = xStreamBufferCreateStatic(
|
||||
SERIAL_RX_STREAM_STORAGE_SIZE, 1U, s_rx_stream_storage,
|
||||
&s_rx_stream_control);
|
||||
}
|
||||
if (s_tx_stream_storage != NULL) {
|
||||
s_tx_stream = xStreamBufferCreateStatic(
|
||||
SERIAL_TX_STREAM_STORAGE_SIZE, 1U, s_tx_stream_storage,
|
||||
&s_tx_stream_control);
|
||||
}
|
||||
if (s_state_mutex == NULL || s_task_stopped == NULL ||
|
||||
s_rx_stream == NULL || s_tx_stream == NULL) {
|
||||
if (s_state_mutex != NULL) {
|
||||
@@ -488,10 +511,14 @@ esp_err_t serial_service_init(const serial_config_t *initial_config)
|
||||
if (s_tx_stream != NULL) {
|
||||
vStreamBufferDelete(s_tx_stream);
|
||||
}
|
||||
heap_caps_free(s_rx_stream_storage);
|
||||
heap_caps_free(s_tx_stream_storage);
|
||||
s_state_mutex = NULL;
|
||||
s_task_stopped = NULL;
|
||||
s_rx_stream = NULL;
|
||||
s_tx_stream = NULL;
|
||||
s_rx_stream_storage = NULL;
|
||||
s_tx_stream_storage = NULL;
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user