RTT-UART驱动框架分析
UART
通过设备管理接口调用UART
在libraries\HAL_Drivers\drivers\drv_usart.c下有串口初始化函数将,串口注册到系统中
1 | int rt_hw_usart_init(void) |
1 | static struct stm32_uart_config uart_config[] = |
其中UART1_CONFIG的定义是
1 |
所以可以通过名字搜索到设备
rt_device_find()
在注册后,可以通过搜索名字找到具体设备
同样是向下调用,在 object 中每一钟类型都有一个链表,如线程、信号量、互斥量、邮箱等等
1 | rt_device_t rt_device_find(const char *name) |
rt_device_open()
设备管理层在rt-thread\components\drivers\core\device.c可搜索到函数rt_device_open()
设备驱动框架层的封装rt-thread\components\drivers\serial\dev_serial.c,如rt_serial_init()
驱动层libraries\HAL_Drivers\drivers\drv_usart.c是具体实现,如stm32_configure()
rt_device_open()
->device_init()->dev->init()
->rt_serial_init()
->result = serial->ops->configure(serial, &serial->config);
->stm32_configure()
->device_open()
->rt_serial_open()
->serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
->stm32_control()
rt_device_write()
过程大同小异
都是向下调用,最终会调用到 stm32_putc()/stm32_dma_transmit(),这里就是往寄存器写了
rt_device_read()
stm32_getc()/dma_recv_isr()
应用层是从上往下
中断是从下往上
USART1_IRQHandler
->uart_isr
->rt_hw_serial_isr
->serial->parent.rx_indicate(&serial->parent,rx_length)
其中可以注册回调函数
1 | rt_err_t rt_device_set_rx_indicate(rt_device_t dev, |