mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 23:28:29 +08:00
risc-v/esp32-c3: complements serial driver
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
85a93be5d7
commit
c885e718a7
@@ -225,4 +225,33 @@ config ESP32C3_RWDT
|
||||
|
||||
endmenu
|
||||
|
||||
menu "UART configuration"
|
||||
depends on ESP32C3_UART
|
||||
|
||||
if ESP32C3_UART0
|
||||
|
||||
config ESP32C3_UART0_TXPIN
|
||||
int "UART0 TX Pin"
|
||||
default 21
|
||||
|
||||
config ESP32C3_UART0_RXPIN
|
||||
int "UART0 RX Pin"
|
||||
default 20
|
||||
|
||||
endif # ESP32C3_UART0
|
||||
|
||||
if ESP32C3_UART1
|
||||
|
||||
config ESP32C3_UART1_TXPIN
|
||||
int "UART1 TX Pin"
|
||||
default 18
|
||||
|
||||
config ESP32C3_UART1_RXPIN
|
||||
int "UART1 RX Pin"
|
||||
default 19
|
||||
|
||||
endif # ESP32C3_UART1
|
||||
|
||||
endmenu
|
||||
|
||||
endif # ARCH_CHIP_ESP32C3
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define MATRIX_DETACH_OUT_SIG 0x100 /* Detach an OUTPUT signal */
|
||||
#define MATRIX_DETACH_IN_LOW_PIN 0x30 /* Detach non-inverted INPUT signal */
|
||||
#define MATRIX_DETACH_IN_LOW_HIGH 0x38 /* Detach inverted INPUT signal */
|
||||
|
||||
/* Bit-encoded input to esp32c3_configgpio() ********************************/
|
||||
|
||||
/* Encoded pin attributes used with esp32c3_configgpio()
|
||||
@@ -149,8 +153,8 @@ bool esp32c3_gpioread(int pin);
|
||||
* Description:
|
||||
* Set gpio input to a signal
|
||||
* NOTE: one gpio can input to several signals
|
||||
* If gpio == 0x30, cancel input to the signal, input 0 to signal
|
||||
* If gpio == 0x38, cancel input to the signal, input 1 to signal
|
||||
* If signal_idx == 0x30, cancel input to the signal, input 0 to signal
|
||||
* If signal_idx == 0x38, cancel input to the signal, input 1 to signal
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,9 +37,13 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "hardware/esp32c3_uart.h"
|
||||
#include "chip.h"
|
||||
|
||||
#include "hardware/esp32c3_uart.h"
|
||||
#include "hardware/esp32c3_gpio_sigmap.h"
|
||||
|
||||
#include "esp32c3_irq.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@@ -68,8 +72,8 @@ enum uart_data_length
|
||||
|
||||
enum uart_stop_length
|
||||
{
|
||||
UART_STOP_BITS_1 = 0x1, /* stop bit: 1 bit */
|
||||
UART_STOP_BITS_2 = 0x3, /* stop bit: 2bits */
|
||||
UART_STOP_BITS_1 = 0x1, /* Stop bit: 1 bit */
|
||||
UART_STOP_BITS_2 = 0x3, /* Stop bit: 2 bits */
|
||||
};
|
||||
|
||||
/* Default FIFOs size */
|
||||
@@ -83,7 +87,6 @@ enum uart_stop_length
|
||||
|
||||
struct esp32c3_uart_s
|
||||
{
|
||||
uint32_t base; /* Base address of UART registers */
|
||||
uint8_t periph; /* UART peripheral ID */
|
||||
int cpuint; /* CPU interrupt assigned to this UART */
|
||||
uint8_t id; /* UART ID */
|
||||
@@ -93,6 +96,10 @@ struct esp32c3_uart_s
|
||||
uint8_t parity; /* 0=no parity, 1=odd parity, 2=even parity */
|
||||
uint8_t stop_b2; /* Use 2 stop bits? 0 no, others yes */
|
||||
uint8_t int_pri; /* UART Interrupt Priority */
|
||||
uint8_t txpin; /* TX pin */
|
||||
uint8_t txsig; /* TX signal */
|
||||
uint8_t rxpin; /* RX pin */
|
||||
uint8_t rxsig; /* RX signal */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@@ -101,101 +108,316 @@ struct esp32c3_uart_s
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_reset_core
|
||||
* Reset both TX and RX core
|
||||
*
|
||||
* Description:
|
||||
* Reset both TX and RX cores.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_reset_core(const struct esp32c3_uart_s *conf);
|
||||
void esp32c3_lowputc_reset_cores(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_rst_tx
|
||||
*
|
||||
* Description:
|
||||
* Reset TX core.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_rst_tx(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_rst_rx
|
||||
*
|
||||
* Description:
|
||||
* Reset RX core.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_rst_rx(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_enable_sclk
|
||||
* Enable clock for whole core
|
||||
*
|
||||
* Description:
|
||||
* Enable clock for whole core.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_enable_sclk(const struct esp32c3_uart_s *conf);
|
||||
void esp32c3_lowputc_enable_sclk(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_disable_sclk
|
||||
* Disable clock for whole core
|
||||
*
|
||||
* Description:
|
||||
* Disable clock for whole core.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_disable_sclk(const struct esp32c3_uart_s *conf);
|
||||
void esp32c3_lowputc_disable_sclk(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_set_sclk
|
||||
* Set a source clock for UART
|
||||
* APB_CLK = 1 80 MHz
|
||||
* CLK_8 = 2 8 MHz
|
||||
* XTAL_CLK = 3
|
||||
*
|
||||
* Description:
|
||||
* Set a source clock for UART.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
* source - APB_CLK = 1 80 MHz
|
||||
* CLK_8 = 2 8 MHz
|
||||
* XTAL_CLK = 3
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_set_sclk(const struct esp32c3_uart_s *conf, enum
|
||||
uart_sclk source);
|
||||
void esp32c3_lowputc_set_sclk(const struct esp32c3_uart_s *priv,
|
||||
enum uart_sclk source);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_get_sclk
|
||||
* Get the source clock for UART
|
||||
*
|
||||
* Description:
|
||||
* Get the source clock for UART.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
* Returned Value:
|
||||
* The frequency of the clock in Hz.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t esp32c3_lowputc_get_sclk(const struct esp32c3_uart_s *conf);
|
||||
uint32_t esp32c3_lowputc_get_sclk(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_baud
|
||||
* Set the baud rate
|
||||
*
|
||||
* Description:
|
||||
* Set the baud rate according to the value in the private driver
|
||||
* struct.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_baud(const struct esp32c3_uart_s * conf);
|
||||
void esp32c3_lowputc_baud(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_normal_mode
|
||||
* Set the UART to operate in normal mode
|
||||
*
|
||||
* Description:
|
||||
* Set the UART to operate in normal mode, i.e., disable the RS485 mode and
|
||||
* IRDA mode.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_normal_mode(const struct esp32c3_uart_s * conf);
|
||||
void esp32c3_lowputc_normal_mode(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_parity
|
||||
* Set the parity
|
||||
*
|
||||
* Description:
|
||||
* Set the parity, according to the value in the private driver
|
||||
* struct.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_parity(const struct esp32c3_uart_s * conf);
|
||||
void esp32c3_lowputc_parity(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_data_length
|
||||
* Set the data length
|
||||
*
|
||||
* Description:
|
||||
* Set the data bits length, according to the value in the private driver
|
||||
* struct.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp32c3_lowputc_data_length(const struct esp32c3_uart_s * conf);
|
||||
int esp32c3_lowputc_data_length(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_stop_length
|
||||
* Set the stop length
|
||||
*
|
||||
* Description:
|
||||
* Set the stop bits length, according to the value in the private driver
|
||||
* struct.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_stop_length(const struct esp32c3_uart_s * conf);
|
||||
void esp32c3_lowputc_stop_length(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_set_tx_idle_time
|
||||
* Set the idle time between transfers
|
||||
*
|
||||
* Description:
|
||||
* Set the idle time between transfers.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
* time - Desired time interval between the transfers.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_set_tx_idle_time(const struct esp32c3_uart_s *
|
||||
conf, uint32_t time);
|
||||
void esp32c3_lowputc_set_tx_idle_time(const struct esp32c3_uart_s *priv,
|
||||
uint32_t time);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_send_byte
|
||||
* Send one byte
|
||||
*
|
||||
* Description:
|
||||
* Send one byte.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
* byte - Byte to be sent.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_send_byte(const struct esp32c3_uart_s * conf,
|
||||
void esp32c3_lowputc_send_byte(const struct esp32c3_uart_s *priv,
|
||||
char byte);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_is_tx_fifo_full
|
||||
* Send one byte
|
||||
*
|
||||
* Description:
|
||||
* Verify if TX FIFO is full.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
* Returned Value:
|
||||
* True if it is full, otherwise false.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool esp32c3_lowputc_is_tx_fifo_full(const struct esp32c3_uart_s *
|
||||
conf);
|
||||
bool esp32c3_lowputc_is_tx_fifo_full(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_rst_peripheral
|
||||
*
|
||||
* Description:
|
||||
* Reset the UART peripheral by using System reg.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_rst_peripheral(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_rst_txfifo
|
||||
*
|
||||
* Description:
|
||||
* Reset TX FIFO.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_rst_txfifo(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_rst_rxfifo
|
||||
*
|
||||
* Description:
|
||||
* Reset RX FIFO.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_rst_rxfifo(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_disable_all_uart_int
|
||||
*
|
||||
* Description:
|
||||
* Disable all UART interrupts.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
* current_status - Pointer to a variable to store the current status of
|
||||
* the interrupt enable register before disabling
|
||||
* UART interrupts.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_disable_all_uart_int(const struct esp32c3_uart_s *priv,
|
||||
uint32_t *current_status);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_restore_all_uart_int
|
||||
*
|
||||
* Description:
|
||||
* Restore all UART interrupts.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
* last_status - Pointer to a variable that stored the last state of the
|
||||
* interrupt enable register.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_restore_all_uart_int(const struct esp32c3_uart_s *priv,
|
||||
uint32_t * last_status);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_config_pins
|
||||
*
|
||||
* Description:
|
||||
* Configure TX and RX UART pins.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_config_pins(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowputc_restore_pins
|
||||
*
|
||||
* Description:
|
||||
* Configure both pins back to INPUT mode and detach the TX pin from the
|
||||
* output signal and the RX pin from the input signal.
|
||||
*
|
||||
* Parameters:
|
||||
* priv - Pointer to the private driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp32c3_lowputc_restore_pins(const struct esp32c3_uart_s *priv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_lowsetup
|
||||
|
||||
@@ -35,13 +35,16 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "hardware/esp32c3_uart.h"
|
||||
#include "riscv_internal.h"
|
||||
#include "riscv_arch.h"
|
||||
#include "chip.h"
|
||||
#include "esp32c3_lowputc.h"
|
||||
|
||||
#include "hardware/esp32c3_uart.h"
|
||||
#include "hardware/esp32c3_system.h"
|
||||
|
||||
#include "esp32c3_config.h"
|
||||
#include "esp32c3_irq.h"
|
||||
#include "esp32c3_lowputc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -149,15 +152,19 @@ static char g_uart0_txbuffer[CONFIG_UART0_TXBUFSIZE];
|
||||
|
||||
static struct esp32c3_uart_s g_uart0_config =
|
||||
{
|
||||
.base = REG_UART_BASE(0),
|
||||
.periph = ESP32C3_PERIPH_UART0,
|
||||
.id = 0,
|
||||
.cpuint = -ENOMEM,
|
||||
.irq = ESP32C3_IRQ_UART0,
|
||||
.baud = CONFIG_UART0_BAUD,
|
||||
.bits = CONFIG_UART0_BITS,
|
||||
.parity = CONFIG_UART0_PARITY,
|
||||
.stop_b2 = CONFIG_UART0_2STOP,
|
||||
.int_pri = 1
|
||||
.int_pri = ESP32C3_INT_PRIO_DEF,
|
||||
.txpin = CONFIG_ESP32C3_UART0_TXPIN,
|
||||
.txsig = U0TXD_OUT_IDX,
|
||||
.rxpin = CONFIG_ESP32C3_UART0_RXPIN,
|
||||
.rxsig = U0RXD_IN_IDX,
|
||||
};
|
||||
|
||||
/* Fill only the requested fields */
|
||||
@@ -195,15 +202,19 @@ static char g_uart1_txbuffer[CONFIG_UART1_TXBUFSIZE];
|
||||
|
||||
static struct esp32c3_uart_s g_uart1_config =
|
||||
{
|
||||
.base = REG_UART_BASE(1),
|
||||
.periph = ESP32C3_PERIPH_UART1,
|
||||
.id = 1,
|
||||
.cpuint = -ENOMEM,
|
||||
.irq = ESP32C3_IRQ_UART1,
|
||||
.baud = CONFIG_UART1_BAUD,
|
||||
.bits = CONFIG_UART1_BITS,
|
||||
.parity = CONFIG_UART1_PARITY,
|
||||
.stop_b2 = CONFIG_UART1_2STOP,
|
||||
.int_pri = 1
|
||||
.int_pri = ESP32C3_INT_PRIO_DEF,
|
||||
.txpin = CONFIG_ESP32C3_UART1_TXPIN,
|
||||
.txsig = U1TXD_OUT_IDX,
|
||||
.rxpin = CONFIG_ESP32C3_UART1_RXPIN,
|
||||
.rxsig = U1RXD_IN_IDX,
|
||||
};
|
||||
|
||||
/* Fill only the requested fields */
|
||||
@@ -241,8 +252,8 @@ static uart_dev_t g_uart1_dev =
|
||||
*
|
||||
* Description:
|
||||
* This is the UART interrupt handler. It will be invoked when an
|
||||
* interrupt received on the 'irq' It should call uart_transmitchars or
|
||||
* uart_receivechar to perform the appropriate data transfers. The
|
||||
* interrupt is received on the 'irq' It should call uart_xmitchars or
|
||||
* uart_recvchars to perform the appropriate data transfers. The
|
||||
* interrupt handling logic must be able to map the 'irq' number into the
|
||||
* appropriate uart_dev_s structure in order to call these functions.
|
||||
*
|
||||
@@ -289,10 +300,52 @@ static int uart_handler(int irq, FAR void *context, FAR void *arg)
|
||||
* That portion of the UART setup is performed when the attach() method
|
||||
* is called.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
*
|
||||
* Returned Values:
|
||||
* Zero (OK) is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int esp32c3_setup(struct uart_dev_s *dev)
|
||||
{
|
||||
struct esp32c3_uart_s *priv = dev->priv;
|
||||
|
||||
/* Initialize UART module */
|
||||
|
||||
/* Configure the UART Baud Rate */
|
||||
|
||||
esp32c3_lowputc_baud(priv);
|
||||
|
||||
/* Set a mode */
|
||||
|
||||
esp32c3_lowputc_normal_mode(priv);
|
||||
|
||||
/* Parity */
|
||||
|
||||
esp32c3_lowputc_parity(priv);
|
||||
|
||||
/* Data Frame size */
|
||||
|
||||
esp32c3_lowputc_data_length(priv);
|
||||
|
||||
/* Stop bit */
|
||||
|
||||
esp32c3_lowputc_stop_length(priv);
|
||||
|
||||
/* No Tx idle interval */
|
||||
|
||||
esp32c3_lowputc_set_tx_idle_time(priv, 0);
|
||||
|
||||
/* Set pins */
|
||||
|
||||
esp32c3_lowputc_config_pins(priv);
|
||||
|
||||
/* Enable cores */
|
||||
|
||||
esp32c3_lowputc_enable_sclk(priv);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -304,10 +357,27 @@ static int esp32c3_setup(struct uart_dev_s *dev)
|
||||
* This method reverses the operation the setup method. NOTE that the serial
|
||||
* console is never shutdown.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp32c3_shutdown(struct uart_dev_s *dev)
|
||||
{
|
||||
struct esp32c3_uart_s *priv = dev->priv;
|
||||
|
||||
/* Clear FIFOs */
|
||||
|
||||
esp32c3_lowputc_rst_txfifo(priv);
|
||||
esp32c3_lowputc_rst_rxfifo(priv);
|
||||
|
||||
/* Disable ints */
|
||||
|
||||
esp32c3_lowputc_disable_all_uart_int(priv, NULL);
|
||||
|
||||
/* Back pins to normal */
|
||||
|
||||
esp32c3_lowputc_restore_pins(priv);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -324,6 +394,13 @@ static void esp32c3_shutdown(struct uart_dev_s *dev)
|
||||
* and TX interrupts are not enabled until the txint() and rxint() methods
|
||||
* are called.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
*
|
||||
* Returned Values:
|
||||
* Zero (OK) is returned on success; A negated errno value is returned
|
||||
* to indicate the nature of any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int esp32c3_attach(struct uart_dev_s *dev)
|
||||
@@ -331,6 +408,8 @@ static int esp32c3_attach(struct uart_dev_s *dev)
|
||||
struct esp32c3_uart_s *priv = dev->priv;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(priv->cpuint == -ENOMEM);
|
||||
|
||||
/* Try to attach the IRQ to a CPU int */
|
||||
|
||||
priv->cpuint = esp32c3_request_irq(priv->periph, priv->int_pri,
|
||||
@@ -347,6 +426,10 @@ static int esp32c3_attach(struct uart_dev_s *dev)
|
||||
{
|
||||
up_enable_irq(priv->cpuint);
|
||||
}
|
||||
else
|
||||
{
|
||||
up_disable_irq(priv->cpuint);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -359,39 +442,45 @@ static int esp32c3_attach(struct uart_dev_s *dev)
|
||||
* closed normally just before the shutdown method is called. The
|
||||
* exception is the serial console which is never shutdown.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp32c3_detach(struct uart_dev_s *dev)
|
||||
{
|
||||
struct esp32c3_uart_s *priv = dev->priv;
|
||||
|
||||
DEBUGASSERT(priv->cpuint != -ENOMEM);
|
||||
|
||||
up_disable_irq(priv->cpuint);
|
||||
irq_detach(priv->irq);
|
||||
esp32c3_free_cpuint(priv->periph);
|
||||
priv->cpuint = -ENOMEM;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_txint
|
||||
*
|
||||
* Description:
|
||||
* Call to enable or disable TX interrupts
|
||||
* Enable or disable TX interrupts.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
* enable - If true enables the TX interrupt, if false disables it.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp32c3_txint(struct uart_dev_s *dev, bool enable)
|
||||
{
|
||||
struct esp32c3_uart_s *priv = dev->priv;
|
||||
irqstate_t flags;
|
||||
uint32_t ints_mask = UART_TXFIFO_EMPTY_INT_ENA_M | UART_TX_DONE_INT_ENA_M;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
if (enable)
|
||||
{
|
||||
/* Set to receive an interrupt when the TX holding register register
|
||||
* is empty
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
|
||||
modifyreg32(UART_INT_ENA_REG(priv->id), ints_mask, ints_mask);
|
||||
#endif
|
||||
@@ -402,52 +491,58 @@ static void esp32c3_txint(struct uart_dev_s *dev, bool enable)
|
||||
|
||||
modifyreg32(UART_INT_ENA_REG(priv->id), ints_mask, 0);
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_rxint
|
||||
*
|
||||
* Description:
|
||||
* Call to enable or disable RXRDY interrupts
|
||||
* Enable or disable RX interrupts.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
* enable - If true enables the RX interrupt, if false disables it.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp32c3_rxint(struct uart_dev_s *dev, bool enable)
|
||||
{
|
||||
struct esp32c3_uart_s *priv = dev->priv;
|
||||
irqstate_t flags;
|
||||
uint32_t ints_mask = UART_RXFIFO_TOUT_INT_ENA_M |
|
||||
UART_RXFIFO_FULL_INT_ENA_M;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
if (enable)
|
||||
{
|
||||
/* Receive an interrupt when their is anything in the Rx data register
|
||||
/* Receive an interrupt when there is anything in the Rx data register
|
||||
* (or an Rx timeout occurs).
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
|
||||
modifyreg32(UART_CONF1_REG(priv->id), UART_RX_TOUT_EN_M,
|
||||
UART_RX_TOUT_EN_M);
|
||||
modifyreg32(UART_INT_ENA_REG(priv->id), ints_mask, ints_mask);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
modifyreg32(UART_CONF1_REG(priv->id), UART_RX_TOUT_EN_M, 0);
|
||||
|
||||
/* Disable the RX interrupts */
|
||||
|
||||
modifyreg32(UART_INT_ENA_REG(priv->id), ints_mask, 0);
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_rxavailable
|
||||
*
|
||||
* Description:
|
||||
* Return true if the receive holding register is not empty
|
||||
* Check if there is any data available to be read.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
*
|
||||
* Returned Values:
|
||||
* Return true if the RX FIFO is not empty and false if RX FIFO is empty.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -467,8 +562,15 @@ static bool esp32c3_rxavailable(struct uart_dev_s *dev)
|
||||
* Name: esp32c3_txready
|
||||
*
|
||||
* Description:
|
||||
* Return true if the tranmsit hardware is ready to send another byte. This
|
||||
* is used to determine if send() method can be called.
|
||||
* Check if the transmit hardware is ready to send another byte.
|
||||
* This is used to determine if send() method can be called.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
*
|
||||
* Returned Values:
|
||||
* Return true if the transmit hardware is ready to send another byte,
|
||||
* false otherwise.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -481,10 +583,16 @@ static bool esp32c3_txready(struct uart_dev_s *dev)
|
||||
* Name: esp32c3_txempty
|
||||
*
|
||||
* Description:
|
||||
* Return true if all characters have been sent. If for example, the UART
|
||||
* hardware implements FIFOs, then this would mean the transmit FIFO is
|
||||
* empty. This method is called when the driver needs to make sure that
|
||||
* all characters are "drained" from the TX hardware.
|
||||
* Verify if all characters have been sent. If for example, the UART
|
||||
* hardware implements FIFOs, then this would mean the transmit FIFO is
|
||||
* empty. This method is called when the driver needs to make sure that
|
||||
* all characters are "drained" from the TX hardware.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
*
|
||||
* Returned Values:
|
||||
* Return true if the TX FIFO is empty, false if it is not.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -500,19 +608,19 @@ static bool esp32c3_txempty(struct uart_dev_s *dev)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32c3_shutdown
|
||||
* Name: esp32c3_send
|
||||
*
|
||||
* Description:
|
||||
* Disable the UART. This method is called when the serial port is closed.
|
||||
* This method reverses the operation the setup method. NOTE that the serial
|
||||
* console is never shutdown.
|
||||
* Send a unique character
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
* ch - Byte to be sent.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp32c3_send(struct uart_dev_s *dev, int ch)
|
||||
{
|
||||
/* Then send the character */
|
||||
|
||||
esp32c3_lowputc_send_byte(dev->priv, ch);
|
||||
}
|
||||
|
||||
@@ -524,6 +632,13 @@ static void esp32c3_send(struct uart_dev_s *dev, int ch)
|
||||
* character from the UART. Error bits associated with the
|
||||
* receipt are provided in the return 'status'.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - Pointer to the serial driver struct.
|
||||
* status - Pointer to a variable to store eventual error bits.
|
||||
*
|
||||
* Returned Values:
|
||||
* Return the byte read from the RX FIFO.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int esp32c3_receive(struct uart_dev_s *dev, unsigned int *status)
|
||||
@@ -534,6 +649,10 @@ static int esp32c3_receive(struct uart_dev_s *dev, unsigned int *status)
|
||||
rx_fifo = getreg32(UART_FIFO_REG(priv->id));
|
||||
rx_fifo = rx_fifo & UART_RXFIFO_RD_BYTE_M;
|
||||
|
||||
/* Since we don't have error bits associated with receipt, we set zero */
|
||||
|
||||
*status = 0;
|
||||
|
||||
return (int)rx_fifo;
|
||||
}
|
||||
|
||||
@@ -582,8 +701,6 @@ void up_earlyserialinit(void)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* TODO */
|
||||
|
||||
void up_serialinit(void)
|
||||
{
|
||||
#ifdef HAVE_SERIAL_CONSOLE
|
||||
@@ -607,13 +724,12 @@ void up_serialinit(void)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* TODO - To finish later with interrupt */
|
||||
|
||||
int up_putc(int ch)
|
||||
{
|
||||
#ifdef HAVE_SERIAL_CONSOLE
|
||||
uint32_t int_status;
|
||||
|
||||
/* TODO disable uart ints */
|
||||
esp32c3_lowputc_disable_all_uart_int(CONSOLE_DEV.priv, &int_status);
|
||||
|
||||
/* Check for LF */
|
||||
|
||||
@@ -625,8 +741,7 @@ int up_putc(int ch)
|
||||
}
|
||||
|
||||
up_lowputc(ch);
|
||||
|
||||
/* TODO restore ints */
|
||||
esp32c3_lowputc_restore_all_uart_int(CONSOLE_DEV.priv, &int_status);
|
||||
#endif
|
||||
return ch;
|
||||
}
|
||||
@@ -674,11 +789,13 @@ int up_putc(int ch)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* TODO - Finish it disabling interrupt and restoring it later */
|
||||
|
||||
int up_putc(int ch)
|
||||
{
|
||||
#ifdef HAVE_SERIAL_CONSOLE
|
||||
uint32_t int_status;
|
||||
|
||||
esp32c3_lowputc_disable_all_uart_int(CONSOLE_DEV.priv, &int_status);
|
||||
|
||||
/* Check for LF */
|
||||
|
||||
if (ch == '\n')
|
||||
@@ -689,6 +806,7 @@ int up_putc(int ch)
|
||||
}
|
||||
|
||||
up_lowputc(ch);
|
||||
esp32c3_lowputc_restore_all_uart_int(CONSOLE_DEV.priv, &int_status);
|
||||
#endif
|
||||
return ch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user