IgH EtherCAT Master  1.5.3
datagram.c File Reference

Methods of an EtherCAT datagram. More...

Go to the source code of this file.

Functions

void ec_datagram_init (ec_datagram_t *datagram)
 Constructor. More...
 
void ec_datagram_clear (ec_datagram_t *datagram)
 Destructor. More...
 
void ec_datagram_unqueue (ec_datagram_t *datagram)
 Unqueue datagram. More...
 
int ec_datagram_prealloc (ec_datagram_t *datagram, size_t size)
 Allocates internal payload memory. More...
 
void ec_datagram_zero (ec_datagram_t *datagram)
 Fills the datagram payload memory with zeros. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int ec_datagram_brd (ec_datagram_t *datagram, uint16_t mem_address, size_t data_size)
 Initializes an EtherCAT BRD datagram. More...
 
int ec_datagram_bwr (ec_datagram_t *datagram, uint16_t mem_address, size_t data_size)
 Initializes an EtherCAT BWR datagram. More...
 
int ec_datagram_brw (ec_datagram_t *datagram, uint16_t mem_address, size_t data_size)
 Initializes an EtherCAT BRW datagram. More...
 
int ec_datagram_lrd (ec_datagram_t *datagram, uint32_t offset, size_t data_size)
 Initializes an EtherCAT LRD datagram. More...
 
int ec_datagram_lwr (ec_datagram_t *datagram, uint32_t offset, size_t data_size)
 Initializes an EtherCAT LWR datagram. More...
 
int ec_datagram_lrw (ec_datagram_t *datagram, uint32_t offset, size_t data_size)
 Initializes an EtherCAT LRW datagram. More...
 
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. More...
 
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. More...
 
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. More...
 
void ec_datagram_print_state (const ec_datagram_t *datagram)
 Prints the state of a datagram. More...
 
void ec_datagram_print_wc_error (const ec_datagram_t *datagram)
 Evaluates the working counter of a single-cast datagram. More...
 
void ec_datagram_output_stats (ec_datagram_t *datagram)
 Outputs datagram statistics at most every second.
 
const char * ec_datagram_type_string (const ec_datagram_t *datagram)
 Returns a string describing the datagram type. More...
 

Variables

static const char * type_strings []
 Array of datagram type strings used in ec_datagram_type_string(). More...
 

Detailed Description

Methods of an EtherCAT datagram.

Definition in file datagram.c.

Function Documentation

◆ ec_datagram_init()

void ec_datagram_init ( ec_datagram_t datagram)

Constructor.

Parameters
datagramEtherCAT datagram.

Definition at line 88 of file datagram.c.

◆ ec_datagram_clear()

void ec_datagram_clear ( ec_datagram_t datagram)

Destructor.

Parameters
datagramEtherCAT datagram.

Definition at line 118 of file datagram.c.

◆ ec_datagram_unqueue()

void ec_datagram_unqueue ( ec_datagram_t datagram)

Unqueue datagram.

Parameters
datagramEtherCAT datagram.

Definition at line 132 of file datagram.c.

◆ 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 150 of file datagram.c.

◆ ec_datagram_zero()

void ec_datagram_zero ( ec_datagram_t datagram)

Fills the datagram payload memory with zeros.

Parameters
datagramEtherCAT datagram.

Definition at line 178 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 189 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 210 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 231 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 252 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 273 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 298 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 323 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 348 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 373 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 393 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 413 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 433 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 452 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 471 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 493 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 518 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 543 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 565 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 602 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 645 of file datagram.c.

Variable Documentation

◆ type_strings

const char* type_strings[]
static
Initial value:
= {
"?",
"APRD",
"APWR",
"APRW",
"FPRD",
"FPWR",
"FPRW",
"BRD",
"BWR",
"BRW",
"LRD",
"LWR",
"LRW",
"ARMW",
"FRMW"
}

Array of datagram type strings used in ec_datagram_type_string().

Attention
This is indexed by ec_datagram_type_t.

Definition at line 66 of file datagram.c.