Files
DCU_APP/GD32E508_DCU_APP/device/usart0.h
T
cbb 76da7a3dd6 Refactor and clean up codebase
- Removed unused constants and type aliases in app_spi_command_defs.h and temp_sensor.h.
- Simplified ISpiCommandHandler destructor to default.
- Eliminated redundant methods and comments in temp_sensor and usart0 files.
- Consolidated writeU32Le function to app_spi_command_defs.h for reuse.
- Updated comments for clarity and accuracy in task_manager.h and task_runner.cpp.
- Removed hardfault.h as it contained no declarations.
- Cleaned up CANFD and watchdog implementations by removing dead code and unnecessary comments.
- Updated version numbers in config.h to reflect recent changes.
- Enhanced error handling and diagnostics in hardfault handling.
2026-07-15 02:49:37 +08:00

75 lines
2.1 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 isBufferEmpty();
static bool putCharNonBlocking(int ch);
static constexpr uint16_t kTxBufSize = 1024U;
static uint8_t s_txBuf[kTxBufSize];
static volatile uint16_t s_txHead;
static volatile uint16_t s_txTail;
};
#endif /* DEVICE_USART0_H */