Main EtherCAT functions. More...
#include <stdio.h>
#include <string.h>
#include "osal.h"
#include "oshw.h"
#include "ethercattype.h"
#include "ethercatbase.h"
#include "ethercatmain.h"
Go to the source code of this file.
Classes | |
struct | PACKED |
struct | PACKED |
struct | PACKED |
Macros | |
#define | EC_LOCALDELAY 200 |
Typedefs | |
typedef PACKED_BEGIN struct PACKED | ec_eepromt |
typedef PACKED_END PACKED_BEGIN struct PACKED | ec_emcyt |
typedef PACKED_END PACKED_BEGIN struct PACKED | ec_mbxerrort |
Variables | |
int64 | ec_DCtime |
static ec_eringt | ec_elist |
static ec_eepromFMMUt | ec_FMMU |
ec_groupt | ec_group [EC_MAXGROUP] |
static ec_idxstackT | ec_idxstack |
static ec_PDOassignt | ec_PDOassign |
static ec_PDOdesct | ec_PDOdesc |
PACKED_END ec_slavet | ec_slave [EC_MAXSLAVE] |
int | ec_slavecount |
static ec_eepromSMt | ec_SM |
static ec_SMcommtypet | ec_SMcommtype |
boolean | EcatError = FALSE |
ecx_contextt | ecx_context |
ecx_portt | ecx_port |
ecx_redportt | ecx_redport |
static uint8 | esibuf [EC_MAXEEPBUF] |
static uint32 | esimap [EC_MAXEEPBITMAP] |
Main EtherCAT functions.
Initialisation, state set and read, mailbox primitives, EEPROM primitives, SII reading and processdata exchange.
Defines ec_slave[]. All slave information is put in this structure. Needed for most user interaction with slaves.
Definition in file ethercatmain.c.
#define EC_LOCALDELAY 200 |
delay in us for eeprom ready loop
Definition at line 63 of file ethercatmain.c.
typedef PACKED_BEGIN struct PACKED ec_eepromt |
record for ethercat eeprom communications
typedef PACKED_END PACKED_BEGIN struct PACKED ec_mbxerrort |
mailbox error structure
void ec_clearmbx | ( | ec_mbxbuft * | Mbx | ) |
Clear mailbox buffer.
[out] | Mbx | = Mailbox buffer to clear |
Definition at line 832 of file ethercatmain.c.
void ec_close | ( | void | ) |
Definition at line 1852 of file ethercatmain.c.
int ec_eeprom2master | ( | uint16 | slave | ) |
Definition at line 1937 of file ethercatmain.c.
int ec_eeprom2pdi | ( | uint16 | slave | ) |
Definition at line 1942 of file ethercatmain.c.
Definition at line 1947 of file ethercatmain.c.
Definition at line 1962 of file ethercatmain.c.
Definition at line 1922 of file ethercatmain.c.
ec_adaptert* ec_find_adapters | ( | void | ) |
Create list over available network adapters.
Definition at line 165 of file ethercatmain.c.
void ec_free_adapters | ( | ec_adaptert * | adapter | ) |
Free dynamically allocated list over available network adapters.
[in] | adapter | = Struct holding adapter name, description and pointer to next. |
Definition at line 178 of file ethercatmain.c.
int ec_init | ( | char * | ifname | ) |
Definition at line 1842 of file ethercatmain.c.
int ec_init_redundant | ( | char * | ifname, |
char * | if2name | ||
) |
Definition at line 1847 of file ethercatmain.c.
boolean ec_iserror | ( | void | ) |
Definition at line 1821 of file ethercatmain.c.
|
static |
Definition at line 1836 of file ethercatmain.c.
int ec_mbxempty | ( | uint16 | slave, |
int | timeout | ||
) |
Definition at line 1907 of file ethercatmain.c.
Definition at line 1831 of file ethercatmain.c.
int ec_mbxreceive | ( | uint16 | slave, |
ec_mbxbuft * | mbx, | ||
int | timeout | ||
) |
Definition at line 1917 of file ethercatmain.c.
int ec_mbxsend | ( | uint16 | slave, |
ec_mbxbuft * | mbx, | ||
int | timeout | ||
) |
Definition at line 1912 of file ethercatmain.c.
Get index of next mailbox counter value. Used for Mailbox Link Layer.
[in] | cnt | = Mailbox counter value [0..7] |
Definition at line 818 of file ethercatmain.c.
Definition at line 1826 of file ethercatmain.c.
Definition at line 1816 of file ethercatmain.c.
void ec_pusherror | ( | const ec_errort * | Ec | ) |
Definition at line 1811 of file ethercatmain.c.
Definition at line 1927 of file ethercatmain.c.
Definition at line 1977 of file ethercatmain.c.
Definition at line 1982 of file ethercatmain.c.
Definition at line 1952 of file ethercatmain.c.
Definition at line 1967 of file ethercatmain.c.
int ec_readstate | ( | void | ) |
Definition at line 1892 of file ethercatmain.c.
int ec_receive_processdata | ( | int | timeout | ) |
Definition at line 2002 of file ethercatmain.c.
int ec_receive_processdata_group | ( | uint8 | group, |
int | timeout | ||
) |
Definition at line 1992 of file ethercatmain.c.
int ec_send_processdata | ( | void | ) |
Definition at line 1997 of file ethercatmain.c.
int ec_send_processdata_group | ( | uint8 | group | ) |
Definition at line 1987 of file ethercatmain.c.
Definition at line 1862 of file ethercatmain.c.
uint16 ec_siiFMMU | ( | uint16 | slave, |
ec_eepromFMMUt * | FMMU | ||
) |
Definition at line 1872 of file ethercatmain.c.
Definition at line 1857 of file ethercatmain.c.
int ec_siiPDO | ( | uint16 | slave, |
ec_eepromPDOt * | PDO, | ||
uint8 | t | ||
) |
Definition at line 1887 of file ethercatmain.c.
uint16 ec_siiSM | ( | uint16 | slave, |
ec_eepromSMt * | SM | ||
) |
Definition at line 1877 of file ethercatmain.c.
uint16 ec_siiSMnext | ( | uint16 | slave, |
ec_eepromSMt * | SM, | ||
uint16 | n | ||
) |
Definition at line 1882 of file ethercatmain.c.
Definition at line 1867 of file ethercatmain.c.
Definition at line 1902 of file ethercatmain.c.
Definition at line 1932 of file ethercatmain.c.
Definition at line 1957 of file ethercatmain.c.
Definition at line 1972 of file ethercatmain.c.
int ec_writestate | ( | uint16 | slave | ) |
Definition at line 1897 of file ethercatmain.c.
void ecx_close | ( | ecx_contextt * | context | ) |
int ecx_eeprom2master | ( | ecx_contextt * | context, |
uint16 | slave | ||
) |
Set eeprom control to master. Only if set to PDI.
[in] | context | = context struct |
[in] | slave | = Slave number |
Definition at line 1078 of file ethercatmain.c.
int ecx_eeprom2pdi | ( | ecx_contextt * | context, |
uint16 | slave | ||
) |
Set eeprom control to PDI. Only if set to master.
[in] | context | = context struct |
[in] | slave | = Slave number |
Definition at line 1111 of file ethercatmain.c.
uint16 ecx_eeprom_waitnotbusyAP | ( | ecx_contextt * | context, |
uint16 | aiadr, | ||
uint16 * | estat, | ||
int | timeout | ||
) |
Definition at line 1132 of file ethercatmain.c.
uint16 ecx_eeprom_waitnotbusyFP | ( | ecx_contextt * | context, |
uint16 | configadr, | ||
uint16 * | estat, | ||
int | timeout | ||
) |
Definition at line 1300 of file ethercatmain.c.
void ecx_esidump | ( | ecx_contextt * | context, |
uint16 | slave, | ||
uint8 * | esibuf | ||
) |
Dump complete EEPROM data from slave in buffer.
[in] | context | = context struct |
[in] | slave | = Slave number |
[out] | esibuf | = EEPROM data buffer, make sure it is big enough. |
Definition at line 1003 of file ethercatmain.c.
int ecx_init | ( | ecx_contextt * | context, |
char * | ifname | ||
) |
Initialise lib in single NIC mode
[in] | context | = context struct |
[in] | ifname | = Dev name, f.e. "eth0" |
Definition at line 319 of file ethercatmain.c.
int ecx_init_redundant | ( | ecx_contextt * | context, |
ecx_redportt * | redport, | ||
char * | ifname, | ||
char * | if2name | ||
) |
Initialise lib in redundant NIC mode
[in] | context | = context struct |
[in] | redport | = pointer to redport, redundant port data |
[in] | ifname | = Primary Dev name, f.e. "eth0" |
[in] | if2name | = Secondary Dev name, f.e. "eth1" |
Definition at line 331 of file ethercatmain.c.
boolean ecx_iserror | ( | ecx_contextt * | context | ) |
Check if error list has entries.
[in] | context | = context struct |
Definition at line 240 of file ethercatmain.c.
|
static |
Report Mailbox Emergency Error
[in] | context | = context struct |
[in] | Slave | = Slave number |
[in] | ErrorCode | = Following EtherCAT specification |
[in] | ErrorReg | |
[in] | b1 | |
[in] | w1 | |
[in] | w2 |
Definition at line 296 of file ethercatmain.c.
int ecx_mbxempty | ( | ecx_contextt * | context, |
uint16 | slave, | ||
int | timeout | ||
) |
Check if IN mailbox of slave is empty.
[in] | context | = context struct |
[in] | slave | = Slave number |
[in] | timeout | = Timeout in us |
Definition at line 843 of file ethercatmain.c.
|
static |
Report Mailbox Error
[in] | context | = context struct |
[in] | Slave | = Slave number |
[in] | Detail | = Following EtherCAT specification |
Definition at line 273 of file ethercatmain.c.
int ecx_mbxreceive | ( | ecx_contextt * | context, |
uint16 | slave, | ||
ec_mbxbuft * | mbx, | ||
int | timeout | ||
) |
Read OUT mailbox from slave. Supports Mailbox Link Layer with repeat requests.
[in] | context | = context struct |
[in] | slave | = Slave number |
[out] | mbx | = Mailbox data |
[in] | timeout | = Timeout in us |
Definition at line 911 of file ethercatmain.c.
int ecx_mbxsend | ( | ecx_contextt * | context, |
uint16 | slave, | ||
ec_mbxbuft * | mbx, | ||
int | timeout | ||
) |
Write IN mailbox to slave.
[in] | context | = context struct |
[in] | slave | = Slave number |
[out] | mbx | = Mailbox data |
[in] | timeout | = Timeout in us |
Definition at line 878 of file ethercatmain.c.
void ecx_packeterror | ( | ecx_contextt * | context, |
uint16 | Slave, | ||
uint16 | Index, | ||
uint8 | SubIdx, | ||
uint16 | ErrorCode | ||
) |
Report packet error
[in] | context | = context struct |
[in] | Slave | = Slave number |
[in] | Index | = Index that generated error |
[in] | SubIdx | = Subindex that generated error |
[in] | ErrorCode | = Error code |
Definition at line 253 of file ethercatmain.c.
boolean ecx_poperror | ( | ecx_contextt * | context, |
ec_errort * | Ec | ||
) |
Pops an error from the list.
[in] | context | = context struct |
[out] | Ec | = Struct describing the error. |
Definition at line 214 of file ethercatmain.c.
|
static |
Pull index of segmented LRD/LWR/LRW combination.
[in] | context | = context struct |
Definition at line 1547 of file ethercatmain.c.
void ecx_pusherror | ( | ecx_contextt * | context, |
const ec_errort * | Ec | ||
) |
Pushes an error on the error list.
[in] | context | = context struct |
[in] | Ec | pointer describing the error. |
Definition at line 188 of file ethercatmain.c.
|
static |
Push index of segmented LRD/LWR/LRW combination.
[in] | context | = context struct |
[in] | idx | = Used datagram index. |
[in] | data | = Pointer to process data segment. |
[in] | length | = Length of data segment in bytes. |
Definition at line 1532 of file ethercatmain.c.
uint32 ecx_readeeprom | ( | ecx_contextt * | context, |
uint16 | slave, | ||
uint16 | eeproma, | ||
int | timeout | ||
) |
Read EEPROM from slave bypassing cache.
[in] | context | = context struct |
[in] | slave | = Slave number |
[in] | eeproma | = (WORD) Address in the EEPROM |
[in] | timeout | = Timeout in us. |
Definition at line 1046 of file ethercatmain.c.
void ecx_readeeprom1 | ( | ecx_contextt * | context, |
uint16 | slave, | ||
uint16 | eeproma | ||
) |
Read EEPROM from slave bypassing cache. Parallel read step 1, make request to slave.
[in] | context | = context struct |
[in] | slave | = Slave number |
[in] | eeproma | = (WORD) Address in the EEPROM |
Definition at line 1472 of file ethercatmain.c.
uint32 ecx_readeeprom2 | ( | ecx_contextt * | context, |
uint16 | slave, | ||
int | timeout | ||
) |
Read EEPROM from slave bypassing cache. Parallel read step 2, actual read from slave.
[in] | context | = context struct |
[in] | slave | = Slave number |
[in] | timeout | = Timeout in us. |
Definition at line 1505 of file ethercatmain.c.
uint64 ecx_readeepromAP | ( | ecx_contextt * | context, |
uint16 | aiadr, | ||
uint16 | eeproma, | ||
int | timeout | ||
) |
Read EEPROM from slave bypassing cache. APRD method.
[in] | context | = context struct |
[in] | aiadr | = auto increment address of slave |
[in] | eeproma | = (WORD) Address in the EEPROM |
[in] | timeout | = Timeout in us. |
Definition at line 1163 of file ethercatmain.c.
uint64 ecx_readeepromFP | ( | ecx_contextt * | context, |
uint16 | configadr, | ||
uint16 | eeproma, | ||
int | timeout | ||
) |
Read EEPROM from slave bypassing cache. FPRD method.
[in] | context | = context struct |
[in] | configadr | = configured address of slave |
[in] | eeproma | = (WORD) Address in the EEPROM |
[in] | timeout | = Timeout in us. |
Definition at line 1331 of file ethercatmain.c.
int ecx_readstate | ( | ecx_contextt * | context | ) |
Read all slave states in ec_slave.
[in] | context | = context struct |
Definition at line 714 of file ethercatmain.c.
int ecx_receive_processdata | ( | ecx_contextt * | context, |
int | timeout | ||
) |
Definition at line 1805 of file ethercatmain.c.
int ecx_receive_processdata_group | ( | ecx_contextt * | context, |
uint8 | group, | ||
int | timeout | ||
) |
Receive processdata from slaves. Second part from ec_send_processdata(). Received datagrams are recombined with the processdata with help from the stack. If a datagram contains input processdata it copies it to the processdata structure.
[in] | context | = context struct |
[in] | group | = group number |
[in] | timeout | = Timeout in us. |
Definition at line 1732 of file ethercatmain.c.
int ecx_send_processdata | ( | ecx_contextt * | context | ) |
Definition at line 1800 of file ethercatmain.c.
int ecx_send_processdata_group | ( | ecx_contextt * | context, |
uint8 | group | ||
) |
Transmit processdata to slaves. Uses LRW, or LRD/LWR if LRW is not allowed (blockLRW). Both the input and output processdata are transmitted. The outputs with the actual data, the inputs have a placeholder. The inputs are gathered with the receive processdata function. In contrast to the base LRW function this function is non-blocking. If the processdata does not fit in one datagram, multiple are used. In order to recombine the slave response, a stack is used.
[in] | context | = context struct |
[in] | group | = group number |
Definition at line 1571 of file ethercatmain.c.
int16 ecx_siifind | ( | ecx_contextt * | context, |
uint16 | slave, | ||
uint16 | cat | ||
) |
Find SII section header in slave EEPROM.
[in] | context | = context struct |
[in] | slave | = slave number |
[in] | cat | = section category |
Definition at line 434 of file ethercatmain.c.
uint16 ecx_siiFMMU | ( | ecx_contextt * | context, |
uint16 | slave, | ||
ec_eepromFMMUt * | FMMU | ||
) |
Get FMMU data from SII FMMU section in slave EEPROM.
[in] | context | = context struct |
[in] | slave | = slave number |
[out] | FMMU | = FMMU struct from SII, max. 4 FMMU's |
Definition at line 532 of file ethercatmain.c.
uint8 ecx_siigetbyte | ( | ecx_contextt * | context, |
uint16 | slave, | ||
uint16 | address | ||
) |
Read one byte from slave EEPROM via cache. If the cache location is empty then a read request is made to the slave. Depending on the slave capabillities the request is 4 or 8 bytes.
[in] | context | = context struct |
[in] | slave | = slave number |
[in] | address | = eeprom address in bytes (slave uses words) |
Definition at line 365 of file ethercatmain.c.
int ecx_siiPDO | ( | ecx_contextt * | context, |
uint16 | slave, | ||
ec_eepromPDOt * | PDO, | ||
uint8 | t | ||
) |
Get PDO data from SII PDO section in slave EEPROM.
[in] | context | = context struct |
[in] | slave | = slave number |
[out] | PDO | = PDO struct from SII |
[in] | t | = 0=RXPDO 1=TXPDO |
Definition at line 643 of file ethercatmain.c.
uint16 ecx_siiSM | ( | ecx_contextt * | context, |
uint16 | slave, | ||
ec_eepromSMt * | SM | ||
) |
Get SM data from SII SM section in slave EEPROM.
[in] | context | = context struct |
[in] | slave | = slave number |
[out] | SM | = first SM struct from SII |
Definition at line 572 of file ethercatmain.c.
uint16 ecx_siiSMnext | ( | ecx_contextt * | context, |
uint16 | slave, | ||
ec_eepromSMt * | SM, | ||
uint16 | n | ||
) |
Get next SM data from SII SM section in slave EEPROM.
[in] | context | = context struct |
[in] | slave | = slave number |
[out] | SM | = first SM struct from SII |
[in] | n | = SM number |
Definition at line 609 of file ethercatmain.c.
void ecx_siistring | ( | ecx_contextt * | context, |
char * | str, | ||
uint16 | slave, | ||
uint16 | Sn | ||
) |
Get string from SII string section in slave EEPROM.
[in] | context | = context struct |
[out] | str | = requested string, 0x00 if not found |
[in] | slave | = slave number |
[in] | Sn | = string number |
Definition at line 474 of file ethercatmain.c.
uint16 ecx_statecheck | ( | ecx_contextt * | context, |
uint16 | slave, | ||
uint16 | reqstate, | ||
int | timeout | ||
) |
Check actual slave state. This is a blocking function.
[in] | context | = context struct |
[in] | slave | = Slave number, 0 = all slaves |
[in] | reqstate | = Requested state |
[in] | timeout | = Timout value in us |
Definition at line 773 of file ethercatmain.c.
int ecx_writeeeprom | ( | ecx_contextt * | context, |
uint16 | slave, | ||
uint16 | eeproma, | ||
uint16 | data, | ||
int | timeout | ||
) |
Write EEPROM to slave bypassing cache.
[in] | context | = context struct |
[in] | slave | = Slave number |
[in] | eeproma | = (WORD) Address in the EEPROM |
[in] | data | = 16bit data |
[in] | timeout | = Timeout in us. |
Definition at line 1064 of file ethercatmain.c.
int ecx_writeeepromAP | ( | ecx_contextt * | context, |
uint16 | aiadr, | ||
uint16 | eeproma, | ||
uint16 | data, | ||
int | timeout | ||
) |
Write EEPROM to slave bypassing cache. APWR method.
[in] | context | = context struct |
[in] | aiadr | = configured address of slave |
[in] | eeproma | = (WORD) Address in the EEPROM |
[in] | data | = 16bit data |
[in] | timeout | = Timeout in us. |
Definition at line 1243 of file ethercatmain.c.
int ecx_writeeepromFP | ( | ecx_contextt * | context, |
uint16 | configadr, | ||
uint16 | eeproma, | ||
uint16 | data, | ||
int | timeout | ||
) |
Write EEPROM to slave bypassing cache. FPWR method.
[in] | context | = context struct |
[in] | configadr | = configured address of slave |
[in] | eeproma | = (WORD) Address in the EEPROM |
[in] | data | = 16bit data |
[in] | timeout | = Timeout in us. |
Definition at line 1411 of file ethercatmain.c.
int ecx_writestate | ( | ecx_contextt * | context, |
uint16 | slave | ||
) |
Write slave state, if slave = 0 then write to all slaves. The function does not check if the actual state is changed.
[in] | context | = context struct |
[in] | slave | = Slave number, 0 = master |
Definition at line 747 of file ethercatmain.c.
int64 ec_DCtime |
Definition at line 132 of file ethercatmain.c.
|
static |
current slave for EEPROM cache buffer
Definition at line 115 of file ethercatmain.c.
|
static |
buffer for EEPROM FMMU data
Definition at line 128 of file ethercatmain.c.
ec_groupt ec_group[EC_MAXGROUP] |
slave group structure
Definition at line 108 of file ethercatmain.c.
|
static |
Definition at line 116 of file ethercatmain.c.
|
static |
PDO assign struct to store data of one slave
Definition at line 121 of file ethercatmain.c.
|
static |
PDO description struct to store data of one slave
Definition at line 123 of file ethercatmain.c.
PACKED_END ec_slavet ec_slave[EC_MAXSLAVE] |
Main slave data array. Each slave found on the network gets its own record. ec_slave[0] is reserved for the master. Structure gets filled in by the configuration function ec_config().
Definition at line 104 of file ethercatmain.c.
int ec_slavecount |
number of slaves found on the network
Definition at line 106 of file ethercatmain.c.
|
static |
buffer for EEPROM SM data
Definition at line 126 of file ethercatmain.c.
|
static |
SyncManager Communication Type struct to store data of one slave
Definition at line 119 of file ethercatmain.c.
Global variable TRUE if error available in error stack
Definition at line 130 of file ethercatmain.c.
ecx_contextt ecx_context |
ecx_portt ecx_port |
Definition at line 134 of file ethercatmain.c.
ecx_redportt ecx_redport |
Definition at line 135 of file ethercatmain.c.
|
static |
cache for EEPROM read functions
Definition at line 111 of file ethercatmain.c.
|
static |
bitmap for filled cache buffer bytes
Definition at line 113 of file ethercatmain.c.