mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-05 05:23:46 +00:00
[drivers][serial_v2]允许阻塞接收超过rx缓冲区大小的数据、增加超时时间、flush、获取缓冲区数据长度命令、数据溢出逻辑修复、稳定性细节优化、添加更多serial_v2测试用例
[components][serial_v2] 优化txflush逻辑、对tx的activated做中断保护 [components][at] at_client适配新版serial_v2 [components][at] at_server适配新版serial_v2 [components][serial_v2] 测试用例增加循环调用,format测试用例 [components][serial_v2] poll模式判断逻辑错误 [components][serial_v2] 测试用例去掉一些非必要延时 [components][serial_v2] 测试例程使用menuconfig进行配置,更新readme [components][at_client] at_client_getchar返回值错误、at_client解析线程优先级错误设置 [components][at] 错误码应该返回负值 [components][serial_v2] TCFLSH和FIONREAD完善、control函数增加错误返回值 [components][serial_v2] RT_SERIAL_CTRL_GET_RX_DATA_LEN更改为RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT [utest][serial_v2] TC_UART_SEND_TIMES替换为RT_SERIAL_TC_SEND_ITERATIONS [components][serial_v2] FIONREAD参数应该是无符号类型 [utest][serial_v2] 完善测试用例 [components][serial_v2] 避免使用三目运算符 [components][serial_v2] 使用clang-format格式化代码 [components][serial_v2] 添加get超时时间命令 [components][serial_v2] 完善posix接口 [components][serial_v2] 阻塞接口添加阻塞时间为0时的处理逻辑、优化RX阻塞接收逻辑 [components][serial_v2] 设置超时时间命令的参数改为指针形式 [components][serial_v2] nbuf发送添加超时时间为0时的逻辑 [components][serial_v2] 完善添加测试用例 [utest][serial_v2] 修复依赖关系 [components][serial_v2] 非阻塞模式下tx_flush错误修复 [components][serial_v2] activated使用原子API [components][serial_v2] 优化DMA逻辑、没使能DMA时屏蔽DMA逻辑节约资源 [components][serial_v2] 提供写满时丢弃新数据和覆盖旧数据策略,写满丢弃策略效率更高 [components][serial_v2] 部分平台适配写满时两种策略功能 [components][serial_v2] DMA模式暂不支持丢弃新数据策略 [utest][serial_v2] 优化测试代码 [components][serial_v2] DMA模式下使用乒乓缓冲、DMA模式支持丢弃新数据策略 [utest][serial_v2] 适配DMA乒乓缓冲 [bsp][serial_v2] 部分bsp适配DMA下乒乓缓冲 [components][serial_v2] 使用spinlock替换中断,对部分结构体变量使用原子操作 [utest][serial_v2] 更新测试用例 [components][at] 适配new serialv2不再判断RTT版本号 [components][at] 删除多余的中文注释 [utest][serial_v2] 添加交叉echo示例,qemu环境下专用 [bsp][qemu] 适配串口v2并开启fifo [components][at] 修复合并导致的错误 [bsp][n32] 适配serial_v2,没有经过测试 [components][serial_v2] 格式化代码 [utest][serial_v2] 删除无意义的打印
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@@ -12,8 +12,7 @@
|
||||
#define __DEV_SERIAL_V2_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
|
||||
#include <rtdevice.h>
|
||||
/**
|
||||
* @addtogroup group_Drivers RTTHREAD Driver
|
||||
* @defgroup group_Serial_v2 Serial v2
|
||||
@@ -169,6 +168,9 @@
|
||||
#define NRZ_NORMAL 0 /* Non Return to Zero : normal mode */
|
||||
#define NRZ_INVERTED 1 /* Non Return to Zero : inverted mode */
|
||||
|
||||
/**
|
||||
* device flag
|
||||
*/
|
||||
#define RT_DEVICE_FLAG_RX_BLOCKING 0x1000
|
||||
#define RT_DEVICE_FLAG_RX_NON_BLOCKING 0x2000
|
||||
|
||||
@@ -180,21 +182,42 @@
|
||||
#define RT_SERIAL_TX_BLOCKING RT_DEVICE_FLAG_TX_BLOCKING
|
||||
#define RT_SERIAL_TX_NON_BLOCKING RT_DEVICE_FLAG_TX_NON_BLOCKING
|
||||
|
||||
/**
|
||||
* hw device control commands
|
||||
*/
|
||||
#define RT_DEVICE_CHECK_OPTMODE 0x20
|
||||
|
||||
/**
|
||||
* hw serial control commands
|
||||
*/
|
||||
#define RT_HW_SERIAL_CTRL_GETC 0x01 /* Tx irq get char */
|
||||
#define RT_HW_SERIAL_CTRL_PUTC 0x02 /* Rx irq put char */
|
||||
#define RT_HW_SERIAL_CTRL_GET_DMA_PING_BUF 0x03 /* Get DMA ping-pong buffer */
|
||||
|
||||
/**
|
||||
* hw isr event
|
||||
*/
|
||||
#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 */
|
||||
|
||||
/**
|
||||
* device commands
|
||||
* 0x40 - special device control commands
|
||||
*/
|
||||
#define RT_SERIAL_CTRL_SET_RX_TIMEOUT 0x41 /* set Rx timeout. Call before rt_device_read. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_SET_TX_TIMEOUT 0x42 /* set Tx timeout. Call before rt_device_write. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_GET_RX_TIMEOUT 0x43 /* get Rx timeout. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_GET_TX_TIMEOUT 0x44 /* get Tx timeout. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_RX_FLUSH 0x45 /* clear rx buffer. Discard all data */
|
||||
#define RT_SERIAL_CTRL_TX_FLUSH 0x46 /* clear tx buffer. Blocking and wait for the send buffer data to be sent. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT 0x47 /* get unread bytes count. not supported in poll mode */
|
||||
|
||||
#define RT_SERIAL_ERR_OVERRUN 0x01
|
||||
#define RT_SERIAL_ERR_FRAMING 0x02
|
||||
#define RT_SERIAL_ERR_PARITY 0x03
|
||||
|
||||
#define RT_SERIAL_TX_DATAQUEUE_SIZE 2048
|
||||
#define RT_SERIAL_TX_DATAQUEUE_LWM 30
|
||||
|
||||
#define RT_SERIAL_RX_MINBUFSZ 64
|
||||
#define RT_SERIAL_TX_MINBUFSZ 64
|
||||
|
||||
@@ -216,7 +239,8 @@
|
||||
RT_SERIAL_RX_MINBUFSZ, /* rxBuf size */ \
|
||||
RT_SERIAL_TX_MINBUFSZ, /* txBuf size */ \
|
||||
RT_SERIAL_FLOWCONTROL_NONE, /* Off flowcontrol */ \
|
||||
0 \
|
||||
0, /* reserved */ \
|
||||
0, /* dma_ping_bufsz */ \
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,6 +263,10 @@ struct serial_configure
|
||||
rt_uint32_t tx_bufsz :16;
|
||||
rt_uint32_t flowcontrol :1;
|
||||
rt_uint32_t reserved :5;
|
||||
|
||||
#ifdef RT_SERIAL_USING_DMA
|
||||
rt_uint32_t dma_ping_bufsz :16;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -248,12 +276,15 @@ struct rt_serial_rx_fifo
|
||||
{
|
||||
struct rt_ringbuffer rb;
|
||||
|
||||
#ifdef RT_SERIAL_USING_DMA
|
||||
struct rt_ringbuffer dma_ping_rb;
|
||||
#endif
|
||||
|
||||
struct rt_completion rx_cpt;
|
||||
|
||||
rt_uint16_t rx_cpt_index;
|
||||
rt_size_t rx_cpt_index;
|
||||
|
||||
/* software fifo */
|
||||
rt_uint8_t buffer[];
|
||||
rt_atomic_t rx_timeout;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -264,14 +295,13 @@ struct rt_serial_tx_fifo
|
||||
{
|
||||
struct rt_ringbuffer rb;
|
||||
|
||||
rt_size_t put_size;
|
||||
|
||||
rt_bool_t activated;
|
||||
|
||||
struct rt_completion tx_cpt;
|
||||
|
||||
/* software fifo */
|
||||
rt_uint8_t buffer[];
|
||||
rt_size_t put_size;
|
||||
|
||||
rt_atomic_t tx_timeout;
|
||||
|
||||
rt_atomic_t activated;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -288,6 +318,8 @@ struct rt_serial_device
|
||||
void *serial_rx;
|
||||
void *serial_tx;
|
||||
|
||||
struct rt_spinlock spinlock;
|
||||
|
||||
struct rt_device_notify rx_notify;
|
||||
};
|
||||
|
||||
@@ -321,6 +353,7 @@ struct rt_uart_ops
|
||||
*/
|
||||
void rt_hw_serial_isr(struct rt_serial_device *serial, int event);
|
||||
|
||||
rt_err_t rt_hw_serial_control_isr(struct rt_serial_device *serial, int cmd, void *args);
|
||||
|
||||
/**
|
||||
* @brief Register a serial device to device list
|
||||
|
||||
Reference in New Issue
Block a user