37 #include <linux/slab.h> 46 #define EC_FUNC_HEADER \ 47 ret = ec_datagram_prealloc(datagram, data_size); \ 50 datagram->index = 0; \ 51 datagram->working_counter = 0; \ 52 datagram->state = EC_DATAGRAM_INIT; 54 #define EC_FUNC_FOOTER \ 55 datagram->data_size = data_size; \ 90 INIT_LIST_HEAD(&datagram->
queue);
94 datagram->
data = NULL;
98 datagram->
index = 0x00;
101 #ifdef EC_HAVE_CYCLES 102 datagram->cycles_sent = 0;
105 #ifdef EC_HAVE_CYCLES 106 datagram->cycles_received = 0;
123 kfree(datagram->
data);
124 datagram->
data = NULL;
134 if (!list_empty(&datagram->
queue)) {
135 list_del_init(&datagram->
queue);
156 || size <= datagram->mem_size)
159 if (datagram->
data) {
160 kfree(datagram->
data);
161 datagram->
data = NULL;
165 if (!(datagram->
data = kmalloc(size, GFP_KERNEL))) {
166 EC_ERR(
"Failed to allocate %zu bytes of datagram memory!\n", size);
191 uint16_t ring_position,
192 uint16_t mem_address,
212 uint16_t ring_position,
213 uint16_t mem_address,
233 uint16_t ring_position,
234 uint16_t mem_address,
254 uint16_t ring_position,
255 uint16_t mem_address,
275 uint16_t configured_address,
276 uint16_t mem_address,
282 if (unlikely(configured_address == 0x0000))
283 EC_WARN(
"Using configured station address 0x0000!\n");
300 uint16_t configured_address,
301 uint16_t mem_address,
307 if (unlikely(configured_address == 0x0000))
308 EC_WARN(
"Using configured station address 0x0000!\n");
325 uint16_t configured_address,
326 uint16_t mem_address,
332 if (unlikely(configured_address == 0x0000))
333 EC_WARN(
"Using configured station address 0x0000!\n");
350 uint16_t configured_address,
351 uint16_t mem_address,
357 if (unlikely(configured_address == 0x0000))
358 EC_WARN(
"Using configured station address 0x0000!\n");
375 uint16_t mem_address,
395 uint16_t mem_address,
415 uint16_t mem_address,
497 uint8_t *external_memory
501 datagram->
data = external_memory;
522 uint8_t *external_memory
526 datagram->
data = external_memory;
547 uint8_t *external_memory
551 datagram->
data = external_memory;
569 printk(KERN_CONT
"Datagram ");
570 switch (datagram->
state) {
572 printk(KERN_CONT
"initialized");
575 printk(KERN_CONT
"queued");
578 printk(KERN_CONT
"sent");
581 printk(KERN_CONT
"received");
584 printk(KERN_CONT
"timed out");
587 printk(KERN_CONT
"error");
590 printk(KERN_CONT
"???");
593 printk(KERN_CONT
".\n");
607 printk(KERN_CONT
"No response.");
613 printk(KERN_CONT
"Success.");
615 printk(KERN_CONT
"\n");
630 EC_WARN(
"Datagram %p (%s) was SKIPPED %u time%s.\n",
631 datagram, datagram->
name,
#define EC_WARN(fmt, args...)
Convenience macro for printing EtherCAT-specific warnings to syslog.
unsigned long jiffies_sent
Jiffies, when the datagram was sent.
Auto Increment Physical Read Multiple Write.
#define EC_ADDR_LEN
Size of the EtherCAT address field.
static const char * type_strings[]
Array of datagram type strings used in ec_datagram_type_string().
#define EC_DATAGRAM_NAME_SIZE
Size of the datagram description string.
Auto Increment Physical ReadWrite.
size_t data_size
Size of the data in data.
unsigned long stats_output_jiffies
Last statistics output.
ec_origin_t data_origin
Origin of the data memory.
int ec_datagram_lwr_ext(ec_datagram_t *datagram, uint32_t offset, size_t data_size, uint8_t *external_memory)
Initializes an EtherCAT LWR datagram with external memory.
char name[EC_DATAGRAM_NAME_SIZE]
Description of the datagram.
uint16_t working_counter
Working counter.
#define EC_WRITE_S16(DATA, VAL)
Write a 16-bit signed value to EtherCAT data.
Sent (still in the queue).
Configured Address Physical Read.
void ec_datagram_output_stats(ec_datagram_t *datagram)
Outputs datagram statistics at most every second.
int ec_datagram_lwr(ec_datagram_t *datagram, uint32_t offset, size_t data_size)
Initializes an EtherCAT LWR datagram.
int ec_datagram_aprd(ec_datagram_t *datagram, uint16_t ring_position, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT APRD datagram.
ec_datagram_type_t type
Datagram type (APRD, BWR, etc.).
EtherCAT master structure.
Initial state of a new datagram.
int ec_datagram_apwr(ec_datagram_t *datagram, uint16_t ring_position, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT APWR datagram.
void ec_datagram_zero(ec_datagram_t *datagram)
Fills the datagram payload memory with zeros.
ec_datagram_state_t state
State.
#define EC_WRITE_U32(DATA, VAL)
Write a 32-bit unsigned value to EtherCAT data.
int ec_datagram_frmw(ec_datagram_t *datagram, uint16_t configured_address, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT FRMW datagram.
void ec_datagram_print_wc_error(const ec_datagram_t *datagram)
Evaluates the working counter of a single-cast datagram.
#define EC_WRITE_U16(DATA, VAL)
Write a 16-bit unsigned value to EtherCAT data.
unsigned int skip_count
Number of requeues when not yet received.
Auto Increment Physical Read.
int ec_datagram_brd(ec_datagram_t *datagram, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT BRD datagram.
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.
void ec_datagram_unqueue(ec_datagram_t *datagram)
Unqueue datagram.
int ec_datagram_lrd_ext(ec_datagram_t *datagram, uint32_t offset, size_t data_size, uint8_t *external_memory)
Initializes an EtherCAT LRD datagram with external memory.
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.
EtherCAT datagram structure.
ec_device_index_t device_index
Device via which the datagram shall be / was sent.
int ec_datagram_aprw(ec_datagram_t *datagram, uint16_t ring_position, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT APRW datagram.
int ec_datagram_lrd(ec_datagram_t *datagram, uint32_t offset, size_t data_size)
Initializes an EtherCAT LRD datagram.
int ec_datagram_fprw(ec_datagram_t *datagram, uint16_t configured_address, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT FPRW datagram.
int ec_datagram_prealloc(ec_datagram_t *datagram, size_t size)
Allocates internal payload memory.
Configured Address Physical Read Multiple Write.
void ec_datagram_print_state(const ec_datagram_t *datagram)
Prints the state of a datagram.
#define EC_ERR(fmt, args...)
Convenience macro for printing EtherCAT-specific errors to syslog.
int ec_datagram_brw(ec_datagram_t *datagram, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT BRW datagram.
void ec_datagram_init(ec_datagram_t *datagram)
Constructor.
int ec_datagram_lrw_ext(ec_datagram_t *datagram, uint32_t offset, size_t data_size, uint8_t *external_memory)
Initializes an EtherCAT LRW datagram with external memory.
const char * ec_datagram_type_string(const ec_datagram_t *datagram)
Returns a string describing the datagram type.
uint8_t * data
Datagram payload.
Configured Address Physical ReadWrite.
struct list_head queue
Master datagram queue item.
size_t mem_size
Datagram data memory size.
Error while sending/receiving (dequeued).
Auto Increment Physical Write.
uint8_t address[EC_ADDR_LEN]
Recipient address.
Configured Address Physical Write.
uint8_t index
Index (set by master).
int ec_datagram_lrw(ec_datagram_t *datagram, uint32_t offset, size_t data_size)
Initializes an EtherCAT LRW datagram.
unsigned long jiffies_received
Jiffies, when the datagram was received.
int ec_datagram_armw(ec_datagram_t *datagram, uint16_t ring_position, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT ARMW datagram.
int ec_datagram_bwr(ec_datagram_t *datagram, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT BWR datagram.
void ec_datagram_clear(ec_datagram_t *datagram)
Destructor.