64 INIT_LIST_HEAD(&fsm->
list);
128 fsm->
state(fsm, datagram);
139 return datagram_used;
233 list_del_init(&request->
list);
237 " slave has error flag set.\n");
238 request->
state = EC_INT_REQUEST_FAILURE;
245 EC_SLAVE_WARN(slave,
"Aborting SDO request, slave is in INIT.\n");
246 request->
state = EC_INT_REQUEST_FAILURE;
253 request->
state = EC_INT_REQUEST_BUSY;
282 EC_SLAVE_ERR(slave,
"Failed to process SDO request.\n");
283 request->
state = EC_INT_REQUEST_FAILURE;
293 request->
state = EC_INT_REQUEST_SUCCESS;
318 if (reg->
state == EC_INT_REQUEST_QUEUED) {
338 " slave has error flag set.\n");
347 EC_SLAVE_DBG(slave, 1,
"Processing register request...\n");
388 " request datagram: ");
390 reg->
state = EC_INT_REQUEST_FAILURE;
402 reg->
state = EC_INT_REQUEST_SUCCESS;
403 EC_SLAVE_DBG(slave, 1,
"Register request successful.\n");
405 reg->
state = EC_INT_REQUEST_FAILURE;
408 " (working counter is %u).\n",
437 list_del_init(&request->
list);
441 " slave has error flag set.\n");
442 request->
state = EC_INT_REQUEST_FAILURE;
448 request->
state = EC_INT_REQUEST_BUSY;
477 request->
state = EC_INT_REQUEST_FAILURE;
485 EC_SLAVE_DBG(slave, 1,
"Successfully transferred %zu bytes of FoE" 488 request->
state = EC_INT_REQUEST_SUCCESS;
514 list_del_init(&req->
list);
518 " slave has error flag set.\n");
519 req->
state = EC_INT_REQUEST_FAILURE;
526 EC_SLAVE_WARN(slave,
"Aborting SoE request, slave is in INIT.\n");
527 req->
state = EC_INT_REQUEST_FAILURE;
534 req->
state = EC_INT_REQUEST_BUSY;
563 EC_SLAVE_ERR(slave,
"Failed to process SoE request.\n");
564 request->
state = EC_INT_REQUEST_FAILURE;
574 request->
state = EC_INT_REQUEST_SUCCESS;
ec_internal_request_state_t state
Request state.
void ec_fsm_slave_clear(ec_fsm_slave_t *fsm)
Destructor.
int ec_fsm_foe_success(const ec_fsm_foe_t *fsm)
Returns, if the state machine terminated with success.
void ec_fsm_slave_state_foe_request(ec_fsm_slave_t *, ec_datagram_t *)
Slave state: FOE REQUEST.
size_t transfer_size
Size of the data to transfer.
ec_foe_request_t * foe_request
FoE request to process.
void ec_fsm_foe_clear(ec_fsm_foe_t *fsm)
Destructor.
#define EC_SLAVE_DBG(slave, level, fmt, args...)
Convenience macro for printing slave-specific debug messages to syslog.
ec_reg_request_t * reg_request
Register request to process.
int ec_fsm_slave_is_ready(const ec_fsm_slave_t *fsm)
Returns, if the FSM is currently not busy and ready to execute.
ec_slave_state_t current_state
Current application state.
ec_internal_request_state_t state
SDO request state.
uint16_t address
Register address.
#define EC_SLAVE_WARN(slave, fmt, args...)
Convenience macro for printing slave-specific warnings to syslog.
void ec_fsm_slave_state_soe_request(ec_fsm_slave_t *, ec_datagram_t *)
Slave state: SOE_REQUEST.
ec_fsm_soe_t fsm_soe
SoE state machine.
Finite state machine of an EtherCAT slave.
ec_datagram_t * datagram
Previous state datagram.
struct list_head reg_requests
Register access requests.
uint16_t working_counter
Working counter.
int ec_fsm_slave_action_process_foe(ec_fsm_slave_t *, ec_datagram_t *)
Check for pending FoE requests and process one.
void ec_fsm_foe_transfer(ec_fsm_foe_t *fsm, ec_slave_t *slave, ec_foe_request_t *request)
Prepares an FoE transfer.
Acknowledge/Error bit (no actual state)
int ec_fsm_coe_success(const ec_fsm_coe_t *fsm)
Returns, if the state machine terminated with success.
wait_queue_head_t request_queue
Wait queue for external requests from user space.
ec_sdo_request_t * sdo_request
SDO request to process.
int ec_fsm_slave_action_process_reg(ec_fsm_slave_t *, ec_datagram_t *)
Check for pending register requests and process one.
uint16_t station_address
Configured station address.
int ec_fsm_slave_action_process_soe(ec_fsm_slave_t *, ec_datagram_t *)
Check for pending SoE requests and process one.
Global definitions and macros.
EtherCAT master structure.
void ec_fsm_slave_state_sdo_request(ec_fsm_slave_t *, ec_datagram_t *)
Slave state: SDO_REQUEST.
ec_slave_t * slave
slave the FSM runs on
struct list_head sdo_requests
SDO access requests.
void ec_datagram_zero(ec_datagram_t *datagram)
Fills the datagram payload memory with zeros.
void ec_fsm_foe_init(ec_fsm_foe_t *fsm)
Constructor.
void ec_fsm_soe_transfer(ec_fsm_soe_t *fsm, ec_slave_t *slave, ec_soe_request_t *request)
Starts to transfer an IDN to/from a slave.
int ec_fsm_soe_success(const ec_fsm_soe_t *fsm)
Returns, if the state machine terminated with success.
struct list_head soe_requests
SoE write requests.
ec_datagram_state_t state
State.
ec_slave_config_t * config
Current configuration.
struct list_head reg_requests
List of register requests.
#define EC_SLAVE_ERR(slave, fmt, args...)
Convenience macro for printing slave-specific errors to syslog.
void ec_fsm_slave_state_reg_request(ec_fsm_slave_t *, ec_datagram_t *)
Slave state: Register request.
void ec_fsm_slave_set_ready(ec_fsm_slave_t *fsm)
Sets the current state of the state machine to READY.
struct list_head list
List item.
ec_soe_request_t * soe_request
SoE request to process.
void ec_fsm_coe_clear(ec_fsm_coe_t *fsm)
Destructor.
int ec_fsm_slave_exec(ec_fsm_slave_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
ec_master_t * master
Master owning the slave.
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.
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.
Values read by the master.
ec_device_index_t device_index
Device via which the datagram shall be / was sent.
void ec_fsm_slave_state_ready(ec_fsm_slave_t *, ec_datagram_t *)
Slave state: READY.
size_t data_size
Size of FoE data.
void ec_fsm_coe_init(ec_fsm_coe_t *fsm)
Constructor.
INIT state (no mailbox communication, no IO)
struct list_head foe_requests
FoE write requests.
int ec_fsm_slave_action_process_sdo(ec_fsm_slave_t *, ec_datagram_t *)
Check for pending SDO requests and process one.
int ec_fsm_foe_exec(ec_fsm_foe_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
void ec_datagram_print_state(const ec_datagram_t *datagram)
Prints the state of a datagram.
struct list_head list
Used for execution list.
uint8_t * data
Pointer to data memory.
struct list_head list
List item.
void ec_fsm_slave_init(ec_fsm_slave_t *fsm, ec_slave_t *slave)
Constructor.
int ec_fsm_coe_exec(ec_fsm_coe_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
EtherCAT slave request state machine.
ec_direction_t dir
Direction.
ec_fsm_foe_t fsm_foe
FoE state machine.
void ec_fsm_soe_init(ec_fsm_soe_t *fsm)
Constructor.
void ec_fsm_soe_clear(ec_fsm_soe_t *fsm)
Destructor.
uint8_t * data
Datagram payload.
ec_fsm_coe_t fsm_coe
CoE state machine.
EtherCAT slave configuration structure.
ec_internal_request_state_t state
FoE request state.
ec_device_index_t device_index
Index of device the slave responds on.
int ec_fsm_soe_exec(ec_fsm_soe_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
void ec_fsm_coe_transfer(ec_fsm_coe_t *fsm, ec_slave_t *slave, ec_sdo_request_t *request)
Starts to transfer an SDO to/from a slave.
void ec_fsm_slave_state_idle(ec_fsm_slave_t *, ec_datagram_t *)
Slave state: IDLE.
struct list_head list
List item.
void(* state)(ec_fsm_slave_t *, ec_datagram_t *)
State function.
ec_internal_request_state_t state
Request state.
Sercos-over-EtherCAT request.
struct list_head list
List item.