Skip to content

Commit 3d86dd0

Browse files
committed
Merge branch 'fix/slip_frame' into 'main'
fix SLIP framing See merge request espressif/esp-zigbee-sdk!211
2 parents 005fe00 + 157c694 commit 3d86dd0

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

components/esp-zigbee-ncp/src/esp_ncp_bus.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "esp_ncp_bus.h"
2222
#include "esp_ncp_frame.h"
2323
#include "esp_ncp_main.h"
24+
#include "slip.h"
2425

2526
static const char* TAG = "ESP_NCP_BUS";
2627

@@ -56,7 +57,12 @@ static esp_err_t ncp_bus_init_hdl(uint8_t transport)
5657
uart_driver_install(CONFIG_NCP_BUS_UART_NUM, NCP_BUS_BUF_SIZE * 2, NCP_BUS_BUF_SIZE * 2, 20, &uart0_queue, 0);
5758
uart_param_config(CONFIG_NCP_BUS_UART_NUM, &uart_config);
5859
uart_set_pin(CONFIG_NCP_BUS_UART_NUM, CONFIG_NCP_BUS_UART_TX_PIN, CONFIG_NCP_BUS_UART_RX_PIN, CONFIG_NCP_BUS_UART_RTS_PIN, CONFIG_NCP_BUS_UART_CTS_PIN);
59-
60+
// configure a SLIP framing detector
61+
esp_err_t err = uart_enable_pattern_det_baud_intr(CONFIG_NCP_BUS_UART_NUM, SLIP_END, 1, 1, 0, 0);
62+
if (err != ESP_OK) {
63+
ESP_LOGE(TAG, "uart_enable_pattern_det_baud_intr failed");
64+
return err;
65+
}
6066
return ESP_OK;
6167
}
6268

@@ -76,9 +82,7 @@ static void esp_ncp_bus_task(void *pvParameter)
7682
bzero(dtmp, NCP_BUS_BUF_SIZE);
7783
switch(event.type) {
7884
case UART_DATA:
79-
ncp_event.size = uart_read_bytes(CONFIG_NCP_BUS_UART_NUM, dtmp, event.size, portMAX_DELAY);
80-
xStreamBufferSend(bus->output_buf, dtmp, ncp_event.size, 0);
81-
esp_ncp_send_event(&ncp_event);
85+
// pass, handled by the pattern detector
8286
break;
8387
case UART_FIFO_OVF:
8488
ESP_LOGI(TAG, "hw fifo overflow");
@@ -90,6 +94,20 @@ static void esp_ncp_bus_task(void *pvParameter)
9094
uart_flush_input(CONFIG_NCP_BUS_UART_NUM);
9195
xQueueReset(uart0_queue);
9296
break;
97+
case UART_PATTERN_DET:
98+
ESP_LOGI(TAG, "uart pattern detection");
99+
int pos;
100+
do {
101+
pos = uart_pattern_pop_pos(CONFIG_NCP_BUS_UART_NUM);
102+
if (pos > 0) {
103+
// here we have the position of an END marker at the end (>0) of a frame
104+
ncp_event.size = uart_read_bytes(CONFIG_NCP_BUS_UART_NUM, dtmp, pos + 1, portMAX_DELAY);
105+
xStreamBufferSend(bus->output_buf, dtmp, ncp_event.size, 0);
106+
esp_ncp_send_event(&ncp_event);
107+
break; // one frame at a time
108+
}
109+
} while (pos >= 0);
110+
break;
93111
default:
94112
ESP_LOGI(TAG, "uart event type: %d", event.type);
95113
break;

0 commit comments

Comments
 (0)