39#define EC_FSM_FOE_TIMEOUT 3000
43#define EC_FOE_HEADER_SIZE 6
122 int datagram_used = 0;
129 return datagram_used;
132 fsm->
state(fsm, datagram);
143 return datagram_used;
229 size_t remaining_size, current_size;
234 if (remaining_size < fsm->slave->configured_tx_mailbox_size
236 current_size = remaining_size;
345 EC_SLAVE_ERR(slave,
"Failed to receive FoE mailbox check datagram: ");
352 EC_SLAVE_ERR(slave,
"Reception of FoE mailbox check datagram"
364 EC_SLAVE_ERR(slave,
"Timeout while waiting for ack response.\n");
390 uint8_t *data, mbox_prot;
400 EC_SLAVE_ERR(slave,
"Failed to receive FoE ack response datagram: ");
407 EC_SLAVE_ERR(slave,
"Reception of FoE ack response failed: ");
418 if (mbox_prot != EC_MBOX_TYPE_FOE) {
420 EC_SLAVE_ERR(slave,
"Received mailbox protocol 0x%02X as response.\n",
518 EC_SLAVE_ERR(slave,
"Failed to receive FoE ack response datagram: ");
525 EC_SLAVE_ERR(slave,
"Reception of FoE data send failed: ");
703 EC_SLAVE_ERR(slave,
"Timeout while waiting for ack response.\n");
729 uint8_t *data, opCode, packet_no, mbox_prot;
739 EC_SLAVE_ERR(slave,
"Failed to receive FoE DATA READ datagram: ");
746 EC_SLAVE_ERR(slave,
"Reception of FoE DATA READ failed: ");
757 if (mbox_prot != EC_MBOX_TYPE_FOE) {
758 EC_SLAVE_ERR(slave,
"Received mailbox protocol 0x%02X as response.\n",
775 EC_SLAVE_ERR(slave,
"Received FoE Error Request (code 0x%08x).\n",
779 strncpy(text, data + 6, min(rec_size - 6,
sizeof(text)));
787 EC_SLAVE_ERR(slave,
"Received OPCODE %x, expected %x.\n",
796 EC_SLAVE_ERR(slave,
"Received unexpected packet number.\n");
832 EC_SLAVE_ERR(slave,
"Data do not fit in receive buffer!\n");
835 printk(KERN_CONT
" rec_size = %zd\n", rec_size);
836 printk(KERN_CONT
" rx_mailbox_size = %d\n",
void ec_datagram_print_wc_error(const ec_datagram_t *datagram)
Evaluates the working counter of a single-cast datagram.
void ec_datagram_print_state(const ec_datagram_t *datagram)
Prints the state of a datagram.
@ EC_DATAGRAM_INIT
Initial state of a new datagram.
@ EC_DATAGRAM_RECEIVED
Received (dequeued).
@ EC_DATAGRAM_SENT
Sent (still in the queue).
@ EC_DATAGRAM_QUEUED
Queued for sending.
@ FOE_RX_DATA_ACK_ERROR
Error acknowledging received data.
@ FOE_WC_ERROR
Working counter error.
@ FOE_MBOX_PROT_ERROR
Mailbox protocol error.
@ FOE_RECEIVE_ERROR
Receive error.
@ FOE_OPCODE_ERROR
OpCode error.
@ FOE_PACKETNO_ERROR
Packet number error.
@ FOE_ACK_ERROR
Acknowledge error.
@ FOE_TIMEOUT_ERROR
Timeout error.
@ FOE_MBOX_FETCH_ERROR
Error fetching data from mailbox.
@ FOE_PROT_ERROR
Protocol error.
#define EC_FOE_HEADER_SIZE
Size of the FoE header.
void ec_fsm_foe_state_wrq_sent(ec_fsm_foe_t *, ec_datagram_t *)
State: WRQ SENT.
void ec_fsm_foe_state_rrq_sent(ec_fsm_foe_t *, ec_datagram_t *)
State: RRQ SENT.
void ec_fsm_foe_state_ack_check(ec_fsm_foe_t *, ec_datagram_t *)
Check for acknowledge.
void ec_fsm_foe_write_start(ec_fsm_foe_t *, ec_datagram_t *)
Initializes the FoE write state machine.
int ec_fsm_foe_exec(ec_fsm_foe_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
void ec_fsm_foe_read_start(ec_fsm_foe_t *, ec_datagram_t *)
Starting state for read operations.
int ec_foe_prepare_data_send(ec_fsm_foe_t *, ec_datagram_t *)
Sends a file or the next fragment.
int ec_foe_prepare_rrq_send(ec_fsm_foe_t *, ec_datagram_t *)
Prepare a read request (RRQ) with filename.
#define EC_FSM_FOE_TIMEOUT
Maximum time in ms to wait for responses when reading out the dictionary.
void ec_fsm_foe_clear(ec_fsm_foe_t *fsm)
Destructor.
@ EC_FOE_OPCODE_RRQ
Read request.
@ EC_FOE_OPCODE_ERR
Error.
@ EC_FOE_OPCODE_WRQ
Write request.
@ EC_FOE_OPCODE_BUSY
Busy.
@ EC_FOE_OPCODE_DATA
Data.
@ EC_FOE_OPCODE_ACK
Acknowledge.
void ec_fsm_foe_state_data_sent(ec_fsm_foe_t *, ec_datagram_t *)
State: WRQ SENT.
int ec_foe_prepare_send_ack(ec_fsm_foe_t *, ec_datagram_t *)
Prepare to send an acknowledge.
void ec_foe_set_tx_error(ec_fsm_foe_t *, uint32_t)
Set an error code and go to the send error state.
void ec_foe_set_rx_error(ec_fsm_foe_t *, uint32_t)
Set an error code and go to the receive error state.
int ec_fsm_foe_success(const ec_fsm_foe_t *fsm)
Returns, if the state machine terminated with success.
void ec_fsm_foe_state_sent_ack(ec_fsm_foe_t *, ec_datagram_t *)
Sent an acknowledge.
void ec_fsm_foe_init(ec_fsm_foe_t *fsm)
Constructor.
int ec_foe_prepare_wrq_send(ec_fsm_foe_t *, ec_datagram_t *)
Prepare a write request (WRQ) with filename.
void ec_fsm_foe_state_data_read(ec_fsm_foe_t *, ec_datagram_t *)
Start reading data.
void ec_fsm_foe_transfer(ec_fsm_foe_t *fsm, ec_slave_t *slave, ec_foe_request_t *request)
Prepares an FoE transfer.
void ec_fsm_foe_state_ack_read(ec_fsm_foe_t *, ec_datagram_t *)
Acknowledge a read operation.
void ec_fsm_foe_error(ec_fsm_foe_t *, ec_datagram_t *)
State: ERROR.
void ec_fsm_foe_end(ec_fsm_foe_t *, ec_datagram_t *)
State: END.
void ec_fsm_foe_state_data_check(ec_fsm_foe_t *, ec_datagram_t *)
Check for data.
EtherCAT FoE state machines.
struct ec_fsm_foe ec_fsm_foe_t
Global definitions and macros.
#define EC_MBOX_HEADER_SIZE
Mailbox header size.
#define EC_FSM_RETRIES
Number of state machine retries on datagram timeout.
@ EC_MBOX_FOE
File-Access over EtherCAT.
struct ec_slave ec_slave_t
void ec_print_data(const uint8_t *, size_t)
Outputs frame contents for debugging purposes.
#define EC_WRITE_U32(DATA, VAL)
Write a 32-bit unsigned value to EtherCAT data.
#define EC_READ_U16(DATA)
Read a 16-bit unsigned value from EtherCAT data.
#define EC_READ_U8(DATA)
Read an 8-bit unsigned value from EtherCAT data.
#define EC_READ_U32(DATA)
Read a 32-bit unsigned value from EtherCAT data.
#define EC_WRITE_U16(DATA, VAL)
Write a 16-bit unsigned value to EtherCAT data.
@ EC_DIR_OUTPUT
Values written by the master.
uint8_t * ec_slave_mbox_fetch(const ec_slave_t *slave, const ec_datagram_t *datagram, uint8_t *type, size_t *size)
Processes received mailbox data.
int ec_slave_mbox_prepare_check(const ec_slave_t *slave, ec_datagram_t *datagram)
Prepares a datagram for checking the mailbox state.
int ec_slave_mbox_prepare_fetch(const ec_slave_t *slave, ec_datagram_t *datagram)
Prepares a datagram to fetch mailbox data.
uint8_t * ec_slave_mbox_prepare_send(const ec_slave_t *slave, ec_datagram_t *datagram, uint8_t type, size_t size)
Prepares a mailbox-send datagram.
int ec_slave_mbox_check(const ec_datagram_t *datagram)
Processes a mailbox state checking datagram.
EtherCAT master structure.
#define EC_SLAVE_DBG(slave, level, fmt, args...)
Convenience macro for printing slave-specific debug messages to syslog.
#define EC_SLAVE_ERR(slave, fmt, args...)
Convenience macro for printing slave-specific errors to syslog.
uint16_t working_counter
Working counter.
unsigned long jiffies_received
Jiffies, when the datagram was received.
unsigned long jiffies_sent
Jiffies, when the datagram was sent.
ec_datagram_state_t state
State.
ec_direction_t dir
Direction.
uint32_t result
FoE request abort code.
size_t buffer_size
Size of FoE data memory.
uint32_t error_code
Error code from an FoE Error Request.
uint8_t * buffer
Pointer to FoE data.
uint8_t * file_name
Pointer to the filename.
size_t data_size
Size of FoE data.
ec_foe_request_t * request
FoE request.
uint32_t rx_last_packet
Current packet is the last to receive.
ec_datagram_t * datagram
Datagram used in previous step.
uint8_t * rx_buffer
Buffer for received data.
uint32_t tx_buffer_size
Size of data to transmit.
unsigned int retries
Retries upon datagram timeout.
unsigned long jiffies_start
FoE timestamp.
uint32_t rx_expected_packet_no
Expected receive packet number.
uint32_t tx_filename_len
Lenth of transmit file name.
uint32_t tx_packet_no
FoE packet number.
uint32_t rx_buffer_offset
Offset in receive buffer.
uint8_t * tx_filename
Name of file to transmit.
uint32_t tx_last_packet
Current packet is last one to send.
uint32_t rx_filename_len
Length of the receive file name.
uint32_t rx_buffer_size
Size of receive buffer.
ec_slave_t * slave
Slave the FSM runs on.
uint32_t tx_buffer_offset
Offset of data to tranmit next.
uint8_t * rx_filename
Name of the file to receive.
void(* state)(ec_fsm_foe_t *, ec_datagram_t *)
FoE state function.
uint32_t tx_current_size
Size of current packet to send.
uint8_t * tx_buffer
Buffer with data to transmit.
unsigned int debug_level
Master debug level.
uint16_t mailbox_protocols
Supported mailbox protocols.
uint16_t configured_rx_mailbox_size
Configured receive mailbox size.
ec_sii_t sii
Extracted SII data.
uint16_t configured_tx_mailbox_size
Configured send mailbox size.
ec_master_t * master
Master owning the slave.