Detailed Description
General
The SOES is a library that provides the Micro Controller user application with the means to access the EtherCAT fieldbus communication environment:
- EtherCAT State Machine
- Mailbox Interfaces
- Protocols
- CoE
- FoE + bootstrap template
Support for mailbox and protocols are typical examples when you need a slave stack to control the Application Layer of EtherCAT. The PDI used for such applications is either SPI or some Micro Controller Interface
The following sections show some basic examples on how to get the SOES up and running, as well as a lightweight example on howto design your slave. Since all code is local to the application or global variables, it is possible to tweak and optimize when possible.
Our target Application:
- Inputs 40bit
- One button 8bit
- One encoder value 32bit
- Outputs 8bit
- LED 8bit
- Parameters
- Encoder settings
- Slave commands
- Reset counter
Now to translate and implement on top of SOES.
First look on the start up code. This example shows how to add a main function that will be called by startup code. In this example main's only purpose is to spawn(产生) two new tasks. One that executes SOES and one that control the ERROR LED. Some ESCs provided a pin for the RUN LED, some even for the ERROR LED, if it don't you can control them from the slave Micro Controller. We'll focus on the "soes" task.主要关注soe任务
int main (void) { rprintp ("SOES (Simple Open EtherCAT Slave)\nsoes test\n"); /* task_spawn ("led_run", led_error, 15, 512, NULL); / task_spawn ("led_error", led_error, 15, 512, NULL); task_spawn ("soes", soes, 9, 1024, NULL); return (0); }
Configuration
The function soes is our EtherCAT slave device and can be split in 3 parts. Hardware Init, Software Init and Application loop. We will start with the Hardware Init.包括硬件初始化,软件初始化,应用循环
- Hardware Init
- esc_reset, special function used for ESC reset if no Physical EEPROM used. This is local to the Application not part of the generic ESC handling.
- ESC_init, initialise SPI communication or similar SPI初始化
- Wait for ESC is started, waiting for SPI to be up and running, we'll query the ESC register DL status if EEPROM loaded OK and PDI operational, eg. SPI OK.等待ESC started up
void soes (void *arg) { TXPDOsize = SM3_sml = sizeTXPDO (); RXPDOsize = SM2_sml = sizeRXPDO (); esc_reset (); ESC_init ((void *)spi_name); task_delay (tick_from_ms (200)); // wait until ESC is started up while ((ESCvar.DLstatus & 0x0001) == 0) { ESC_read (ESCREG_DLSTATUS, (void *) &ESCvar.DLstatus, sizeof (ESCvar.DLstatus), (void *) &ESCvar.