Driver Interface
The EtherCAT library uses an Hardware Abstraction Layer (HAL). Usually a delivery of this library contains a driver package that is ready to run. But you might need to do some adaption or you have decided to write your own driver package.
The files ec_cpu_xxx.c and ec_cpu_xxx.h implement CPU specific tasks.
Task | Function |
---|---|
printing debug messages (blocking/non-blocking) | ec_drvPrint(), ec_drvPutchar() |
initializing the timer | ec_initTimer() |
handling the timer interrupt | ISR must call ec_tmrIrq() |
enabling disabling the interrupts | target specific functions should be mapped to macros EC_DRV_INT_ENABLE and EC_DRV_INT_DISABLE in header file |
Table: function usage in ec_cpu_xxx.c/.h
Â
The file ec_init_xxx.c is responsible for connecting the ESC to the application CPU.
Task | Function |
---|---|
set up all GPIOs and configure interfaces, enable interrupts | ec_initDevice() |
set up interface to ESC and set ESC base address | ec_escHwInit() |
set the expected PDI ID | ec_escHwReadyCheck() |
implement the target specific ISRs for PDI & DC interrupts | ISR must call ec_mainIrqPdi() or ec_mainIrqSync0() |
Table: function usage in ec_init_xxx.c
Â
The function must set the base address of the ESC if the ESC is memory mapped. This is done in ec_escHwInit().
If the ESC is connected via SPI to the CPU the macro EC_CONFIG_SPI must be defined. In that case all ESC access functions call the following functions that must be implemented in the driver.
Function | Description |
---|---|
ec_spiWriteCopy() | write data to the ESC via SPI |
ec_spiReadCopy() | read data from the ESC via SPI |
Table: ESC access via SPI
Â
Please note that the SPI driver also depends on the ESC. ESCs from different vendors require different addressing mechanisms.
Other ESC might require a Board Support Package (BSP) for special handling of each access, e.g. if the ESC is emulated in a co-processor.
In that case the macro EC_CONFIG_BSP must be defined so that all ESC access functions are redirected to the following driver functions:
Function | Description |
---|---|
ec_escBspReadB() | read BYTE from ESC |
ec_escBspReadW() | read WORD from ESC |
ec_escBspReadL() | read DWORD from ESC |
ec_escBspWriteB() | write BYTE to ESC |
ec_escBspWriteW() | write WORD to ESC |
ec_escBspWriteL() | write DWORD o ESC |
ec_escBspWriteGen() | write arbitrary data to ESC |
ec_escBspReadGen() | read arbitrary data from ESC |
Table: ESC Access via BSP
In these functions you can also trigger special handlers of the emulated ESC if required.