mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-04-29 12:05:12 +00:00
uart buffer size
This commit is contained in:
@@ -39,21 +39,19 @@ uint32_t inverse_mask = 0;
|
|||||||
// receive task, wait for break and call incoming_telegram
|
// receive task, wait for break and call incoming_telegram
|
||||||
void EMSuart::uart_event_task(void * pvParameters) {
|
void EMSuart::uart_event_task(void * pvParameters) {
|
||||||
uart_event_t event;
|
uart_event_t event;
|
||||||
uint8_t telegram[EMS_MAXBUFFERSIZE];
|
uint8_t telegram[UART_FIFO_LEN + 1]; // same size as in driver_install
|
||||||
uint8_t length = 0;
|
uint8_t length = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
//Waiting for UART event.
|
// Waiting for UART event.
|
||||||
if (xQueueReceive(uart_queue, (void *)&event, portMAX_DELAY)) {
|
if (xQueueReceive(uart_queue, (void *)&event, portMAX_DELAY)) {
|
||||||
if (event.type == UART_DATA) {
|
if (event.type == UART_DATA) {
|
||||||
length += event.size;
|
length += event.size;
|
||||||
} else if (event.type == UART_BREAK) {
|
} else if (event.type == UART_BREAK) {
|
||||||
if (length == 2 || (length >= 6 && length <= EMS_MAXBUFFERSIZE)) {
|
// read buffer up to break
|
||||||
uart_read_bytes(EMSUART_NUM, telegram, length, portMAX_DELAY);
|
uart_read_bytes(EMSUART_NUM, telegram, length, portMAX_DELAY);
|
||||||
|
if (length == 2 || (length >= 6 && length <= EMS_MAXBUFFERSIZE)) {
|
||||||
EMSESP::incoming_telegram(telegram, (uint8_t)(length - 1));
|
EMSESP::incoming_telegram(telegram, (uint8_t)(length - 1));
|
||||||
} else { // flush buffer up to break
|
|
||||||
uint8_t buf[UART_FIFO_LEN];
|
|
||||||
uart_read_bytes(EMSUART_NUM, buf, length, portMAX_DELAY);
|
|
||||||
}
|
}
|
||||||
length = 0;
|
length = 0;
|
||||||
} else if (event.type == UART_BUFFER_FULL) {
|
} else if (event.type == UART_BUFFER_FULL) {
|
||||||
@@ -68,14 +66,6 @@ void EMSuart::uart_event_task(void * pvParameters) {
|
|||||||
// initialize UART driver
|
// initialize UART driver
|
||||||
void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio) {
|
void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio) {
|
||||||
if (tx_mode_ == EMS_TXMODE_INIT) {
|
if (tx_mode_ == EMS_TXMODE_INIT) {
|
||||||
#if CONFIG_IDF_TARGET_ESP32C6
|
|
||||||
uart_config_t uart_config = {.baud_rate = EMSUART_BAUD,
|
|
||||||
.data_bits = UART_DATA_8_BITS,
|
|
||||||
.parity = UART_PARITY_DISABLE,
|
|
||||||
.stop_bits = UART_STOP_BITS_1,
|
|
||||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
|
||||||
.rx_flow_ctrl_thresh = 0};
|
|
||||||
#else
|
|
||||||
uart_config_t uart_config = {.baud_rate = EMSUART_BAUD,
|
uart_config_t uart_config = {.baud_rate = EMSUART_BAUD,
|
||||||
.data_bits = UART_DATA_8_BITS,
|
.data_bits = UART_DATA_8_BITS,
|
||||||
.parity = UART_PARITY_DISABLE,
|
.parity = UART_PARITY_DISABLE,
|
||||||
@@ -85,10 +75,9 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
|
|||||||
.source_clk = UART_SCLK_APB
|
.source_clk = UART_SCLK_APB
|
||||||
#if ESP_ARDUINO_VERSION_MAJOR >= 3
|
#if ESP_ARDUINO_VERSION_MAJOR >= 3
|
||||||
,
|
,
|
||||||
.flags = {0, 0}
|
.flags = {0}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
#if defined(EMSUART_RX_INVERT)
|
#if defined(EMSUART_RX_INVERT)
|
||||||
inverse_mask |= UART_SIGNAL_RXD_INV;
|
inverse_mask |= UART_SIGNAL_RXD_INV;
|
||||||
#endif
|
#endif
|
||||||
@@ -98,7 +87,7 @@ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t
|
|||||||
uart_param_config(EMSUART_NUM, &uart_config);
|
uart_param_config(EMSUART_NUM, &uart_config);
|
||||||
uart_set_pin(EMSUART_NUM, tx_gpio, rx_gpio, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
uart_set_pin(EMSUART_NUM, tx_gpio, rx_gpio, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||||
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
uart_set_line_inverse(EMSUART_NUM, inverse_mask);
|
||||||
uart_driver_install(EMSUART_NUM, UART_FIFO_LEN + 1, 0, (EMS_MAXBUFFERSIZE + 1) * 2, &uart_queue, 0); // buffer must be > fifo
|
uart_driver_install(EMSUART_NUM, UART_FIFO_LEN + 1, 0, UART_FIFO_LEN + 3, &uart_queue, 0); // buffer must be > fifo, queue can hold data+break+overflow message
|
||||||
uart_set_rx_full_threshold(EMSUART_NUM, 1);
|
uart_set_rx_full_threshold(EMSUART_NUM, 1);
|
||||||
uart_set_rx_timeout(EMSUART_NUM, 0); // disable
|
uart_set_rx_timeout(EMSUART_NUM, 0); // disable
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user