IgH EtherCAT Master  1.7.0
fsm_mbox.h File Reference

EtherCAT mailbox receive state machine. More...

Go to the source code of this file.

Data Structures

struct  ec_fsm_mbox
 EtherCAT mailbox receive state machine. More...
 

Typedefs

typedef struct ec_fsm_mbox ec_fsm_mbox_t
 

Enumerations

enum  ec_fsm_mbox_mode_t { EC_FSM_MBOX_WAIT, EC_FSM_MBOX_POLL, EC_FSM_MBOX_NOSYNC }
 Mode of the mailbox receive state machine. More...
 

Functions

void ec_fsm_mbox_init (ec_fsm_mbox_t *)
 Constructor.
 
void ec_fsm_mbox_clear (ec_fsm_mbox_t *)
 Destructor.
 
void ec_fsm_mbox_receive (ec_fsm_mbox_t *, ec_slave_t *, ec_mbox_data_t *, unsigned long, unsigned long)
 Starts waiting for a mailbox response. More...
 
void ec_fsm_mbox_poll (ec_fsm_mbox_t *, ec_slave_t *, ec_mbox_data_t *)
 Starts a single mailbox check without waiting. More...
 
void ec_fsm_mbox_fetch_nosync (ec_fsm_mbox_t *, ec_slave_t *, ec_mbox_data_t *, unsigned long, unsigned long)
 Starts a single mailbox fetch without a preceding check. More...
 
int ec_fsm_mbox_exec (ec_fsm_mbox_t *, ec_datagram_t *)
 Executes the current state of the state machine. More...
 
int ec_fsm_mbox_result (const ec_fsm_mbox_t *)
 Returns the result of the terminated state machine. More...
 
int ec_fsm_mbox_holds_lock (const ec_fsm_mbox_t *)
 Checks, if the state machine holds the slave's mailbox read lock. More...
 
void ec_fsm_mbox_abort (ec_fsm_mbox_t *)
 Aborts the state machine and releases the mailbox read lock, if held.
 

Detailed Description

EtherCAT mailbox receive state machine.

Definition in file fsm_mbox.h.

Typedef Documentation

◆ ec_fsm_mbox_t

typedef struct ec_fsm_mbox ec_fsm_mbox_t
See also
ec_fsm_mbox

Definition at line 47 of file fsm_mbox.h.

Enumeration Type Documentation

◆ ec_fsm_mbox_mode_t

Mode of the mailbox receive state machine.

Enumerator
EC_FSM_MBOX_WAIT 

Wait for a response until the timeout elapsed.

EC_FSM_MBOX_POLL 

Check the mailbox once, do not wait.

EC_FSM_MBOX_NOSYNC 

Fetch the mailbox once without checking it.

Definition at line 39 of file fsm_mbox.h.

Function Documentation

◆ ec_fsm_mbox_receive()

void ec_fsm_mbox_receive ( ec_fsm_mbox_t *  fsm,
ec_slave_t *  slave,
ec_mbox_data_t *  mbox_data,
unsigned long  jiffies_start,
unsigned long  timeout_ms 
)

Starts waiting for a mailbox response.

The state machine checks the mailbox until a response for the protocol is stored in mbox_data, or the timeout elapsed.

Parameters
fsmFinite state machine.
slaveEtherCAT slave.
mbox_dataResponse buffer of the protocol.
jiffies_startReference time for the timeout, usually the time the request was sent.
timeout_msResponse timeout in [ms].

Definition at line 102 of file fsm_mbox.c.

◆ ec_fsm_mbox_poll()

void ec_fsm_mbox_poll ( ec_fsm_mbox_t *  fsm,
ec_slave_t *  slave,
ec_mbox_data_t *  mbox_data 
)

Starts a single mailbox check without waiting.

If no message for the protocol is available, or another state machine reads the mailbox, the state machine fails with -EAGAIN or -EBUSY.

Parameters
fsmFinite state machine.
slaveEtherCAT slave.
mbox_dataResponse buffer of the protocol.

Definition at line 123 of file fsm_mbox.c.

◆ ec_fsm_mbox_fetch_nosync()

void ec_fsm_mbox_fetch_nosync ( ec_fsm_mbox_t *  fsm,
ec_slave_t *  slave,
ec_mbox_data_t *  mbox_data,
unsigned long  jiffies_start,
unsigned long  timeout_ms 
)

Starts a single mailbox fetch without a preceding check.

Waits for the mailbox read lock until the timeout elapsed. If the fetched mailbox contains no message for the protocol, the state machine fails with -EAGAIN.

Parameters
fsmFinite state machine.
slaveEtherCAT slave.
mbox_dataResponse buffer of the protocol.
jiffies_startReference time for the timeout.
timeout_msTimeout in [ms].

Definition at line 140 of file fsm_mbox.c.

◆ ec_fsm_mbox_exec()

int ec_fsm_mbox_exec ( ec_fsm_mbox_t *  fsm,
ec_datagram_t *  datagram 
)

Executes the current state of the state machine.

Every state either uses the datagram, or marks it as unused.

Returns
1, if the state machine is still running, 0 if it terminated. Use ec_fsm_mbox_result() to get the result.
Parameters
fsmFinite state machine.
datagramDatagram to use.

Definition at line 161 of file fsm_mbox.c.

◆ ec_fsm_mbox_result()

int ec_fsm_mbox_result ( const ec_fsm_mbox_t *  fsm)

Returns the result of the terminated state machine.

Return values
0A message for the protocol is available in the response buffer.
-EIOMailbox check or fetch failed.
-ETIMEDOUTNo response within the timeout.
-EAGAINNo message for the protocol (poll and nosync mode).
-EBUSYAnother state machine reads the mailbox (poll mode).
Parameters
fsmFinite state machine.

Definition at line 195 of file fsm_mbox.c.

◆ ec_fsm_mbox_holds_lock()

int ec_fsm_mbox_holds_lock ( const ec_fsm_mbox_t *  fsm)

Checks, if the state machine holds the slave's mailbox read lock.

Returns
Non-zero, if the lock is held.
Parameters
fsmFinite state machine.

Definition at line 208 of file fsm_mbox.c.