SOEM  v1.4.0
Data Structures | Macros | Typedefs | Functions
ethercatmain.h File Reference

Headerfile for ethercatmain.c. More...

Data Structures

struct  ec_adaptert
 
struct  ec_fmmut
 
struct  ec_smt
 
struct  ec_state_status
 
struct  ec_slavet
 
struct  ec_groupt
 
struct  ec_eepromFMMUt
 
struct  ec_eepromSMt
 
struct  ec_eepromPDOt
 
struct  ec_mbxheadert
 
struct  ec_alstatust
 
struct  ec_idxstackT
 
struct  ec_eringt
 
struct  ec_SMcommtypet
 
struct  ec_PDOassignt
 
struct  ec_PDOdesct
 
struct  ecx_contextt
 

Macros

#define EC_MAXELIST   64
 
#define EC_MAXNAME   40
 
#define EC_MAXSLAVE   200
 
#define EC_MAXGROUP   2
 
#define EC_MAXIOSEGMENTS   64
 
#define EC_MAXMBX   1486
 
#define EC_MAXEEPDO   0x200
 
#define EC_MAXSM   8
 
#define EC_MAXFMMU   4
 
#define EC_MAXLEN_ADAPTERNAME   128
 
#define EC_MAX_MAPT   1
 
#define ECT_MBXPROT_AOE   0x0001
 
#define ECT_MBXPROT_EOE   0x0002
 
#define ECT_MBXPROT_COE   0x0004
 
#define ECT_MBXPROT_FOE   0x0008
 
#define ECT_MBXPROT_SOE   0x0010
 
#define ECT_MBXPROT_VOE   0x0020
 
#define ECT_COEDET_SDO   0x01
 
#define ECT_COEDET_SDOINFO   0x02
 
#define ECT_COEDET_PDOASSIGN   0x04
 
#define ECT_COEDET_PDOCONFIG   0x08
 
#define ECT_COEDET_UPLOAD   0x10
 
#define ECT_COEDET_SDOCA   0x20
 
#define EC_SMENABLEMASK   0xfffeffff
 

Typedefs

typedef uint8 ec_mbxbuft[EC_MAXMBX+1]
 

Functions

ec_adaptert * ec_find_adapters (void)
 
void ec_free_adapters (ec_adaptert *adapter)
 
uint8 ec_nextmbxcnt (uint8 cnt)
 
void ec_clearmbx (ec_mbxbuft *Mbx)
 
void ecx_pusherror (ecx_contextt *context, const ec_errort *Ec)
 
boolean ecx_poperror (ecx_contextt *context, ec_errort *Ec)
 
boolean ecx_iserror (ecx_contextt *context)
 
void ecx_packeterror (ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, uint16 ErrorCode)
 
int ecx_init (ecx_contextt *context, const char *ifname)
 
int ecx_init_redundant (ecx_contextt *context, ecx_redportt *redport, const char *ifname, char *if2name)
 
void ecx_close (ecx_contextt *context)
 
uint8 ecx_siigetbyte (ecx_contextt *context, uint16 slave, uint16 address)
 
int16 ecx_siifind (ecx_contextt *context, uint16 slave, uint16 cat)
 
void ecx_siistring (ecx_contextt *context, char *str, uint16 slave, uint16 Sn)
 
uint16 ecx_siiFMMU (ecx_contextt *context, uint16 slave, ec_eepromFMMUt *FMMU)
 
uint16 ecx_siiSM (ecx_contextt *context, uint16 slave, ec_eepromSMt *SM)
 
uint16 ecx_siiSMnext (ecx_contextt *context, uint16 slave, ec_eepromSMt *SM, uint16 n)
 
int ecx_siiPDO (ecx_contextt *context, uint16 slave, ec_eepromPDOt *PDO, uint8 t)
 
int ecx_readstate (ecx_contextt *context)
 
int ecx_writestate (ecx_contextt *context, uint16 slave)
 
uint16 ecx_statecheck (ecx_contextt *context, uint16 slave, uint16 reqstate, int timeout)
 
int ecx_mbxempty (ecx_contextt *context, uint16 slave, int timeout)
 
int ecx_mbxsend (ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout)
 
int ecx_mbxreceive (ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout)
 
void ecx_esidump (ecx_contextt *context, uint16 slave, uint8 *esibuf)
 
uint32 ecx_readeeprom (ecx_contextt *context, uint16 slave, uint16 eeproma, int timeout)
 
int ecx_writeeeprom (ecx_contextt *context, uint16 slave, uint16 eeproma, uint16 data, int timeout)
 
int ecx_eeprom2master (ecx_contextt *context, uint16 slave)
 
int ecx_eeprom2pdi (ecx_contextt *context, uint16 slave)
 
uint64 ecx_readeepromAP (ecx_contextt *context, uint16 aiadr, uint16 eeproma, int timeout)
 
int ecx_writeeepromAP (ecx_contextt *context, uint16 aiadr, uint16 eeproma, uint16 data, int timeout)
 
uint64 ecx_readeepromFP (ecx_contextt *context, uint16 configadr, uint16 eeproma, int timeout)
 
int ecx_writeeepromFP (ecx_contextt *context, uint16 configadr, uint16 eeproma, uint16 data, int timeout)
 
void ecx_readeeprom1 (ecx_contextt *context, uint16 slave, uint16 eeproma)
 
uint32 ecx_readeeprom2 (ecx_contextt *context, uint16 slave, int timeout)
 
int ecx_send_overlap_processdata_group (ecx_contextt *context, uint8 group)
 
int ecx_receive_processdata_group (ecx_contextt *context, uint8 group, int timeout)
 
int ecx_send_processdata (ecx_contextt *context)
 
int ecx_send_overlap_processdata (ecx_contextt *context)
 
int ecx_receive_processdata (ecx_contextt *context, int timeout)
 
int ecx_send_processdata_group (ecx_contextt *context, uint8 group)
 

Detailed Description

Headerfile for ethercatmain.c.

Macro Definition Documentation

◆ EC_MAX_MAPT

#define EC_MAX_MAPT   1

define maximum number of concurrent threads in mapping

◆ EC_MAXEEPDO

#define EC_MAXEEPDO   0x200

max. eeprom PDO entries

◆ EC_MAXELIST

#define EC_MAXELIST   64

max. entries in EtherCAT error list

◆ EC_MAXFMMU

#define EC_MAXFMMU   4

max. FMMU used

◆ EC_MAXGROUP

#define EC_MAXGROUP   2

max. number of groups

◆ EC_MAXIOSEGMENTS

#define EC_MAXIOSEGMENTS   64

max. number of IO segments per group

◆ EC_MAXLEN_ADAPTERNAME

#define EC_MAXLEN_ADAPTERNAME   128

max. Adapter

◆ EC_MAXMBX

#define EC_MAXMBX   1486

max. mailbox size

◆ EC_MAXNAME

#define EC_MAXNAME   40

max. length of readable name in slavelist and Object Description List

◆ EC_MAXSLAVE

#define EC_MAXSLAVE   200

max. number of slaves in array

◆ EC_MAXSM

#define EC_MAXSM   8

max. SM used

◆ EC_SMENABLEMASK

#define EC_SMENABLEMASK   0xfffeffff

◆ ECT_COEDET_PDOASSIGN

#define ECT_COEDET_PDOASSIGN   0x04

◆ ECT_COEDET_PDOCONFIG

#define ECT_COEDET_PDOCONFIG   0x08

◆ ECT_COEDET_SDO

#define ECT_COEDET_SDO   0x01

◆ ECT_COEDET_SDOCA

#define ECT_COEDET_SDOCA   0x20

◆ ECT_COEDET_SDOINFO

#define ECT_COEDET_SDOINFO   0x02

◆ ECT_COEDET_UPLOAD

#define ECT_COEDET_UPLOAD   0x10

◆ ECT_MBXPROT_AOE

#define ECT_MBXPROT_AOE   0x0001

◆ ECT_MBXPROT_COE

#define ECT_MBXPROT_COE   0x0004

◆ ECT_MBXPROT_EOE

#define ECT_MBXPROT_EOE   0x0002

◆ ECT_MBXPROT_FOE

#define ECT_MBXPROT_FOE   0x0008

◆ ECT_MBXPROT_SOE

#define ECT_MBXPROT_SOE   0x0010

◆ ECT_MBXPROT_VOE

#define ECT_MBXPROT_VOE   0x0020

Typedef Documentation

◆ ec_mbxbuft

typedef uint8 ec_mbxbuft[EC_MAXMBX+1]

mailbox buffer array

Function Documentation

◆ ec_clearmbx()

void ec_clearmbx ( ec_mbxbuft Mbx)

Clear mailbox buffer.

Parameters
[out]Mbx= Mailbox buffer to clear

◆ ec_find_adapters()

ec_adaptert* ec_find_adapters ( void  )

Create list over available network adapters.

Returns
First element in list over available network adapters.

◆ ec_free_adapters()

void ec_free_adapters ( ec_adaptert *  adapter)

Free dynamically allocated list over available network adapters.

Parameters
[in]adapter= Struct holding adapter name, description and pointer to next.

◆ ec_nextmbxcnt()

uint8 ec_nextmbxcnt ( uint8  cnt)

Get index of next mailbox counter value. Used for Mailbox Link Layer.

Parameters
[in]cnt= Mailbox counter value [0..7]
Returns
next mailbox counter value

◆ ecx_close()

void ecx_close ( ecx_contextt *  context)

Close lib.

Parameters
[in]context= context struct

◆ ecx_eeprom2master()

int ecx_eeprom2master ( ecx_contextt *  context,
uint16  slave 
)

Set eeprom control to master. Only if set to PDI.

Parameters
[in]context= context struct
[in]slave= Slave number
Returns
>0 if OK

◆ ecx_eeprom2pdi()

int ecx_eeprom2pdi ( ecx_contextt *  context,
uint16  slave 
)

Set eeprom control to PDI. Only if set to master.

Parameters
[in]context= context struct
[in]slave= Slave number
Returns
>0 if OK

◆ ecx_esidump()

void ecx_esidump ( ecx_contextt *  context,
uint16  slave,
uint8 *  esibuf 
)

Dump complete EEPROM data from slave in buffer.

Parameters
[in]context= context struct
[in]slave= Slave number
[out]esibuf= EEPROM data buffer, make sure it is big enough.

◆ ecx_init()

int ecx_init ( ecx_contextt *  context,
const char *  ifname 
)

Initialise lib in single NIC mode

Parameters
[in]context= context struct
[in]ifname= Dev name, f.e. "eth0"
Returns
>0 if OK

◆ ecx_init_redundant()

int ecx_init_redundant ( ecx_contextt *  context,
ecx_redportt *  redport,
const char *  ifname,
char *  if2name 
)

Initialise lib in redundant NIC mode

Parameters
[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"
Returns
>0 if OK

◆ ecx_iserror()

boolean ecx_iserror ( ecx_contextt *  context)

Check if error list has entries.

Parameters
[in]context= context struct
Returns
TRUE if error list contains entries.

◆ ecx_mbxempty()

int ecx_mbxempty ( ecx_contextt *  context,
uint16  slave,
int  timeout 
)

Check if IN mailbox of slave is empty.

Parameters
[in]context= context struct
[in]slave= Slave number
[in]timeout= Timeout in us
Returns
>0 is success

◆ ecx_mbxreceive()

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.

Parameters
[in]context= context struct
[in]slave= Slave number
[out]mbx= Mailbox data
[in]timeout= Timeout in us
Returns
Work counter (>0 is success)

◆ ecx_mbxsend()

int ecx_mbxsend ( ecx_contextt *  context,
uint16  slave,
ec_mbxbuft mbx,
int  timeout 
)

Write IN mailbox to slave.

Parameters
[in]context= context struct
[in]slave= Slave number
[out]mbx= Mailbox data
[in]timeout= Timeout in us
Returns
Work counter (>0 is success)

◆ ecx_packeterror()

void ecx_packeterror ( ecx_contextt *  context,
uint16  Slave,
uint16  Index,
uint8  SubIdx,
uint16  ErrorCode 
)

Report packet error

Parameters
[in]context= context struct
[in]Slave= Slave number
[in]Index= Index that generated error
[in]SubIdx= Subindex that generated error
[in]ErrorCode= Error code

◆ ecx_poperror()

boolean ecx_poperror ( ecx_contextt *  context,
ec_errort Ec 
)

Pops an error from the list.

Parameters
[in]context= context struct
[out]Ec= Struct describing the error.
Returns
TRUE if an error was popped.

◆ ecx_pusherror()

void ecx_pusherror ( ecx_contextt *  context,
const ec_errort Ec 
)

Pushes an error on the error list.

Parameters
[in]context= context struct
[in]Ecpointer describing the error.

◆ ecx_readeeprom()

uint32 ecx_readeeprom ( ecx_contextt *  context,
uint16  slave,
uint16  eeproma,
int  timeout 
)

Read EEPROM from slave bypassing cache.

Parameters
[in]context= context struct
[in]slave= Slave number
[in]eeproma= (WORD) Address in the EEPROM
[in]timeout= Timeout in us.
Returns
EEPROM data 32bit

◆ ecx_readeeprom1()

void ecx_readeeprom1 ( ecx_contextt *  context,
uint16  slave,
uint16  eeproma 
)

Read EEPROM from slave bypassing cache. Parallel read step 1, make request to slave.

Parameters
[in]context= context struct
[in]slave= Slave number
[in]eeproma= (WORD) Address in the EEPROM

◆ ecx_readeeprom2()

uint32 ecx_readeeprom2 ( ecx_contextt *  context,
uint16  slave,
int  timeout 
)

Read EEPROM from slave bypassing cache. Parallel read step 2, actual read from slave.

Parameters
[in]context= context struct
[in]slave= Slave number
[in]timeout= Timeout in us.
Returns
EEPROM data 32bit

◆ ecx_readeepromAP()

uint64 ecx_readeepromAP ( ecx_contextt *  context,
uint16  aiadr,
uint16  eeproma,
int  timeout 
)

Read EEPROM from slave bypassing cache. APRD method.

Parameters
[in]context= context struct
[in]aiadr= auto increment address of slave
[in]eeproma= (WORD) Address in the EEPROM
[in]timeout= Timeout in us.
Returns
EEPROM data 64bit or 32bit

◆ ecx_readeepromFP()

uint64 ecx_readeepromFP ( ecx_contextt *  context,
uint16  configadr,
uint16  eeproma,
int  timeout 
)

Read EEPROM from slave bypassing cache. FPRD method.

Parameters
[in]context= context struct
[in]configadr= configured address of slave
[in]eeproma= (WORD) Address in the EEPROM
[in]timeout= Timeout in us.
Returns
EEPROM data 64bit or 32bit

◆ ecx_readstate()

int ecx_readstate ( ecx_contextt *  context)

Read all slave states in ec_slave.

Parameters
[in]context= context struct
Returns
lowest state found

◆ ecx_receive_processdata()

int ecx_receive_processdata ( ecx_contextt *  context,
int  timeout 
)

◆ ecx_receive_processdata_group()

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.

Parameters
[in]context= context struct
[in]group= group number
[in]timeout= Timeout in us.
Returns
Work counter.

◆ ecx_send_overlap_processdata()

int ecx_send_overlap_processdata ( ecx_contextt *  context)

◆ ecx_send_overlap_processdata_group()

int ecx_send_overlap_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 in the overlapped IOmap. The outputs with the actual data, the inputs replace the output data in the returning frame. 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.

Parameters
[in]context= context struct
[in]group= group number
Returns
>0 if processdata is transmitted.

◆ ecx_send_processdata()

int ecx_send_processdata ( ecx_contextt *  context)

◆ ecx_send_processdata_group()

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.

Parameters
[in]context= context struct
[in]group= group number
Returns
>0 if processdata is transmitted.

◆ ecx_siifind()

int16 ecx_siifind ( ecx_contextt *  context,
uint16  slave,
uint16  cat 
)

Find SII section header in slave EEPROM.

Parameters
[in]context= context struct
[in]slave= slave number
[in]cat= section category
Returns
byte address of section at section length entry, if not available then 0

◆ ecx_siiFMMU()

uint16 ecx_siiFMMU ( ecx_contextt *  context,
uint16  slave,
ec_eepromFMMUt FMMU 
)

Get FMMU data from SII FMMU section in slave EEPROM.

Parameters
[in]context= context struct
[in]slave= slave number
[out]FMMU= FMMU struct from SII, max. 4 FMMU's
Returns
number of FMMU's defined in section

◆ ecx_siigetbyte()

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 capabilities the request is 4 or 8 bytes.

Parameters
[in]context= context struct
[in]slave= slave number
[in]address= eeprom address in bytes (slave uses words)
Returns
requested byte, if not available then 0xff

◆ ecx_siiPDO()

int ecx_siiPDO ( ecx_contextt *  context,
uint16  slave,
ec_eepromPDOt PDO,
uint8  t 
)

Get PDO data from SII PDO section in slave EEPROM.

Parameters
[in]context= context struct
[in]slave= slave number
[out]PDO= PDO struct from SII
[in]t= 0=RXPDO 1=TXPDO
Returns
mapping size in bits of PDO

◆ ecx_siiSM()

uint16 ecx_siiSM ( ecx_contextt *  context,
uint16  slave,
ec_eepromSMt SM 
)

Get SM data from SII SM section in slave EEPROM.

Parameters
[in]context= context struct
[in]slave= slave number
[out]SM= first SM struct from SII
Returns
number of SM's defined in section

◆ ecx_siiSMnext()

uint16 ecx_siiSMnext ( ecx_contextt *  context,
uint16  slave,
ec_eepromSMt SM,
uint16  n 
)

Get next SM data from SII SM section in slave EEPROM.

Parameters
[in]context= context struct
[in]slave= slave number
[out]SM= first SM struct from SII
[in]n= SM number
Returns
>0 if OK

◆ ecx_siistring()

void ecx_siistring ( ecx_contextt *  context,
char *  str,
uint16  slave,
uint16  Sn 
)

Get string from SII string section in slave EEPROM.

Parameters
[in]context= context struct
[out]str= requested string, 0x00 if not found
[in]slave= slave number
[in]Sn= string number

◆ ecx_statecheck()

uint16 ecx_statecheck ( ecx_contextt *  context,
uint16  slave,
uint16  reqstate,
int  timeout 
)

Check actual slave state. This is a blocking function. To refresh the state of all slaves ecx_readstate()should be called

Parameters
[in]context= context struct
[in]slave= Slave number, 0 = all slaves (only the "slavelist[0].state" is refreshed)
[in]reqstate= Requested state
[in]timeout= Timeout value in us
Returns
Requested state, or found state after timeout.

◆ ecx_writeeeprom()

int ecx_writeeeprom ( ecx_contextt *  context,
uint16  slave,
uint16  eeproma,
uint16  data,
int  timeout 
)

Write EEPROM to slave bypassing cache.

Parameters
[in]context= context struct
[in]slave= Slave number
[in]eeproma= (WORD) Address in the EEPROM
[in]data= 16bit data
[in]timeout= Timeout in us.
Returns
>0 if OK

◆ ecx_writeeepromAP()

int ecx_writeeepromAP ( ecx_contextt *  context,
uint16  aiadr,
uint16  eeproma,
uint16  data,
int  timeout 
)

Write EEPROM to slave bypassing cache. APWR method.

Parameters
[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.
Returns
>0 if OK

◆ ecx_writeeepromFP()

int ecx_writeeepromFP ( ecx_contextt *  context,
uint16  configadr,
uint16  eeproma,
uint16  data,
int  timeout 
)

Write EEPROM to slave bypassing cache. FPWR method.

Parameters
[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.
Returns
>0 if OK

◆ ecx_writestate()

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.

Parameters
[in]context= context struct
[in]slave= Slave number, 0 = master
Returns
Workcounter or EC_NOFRAME