- 添加CAN反馈和ID快照SPI命令文件 - 移除EXMC组件依赖,精简项目配置 - 添加RAM函数段链接脚本,优化Flash等待周期抖动 - 实现EscExmcBus类,提供16位并行总线访问LAN9252 - 实现EscLan9252驱动,支持寄存器和PDI内存访问 - 实现EthercatSlave类,采用三缓冲机制进行PDO数据交换 - 实现EthercatSync同步管理,支持SYNC0/SYNC1中断和定时器模式 - 添加ISR执行时间统计和诊断功能 - 分离周期路径和事件路径通知机制,避免RMW竞态
84 lines
2.4 KiB
C++
84 lines
2.4 KiB
C++
#ifndef DEVICE_USART0_H
|
|
#define DEVICE_USART0_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
/**
|
|
* @brief USART0 串口模块。
|
|
* @note 负责 GPIO 初始化、外设配置、TX 环形缓冲与中断驱动发送。
|
|
*/
|
|
class Usart0 {
|
|
public:
|
|
/**
|
|
* @brief 配置 USART0 的 GPIO 引脚。
|
|
* @param[in] 无。
|
|
* @param[out] 无。
|
|
* @retval 无返回值。
|
|
* @note 当前配置为:PA9=TX(AF_PP)、PA10=RX(IN_FLOATING)。
|
|
*/
|
|
static void configurePins();
|
|
|
|
/**
|
|
* @brief 初始化 USART0 外设与 NVIC。
|
|
* @param[in] 无。
|
|
* @param[out] 无。
|
|
* @retval 无返回值。
|
|
* @note 使用 8N1 格式,收发使能,同步配置 NVIC 以便 TXE 中断驱动发送。
|
|
*/
|
|
static void init();
|
|
|
|
/**
|
|
* @brief 将字符写入 USART0 发送环形缓冲。
|
|
* @param[in] ch 待发送字符。
|
|
* @param[in] f 标准流指针,实际未使用。
|
|
* @param[out] 无。
|
|
* @retval int 返回已写入缓冲的字符值。
|
|
* @note 新字符写入后自动启动 TXE 中断来推动实际硬件发送。
|
|
*/
|
|
static int putChar(int ch, FILE *f);
|
|
|
|
/**
|
|
* @brief USART0 中断处理入口。
|
|
* @param[in] 无。
|
|
* @param[out] 无。
|
|
* @retval 无返回值。
|
|
* @note 在 TXE 产生时从环形缓冲取下一字节发送;缓冲空后关闭 TXE 中断。
|
|
*/
|
|
static void onInterrupt();
|
|
|
|
private:
|
|
/**
|
|
* @brief 获取环形缓冲下一索引。
|
|
* @param[in] idx 当前索引。
|
|
* @param[out] 无。
|
|
* @retval uint16_t 下一索引值。
|
|
*/
|
|
static uint16_t nextIndex(uint16_t idx);
|
|
|
|
/**
|
|
* @brief 判断环形发送缓冲是否已满。
|
|
* @param[in] 无。
|
|
* @param[out] 无。
|
|
* @retval bool true 表示已满,false 表示可继续写入。
|
|
*/
|
|
static bool isBufferFull();
|
|
|
|
/**
|
|
* @brief 判断环形发送缓冲是否为空。
|
|
* @param[in] 无。
|
|
* @param[out] 无。
|
|
* @retval bool true 表示空,false 表示仍有待发送数据。
|
|
*/
|
|
static bool isBufferEmpty();
|
|
|
|
static bool putCharNonBlocking(int ch);
|
|
|
|
static constexpr uint16_t kTxBufSize = 1024U;
|
|
static volatile uint32_t s_dropCount;
|
|
static uint8_t s_txBuf[kTxBufSize];
|
|
static volatile uint16_t s_txHead;
|
|
static volatile uint16_t s_txTail;
|
|
};
|
|
|
|
#endif /* DEVICE_USART0_H */ |