151 lines
5.9 KiB
C
151 lines
5.9 KiB
C
/**
|
|||
|
|
* @file el9800hw.h
|
||
|
|
* @brief SSC 硬件抽象层 — GD32E508 + LAN9252 (EXMC 16-bit HBI Indexed Mode)
|
||
|
|
*
|
||
|
|
* 本文件替换 Beckhoff EL9800 SPI 版本,提供 SSC 所需的 HW_EscRead/Write 宏
|
||
|
|
* 和中断/定时器控制宏。实际实现在 hw_gd32exmc.cpp。
|
||
|
|
*
|
||
|
|
* HBI Indexed 寻址(A2=PD12=A17, A1=PD11=A16):
|
||
|
|
* IDX_0 = EXMC offset 0x00000 (A2=0, A1=0)
|
||
|
|
* DATA_0 = EXMC offset 0x20000 (A2=1, A1=0) 低 16 位
|
||
|
|
* = EXMC offset 0x30000 (A2=1, A1=1) 高 16 位
|
||
|
|
*/
|
||
|
|
#ifndef _EL9800HW_H_
|
||
|
|
#define _EL9800HW_H_
|
||
|
|
|
||
|
|
/*-----------------------------------------------------------------------------------------
|
||
|
|
------
|
||
|
|
------ Includes
|
||
|
|
------
|
||
|
|
-----------------------------------------------------------------------------------------*/
|
||
|
|
#include "esc.h"
|
||
|
|
|
||
|
|
/* GD32E508 CMSIS (通过 RTE 组件获取) */
|
||
|
|
#include "RTE_Components.h"
|
||
|
|
#include CMSIS_device_header
|
||
|
|
|
||
|
|
/*-----------------------------------------------------------------------------------------
|
||
|
|
------
|
||
|
|
------ Hardware Timer Settings
|
||
|
|
------
|
||
|
|
-----------------------------------------------------------------------------------------*/
|
||
|
|
|
||
|
|
/** SSC 看门狗定时器分辨率:ticks per ms。
|
||
|
|
* 本项目使用 SysTick (180MHz / 1000 = 180000 ticks/ms)。
|
||
|
|
* 实际由 hw_gd32exmc.cpp 中 HW_GetTimer() 实现决定。 */
|
||
|
|
#define ECAT_TIMER_INC_P_MS 180000
|
||
|
|
|
||
|
|
/*-----------------------------------------------------------------------------------------
|
||
|
|
------
|
||
|
|
------ Interrupt Control (ESC IRQ = EXTI1, PB1)
|
||
|
|
------
|
||
|
|
-----------------------------------------------------------------------------------------*/
|
||
|
|
|
||
|
|
#ifndef DISABLE_ESC_INT
|
||
|
|
#define DISABLE_ESC_INT() NVIC_DisableIRQ(EXTI1_IRQn)
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef ENABLE_ESC_INT
|
||
|
|
#define ENABLE_ESC_INT() NVIC_EnableIRQ(EXTI1_IRQn)
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/*-----------------------------------------------------------------------------------------
|
||
|
|
------
|
||
|
|
------ AL Event Interrupt Mask (主循环保护)
|
||
|
|
------
|
||
|
|
------ SSC 在主循环中访问 ESC 时需要 mask SYNC0 ISR (EXTI0, preempt=0)
|
||
|
|
------ 防止 HBI IDX 寄存器被 ISR 抢占导致地址错乱。
|
||
|
|
-----------------------------------------------------------------------------------------*/
|
||
|
|
|
||
|
|
#ifndef DISABLE_AL_EVENT_INT
|
||
|
|
#define DISABLE_AL_EVENT_INT() do { NVIC_DisableIRQ(EXTI0_IRQn); NVIC_DisableIRQ(EXTI1_IRQn); } while(0)
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef ENABLE_AL_EVENT_INT
|
||
|
|
#define ENABLE_AL_EVENT_INT() do { NVIC_EnableIRQ(EXTI1_IRQn); NVIC_EnableIRQ(EXTI0_IRQn); } while(0)
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/*-----------------------------------------------------------------------------------------
|
||
|
|
------
|
||
|
|
------ Timer Access
|
||
|
|
------
|
||
|
|
-----------------------------------------------------------------------------------------*/
|
||
|
|
|
||
|
|
#ifndef HW_GetTimer
|
||
|
|
#define HW_GetTimer() HW_GetTimerValue()
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef HW_ClearTimer
|
||
|
|
#define HW_ClearTimer() HW_ClearTimerValue()
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/*-----------------------------------------------------------------------------------------
|
||
|
|
------
|
||
|
|
------ ESC Access Macros (SSC 核心接口)
|
||
|
|
------
|
||
|
|
------ MEM_ADDR = UINT16 (CONTROLLER_16BIT=1)
|
||
|
|
------ 所有宏最终调用 HW_EscRead / HW_EscWrite (hw_gd32exmc.cpp)
|
||
|
|
-----------------------------------------------------------------------------------------*/
|
||
|
|
|
||
|
|
#define HW_EscReadByte(ByteValue, Address) HW_EscRead(((MEM_ADDR *)&(ByteValue)), ((UINT16)(Address)), 1)
|
||
|
|
#define HW_EscReadWord(WordValue, Address) HW_EscRead(((MEM_ADDR *)&(WordValue)), ((UINT16)(Address)), 2)
|
||
|
|
#define HW_EscReadDWord(DWordValue, Address) HW_EscRead(((MEM_ADDR *)&(DWordValue)), ((UINT16)(Address)), 4)
|
||
|
|
#define HW_EscReadMbxMem(pData, Address, Len) HW_EscRead(((MEM_ADDR *)(pData)), ((UINT16)(Address)), (Len))
|
||
|
|
|
||
|
|
#define HW_EscReadByteIsr(ByteValue, Address) HW_EscReadIsr(((MEM_ADDR *)&(ByteValue)), ((UINT16)(Address)), 1)
|
||
|
|
#define HW_EscReadWordIsr(WordValue, Address) HW_EscReadIsr(((MEM_ADDR *)&(WordValue)), ((UINT16)(Address)), 2)
|
||
|
|
#define HW_EscReadDWordIsr(DWordValue, Address) HW_EscReadIsr(((MEM_ADDR *)&(DWordValue)), ((UINT16)(Address)), 4)
|
||
|
|
|
||
|
|
#define HW_EscWriteByte(ByteValue, Address) HW_EscWrite(((MEM_ADDR *)&(ByteValue)), ((UINT16)(Address)), 1)
|
||
|
|
#define HW_EscWriteWord(WordValue, Address) HW_EscWrite(((MEM_ADDR *)&(WordValue)), ((UINT16)(Address)), 2)
|
||
|
|
#define HW_EscWriteDWord(DWordValue, Address) HW_EscWrite(((MEM_ADDR *)&(DWordValue)), ((UINT16)(Address)), 4)
|
||
|
|
#define HW_EscWriteMbxMem(pData, Address, Len) HW_EscWrite(((MEM_ADDR *)(pData)), ((UINT16)(Address)), (Len))
|
||
|
|
|
||
|
|
#define HW_EscWriteByteIsr(ByteValue, Address) HW_EscWriteIsr(((MEM_ADDR *)&(ByteValue)), ((UINT16)(Address)), 1)
|
||
|
|
#define HW_EscWriteWordIsr(WordValue, Address) HW_EscWriteIsr(((MEM_ADDR *)&(WordValue)), ((UINT16)(Address)), 2)
|
||
|
|
#define HW_EscWriteDWordIsr(DWordValue, Address) HW_EscWriteIsr(((MEM_ADDR *)&(DWordValue)), ((UINT16)(Address)), 4)
|
||
|
|
|
||
|
|
#endif /* _EL9800HW_H_ */
|
||
|
|
|
||
|
|
/*-----------------------------------------------------------------------------------------
|
||
|
|
------
|
||
|
|
------ Function Prototypes
|
||
|
|
------
|
||
|
|
-----------------------------------------------------------------------------------------*/
|
||
|
|
#if _EL9800HW_
|
||
|
|
#define PROTO
|
||
|
|
#else
|
||
|
|
#define PROTO extern
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
extern "C" {
|
||
|
|
#endif
|
||
|
|
|
||
|
|
PROTO UINT8 HW_Init(void);
|
||
|
|
PROTO void HW_Release(void);
|
||
|
|
PROTO UINT16 HW_GetALEventRegister(void);
|
||
|
|
PROTO UINT16 HW_GetALEventRegister_Isr(void);
|
||
|
|
PROTO void HW_ResetALEventMask(UINT16 intMask);
|
||
|
|
PROTO void HW_SetALEventMask(UINT16 intMask);
|
||
|
|
PROTO void HW_SetLed(UINT8 RunLed, UINT8 ErrLed);
|
||
|
|
|
||
|
|
PROTO void HW_EscRead(MEM_ADDR *pData, UINT16 Address, UINT16 Len);
|
||
|
|
PROTO void HW_EscReadIsr(MEM_ADDR *pData, UINT16 Address, UINT16 Len);
|
||
|
|
PROTO void HW_EscWrite(MEM_ADDR *pData, UINT16 Address, UINT16 Len);
|
||
|
|
PROTO void HW_EscWriteIsr(MEM_ADDR *pData, UINT16 Address, UINT16 Len);
|
||
|
|
|
||
|
|
PROTO void HW_DisableSyncManChannel(UINT8 channel);
|
||
|
|
PROTO void HW_EnableSyncManChannel(UINT8 channel);
|
||
|
|
PROTO TSYNCMAN ESCMEM *HW_GetSyncMan(UINT8 channel);
|
||
|
|
|
||
|
|
/* Timer helpers (implemented in hw_gd32exmc.cpp) */
|
||
|
|
PROTO UINT32 HW_GetTimerValue(void);
|
||
|
|
PROTO void HW_ClearTimerValue(void);
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#undef PROTO
|