uart: multichip support

This commit is contained in:
chenjianqiang
2019-06-14 11:01:30 +08:00
committed by Michael (XIAO Xufeng)
parent b2ae2601fd
commit cf2ba210ef
10 changed files with 101 additions and 28 deletions

View File

@@ -28,7 +28,7 @@
#include "esp32/rom/uart.h"
// TODO: make the number of UARTs chip dependent
#define UART_NUM 3
#define UART_NUM SOC_UART_NUM
// Token signifying that no character is available
#define NONE -1
@@ -47,12 +47,27 @@ static void uart_tx_char_via_driver(int fd, int c);
static int uart_rx_char_via_driver(int fd);
// Pointers to UART peripherals
static uart_dev_t* s_uarts[UART_NUM] = {&UART0, &UART1, &UART2};
static uart_dev_t* s_uarts[UART_NUM] = {
&UART0,
&UART1,
#if UART_NUM > 2
&UART2
#endif
};
// One-character buffer used for newline conversion code, per UART
static int s_peek_char[UART_NUM] = {
NONE,
NONE,
#if UART_NUM > 2
NONE
#endif
};
// per-UART locks, lazily initialized
static _lock_t s_uart_read_locks[UART_NUM];
static _lock_t s_uart_write_locks[UART_NUM];
// One-character buffer used for newline conversion code, per UART
static int s_peek_char[UART_NUM] = { NONE, NONE, NONE };
// Per-UART non-blocking flag. Note: default implementation does not honor this
// flag, all reads are non-blocking. This option becomes effective if UART
// driver is used.
@@ -94,12 +109,20 @@ static void uart_end_select();
// Functions used to write bytes to UART. Default to "basic" functions.
static tx_func_t s_uart_tx_func[UART_NUM] = {
&uart_tx_char, &uart_tx_char, &uart_tx_char
&uart_tx_char,
&uart_tx_char,
#if UART_NUM > 2
&uart_tx_char
#endif
};
// Functions used to read bytes from UART. Default to "basic" functions.
static rx_func_t s_uart_rx_func[UART_NUM] = {
&uart_rx_char, &uart_rx_char, &uart_rx_char
&uart_rx_char,
&uart_rx_char,
#if UART_NUM > 2
&uart_rx_char
#endif
};