62 INIT_LIST_HEAD(&fsm->
list);
142 fsm->
state(fsm, datagram);
153 return datagram_used;
254 list_del_init(&request->
list);
258 " slave has error flag set.\n");
259 request->
state = EC_INT_REQUEST_FAILURE;
266 EC_SLAVE_WARN(slave,
"Aborting SDO request, slave is in INIT.\n");
267 request->
state = EC_INT_REQUEST_FAILURE;
274 request->
state = EC_INT_REQUEST_BUSY;
303 EC_SLAVE_ERR(slave,
"Failed to process SDO request.\n");
304 request->
state = EC_INT_REQUEST_FAILURE;
314 request->
state = EC_INT_REQUEST_SUCCESS;
339 if (reg->
state == EC_INT_REQUEST_QUEUED) {
359 " slave has error flag set.\n");
368 EC_SLAVE_DBG(slave, 1,
"Processing register request...\n");
409 " request datagram: ");
411 reg->
state = EC_INT_REQUEST_FAILURE;
423 reg->
state = EC_INT_REQUEST_SUCCESS;
424 EC_SLAVE_DBG(slave, 1,
"Register request successful.\n");
426 reg->
state = EC_INT_REQUEST_FAILURE;
429 " (working counter is %u).\n",
458 list_del_init(&request->
list);
462 " slave has error flag set.\n");
463 request->
state = EC_INT_REQUEST_FAILURE;
469 request->
state = EC_INT_REQUEST_BUSY;
498 request->
state = EC_INT_REQUEST_FAILURE;
506 EC_SLAVE_DBG(slave, 1,
"Successfully transferred %zu bytes of FoE" 509 request->
state = EC_INT_REQUEST_SUCCESS;
535 list_del_init(&req->
list);
539 " slave has error flag set.\n");
540 req->
state = EC_INT_REQUEST_FAILURE;
547 EC_SLAVE_WARN(slave,
"Aborting SoE request, slave is in INIT.\n");
548 req->
state = EC_INT_REQUEST_FAILURE;
555 req->
state = EC_INT_REQUEST_BUSY;
584 EC_SLAVE_ERR(slave,
"Failed to process SoE request.\n");
585 request->
state = EC_INT_REQUEST_FAILURE;
595 request->
state = EC_INT_REQUEST_SUCCESS;
622 list_del_init(&request->
list);
626 " slave has error flag set.\n");
627 request->
state = EC_INT_REQUEST_FAILURE;
634 EC_SLAVE_WARN(slave,
"Aborting EoE request, slave is in INIT.\n");
635 request->
state = EC_INT_REQUEST_FAILURE;
642 request->
state = EC_INT_REQUEST_BUSY;
671 req->
state = EC_INT_REQUEST_SUCCESS;
675 req->
state = EC_INT_REQUEST_FAILURE;
676 EC_SLAVE_ERR(slave,
"Failed to process EoE request.\n");
int ec_fsm_eoe_exec(ec_fsm_eoe_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
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.
void ec_fsm_slave_state_eoe_request(ec_fsm_slave_t *, ec_datagram_t *)
Slave state: EOE_REQUEST.
#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.
void ec_fsm_eoe_init(ec_fsm_eoe_t *fsm)
Constructor.
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.
void ec_fsm_eoe_set_ip_param(ec_fsm_eoe_t *fsm, ec_slave_t *slave, ec_eoe_request_t *request)
Starts to set the EoE IP partameters of a slave.
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_eoe_request_t * eoe_request
SoE request to process.
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 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.
ec_fsm_eoe_t fsm_eoe
EoE state machine.
int ec_fsm_eoe_success(const ec_fsm_eoe_t *fsm)
Returns, if the state machine terminated with success.
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.
Ethernet-over-EtherCAT set IP parameter request.
void ec_fsm_eoe_clear(ec_fsm_eoe_t *fsm)
Destructor.
INIT state (no mailbox communication, no IO)
ec_internal_request_state_t state
Request state.
struct list_head foe_requests
FoE 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.
struct list_head eoe_requests
EoE set IP parameter requests.
int ec_fsm_slave_action_process_eoe(ec_fsm_slave_t *, ec_datagram_t *)
Check for pending EoE IP parameter requests and process one.
void(* state)(ec_fsm_slave_t *, ec_datagram_t *)
State function.
ec_internal_request_state_t state
Request state.
struct list_head list
List item.
Sercos-over-EtherCAT request.
struct list_head list
List item.