mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-22 11:30:01 +08:00
[Drivers] re-write serial framework.
This commit is contained in:
@@ -70,6 +70,15 @@
|
||||
#define RT_DEVICE_CTRL_CLR_INT 0x11 /* disable receive irq */
|
||||
#define RT_DEVICE_CTRL_GET_INT 0x12
|
||||
|
||||
#define RT_SERIAL_EVENT_RX_IND 0x01 /* Rx indication */
|
||||
#define RT_SERIAL_EVENT_TX_DONE 0x02 /* Tx complete */
|
||||
#define RT_SERIAL_EVENT_RX_DMADONE 0x03 /* Rx DMA transfer done */
|
||||
#define RT_SERIAL_EVENT_TX_DMADONE 0x04 /* Tx DMA transfer done */
|
||||
#define RT_SERIAL_EVENT_RX_TIMEOUT 0x05 /* Rx timeout */
|
||||
|
||||
#define RT_SERIAL_DMA_RX 0x01
|
||||
#define RT_SERIAL_DMA_TX 0x02
|
||||
|
||||
#define RT_SERIAL_RX_INT 0x01
|
||||
#define RT_SERIAL_TX_INT 0x02
|
||||
|
||||
@@ -89,24 +98,51 @@
|
||||
PARITY_NONE, /* No parity */ \
|
||||
BIT_ORDER_LSB, /* LSB first sent */ \
|
||||
NRZ_NORMAL, /* Normal mode */ \
|
||||
RT_SERIAL_RB_BUFSZ, /* Buffer size */ \
|
||||
0 \
|
||||
}
|
||||
|
||||
struct serial_ringbuffer
|
||||
{
|
||||
rt_uint8_t buffer[RT_SERIAL_RB_BUFSZ];
|
||||
rt_uint16_t put_index, get_index;
|
||||
};
|
||||
|
||||
struct serial_configure
|
||||
{
|
||||
rt_uint32_t baud_rate;
|
||||
|
||||
rt_uint32_t data_bits :4;
|
||||
rt_uint32_t stop_bits :2;
|
||||
rt_uint32_t parity :2;
|
||||
rt_uint32_t bit_order :1;
|
||||
rt_uint32_t invert :1;
|
||||
rt_uint32_t reserved :20;
|
||||
rt_uint32_t bufsz :16;
|
||||
rt_uint32_t reserved :4;
|
||||
};
|
||||
|
||||
/*
|
||||
* Serial FIFO mode
|
||||
*/
|
||||
struct rt_serial_rx_fifo
|
||||
{
|
||||
/* software fifo */
|
||||
rt_uint8_t *buffer;
|
||||
|
||||
rt_uint16_t put_index, get_index;
|
||||
};
|
||||
|
||||
struct rt_serial_tx_fifo
|
||||
{
|
||||
struct rt_completion completion;
|
||||
};
|
||||
|
||||
/*
|
||||
* Serial DMA mode
|
||||
*/
|
||||
struct rt_serial_rx_dma
|
||||
{
|
||||
rt_bool_t activated;
|
||||
};
|
||||
|
||||
struct rt_serial_tx_dma
|
||||
{
|
||||
rt_bool_t activated;
|
||||
struct rt_data_queue data_queue;
|
||||
};
|
||||
|
||||
struct rt_serial_device
|
||||
@@ -116,14 +152,8 @@ struct rt_serial_device
|
||||
const struct rt_uart_ops *ops;
|
||||
struct serial_configure config;
|
||||
|
||||
/* rx structure */
|
||||
struct serial_ringbuffer *int_rx;
|
||||
/* tx structure */
|
||||
struct serial_ringbuffer *int_tx;
|
||||
|
||||
struct rt_data_queue tx_dq; /* tx dataqueue */
|
||||
|
||||
volatile rt_bool_t dma_flag; /* dma transfer flag */
|
||||
void *serial_rx;
|
||||
void *serial_tx;
|
||||
};
|
||||
typedef struct rt_serial_device rt_serial_t;
|
||||
|
||||
@@ -138,14 +168,15 @@ struct rt_uart_ops
|
||||
int (*putc)(struct rt_serial_device *serial, char c);
|
||||
int (*getc)(struct rt_serial_device *serial);
|
||||
|
||||
rt_size_t (*dma_transmit)(struct rt_serial_device *serial, const char *buf, rt_size_t size);
|
||||
rt_size_t (*dma_transmit)(struct rt_serial_device *serial, const rt_uint8_t *buf, rt_size_t size, int direction);
|
||||
};
|
||||
|
||||
void rt_hw_serial_isr(struct rt_serial_device *serial);
|
||||
void rt_hw_serial_dma_tx_isr(struct rt_serial_device *serial);
|
||||
void rt_hw_serial_isr(struct rt_serial_device *serial, int event);
|
||||
|
||||
rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
|
||||
const char *name,
|
||||
rt_uint32_t flag,
|
||||
void *data);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+415
-276
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user