RTEMS 控制台驱动
uart介绍
https://www.nowcoder.com/discuss/734524892543975424
UART 是一种串行,全双工,低速,异步通信方式(没有时钟线)
UART 需要 RX、TX 两根线
帧格式:起始位(逻辑0) + 数据位(5到9位,常见8位) + 校验位 + 停止位(逻辑1,1到2位)
传输数据以字节为单位,传输速度由波特率控制(常见9600、115200)
串口的波特率表示传输的速率,具体是指每秒钟传输的二进制位数
树莓派4b的uart
termios接口
驱动程序需要将uart设备安装进termios框架
/** Install this device in the file system and Termios. In order* to use the console (i.e. being able to do printf, scanf etc.* on stdin, stdout and stderr), one device must be registered as* "/dev/console" (CONSOLE_DEVICE_NAME).*/sc = rtems_termios_device_install( ctx->device_name, handler, NULL, ctx );
需要提供设备上下文,和一个handler列表。
const rtems_termios_device_handler arm_pl011_fns = {.first_open = arm_pl011_first_open,.write = arm_pl011_write_buffer,.set_attributes = arm_pl011_set_attributes,.ioctl = NULL,
#ifdef BSP_CONSOLE_USE_INTERRUPTS.last_close = arm_pl011_last_close,.poll_read = NULL,.mode = TERMIOS_IRQ_DRIVEN,
#else.last_close = NULL,.poll_read = arm_pl011_read_polled,.mode = TERMIOS_POLLED,
#endif
};
应用层软件可以通过oepn read write 来从uart设备发送接收信息。
通过tcsetattr来配置uart参数,底层调用的就是set_attributes函数。
这里的tc是Terminal Control意思。