diff options
| author | bernard <[email protected]> | 2014-07-18 06:45:54 +0800 |
|---|---|---|
| committer | bernard <[email protected]> | 2014-07-18 06:45:54 +0800 |
| commit | c45f5a249089e1e453f358bcab052ddce8a8dff7 (patch) | |
| tree | c5f7b1a6e234759648eca0456039a930a5435134 /components/drivers/include | |
| parent | fc6747ef6c665195cf3b8fc1c40e93da60872519 (diff) | |
[Drivers] re-write serial framework.
Diffstat (limited to 'components/drivers/include')
| -rw-r--r-- | components/drivers/include/drivers/serial.h | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/components/drivers/include/drivers/serial.h b/components/drivers/include/drivers/serial.h index 9655820736..bf2a25ae1e 100644 --- a/components/drivers/include/drivers/serial.h +++ b/components/drivers/include/drivers/serial.h @@ -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 + |
