IgH EtherCAT Master  1.7.0
fsm_mbox.c File Reference

EtherCAT mailbox receive state machine. More...

Go to the source code of this file.

Functions

void ec_fsm_mbox_state_start (ec_fsm_mbox_t *fsm, ec_datagram_t *datagram)
 State: START. More...
 
void ec_fsm_mbox_state_check (ec_fsm_mbox_t *fsm, ec_datagram_t *datagram)
 State: CHECK. More...
 
void ec_fsm_mbox_state_fetch (ec_fsm_mbox_t *fsm, ec_datagram_t *datagram)
 State: FETCH. More...
 
void ec_fsm_mbox_state_end (ec_fsm_mbox_t *fsm, ec_datagram_t *datagram)
 State: END. More...
 
void ec_fsm_mbox_state_error (ec_fsm_mbox_t *fsm, ec_datagram_t *datagram)
 State: ERROR. More...
 
void ec_fsm_mbox_init (ec_fsm_mbox_t *fsm)
 Constructor. More...
 
void ec_fsm_mbox_clear (ec_fsm_mbox_t *fsm)
 Destructor. More...
 
static void ec_fsm_mbox_start (ec_fsm_mbox_t *fsm, ec_slave_t *slave, ec_mbox_data_t *mbox_data, ec_fsm_mbox_mode_t mode, unsigned long jiffies_start, unsigned long timeout_ms)
 Starts the state machine in the given mode. More...
 
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. More...
 
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. More...
 
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. More...
 
int ec_fsm_mbox_exec (ec_fsm_mbox_t *fsm, ec_datagram_t *datagram)
 Executes the current state of the state machine. More...
 
int ec_fsm_mbox_result (const ec_fsm_mbox_t *fsm)
 Returns the result of the terminated state machine. More...
 
int ec_fsm_mbox_holds_lock (const ec_fsm_mbox_t *fsm)
 Checks, if the state machine holds the slave's mailbox read lock. More...
 
void ec_fsm_mbox_abort (ec_fsm_mbox_t *fsm)
 Aborts the state machine and releases the mailbox read lock, if held. More...
 
static int ec_fsm_mbox_data_available (const ec_fsm_mbox_t *fsm)
 Checks, if a message for the protocol is available. More...
 
static int ec_fsm_mbox_timed_out (const ec_fsm_mbox_t *fsm, unsigned long now)
 Checks, if the timeout elapsed. More...
 
static void ec_fsm_mbox_fail (ec_fsm_mbox_t *fsm, ec_datagram_t *datagram, int result)
 Releases the mailbox read lock and terminates with an error. More...
 

Detailed Description

EtherCAT mailbox receive state machine.

Definition in file fsm_mbox.c.

Function Documentation

◆ ec_fsm_mbox_state_start()

void ec_fsm_mbox_state_start ( ec_fsm_mbox_t *  fsm,
ec_datagram_t *  datagram 
)

State: START.

Takes the mailbox read lock and checks (or fetches) the mailbox. If another state machine holds the lock, waits for the lock or the response.

Parameters
fsmFinite state machine.
datagramDatagram to use.

Definition at line 286 of file fsm_mbox.c.

◆ ec_fsm_mbox_state_check()

void ec_fsm_mbox_state_check ( ec_fsm_mbox_t *  fsm,
ec_datagram_t *  datagram 
)

State: CHECK.

Evaluates the mailbox check datagram. The mailbox read lock is held.

Parameters
fsmFinite state machine.
datagramDatagram to use.

Definition at line 331 of file fsm_mbox.c.

◆ ec_fsm_mbox_state_fetch()

void ec_fsm_mbox_state_fetch ( ec_fsm_mbox_t *  fsm,
ec_datagram_t *  datagram 
)

State: FETCH.

Evaluates the mailbox fetch datagram. The receive path already stored the message in the response buffer of its protocol. The mailbox read lock is held.

Parameters
fsmFinite state machine.
datagramDatagram to use.

Definition at line 403 of file fsm_mbox.c.

◆ ec_fsm_mbox_state_end()

void ec_fsm_mbox_state_end ( ec_fsm_mbox_t *  fsm,
ec_datagram_t *  datagram 
)

State: END.

Parameters
fsmFinite state machine.
datagramDatagram to use.

Definition at line 471 of file fsm_mbox.c.

◆ ec_fsm_mbox_state_error()

void ec_fsm_mbox_state_error ( ec_fsm_mbox_t *  fsm,
ec_datagram_t *  datagram 
)

State: ERROR.

Parameters
fsmFinite state machine.
datagramDatagram to use.

Definition at line 482 of file fsm_mbox.c.

◆ ec_fsm_mbox_init()

void ec_fsm_mbox_init ( ec_fsm_mbox_t *  fsm)

Constructor.

Parameters
fsmFinite state machine.

Definition at line 45 of file fsm_mbox.c.

◆ ec_fsm_mbox_clear()

void ec_fsm_mbox_clear ( ec_fsm_mbox_t *  fsm)

Destructor.

Parameters
fsmFinite state machine.

Definition at line 64 of file fsm_mbox.c.

◆ ec_fsm_mbox_start()

static void ec_fsm_mbox_start ( ec_fsm_mbox_t *  fsm,
ec_slave_t *  slave,
ec_mbox_data_t *  mbox_data,
ec_fsm_mbox_mode_t  mode,
unsigned long  jiffies_start,
unsigned long  timeout_ms 
)
static

Starts the state machine in the given mode.

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

Definition at line 75 of file fsm_mbox.c.

◆ 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.

◆ ec_fsm_mbox_abort()

void ec_fsm_mbox_abort ( ec_fsm_mbox_t *  fsm)

Aborts the state machine and releases the mailbox read lock, if held.

Parameters
fsmFinite state machine.

Definition at line 220 of file fsm_mbox.c.

◆ ec_fsm_mbox_data_available()

static int ec_fsm_mbox_data_available ( const ec_fsm_mbox_t *  fsm)
static

Checks, if a message for the protocol is available.

Returns
Non-zero, if the response buffer contains a message.
Parameters
fsmFinite state machine.

Definition at line 242 of file fsm_mbox.c.

◆ ec_fsm_mbox_timed_out()

static int ec_fsm_mbox_timed_out ( const ec_fsm_mbox_t *  fsm,
unsigned long  now 
)
static

Checks, if the timeout elapsed.

Returns
Non-zero, if the timeout elapsed.
Parameters
fsmFinite state machine.
nowCurrent time in jiffies.

Definition at line 255 of file fsm_mbox.c.

◆ ec_fsm_mbox_fail()

static void ec_fsm_mbox_fail ( ec_fsm_mbox_t *  fsm,
ec_datagram_t *  datagram,
int  result 
)
static

Releases the mailbox read lock and terminates with an error.

Parameters
fsmFinite state machine.
datagramDatagram to use.
resultNegative error code.

Definition at line 267 of file fsm_mbox.c.