IgH EtherCAT Master  1.6.2
datagram.h File Reference

EtherCAT datagram structure. More...

Go to the source code of this file.

Data Structures

struct  ec_datagram_t
 EtherCAT datagram. More...
 

Enumerations

enum  ec_datagram_type_t {
  EC_DATAGRAM_NONE = 0x00, EC_DATAGRAM_APRD = 0x01, EC_DATAGRAM_APWR = 0x02, EC_DATAGRAM_APRW = 0x03,
  EC_DATAGRAM_FPRD = 0x04, EC_DATAGRAM_FPWR = 0x05, EC_DATAGRAM_FPRW = 0x06, EC_DATAGRAM_BRD = 0x07,
  EC_DATAGRAM_BWR = 0x08, EC_DATAGRAM_BRW = 0x09, EC_DATAGRAM_LRD = 0x0A, EC_DATAGRAM_LWR = 0x0B,
  EC_DATAGRAM_LRW = 0x0C, EC_DATAGRAM_ARMW = 0x0D, EC_DATAGRAM_FRMW = 0x0E
}
 EtherCAT datagram type. More...
 
enum  ec_datagram_state_t {
  EC_DATAGRAM_INIT, EC_DATAGRAM_QUEUED, EC_DATAGRAM_SENT, EC_DATAGRAM_RECEIVED,
  EC_DATAGRAM_TIMED_OUT, EC_DATAGRAM_ERROR
}
 EtherCAT datagram state. More...
 

Functions

void ec_datagram_init (ec_datagram_t *)
 Constructor.
 
void ec_datagram_clear (ec_datagram_t *)
 Destructor.
 
void ec_datagram_unqueue (ec_datagram_t *)
 Unqueue datagram.
 
int ec_datagram_prealloc (ec_datagram_t *, size_t)
 Allocates internal payload memory. More...
 
void ec_datagram_zero (ec_datagram_t *)
 Fills the datagram payload memory with zeros.
 
int ec_datagram_aprd (ec_datagram_t *, uint16_t, uint16_t, size_t)
 Initializes an EtherCAT APRD datagram. More...
 
int ec_datagram_apwr (ec_datagram_t *, uint16_t, uint16_t, size_t)
 Initializes an EtherCAT APWR datagram. More...
 
int ec_datagram_aprw (ec_datagram_t *, uint16_t, uint16_t, size_t)
 Initializes an EtherCAT APRW datagram. More...
 
int ec_datagram_armw (ec_datagram_t *, uint16_t, uint16_t, size_t)
 Initializes an EtherCAT ARMW datagram. More...
 
int ec_datagram_fprd (ec_datagram_t *, uint16_t, uint16_t, size_t)
 Initializes an EtherCAT FPRD datagram. More...
 
int ec_datagram_fpwr (ec_datagram_t *, uint16_t, uint16_t, size_t)
 Initializes an EtherCAT FPWR datagram. More...
 
int ec_datagram_fprw (ec_datagram_t *, uint16_t, uint16_t, size_t)
 Initializes an EtherCAT FPRW datagram. More...
 
int ec_datagram_frmw (ec_datagram_t *, uint16_t, uint16_t, size_t)
 Initializes an EtherCAT FRMW datagram. More...
 
int ec_datagram_brd (ec_datagram_t *, uint16_t, size_t)
 Initializes an EtherCAT BRD datagram. More...
 
int ec_datagram_bwr (ec_datagram_t *, uint16_t, size_t)
 Initializes an EtherCAT BWR datagram. More...
 
int ec_datagram_brw (ec_datagram_t *, uint16_t, size_t)
 Initializes an EtherCAT BRW datagram. More...
 
int ec_datagram_lrd (ec_datagram_t *, uint32_t, size_t)
 Initializes an EtherCAT LRD datagram. More...
 
int ec_datagram_lwr (ec_datagram_t *, uint32_t, size_t)
 Initializes an EtherCAT LWR datagram. More...
 
int ec_datagram_lrw (ec_datagram_t *, uint32_t, size_t)
 Initializes an EtherCAT LRW datagram. More...
 
int ec_datagram_lrd_ext (ec_datagram_t *, uint32_t, size_t, uint8_t *)
 Initializes an EtherCAT LRD datagram with external memory. More...
 
int ec_datagram_lwr_ext (ec_datagram_t *, uint32_t, size_t, uint8_t *)
 Initializes an EtherCAT LWR datagram with external memory. More...
 
int ec_datagram_lrw_ext (ec_datagram_t *, uint32_t, size_t, uint8_t *)
 Initializes an EtherCAT LRW datagram with external memory. More...
 
void ec_datagram_print_state (const ec_datagram_t *)
 Prints the state of a datagram. More...
 
void ec_datagram_print_wc_error (const ec_datagram_t *)
 Evaluates the working counter of a single-cast datagram. More...
 
void ec_datagram_output_stats (ec_datagram_t *)
 Outputs datagram statistics at most every second.
 
const char * ec_datagram_type_string (const ec_datagram_t *)
 Returns a string describing the datagram type. More...
 

Detailed Description

EtherCAT datagram structure.

Definition in file datagram.h.

Enumeration Type Documentation

◆ ec_datagram_type_t

EtherCAT datagram type.

Enumerator
EC_DATAGRAM_NONE 

Dummy.

EC_DATAGRAM_APRD 

Auto Increment Physical Read.

EC_DATAGRAM_APWR 

Auto Increment Physical Write.

EC_DATAGRAM_APRW 

Auto Increment Physical ReadWrite.

EC_DATAGRAM_FPRD 

Configured Address Physical Read.

EC_DATAGRAM_FPWR 

Configured Address Physical Write.

EC_DATAGRAM_FPRW 

Configured Address Physical ReadWrite.

EC_DATAGRAM_BRD 

Broadcast Read.

EC_DATAGRAM_BWR 

Broadcast Write.

EC_DATAGRAM_BRW 

Broadcast ReadWrite.

EC_DATAGRAM_LRD 

Logical Read.

EC_DATAGRAM_LWR 

Logical Write.

EC_DATAGRAM_LRW 

Logical ReadWrite.

EC_DATAGRAM_ARMW 

Auto Increment Physical Read Multiple Write.

EC_DATAGRAM_FRMW 

Configured Address Physical Read Multiple Write.

Definition at line 42 of file datagram.h.

◆ ec_datagram_state_t

EtherCAT datagram state.

Enumerator
EC_DATAGRAM_INIT 

Initial state of a new datagram.

EC_DATAGRAM_QUEUED 

Queued for sending.

EC_DATAGRAM_SENT 

Sent (still in the queue).

EC_DATAGRAM_RECEIVED 

Received (dequeued).

EC_DATAGRAM_TIMED_OUT 

Timed out (dequeued).

EC_DATAGRAM_ERROR 

Error while sending/receiving (dequeued).

Definition at line 66 of file datagram.h.

Function Documentation

◆ ec_datagram_prealloc()

int ec_datagram_prealloc ( ec_datagram_t datagram,
size_t  size 
)

Allocates internal payload memory.

If the allocated memory is already larger than requested, nothing ist done.

Attention
If external payload memory has been provided, no range checking is done!
Returns
0 in case of success, otherwise -ENOMEM.
Parameters
datagramEtherCAT datagram.
sizeNew payload size in bytes.

Definition at line 142 of file datagram.c.

◆ ec_datagram_aprd()

int ec_datagram_aprd ( ec_datagram_t datagram,
uint16_t  ring_position,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT APRD datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
ring_positionAuto-increment address.
mem_addressPhysical memory address.
data_sizeNumber of bytes to read.

Definition at line 181 of file datagram.c.

◆ ec_datagram_apwr()

int ec_datagram_apwr ( ec_datagram_t datagram,
uint16_t  ring_position,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT APWR datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
ring_positionAuto-increment address.
mem_addressPhysical memory address.
data_sizeNumber of bytes to write.

Definition at line 202 of file datagram.c.

◆ ec_datagram_aprw()

int ec_datagram_aprw ( ec_datagram_t datagram,
uint16_t  ring_position,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT APRW datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
ring_positionAuto-increment address.
mem_addressPhysical memory address.
data_sizeNumber of bytes to write.

Definition at line 223 of file datagram.c.

◆ ec_datagram_armw()

int ec_datagram_armw ( ec_datagram_t datagram,
uint16_t  ring_position,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT ARMW datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
ring_positionAuto-increment address.
mem_addressPhysical memory address.
data_sizeNumber of bytes to read.

Definition at line 244 of file datagram.c.

◆ ec_datagram_fprd()

int ec_datagram_fprd ( ec_datagram_t datagram,
uint16_t  configured_address,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT FPRD datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
configured_addressConfigured station address.
mem_addressPhysical memory address.
data_sizeNumber of bytes to read.

Definition at line 265 of file datagram.c.

◆ ec_datagram_fpwr()

int ec_datagram_fpwr ( ec_datagram_t datagram,
uint16_t  configured_address,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT FPWR datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
configured_addressConfigured station address.
mem_addressPhysical memory address.
data_sizeNumber of bytes to write.

Definition at line 290 of file datagram.c.

◆ ec_datagram_fprw()

int ec_datagram_fprw ( ec_datagram_t datagram,
uint16_t  configured_address,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT FPRW datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
configured_addressConfigured station address.
mem_addressPhysical memory address.
data_sizeNumber of bytes to write.

Definition at line 315 of file datagram.c.

◆ ec_datagram_frmw()

int ec_datagram_frmw ( ec_datagram_t datagram,
uint16_t  configured_address,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT FRMW datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
configured_addressConfigured station address.
mem_addressPhysical memory address.
data_sizeNumber of bytes to write.

Definition at line 340 of file datagram.c.

◆ ec_datagram_brd()

int ec_datagram_brd ( ec_datagram_t datagram,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT BRD datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
mem_addressPhysical memory address.
data_sizeNumber of bytes to read.

Definition at line 365 of file datagram.c.

◆ ec_datagram_bwr()

int ec_datagram_bwr ( ec_datagram_t datagram,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT BWR datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
mem_addressPhysical memory address.
data_sizeNumber of bytes to write.

Definition at line 385 of file datagram.c.

◆ ec_datagram_brw()

int ec_datagram_brw ( ec_datagram_t datagram,
uint16_t  mem_address,
size_t  data_size 
)

Initializes an EtherCAT BRW datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
mem_addressPhysical memory address.
data_sizeNumber of bytes to write.

Definition at line 405 of file datagram.c.

◆ ec_datagram_lrd()

int ec_datagram_lrd ( ec_datagram_t datagram,
uint32_t  offset,
size_t  data_size 
)

Initializes an EtherCAT LRD datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
offsetLogical address.
data_sizeNumber of bytes to read/write.

Definition at line 425 of file datagram.c.

◆ ec_datagram_lwr()

int ec_datagram_lwr ( ec_datagram_t datagram,
uint32_t  offset,
size_t  data_size 
)

Initializes an EtherCAT LWR datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
offsetLogical address.
data_sizeNumber of bytes to read/write.

Definition at line 444 of file datagram.c.

◆ ec_datagram_lrw()

int ec_datagram_lrw ( ec_datagram_t datagram,
uint32_t  offset,
size_t  data_size 
)

Initializes an EtherCAT LRW datagram.

Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
offsetLogical address.
data_sizeNumber of bytes to read/write.

Definition at line 463 of file datagram.c.

◆ ec_datagram_lrd_ext()

int ec_datagram_lrd_ext ( ec_datagram_t datagram,
uint32_t  offset,
size_t  data_size,
uint8_t *  external_memory 
)

Initializes an EtherCAT LRD datagram with external memory.

Attention
It is assumed, that the external memory is at least data_size bytes large.
Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
offsetLogical address.
data_sizeNumber of bytes to read/write.
external_memoryPointer to the memory to use.

Definition at line 485 of file datagram.c.

◆ ec_datagram_lwr_ext()

int ec_datagram_lwr_ext ( ec_datagram_t datagram,
uint32_t  offset,
size_t  data_size,
uint8_t *  external_memory 
)

Initializes an EtherCAT LWR datagram with external memory.

Attention
It is assumed, that the external memory is at least data_size bytes large.
Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
offsetLogical address.
data_sizeNumber of bytes to read/write.
external_memoryPointer to the memory to use.

Definition at line 510 of file datagram.c.

◆ ec_datagram_lrw_ext()

int ec_datagram_lrw_ext ( ec_datagram_t datagram,
uint32_t  offset,
size_t  data_size,
uint8_t *  external_memory 
)

Initializes an EtherCAT LRW datagram with external memory.

Attention
It is assumed, that the external memory is at least data_size bytes large.
Returns
Return value of ec_datagram_prealloc().
Parameters
datagramEtherCAT datagram.
offsetLogical address.
data_sizeNumber of bytes to read/write.
external_memoryPointer to the memory to use.

Definition at line 535 of file datagram.c.

◆ ec_datagram_print_state()

void ec_datagram_print_state ( const ec_datagram_t datagram)

Prints the state of a datagram.

Outputs a text message.

Parameters
datagramEtherCAT datagram

Definition at line 557 of file datagram.c.

◆ ec_datagram_print_wc_error()

void ec_datagram_print_wc_error ( const ec_datagram_t datagram)

Evaluates the working counter of a single-cast datagram.

Outputs an error message.

Parameters
datagramEtherCAT datagram

Definition at line 594 of file datagram.c.

◆ ec_datagram_type_string()

const char* ec_datagram_type_string ( const ec_datagram_t datagram)

Returns a string describing the datagram type.

Returns
Pointer on a static memory containing the requested string.
Parameters
datagramEtherCAT datagram.

Definition at line 637 of file datagram.c.