2026-06-26 00:57:59 +08:00
|
|
|
/**
|
|
|
|
|
* @file esc_lan9252.h
|
|
|
|
|
* @brief LAN9252 EtherCAT 从站控制器(ESC)驱动接口。
|
|
|
|
|
* @note 通过 EscExmcBus 16-bit 并行总线访问 LAN9252 寄存器与 PDI 内存。
|
2026-06-29 01:51:02 +08:00
|
|
|
*
|
|
|
|
|
* 接口调用约束(避免 EXMC 总线争用):
|
2026-07-15 02:49:37 +08:00
|
|
|
* - readReg/readPdi/writePdi:ISR-only,仅供 preempt=0 的 periodicIsr() 调用,无锁。
|
|
|
|
|
* - initOnlyReadReg:INIT-ONLY,仅允许在 EthercatSync::init() 使能 EXTI NVIC 之前调用;运行期禁止调用,需 ESC 寄存器访问须通过 SYNC0 ISR 代访队列(本 spec 不涵盖)。
|
2026-06-29 01:51:02 +08:00
|
|
|
*
|
|
|
|
|
* PDI offset 语义:offset 参数为 SyncManager 内存区相对偏移,输入 PDO(TxPDO)与输出 PDO(RxPDO)必须使用不同 offset,参见 CONFIG_ESC_PDI_INPUT_OFFSET / CONFIG_ESC_PDI_OUTPUT_OFFSET。
|
2026-06-26 00:57:59 +08:00
|
|
|
*/
|
|
|
|
|
#ifndef COMM_ESC_LAN9252_H
|
|
|
|
|
#define COMM_ESC_LAN9252_H
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief LAN9252 ESC 驱动。
|
|
|
|
|
* @note 封装 ESC 寄存器读写与 PDI(Process Data Interface)内存块访问。
|
|
|
|
|
*/
|
|
|
|
|
class EscLan9252 {
|
|
|
|
|
public:
|
|
|
|
|
/** @brief 初始化 EXMC 总线与 ESC 基本寄存器。 */
|
|
|
|
|
static void init();
|
|
|
|
|
|
|
|
|
|
/**
|
2026-06-29 01:51:02 +08:00
|
|
|
* @brief 读取 ESC 芯片 ID(INIT-ONLY,供 init 打印诊断用)。
|
|
|
|
|
* @return uint32_t 32-bit 芯片 ID(期望值 0x87654321)。
|
2026-06-26 00:57:59 +08:00
|
|
|
*/
|
2026-06-29 01:51:02 +08:00
|
|
|
static uint32_t readChipId();
|
|
|
|
|
|
|
|
|
|
/** @brief ISR-only:仅供 preempt=0 的 periodicIsr() 调用,无锁。主循环必须用 initOnly 版本。 */
|
2026-06-26 00:57:59 +08:00
|
|
|
static uint16_t readReg(uint16_t addr);
|
|
|
|
|
|
2026-06-29 01:51:02 +08:00
|
|
|
/** @brief ISR-only:仅供 preempt=0 的 periodicIsr() 调用,无锁。主循环必须用 initOnly 版本。 */
|
2026-06-26 00:57:59 +08:00
|
|
|
static void readPdi(uint16_t offset, uint8_t *buf, size_t len);
|
|
|
|
|
|
2026-06-29 01:51:02 +08:00
|
|
|
/** @brief ISR-only:仅供 preempt=0 的 periodicIsr() 调用,无锁。主循环必须用 initOnly 版本。 */
|
2026-06-26 00:57:59 +08:00
|
|
|
static void writePdi(uint16_t offset, const uint8_t *buf, size_t len);
|
2026-06-29 01:51:02 +08:00
|
|
|
|
|
|
|
|
/** @brief INIT-ONLY:仅允许在 EthercatSync::init() 使能 EXTI NVIC 之前调用;运行期禁止调用,需 ESC 寄存器访问须通过 SYNC0 ISR 代访队列(本 spec 不涵盖)。 */
|
|
|
|
|
static uint16_t initOnlyReadReg(uint16_t addr);
|
2026-06-26 00:57:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif /* COMM_ESC_LAN9252_H */
|