47 #define EC_FSM_FOE_TIMEOUT 3000 51 #define EC_FOE_HEADER_SIZE 6 130 int datagram_used = 0;
137 return datagram_used;
140 fsm->
state(fsm, datagram);
151 return datagram_used;
237 size_t remaining_size, current_size;
242 if (remaining_size < fsm->slave->configured_tx_mailbox_size
244 current_size = remaining_size;
353 EC_SLAVE_ERR(slave,
"Failed to receive FoE mailbox check datagram: ");
360 EC_SLAVE_ERR(slave,
"Reception of FoE mailbox check datagram" 372 EC_SLAVE_ERR(slave,
"Timeout while waiting for ack response.\n");
398 uint8_t *data, mbox_prot;
408 EC_SLAVE_ERR(slave,
"Failed to receive FoE ack response datagram: ");
415 EC_SLAVE_ERR(slave,
"Reception of FoE ack response failed: ");
426 if (mbox_prot != EC_MBOX_TYPE_FOE) {
428 EC_SLAVE_ERR(slave,
"Received mailbox protocol 0x%02X as response.\n",
526 EC_SLAVE_ERR(slave,
"Failed to receive FoE ack response datagram: ");
533 EC_SLAVE_ERR(slave,
"Reception of FoE data send failed: ");
711 EC_SLAVE_ERR(slave,
"Timeout while waiting for ack response.\n");
737 uint8_t *data, opCode, packet_no, mbox_prot;
747 EC_SLAVE_ERR(slave,
"Failed to receive FoE DATA READ datagram: ");
754 EC_SLAVE_ERR(slave,
"Reception of FoE DATA READ failed: ");
765 if (mbox_prot != EC_MBOX_TYPE_FOE) {
766 EC_SLAVE_ERR(slave,
"Received mailbox protocol 0x%02X as response.\n",
783 EC_SLAVE_ERR(slave,
"Received FoE Error Request (code 0x%08x).\n",
787 strncpy(text, data + 6, min(rec_size - 6,
sizeof(text)));
795 EC_SLAVE_ERR(slave,
"Received OPCODE %x, expected %x.\n",
804 EC_SLAVE_ERR(slave,
"Received unexpected packet number.\n");
840 EC_SLAVE_ERR(slave,
"Data do not fit in receive buffer!\n");
843 printk(KERN_CONT
" rec_size = %zd\n", rec_size);
844 printk(KERN_CONT
" rx_mailbox_size = %d\n",
uint8_t * tx_filename
Name of file to transmit.
#define EC_FSM_RETRIES
Number of state machine retries on datagram timeout.
ec_slave_t * slave
Slave the FSM runs on.
uint8_t * rx_buffer
Buffer for received data.
void ec_fsm_foe_read_start(ec_fsm_foe_t *, ec_datagram_t *)
Starting state for read operations.
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.
unsigned long jiffies_sent
Jiffies, when the datagram was sent.
ec_sii_t sii
Extracted SII data.
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.
Error fetching data from mailbox.
int ec_fsm_foe_success(const ec_fsm_foe_t *fsm)
Returns, if the state machine terminated with success.
ec_direction_t dir
Direction.
uint16_t configured_tx_mailbox_size
Configured send mailbox size.
void ec_fsm_foe_error(ec_fsm_foe_t *, ec_datagram_t *)
State: ERROR.
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.
uint32_t tx_packet_no
FoE packet number.
unsigned long jiffies_start
FoE timestamp.
int ec_slave_mbox_prepare_fetch(const ec_slave_t *slave, ec_datagram_t *datagram)
Prepares a datagram to fetch mailbox data.
void ec_fsm_foe_state_rrq_sent(ec_fsm_foe_t *, ec_datagram_t *)
State: RRQ SENT.
uint8_t * tx_buffer
Buffer with data to transmit.
uint32_t tx_buffer_offset
Offset of data to tranmit next.
#define EC_FOE_HEADER_SIZE
Size of the FoE header.
enum @1 ec_foe_opcode_t
FoE OpCodes.
uint16_t working_counter
Working counter.
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_foe_set_tx_error(ec_fsm_foe_t *, uint32_t)
Set an error code and go to the send error state.
uint32_t tx_filename_len
Lenth of transmit file name.
uint32_t rx_filename_len
Length of the receive file name.
Sent (still in the queue).
uint32_t result
FoE request abort code.
void ec_fsm_foe_end(ec_fsm_foe_t *, ec_datagram_t *)
State: END.
int ec_foe_prepare_wrq_send(ec_fsm_foe_t *, ec_datagram_t *)
Prepare a write request (WRQ) with filename.
Global definitions and macros.
EtherCAT master structure.
Initial state of a new datagram.
File-Access over EtherCAT.
size_t buffer_size
Size of FoE data memory.
uint32_t tx_last_packet
Current packet is last one to send.
void ec_fsm_foe_state_wrq_sent(ec_fsm_foe_t *, ec_datagram_t *)
State: WRQ SENT.
void ec_fsm_foe_init(ec_fsm_foe_t *fsm)
Constructor.
ec_datagram_state_t state
State.
#define EC_WRITE_U32(DATA, VAL)
Write a 32-bit unsigned value to EtherCAT data.
uint8_t * buffer
Pointer to FoE data.
uint32_t rx_expected_packet_no
Expected receive packet number.
uint16_t mailbox_protocols
Supported mailbox protocols.
Error acknowledging received data.
unsigned int debug_level
Master debug level.
#define EC_SLAVE_ERR(slave, fmt, args...)
Convenience macro for printing slave-specific errors to syslog.
void ec_datagram_print_wc_error(const ec_datagram_t *datagram)
Evaluates the working counter of a single-cast datagram.
void ec_foe_set_rx_error(ec_fsm_foe_t *, uint32_t)
Set an error code and go to the receive error state.
uint32_t rx_buffer_size
Size of receive buffer.
void ec_fsm_foe_write_start(ec_fsm_foe_t *, ec_datagram_t *)
Initializes the FoE write state machine.
#define EC_WRITE_U16(DATA, VAL)
Write a 16-bit unsigned value to EtherCAT data.
#define EC_READ_U32(DATA)
Read a 32-bit unsigned value from EtherCAT data.
ec_master_t * master
Master owning the slave.
#define EC_FSM_FOE_TIMEOUT
Maximum time in ms to wait for responses when reading out the dictionary.
void ec_fsm_foe_state_sent_ack(ec_fsm_foe_t *, ec_datagram_t *)
Sent an acknowledge.
uint32_t tx_buffer_size
Size of data to transmit.
int ec_foe_prepare_data_send(ec_fsm_foe_t *, ec_datagram_t *)
Sends a file or the next fragment.
#define EC_MBOX_HEADER_SIZE
Mailbox header size.
size_t data_size
Size of FoE data.
void ec_fsm_foe_state_data_read(ec_fsm_foe_t *, ec_datagram_t *)
Start reading data.
uint32_t rx_last_packet
Current packet is the last to receive.
void ec_print_data(const uint8_t *, size_t)
Outputs frame contents for debugging purposes.
uint8_t * file_name
Pointer to the filename.
unsigned int retries
Retries upon datagram timeout.
int ec_slave_mbox_prepare_check(const ec_slave_t *slave, ec_datagram_t *datagram)
Prepares a datagram for checking the mailbox state.
#define EC_READ_U16(DATA)
Read a 16-bit unsigned value from EtherCAT data.
ec_datagram_t * datagram
Datagram used in previous step.
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.
int ec_foe_prepare_rrq_send(ec_fsm_foe_t *, ec_datagram_t *)
Prepare a read request (RRQ) with filename.
ec_foe_request_t * request
FoE request.
void ec_fsm_foe_state_ack_read(ec_fsm_foe_t *, ec_datagram_t *)
Acknowledge a read operation.
uint16_t configured_rx_mailbox_size
Configured receive mailbox size.
void(* state)(ec_fsm_foe_t *, ec_datagram_t *)
FoE state function.
#define EC_READ_U8(DATA)
Read an 8-bit unsigned value from EtherCAT data.
uint8_t * rx_filename
Name of the file to receive.
uint32_t error_code
Error code from an FoE Error Request.
void ec_fsm_foe_state_data_sent(ec_fsm_foe_t *, ec_datagram_t *)
State: WRQ SENT.
Values written by the master.
uint32_t tx_current_size
Size of current packet to send.
int ec_foe_prepare_send_ack(ec_fsm_foe_t *, ec_datagram_t *)
Prepare to send an acknowledge.
void ec_fsm_foe_state_data_check(ec_fsm_foe_t *, ec_datagram_t *)
Check for data.
EtherCAT FoE state machines.
unsigned long jiffies_received
Jiffies, when the datagram was received.
int ec_slave_mbox_check(const ec_datagram_t *datagram)
Processes a mailbox state checking datagram.
Finite state machines for the CANopen-over-EtherCAT protocol.
uint32_t rx_buffer_offset
Offset in receive buffer.
void ec_fsm_foe_state_ack_check(ec_fsm_foe_t *, ec_datagram_t *)
Check for acknowledge.