IgH EtherCAT Master  1.7.0
fsm_mbox.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2026 Florian Pose, Ingenieurgemeinschaft IgH
4  *
5  * This file is part of the IgH EtherCAT Master.
6  *
7  * The IgH EtherCAT Master is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version 2, as
9  * published by the Free Software Foundation.
10  *
11  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with the IgH EtherCAT Master; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  ****************************************************************************/
21 
26 /****************************************************************************/
27 
28 #ifndef __EC_FSM_MBOX_H__
29 #define __EC_FSM_MBOX_H__
30 
31 #include "globals.h"
32 #include "datagram.h"
33 #include "mailbox.h"
34 
35 /****************************************************************************/
36 
39 typedef enum {
44 
45 /****************************************************************************/
46 
47 typedef struct ec_fsm_mbox ec_fsm_mbox_t;
62 struct ec_fsm_mbox {
66  unsigned long jiffies_start;
67  unsigned long timeout_ms;
70  unsigned int retries;
71  int result;
72 };
73 
74 /****************************************************************************/
75 
78 
80  unsigned long, unsigned long);
83  ec_mbox_data_t *, unsigned long, unsigned long);
84 
89 
90 /****************************************************************************/
91 
92 #endif
ec_fsm_mbox_mode_t mode
Receive mode.
Definition: fsm_mbox.h:65
ec_datagram_t * datagram
Datagram used in the last step.
Definition: fsm_mbox.h:69
EtherCAT mailbox receive state machine.
Definition: fsm_mbox.h:62
unsigned long jiffies_start
Reference time for the timeout.
Definition: fsm_mbox.h:66
Fetch the mailbox once without checking it.
Definition: fsm_mbox.h:42
EtherCAT mailbox response data.
Definition: mailbox.h:58
EtherCAT datagram.
Definition: datagram.h:81
ec_fsm_mbox_mode_t
Mode of the mailbox receive state machine.
Definition: fsm_mbox.h:39
Wait for a response until the timeout elapsed.
Definition: fsm_mbox.h:40
unsigned int retries
Retries upon datagram timeout.
Definition: fsm_mbox.h:70
Global definitions and macros.
void(* state)(ec_fsm_mbox_t *, ec_datagram_t *)
State function.
Definition: fsm_mbox.h:68
EtherCAT slave.
Definition: slave.h:170
void ec_fsm_mbox_poll(ec_fsm_mbox_t *, ec_slave_t *, ec_mbox_data_t *)
Starts a single mailbox check without waiting.
Definition: fsm_mbox.c:123
ec_mbox_data_t * mbox_data
Response buffer of the protocol.
Definition: fsm_mbox.h:64
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.
Definition: fsm_mbox.c:140
unsigned long timeout_ms
Response timeout in [ms].
Definition: fsm_mbox.h:67
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.
Definition: fsm_mbox.c:102
int ec_fsm_mbox_exec(ec_fsm_mbox_t *, ec_datagram_t *)
Executes the current state of the state machine.
Definition: fsm_mbox.c:161
EtherCAT datagram structure.
int ec_fsm_mbox_holds_lock(const ec_fsm_mbox_t *)
Checks, if the state machine holds the slave's mailbox read lock.
Definition: fsm_mbox.c:208
Mailbox functionality.
Check the mailbox once, do not wait.
Definition: fsm_mbox.h:41
void ec_fsm_mbox_init(ec_fsm_mbox_t *)
Constructor.
Definition: fsm_mbox.c:45
void ec_fsm_mbox_clear(ec_fsm_mbox_t *)
Destructor.
Definition: fsm_mbox.c:64
ec_slave_t * slave
Slave the FSM runs on.
Definition: fsm_mbox.h:63
int result
Zero on success, otherwise a negative error code.
Definition: fsm_mbox.h:71
int ec_fsm_mbox_result(const ec_fsm_mbox_t *)
Returns the result of the terminated state machine.
Definition: fsm_mbox.c:195
void ec_fsm_mbox_abort(ec_fsm_mbox_t *)
Aborts the state machine and releases the mailbox read lock, if held.
Definition: fsm_mbox.c:220