feat(ethercat): 添加EtherCAT从站功能支持并优化同步机制
- 添加CAN反馈和ID快照SPI命令文件 - 移除EXMC组件依赖,精简项目配置 - 添加RAM函数段链接脚本,优化Flash等待周期抖动 - 实现EscExmcBus类,提供16位并行总线访问LAN9252 - 实现EscLan9252驱动,支持寄存器和PDI内存访问 - 实现EthercatSlave类,采用三缓冲机制进行PDO数据交换 - 实现EthercatSync同步管理,支持SYNC0/SYNC1中断和定时器模式 - 添加ISR执行时间统计和诊断功能 - 分离周期路径和事件路径通知机制,避免RMW竞态
This commit is contained in:
@@ -2,6 +2,12 @@
|
||||
* @file esc_lan9252.h
|
||||
* @brief LAN9252 EtherCAT 从站控制器(ESC)驱动接口。
|
||||
* @note 通过 EscExmcBus 16-bit 并行总线访问 LAN9252 寄存器与 PDI 内存。
|
||||
*
|
||||
* 接口调用约束(避免 EXMC 总线争用):
|
||||
* - readReg/writeReg/readPdi/writePdi:ISR-only,仅供 preempt=0 的 periodicIsr() 调用,无锁。
|
||||
* - initOnlyReadReg/initOnlyWriteReg/initOnlyReadPdi/initOnlyWritePdi:INIT-ONLY,仅允许在 EthercatSync::init() 使能 EXTI NVIC 之前调用;运行期禁止调用,需 ESC 寄存器访问须通过 SYNC0 ISR 代访队列(本 spec 不涵盖)。
|
||||
*
|
||||
* PDI offset 语义:offset 参数为 SyncManager 内存区相对偏移,输入 PDO(TxPDO)与输出 PDO(RxPDO)必须使用不同 offset,参见 CONFIG_ESC_PDI_INPUT_OFFSET / CONFIG_ESC_PDI_OUTPUT_OFFSET。
|
||||
*/
|
||||
#ifndef COMM_ESC_LAN9252_H
|
||||
#define COMM_ESC_LAN9252_H
|
||||
@@ -25,34 +31,34 @@ public:
|
||||
static bool selfTest();
|
||||
|
||||
/**
|
||||
* @brief 读取 ESC 寄存器(16-bit)。
|
||||
* @param[in] addr 寄存器地址(ESC 寄存器空间偏移)。
|
||||
* @return uint16_t 寄存器值。
|
||||
* @brief 读取 ESC 芯片 ID(INIT-ONLY,供 init 打印诊断用)。
|
||||
* @return uint32_t 32-bit 芯片 ID(期望值 0x87654321)。
|
||||
*/
|
||||
static uint32_t readChipId();
|
||||
|
||||
/** @brief ISR-only:仅供 preempt=0 的 periodicIsr() 调用,无锁。主循环必须用 initOnly 版本。 */
|
||||
static uint16_t readReg(uint16_t addr);
|
||||
|
||||
/**
|
||||
* @brief 写入 ESC 寄存器(16-bit)。
|
||||
* @param[in] addr 寄存器地址。
|
||||
* @param[in] val 待写入值。
|
||||
*/
|
||||
/** @brief ISR-only:仅供 preempt=0 的 periodicIsr() 调用,无锁。主循环必须用 initOnly 版本。 */
|
||||
static void writeReg(uint16_t addr, uint16_t val);
|
||||
|
||||
/**
|
||||
* @brief 从 PDI 内存读取一块数据。
|
||||
* @param[in] offset PDI 偏移(字节)。
|
||||
* @param[out] buf 输出缓冲。
|
||||
* @param[in] len 读取字节数。
|
||||
*/
|
||||
/** @brief ISR-only:仅供 preempt=0 的 periodicIsr() 调用,无锁。主循环必须用 initOnly 版本。 */
|
||||
static void readPdi(uint16_t offset, uint8_t *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief 向 PDI 内存写入一块数据。
|
||||
* @param[in] offset PDI 偏移(字节)。
|
||||
* @param[in] buf 数据缓冲。
|
||||
* @param[in] len 写入字节数。
|
||||
*/
|
||||
/** @brief ISR-only:仅供 preempt=0 的 periodicIsr() 调用,无锁。主循环必须用 initOnly 版本。 */
|
||||
static void writePdi(uint16_t offset, const uint8_t *buf, size_t len);
|
||||
|
||||
/** @brief INIT-ONLY:仅允许在 EthercatSync::init() 使能 EXTI NVIC 之前调用;运行期禁止调用,需 ESC 寄存器访问须通过 SYNC0 ISR 代访队列(本 spec 不涵盖)。 */
|
||||
static uint16_t initOnlyReadReg(uint16_t addr);
|
||||
|
||||
/** @brief INIT-ONLY:仅允许在 EthercatSync::init() 使能 EXTI NVIC 之前调用;运行期禁止调用,需 ESC 寄存器访问须通过 SYNC0 ISR 代访队列(本 spec 不涵盖)。 */
|
||||
static void initOnlyWriteReg(uint16_t addr, uint16_t val);
|
||||
|
||||
/** @brief INIT-ONLY:仅允许在 EthercatSync::init() 使能 EXTI NVIC 之前调用;运行期禁止调用,需 ESC 寄存器访问须通过 SYNC0 ISR 代访队列(本 spec 不涵盖)。 */
|
||||
static void initOnlyReadPdi(uint16_t offset, uint8_t *buf, size_t len);
|
||||
|
||||
/** @brief INIT-ONLY:仅允许在 EthercatSync::init() 使能 EXTI NVIC 之前调用;运行期禁止调用,需 ESC 寄存器访问须通过 SYNC0 ISR 代访队列(本 spec 不涵盖)。 */
|
||||
static void initOnlyWritePdi(uint16_t offset, const uint8_t *buf, size_t len);
|
||||
};
|
||||
|
||||
#endif /* COMM_ESC_LAN9252_H */
|
||||
|
||||
Reference in New Issue
Block a user