71 lines
2.6 KiB
C
71 lines
2.6 KiB
C
#ifndef _BSP_UART_H_
|
|
#define _BSP_UART_H_
|
|
|
|
#include "main.h"
|
|
#include "algo_queue.h"
|
|
|
|
/******************************************
|
|
* 结构体: bsp_uart_t
|
|
* 功能: UART控制结构体
|
|
* 描述: 包含UART的所有配置和状态信息
|
|
*******************************************/
|
|
typedef struct bsp_uart_t bsp_uart_t;
|
|
|
|
/* 类型重定义 */
|
|
#define usart_type UART_HandleTypeDef
|
|
#define dma_type DMA_HandleTypeDef
|
|
|
|
/******************************************
|
|
* 结构体: bsp_uart_relay_t
|
|
* 功能: UART转发结构体
|
|
* 描述: 用于配置UART数据转发功能
|
|
*******************************************/
|
|
typedef struct
|
|
{
|
|
u8 flag; /* 串口转发标志位 */
|
|
bsp_uart_t *uart; /* 转发出去的串口指针 */
|
|
u16 time_out; /* 转发超时时间 */
|
|
} bsp_uart_relay_t;
|
|
|
|
struct bsp_uart_t
|
|
{
|
|
queue rx_queue; /* 数据接收队列 */
|
|
usart_type *uart; /* 串口句柄指针 */
|
|
|
|
dma_type *tx_dma; /* 发送DMA句柄 */
|
|
dma_type *rx_dma; /* 接收DMA句柄 */
|
|
|
|
u8 tx_dma_ch; /* 发送DMA通道号 */
|
|
u8 rx_dma_ch; /* 接收DMA通道号 */
|
|
vu8 tx_dma_complete_flag; /* DMA接收完成标志位 */
|
|
|
|
u8 *tx_addr; /* DMA发送缓冲区地址 */
|
|
u8 *rx_addr; /* DMA接收缓冲区地址 */
|
|
u16 tx_dma_len; /* DMA发送缓冲区长度 */
|
|
u16 rx_dma_len; /* DMA接收缓冲区长度 */
|
|
|
|
u16 rx_len; /* 接收到的数据长度 */
|
|
u16 rx_time_count; /* 超时计数 */
|
|
u16 rx_time_over; /* 超时时间 */
|
|
u8 rx_start_flag; /* 开始超时计数标志位 */
|
|
|
|
bsp_uart_relay_t relay; /* 串口转发配置 */
|
|
|
|
void (*init)(bsp_uart_t *); /* 初始化函数指针 */
|
|
void (*send)(bsp_uart_t *, u8 *, u16); /* 串口发送函数指针 */
|
|
|
|
void (*tx_dma_tc_int)(bsp_uart_t *); /* DMA发送完成中断处理函数指针 */
|
|
|
|
void (*rx_idle_int)(bsp_uart_t *); /* 空闲中断处理函数指针 */
|
|
void (*rx_time_increment_int)(bsp_uart_t *, u16); /* 中断计数函数指针 */
|
|
void (*rx_data_analysis)(u8 *, u16, void *); /* 数据解析函数指针 */
|
|
void (*rx_task)(bsp_uart_t *); /* 串口接收任务函数指针 */
|
|
};
|
|
|
|
/* 声明外部变量 */
|
|
extern bsp_uart_t com_uart1;
|
|
extern bsp_uart_t com_uart2;
|
|
extern bsp_uart_t com_uart4;
|
|
|
|
#endif
|