IgH EtherCAT Master  1.7.0
mailbox.c File Reference

Mailbox functionality. More...

Go to the source code of this file.

Functions

void ec_mbox_data_init (ec_mbox_data_t *mbox_data)
 Initialize mailbox response data. More...
 
void ec_mbox_data_clear (ec_mbox_data_t *mbox_data)
 Free internal memory for mailbox response data. More...
 
static int ec_mbox_data_prealloc (ec_mbox_data_t *mbox_data, size_t size)
 Allocates internal memory for mailbox response data. More...
 
void ec_slave_mbox_prealloc (ec_slave_t *slave)
 Allocates the mailbox response buffers of a slave. More...
 
uint8_t * ec_slave_mbox_prepare_send (const ec_slave_t *slave, ec_datagram_t *datagram, uint8_t type, size_t size)
 Prepares a mailbox-send datagram. More...
 
int ec_slave_mbox_prepare_check (const ec_slave_t *slave, ec_datagram_t *datagram)
 Prepares a datagram for checking the mailbox state. More...
 
int ec_slave_mbox_check (const ec_datagram_t *datagram)
 Processes a mailbox state checking datagram. More...
 
int ec_slave_mbox_prepare_fetch (const ec_slave_t *slave, ec_datagram_t *datagram)
 Prepares a datagram to fetch mailbox data. More...
 
void ec_slave_mbox_take_error (ec_mbox_data_t *mbox_data, const ec_datagram_t *datagram)
 Takes over a mailbox error response from a mailbox fetch datagram. More...
 
uint8_t * ec_slave_mbox_fetch (const ec_slave_t *slave, ec_mbox_data_t *response_data, uint8_t *type, size_t *size)
 Processes received mailbox data. More...
 

Variables

const ec_code_msg_t mbox_error_messages []
 Mailbox error codes. More...
 

Detailed Description

Mailbox functionality.

Definition in file mailbox.c.

Function Documentation

◆ ec_mbox_data_init()

void ec_mbox_data_init ( ec_mbox_data_t *  mbox_data)

Initialize mailbox response data.

Parameters
mbox_dataMailbox response data.

Definition at line 40 of file mailbox.c.

◆ ec_mbox_data_clear()

void ec_mbox_data_clear ( ec_mbox_data_t *  mbox_data)

Free internal memory for mailbox response data.

Parameters
mbox_dataMailbox response data.

Definition at line 53 of file mailbox.c.

◆ ec_mbox_data_prealloc()

static int ec_mbox_data_prealloc ( ec_mbox_data_t *  mbox_data,
size_t  size 
)
static

Allocates internal memory for mailbox response data.

Returns
0 in case of success, otherwise -ENOMEM.
Parameters
mbox_dataMailbox response data.
sizeMailbox size in bytes.

Definition at line 70 of file mailbox.c.

◆ ec_slave_mbox_prealloc()

void ec_slave_mbox_prealloc ( ec_slave_t *  slave)

Allocates the mailbox response buffers of a slave.

The buffers are allocated for the mailbox protocols supported by the slave. They are allocated only once and freed with the slave, because the receive path may write to them at any time. So they are dimensioned for the largest TX mailbox, that can be configured during the lifetime of the slave object (standard and bootstrap mailbox, sync manager configuration from the SII and the currently configured mailbox).

Parameters
slaveEtherCAT slave.

Definition at line 100 of file mailbox.c.

◆ ec_slave_mbox_prepare_send()

uint8_t* ec_slave_mbox_prepare_send ( const ec_slave_t *  slave,
ec_datagram_t *  datagram,
uint8_t  type,
size_t  size 
)

Prepares a mailbox-send datagram.

Returns
Pointer to mailbox datagram data, or ERR_PTR() code.
Parameters
slaveslave
datagramdatagram
typemailbox protocol
sizesize of the data

Definition at line 143 of file mailbox.c.

◆ ec_slave_mbox_prepare_check()

int ec_slave_mbox_prepare_check ( const ec_slave_t *  slave,
ec_datagram_t *  datagram 
)

Prepares a datagram for checking the mailbox state.

Todo:
Determine sync manager used for receive mailbox
Returns
0 in case of success, else < 0
Parameters
slaveslave
datagramdatagram

Definition at line 188 of file mailbox.c.

◆ ec_slave_mbox_check()

int ec_slave_mbox_check ( const ec_datagram_t *  datagram)

Processes a mailbox state checking datagram.

Returns
0 in case of success, else < 0
Parameters
datagramdatagram

Definition at line 207 of file mailbox.c.

◆ ec_slave_mbox_prepare_fetch()

int ec_slave_mbox_prepare_fetch ( const ec_slave_t *  slave,
ec_datagram_t *  datagram 
)

Prepares a datagram to fetch mailbox data.

Returns
0 in case of success, else < 0
Parameters
slaveslave
datagramdatagram

Definition at line 219 of file mailbox.c.

◆ ec_slave_mbox_take_error()

void ec_slave_mbox_take_error ( ec_mbox_data_t *  mbox_data,
const ec_datagram_t *  datagram 
)

Takes over a mailbox error response from a mailbox fetch datagram.

Mailbox error responses (type 0x00) can not be assigned to a protocol, so the mailbox dispatcher leaves them in the memory of the fetch datagram. This function stores such a response in the protocol buffer of the fetching state machine, so that ec_slave_mbox_fetch() reports the error.

The fetch datagram is zeroed in ec_slave_mbox_prepare_fetch(), so the length field is zero, if the response was dispatched to a protocol buffer.

Parameters
mbox_dataprotocol buffer of the fetching FSM
datagrammailbox fetch datagram

Definition at line 246 of file mailbox.c.

◆ ec_slave_mbox_fetch()

uint8_t* ec_slave_mbox_fetch ( const ec_slave_t *  slave,
ec_mbox_data_t *  response_data,
uint8_t *  type,
size_t *  size 
)

Processes received mailbox data.

The response is consumed, i. e. the response buffer is marked as empty.

Returns
Pointer to the received data, or ERR_PTR() code.
Parameters
slaveslave
response_dataresponse
typeexpected mailbox protocol
sizesize of the received data

Definition at line 290 of file mailbox.c.

Variable Documentation

◆ mbox_error_messages

const ec_code_msg_t mbox_error_messages[]
Initial value:
= {
{0x00000001, "MBXERR_SYNTAX"},
{0x00000002, "MBXERR_UNSUPPORTEDPROTOCOL"},
{0x00000003, "MBXERR_INVAILDCHANNEL"},
{0x00000004, "MBXERR_SERVICENOTSUPPORTED"},
{0x00000005, "MBXERR_INVALIDHEADER"},
{0x00000006, "MBXERR_SIZETOOSHORT"},
{0x00000007, "MBXERR_NOMOREMEMORY"},
{0x00000008, "MBXERR_INVALIDSIZE"},
{}
}

Mailbox error codes.

Definition at line 270 of file mailbox.c.