IgH EtherCAT Master  1.5.2
domain.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
6  *
7  * This file is part of the IgH EtherCAT Master.
8  *
9  * The IgH EtherCAT Master is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version 2, as
11  * published by the Free Software Foundation.
12  *
13  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with the IgH EtherCAT Master; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * ---
23  *
24  * The license mentioned above concerns the source code only. Using the
25  * EtherCAT technology and brand is only permitted in compliance with the
26  * industrial property and similar rights of Beckhoff Automation GmbH.
27  *
28  *****************************************************************************/
29 
35 /*****************************************************************************/
36 
37 #include <linux/module.h>
38 
39 #include "globals.h"
40 #include "master.h"
41 #include "slave_config.h"
42 
43 #include "domain.h"
44 #include "datagram_pair.h"
45 
48 #define DEBUG_REDUNDANCY 0
49 
50 #ifndef list_next_entry
51 #define list_next_entry(pos, member) \
52  list_entry((pos)->member.next, typeof(*(pos)), member)
53 #endif
54 
55 /*****************************************************************************/
56 
58 
59 /*****************************************************************************/
60 
64  ec_domain_t *domain,
65  ec_master_t *master,
66  unsigned int index
67  )
68 {
69  unsigned int dev_idx;
70 
71  domain->master = master;
72  domain->index = index;
73  INIT_LIST_HEAD(&domain->fmmu_configs);
74  domain->data_size = 0;
75  domain->data = NULL;
76  domain->data_origin = EC_ORIG_INTERNAL;
77  domain->logical_base_address = 0x00000000;
78  INIT_LIST_HEAD(&domain->datagram_pairs);
79  for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
80  dev_idx++) {
81  domain->working_counter[dev_idx] = 0x0000;
82  }
83  domain->expected_working_counter = 0x0000;
84  domain->working_counter_changes = 0;
85  domain->redundancy_active = 0;
86  domain->notify_jiffies = 0;
87 
88  /* Used by ec_domain_add_fmmu_config */
89  memset(domain->offset_used, 0, sizeof(domain->offset_used));
90  domain->sc_in_work = 0;
91 }
92 
93 /*****************************************************************************/
94 
98 {
99  ec_datagram_pair_t *datagram_pair, *next_pair;
100 
101  // dequeue and free datagrams
102  list_for_each_entry_safe(datagram_pair, next_pair,
103  &domain->datagram_pairs, list) {
104  ec_datagram_pair_clear(datagram_pair);
105  kfree(datagram_pair);
106  }
107 
108  ec_domain_clear_data(domain);
109 }
110 
111 /*****************************************************************************/
112 
116  ec_domain_t *domain
117  )
118 {
119  if (domain->data_origin == EC_ORIG_INTERNAL && domain->data) {
120  kfree(domain->data);
121  }
122 
123  domain->data = NULL;
124  domain->data_origin = EC_ORIG_INTERNAL;
125 }
126 
127 /*****************************************************************************/
128 
132  ec_domain_t *domain,
133  ec_fmmu_config_t *fmmu
134  )
135 {
136  const ec_slave_config_t *sc;
137  uint32_t logical_domain_offset;
138  unsigned fmmu_data_size;
139 
140  fmmu->domain = domain;
141  sc = fmmu->sc;
142 
143  fmmu_data_size = ec_pdo_list_total_size(
144  &sc->sync_configs[fmmu->sync_index].pdos);
145 
146  if (sc->allow_overlapping_pdos && (sc == domain->sc_in_work)) {
147  // If we permit overlapped PDOs, and we already have an allocated FMMU
148  // for this slave, allocate the subsequent FMMU offsets by direction
149  logical_domain_offset = domain->offset_used[fmmu->dir];
150  } else {
151  // otherwise, allocate to the furthest extent of any allocated
152  // FMMU on this domain.
153  logical_domain_offset = max(domain->offset_used[EC_DIR_INPUT],
154  domain->offset_used[EC_DIR_OUTPUT]);
155  // rebase the free offsets to the current position
156  domain->offset_used[EC_DIR_INPUT] = logical_domain_offset;
157  domain->offset_used[EC_DIR_OUTPUT] = logical_domain_offset;
158  }
159  domain->sc_in_work = sc;
160 
161  // consume the offset space for this FMMU's direction
162  domain->offset_used[fmmu->dir] += fmmu_data_size;
163 
164  ec_fmmu_set_domain_offset_size(fmmu, logical_domain_offset, fmmu_data_size);
165 
166  list_add_tail(&fmmu->list, &domain->fmmu_configs);
167 
168  // Determine domain size from furthest extent of FMMU data
169  domain->data_size = max(domain->offset_used[EC_DIR_INPUT],
170  domain->offset_used[EC_DIR_OUTPUT]);
171 
172  EC_MASTER_DBG(domain->master, 1, "Domain %u:"
173  " Added %u bytes at %u.\n",
174  domain->index, fmmu->data_size, logical_domain_offset);
175 }
176 
177 /*****************************************************************************/
178 
188  ec_domain_t *domain,
189  uint32_t logical_offset,
190  size_t data_size,
191  uint8_t *data,
192  const unsigned int used[]
193  )
194 {
195  ec_datagram_pair_t *datagram_pair;
196  int ret;
197 
198  if (!(datagram_pair = kmalloc(sizeof(ec_datagram_pair_t), GFP_KERNEL))) {
199  EC_MASTER_ERR(domain->master,
200  "Failed to allocate domain datagram pair!\n");
201  return -ENOMEM;
202  }
203 
204  ret = ec_datagram_pair_init(datagram_pair, domain, logical_offset, data,
205  data_size, used);
206  if (ret) {
207  kfree(datagram_pair);
208  return ret;
209  }
210 
211  domain->expected_working_counter +=
212  datagram_pair->expected_working_counter;
213 
214  EC_MASTER_DBG(domain->master, 1,
215  "Adding datagram pair with expected WC %u.\n",
216  datagram_pair->expected_working_counter);
217 
218 
219  list_add_tail(&datagram_pair->list, &domain->datagram_pairs);
220  return 0;
221 }
222 
223 /*****************************************************************************/
224 
235 static int shall_count(
236  const ec_fmmu_config_t *cur_fmmu,
238  const ec_fmmu_config_t *first_fmmu
239  )
240 {
241  for (; first_fmmu != cur_fmmu;
242  first_fmmu = list_entry(first_fmmu->list.next,
243  ec_fmmu_config_t, list)) {
244 
245  if (first_fmmu->sc == cur_fmmu->sc
246  && first_fmmu->dir == cur_fmmu->dir) {
247  return 0; // was already counted
248  }
249  }
250 
251  return 1;
252 }
253 
254 /*****************************************************************************/
255 
269 static int emplace_datagram(ec_domain_t *domain,
270  uint32_t datagram_begin_offset,
271  uint32_t datagram_end_offset,
272  const ec_fmmu_config_t *datagram_first_fmmu,
273  const ec_fmmu_config_t *datagram_end_fmmu
274  )
275 {
276  unsigned int datagram_used[EC_DIR_COUNT];
277  const ec_fmmu_config_t *curr_fmmu;
278  size_t data_size;
279 
280  data_size = datagram_end_offset - datagram_begin_offset;
281 
282  memset(datagram_used, 0, sizeof(datagram_used));
283  for (curr_fmmu = datagram_first_fmmu;
284  &curr_fmmu->list != &datagram_end_fmmu->list;
285  curr_fmmu = list_next_entry(curr_fmmu, list)) {
286  if (shall_count(curr_fmmu, datagram_first_fmmu)) {
287  datagram_used[curr_fmmu->dir]++;
288  }
289  }
290 
291  return ec_domain_add_datagram_pair(domain,
292  domain->logical_base_address + datagram_begin_offset,
293  data_size,
294  domain->data + datagram_begin_offset,
295  datagram_used);
296 }
297 
298 /*****************************************************************************/
299 
309  ec_domain_t *domain,
310  uint32_t base_address
311  )
312 {
313  uint32_t datagram_offset = 0;
314  unsigned int datagram_count = 0;
315  ec_fmmu_config_t *fmmu;
316  const ec_fmmu_config_t *datagram_first_fmmu = NULL;
317  const ec_fmmu_config_t *valid_fmmu = NULL;
318  unsigned candidate_start = 0;
319  unsigned valid_start = 0;
320  const ec_datagram_pair_t *datagram_pair;
321  int ret;
322 
323  domain->logical_base_address = base_address;
324 
325  if (domain->data_size && domain->data_origin == EC_ORIG_INTERNAL) {
326  if (!(domain->data =
327  (uint8_t *) kmalloc(domain->data_size, GFP_KERNEL))) {
328  EC_MASTER_ERR(domain->master, "Failed to allocate %zu bytes"
329  " internal memory for domain %u!\n",
330  domain->data_size, domain->index);
331  return -ENOMEM;
332  }
333  }
334 
335  // Cycle through all domain FMMUs and
336  // - correct the logical base addresses
337  // - set up the datagrams to carry the process data
338  // - calculate the datagrams' expected working counters
339  if (!list_empty(&domain->fmmu_configs)) {
340  datagram_first_fmmu =
341  list_entry(domain->fmmu_configs.next, ec_fmmu_config_t, list);
342  }
343 
344  list_for_each_entry(fmmu, &domain->fmmu_configs, list) {
345  if (fmmu->data_size > EC_MAX_DATA_SIZE) {
346  EC_MASTER_ERR(domain->master,
347  "FMMU size %u bytes exceeds maximum data size %u",
348  fmmu->data_size, EC_MAX_DATA_SIZE);
349  return -EINVAL;
350  }
351  if (fmmu->logical_domain_offset >= candidate_start) {
352  // As FMMU offsets increase monotonically, and candidate start
353  // offset has never been contradicted, it can now never be
354  // contradicted, as no future FMMU can cross it.
355  // All FMMUs prior to this point approved for next datagram
356  valid_fmmu = fmmu;
357  valid_start = candidate_start;
358  if (fmmu->logical_domain_offset + fmmu->data_size - datagram_offset
359  > EC_MAX_DATA_SIZE) {
360  // yet the new candidate exceeds the datagram size, so we
361  // use the last known valid candidate to create the datagram
362  ret = emplace_datagram(domain, datagram_offset, valid_start,
363  datagram_first_fmmu, valid_fmmu);
364  if (ret < 0)
365  return ret;
366 
367  datagram_offset = valid_start;
368  datagram_count++;
369  datagram_first_fmmu = fmmu;
370  }
371  }
372  if (fmmu->logical_domain_offset + fmmu->data_size > candidate_start) {
373  candidate_start = fmmu->logical_domain_offset + fmmu->data_size;
374  }
375  }
376 
377  /* Allocate last datagram pair, if data are left (this is also the case if
378  * the process data fit into a single datagram) */
379  if (domain->data_size > datagram_offset) {
380  ret = emplace_datagram(domain, datagram_offset, domain->data_size,
381  datagram_first_fmmu, fmmu);
382  if (ret < 0)
383  return ret;
384  datagram_count++;
385  }
386 
387  EC_MASTER_INFO(domain->master, "Domain%u: Logical address 0x%08x,"
388  " %zu byte, expected working counter %u.\n", domain->index,
389  domain->logical_base_address, domain->data_size,
390  domain->expected_working_counter);
391 
392  list_for_each_entry(datagram_pair, &domain->datagram_pairs, list) {
393  const ec_datagram_t *datagram =
394  &datagram_pair->datagrams[EC_DEVICE_MAIN];
395  EC_MASTER_INFO(domain->master, " Datagram %s: Logical offset 0x%08x,"
396  " %zu byte, type %s at %p.\n", datagram->name,
397  EC_READ_U32(datagram->address), datagram->data_size,
398  ec_datagram_type_string(datagram), datagram);
399  }
400 
401  return 0;
402 }
403 
404 /*****************************************************************************/
405 
408 unsigned int ec_domain_fmmu_count(const ec_domain_t *domain)
409 {
410  const ec_fmmu_config_t *fmmu;
411  unsigned int num = 0;
412 
413  list_for_each_entry(fmmu, &domain->fmmu_configs, list) {
414  num++;
415  }
416 
417  return num;
418 }
419 
420 /*****************************************************************************/
421 
427  const ec_domain_t *domain,
428  unsigned int pos
429  )
430 {
431  const ec_fmmu_config_t *fmmu;
432 
433  list_for_each_entry(fmmu, &domain->fmmu_configs, list) {
434  if (pos--)
435  continue;
436  return fmmu;
437  }
438 
439  return NULL;
440 }
441 
442 /*****************************************************************************/
443 
444 #if EC_MAX_NUM_DEVICES > 1
445 
448 int data_changed(
449  uint8_t *send_buffer,
450  const ec_datagram_t *datagram,
451  size_t offset,
452  size_t size
453  )
454 {
455  uint8_t *sent = send_buffer + offset;
456  uint8_t *recv = datagram->data + offset;
457  size_t i;
458 
459  for (i = 0; i < size; i++) {
460  if (recv[i] != sent[i]) {
461  return 1;
462  }
463  }
464 
465  return 0;
466 }
467 
468 #endif
469 
470 /******************************************************************************
471  * Application interface
472  *****************************************************************************/
473 
475  const ec_pdo_entry_reg_t *regs)
476 {
477  const ec_pdo_entry_reg_t *reg;
478  ec_slave_config_t *sc;
479  int ret;
480 
481  EC_MASTER_DBG(domain->master, 1, "ecrt_domain_reg_pdo_entry_list("
482  "domain = 0x%p, regs = 0x%p)\n", domain, regs);
483 
484  for (reg = regs; reg->index; reg++) {
485  sc = ecrt_master_slave_config_err(domain->master, reg->alias,
486  reg->position, reg->vendor_id, reg->product_code);
487  if (IS_ERR(sc))
488  return PTR_ERR(sc);
489 
490  ret = ecrt_slave_config_reg_pdo_entry(sc, reg->index,
491  reg->subindex, domain, reg->bit_position);
492  if (ret < 0)
493  return ret;
494 
495  *reg->offset = ret;
496  }
497 
498  return 0;
499 }
500 
501 /*****************************************************************************/
502 
503 size_t ecrt_domain_size(const ec_domain_t *domain)
504 {
505  return domain->data_size;
506 }
507 
508 /*****************************************************************************/
509 
510 void ecrt_domain_external_memory(ec_domain_t *domain, uint8_t *mem)
511 {
512  EC_MASTER_DBG(domain->master, 1, "ecrt_domain_external_memory("
513  "domain = 0x%p, mem = 0x%p)\n", domain, mem);
514 
515  ec_lock_down(&domain->master->master_sem);
516 
517  ec_domain_clear_data(domain);
518 
519  domain->data = mem;
520  domain->data_origin = EC_ORIG_EXTERNAL;
521 
522  ec_lock_up(&domain->master->master_sem);
523 }
524 
525 /*****************************************************************************/
526 
527 uint8_t *ecrt_domain_data(ec_domain_t *domain)
528 {
529  return domain->data;
530 }
531 
532 /*****************************************************************************/
533 
535 {
536  uint16_t wc_sum[EC_MAX_NUM_DEVICES] = {}, wc_total;
537  ec_datagram_pair_t *pair;
538 #if EC_MAX_NUM_DEVICES > 1
539  uint16_t datagram_pair_wc, redundant_wc;
540  unsigned int datagram_offset;
541  ec_fmmu_config_t *fmmu = list_first_entry(&domain->fmmu_configs,
542  ec_fmmu_config_t, list);
543  unsigned int redundancy;
544 #endif
545  unsigned int dev_idx;
546 #ifdef EC_RT_SYSLOG
547  unsigned int wc_change;
548 #endif
549 
550 #if DEBUG_REDUNDANCY
551  EC_MASTER_DBG(domain->master, 1, "domain %u process\n", domain->index);
552 #endif
553 
554  list_for_each_entry(pair, &domain->datagram_pairs, list) {
555 #if EC_MAX_NUM_DEVICES > 1
556  datagram_pair_wc = ec_datagram_pair_process(pair, wc_sum);
557 #else
558  ec_datagram_pair_process(pair, wc_sum);
559 #endif
560 
561 #if EC_MAX_NUM_DEVICES > 1
562  if (ec_master_num_devices(domain->master) > 1) {
563  ec_datagram_t *main_datagram = &pair->datagrams[EC_DEVICE_MAIN];
564  uint32_t logical_datagram_address =
565  EC_READ_U32(main_datagram->address);
566  size_t datagram_size = main_datagram->data_size;
567 
568 #if DEBUG_REDUNDANCY
569  EC_MASTER_DBG(domain->master, 1, "dgram %s log=%u\n",
570  main_datagram->name, logical_datagram_address);
571 #endif
572 
573  /* Redundancy: Go through FMMU configs to detect data changes. */
574  list_for_each_entry_from(fmmu, &domain->fmmu_configs, list) {
575  ec_datagram_t *backup_datagram =
576  &pair->datagrams[EC_DEVICE_BACKUP];
577 
578  if (fmmu->dir != EC_DIR_INPUT) {
579  continue;
580  }
581 
582  if (fmmu->logical_domain_offset >= datagram_size) {
583  // fmmu data contained in next datagram pair
584  break;
585  }
586 
587  datagram_offset = fmmu->logical_domain_offset;
588 
589 #if DEBUG_REDUNDANCY
590  EC_MASTER_DBG(domain->master, 1,
591  "input fmmu log_off=%u size=%u offset=%u\n",
592  fmmu->logical_domain_offset, fmmu->data_size,
593  datagram_offset);
594  if (domain->master->debug_level > 0) {
595  ec_print_data(pair->send_buffer + datagram_offset,
596  fmmu->data_size);
597  ec_print_data(main_datagram->data + datagram_offset,
598  fmmu->data_size);
599  ec_print_data(backup_datagram->data + datagram_offset,
600  fmmu->data_size);
601  }
602 #endif
603 
604  if (data_changed(pair->send_buffer, main_datagram,
605  datagram_offset, fmmu->data_size)) {
606  /* data changed on main link: no copying necessary. */
607 #if DEBUG_REDUNDANCY
608  EC_MASTER_DBG(domain->master, 1, "main changed\n");
609 #endif
610  } else if (data_changed(pair->send_buffer, backup_datagram,
611  datagram_offset, fmmu->data_size)) {
612  /* data changed on backup link: copy to main memory. */
613 #if DEBUG_REDUNDANCY
614  EC_MASTER_DBG(domain->master, 1, "backup changed\n");
615 #endif
616  memcpy(main_datagram->data + datagram_offset,
617  backup_datagram->data + datagram_offset,
618  fmmu->data_size);
619  } else if (datagram_pair_wc ==
620  pair->expected_working_counter) {
621  /* no change, but WC complete: use main data. */
622 #if DEBUG_REDUNDANCY
623  EC_MASTER_DBG(domain->master, 1,
624  "no change but complete\n");
625 #endif
626  } else {
627  /* no change and WC incomplete: mark WC as zero to avoid
628  * data.dependent WC flickering. */
629  datagram_pair_wc = 0;
630 #if DEBUG_REDUNDANCY
631  EC_MASTER_DBG(domain->master, 1,
632  "no change and incomplete\n");
633 #endif
634  }
635  }
636  }
637 #endif // EC_MAX_NUM_DEVICES > 1
638  }
639 
640 #if EC_MAX_NUM_DEVICES > 1
641  redundant_wc = 0;
642  for (dev_idx = EC_DEVICE_BACKUP;
643  dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
644  redundant_wc += wc_sum[dev_idx];
645  }
646 
647  redundancy = redundant_wc > 0;
648  if (redundancy != domain->redundancy_active) {
649 #ifdef EC_RT_SYSLOG
650  if (redundancy) {
651  EC_MASTER_WARN(domain->master,
652  "Domain %u: Redundant link in use!\n",
653  domain->index);
654  } else {
655  EC_MASTER_INFO(domain->master,
656  "Domain %u: Redundant link unused again.\n",
657  domain->index);
658  }
659 #endif
660  domain->redundancy_active = redundancy;
661  }
662 #else
663  domain->redundancy_active = 0;
664 #endif
665 
666 #ifdef EC_RT_SYSLOG
667  wc_change = 0;
668 #endif
669  wc_total = 0;
670  for (dev_idx = EC_DEVICE_MAIN;
671  dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
672  if (wc_sum[dev_idx] != domain->working_counter[dev_idx]) {
673 #ifdef EC_RT_SYSLOG
674  wc_change = 1;
675 #endif
676  domain->working_counter[dev_idx] = wc_sum[dev_idx];
677  }
678  wc_total += wc_sum[dev_idx];
679  }
680 
681 #ifdef EC_RT_SYSLOG
682  if (wc_change) {
683  domain->working_counter_changes++;
684  }
685 
686  if (domain->working_counter_changes &&
687  jiffies - domain->notify_jiffies > HZ) {
688  domain->notify_jiffies = jiffies;
689  if (domain->working_counter_changes == 1) {
690  EC_MASTER_INFO(domain->master, "Domain %u: Working counter"
691  " changed to %u/%u", domain->index,
692  wc_total, domain->expected_working_counter);
693  } else {
694  EC_MASTER_INFO(domain->master, "Domain %u: %u working counter"
695  " changes - now %u/%u", domain->index,
696  domain->working_counter_changes,
697  wc_total, domain->expected_working_counter);
698  }
699 #if EC_MAX_NUM_DEVICES > 1
700  if (ec_master_num_devices(domain->master) > 1) {
701  printk(KERN_CONT " (");
702  for (dev_idx = EC_DEVICE_MAIN;
703  dev_idx < ec_master_num_devices(domain->master);
704  dev_idx++) {
705  printk(KERN_CONT "%u", domain->working_counter[dev_idx]);
706  if (dev_idx + 1 < ec_master_num_devices(domain->master)) {
707  printk(KERN_CONT "+");
708  }
709  }
710  printk(KERN_CONT ")");
711  }
712 #endif
713  printk(KERN_CONT ".\n");
714 
715  domain->working_counter_changes = 0;
716  }
717 #endif
718 }
719 
720 /*****************************************************************************/
721 
723 {
724  ec_datagram_pair_t *datagram_pair;
725  ec_device_index_t dev_idx;
726 
727  list_for_each_entry(datagram_pair, &domain->datagram_pairs, list) {
728 
729 #if EC_MAX_NUM_DEVICES > 1
730  /* copy main data to send buffer */
731  memcpy(datagram_pair->send_buffer,
732  datagram_pair->datagrams[EC_DEVICE_MAIN].data,
733  datagram_pair->datagrams[EC_DEVICE_MAIN].data_size);
734 #endif
736  &datagram_pair->datagrams[EC_DEVICE_MAIN]);
737 
738  /* copy main data to backup datagram */
739  for (dev_idx = EC_DEVICE_BACKUP;
740  dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
741  memcpy(datagram_pair->datagrams[dev_idx].data,
742  datagram_pair->datagrams[EC_DEVICE_MAIN].data,
743  datagram_pair->datagrams[EC_DEVICE_MAIN].data_size);
745  &datagram_pair->datagrams[dev_idx]);
746  }
747  }
748 }
749 
750 /*****************************************************************************/
751 
753 {
754  unsigned int dev_idx;
755  uint16_t wc = 0;
756 
757  for (dev_idx = EC_DEVICE_MAIN;
758  dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
759  wc += domain->working_counter[dev_idx];
760  }
761 
762  state->working_counter = wc;
763 
764  if (wc) {
765  if (wc == domain->expected_working_counter) {
766  state->wc_state = EC_WC_COMPLETE;
767  } else {
768  state->wc_state = EC_WC_INCOMPLETE;
769  }
770  } else {
771  state->wc_state = EC_WC_ZERO;
772  }
773 
774  state->redundancy_active = domain->redundancy_active;
775 }
776 
777 /*****************************************************************************/
778 
781 EXPORT_SYMBOL(ecrt_domain_reg_pdo_entry_list);
782 EXPORT_SYMBOL(ecrt_domain_size);
783 EXPORT_SYMBOL(ecrt_domain_external_memory);
784 EXPORT_SYMBOL(ecrt_domain_data);
785 EXPORT_SYMBOL(ecrt_domain_process);
786 EXPORT_SYMBOL(ecrt_domain_queue);
787 EXPORT_SYMBOL(ecrt_domain_state);
788 
791 /*****************************************************************************/
unsigned int working_counter
Value of the last working counter.
Definition: ecrt.h:427
size_t ecrt_domain_size(const ec_domain_t *domain)
Returns the current size of the domain&#39;s process data.
Definition: domain.c:503
const ec_slave_config_t * sc
EtherCAT slave config.
Definition: fmmu_config.h:48
uint8_t subindex
PDO entry subindex.
Definition: ecrt.h:521
uint16_t position
Slave position.
Definition: ecrt.h:517
size_t data_size
Size of the data in data.
Definition: datagram.h:98
Domain datagram pair.
Definition: datagram_pair.h:49
uint32_t logical_domain_offset
Logical offset address relative to domain->logical_base_address.
Definition: fmmu_config.h:52
FMMU configuration.
Definition: fmmu_config.h:46
size_t data_size
Size of the process data.
Definition: domain.h:61
uint32_t offset_used[EC_DIR_COUNT]
Next available domain offset of PDO, by direction.
Definition: domain.h:75
unsigned int expected_working_counter
Expectord working conter.
Definition: datagram_pair.h:56
unsigned int redundancy_active
Redundant link is in use.
Definition: ecrt.h:429
uint16_t index
PDO entry index.
Definition: ecrt.h:520
#define ec_master_num_devices(MASTER)
Number of Ethernet devices.
Definition: master.h:359
int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain, const ec_pdo_entry_reg_t *regs)
Registers a bunch of PDO entries for a domain.
Definition: domain.c:474
static int emplace_datagram(ec_domain_t *domain, uint32_t datagram_begin_offset, uint32_t datagram_end_offset, const ec_fmmu_config_t *datagram_first_fmmu, const ec_fmmu_config_t *datagram_end_fmmu)
Domain finish helper function.
Definition: domain.c:269
EtherCAT datagram.
Definition: datagram.h:88
unsigned int data_size
Covered PDO size.
Definition: fmmu_config.h:54
char name[EC_DATAGRAM_NAME_SIZE]
Description of the datagram.
Definition: datagram.h:114
ec_wc_state_t wc_state
Working counter interpretation.
Definition: ecrt.h:428
void ecrt_domain_external_memory(ec_domain_t *domain, uint8_t *mem)
Provide external memory to store the domain&#39;s process data.
Definition: domain.c:510
void ec_domain_clear_data(ec_domain_t *)
Frees internally allocated memory.
Definition: domain.c:115
Global definitions and macros.
Some of the registered process data were exchanged.
Definition: ecrt.h:415
EtherCAT master structure.
uint8_t * data
Memory for the process data.
Definition: domain.h:62
uint16_t alias
Slave alias address.
Definition: ecrt.h:516
Internal.
Definition: globals.h:342
#define EC_MASTER_DBG(master, level, fmt, args...)
Convenience macro for printing master-specific debug messages to syslog.
Definition: master.h:106
struct list_head list
List node used by domain.
Definition: fmmu_config.h:47
unsigned int working_counter_changes
Working counter changes since last notification.
Definition: domain.h:71
uint16_t ec_pdo_list_total_size(const ec_pdo_list_t *pl)
Calculates the total size of the mapped PDO entries.
Definition: pdo_list.c:87
const ec_domain_t * domain
Domain.
Definition: fmmu_config.h:49
ec_sync_config_t sync_configs[EC_MAX_SYNC_MANAGERS]
Sync manager configurations.
Definition: slave_config.h:138
Domain state.
Definition: ecrt.h:426
uint32_t vendor_id
Slave vendor ID.
Definition: ecrt.h:518
unsigned int * bit_position
Pointer to a variable to store a bit position (0-7) within the offset.
Definition: ecrt.h:524
void ec_domain_clear(ec_domain_t *domain)
Domain destructor.
Definition: domain.c:97
uint8_t sync_index
Index of sync manager to use.
Definition: fmmu_config.h:50
int ec_domain_finish(ec_domain_t *domain, uint32_t base_address)
Finishes a domain.
Definition: domain.c:308
unsigned int debug_level
Master debug level.
Definition: master.h:310
uint16_t ec_datagram_pair_process(ec_datagram_pair_t *pair, uint16_t wc_sum[])
Process received data.
ec_pdo_list_t pdos
Current PDO assignment.
Definition: sync_config.h:49
ec_device_index_t
Master devices.
Definition: globals.h:236
void ec_datagram_pair_clear(ec_datagram_pair_t *pair)
Datagram pair destructor.
unsigned int index
Index (just a number).
Definition: domain.h:58
External.
Definition: globals.h:343
Main device.
Definition: globals.h:237
#define EC_READ_U32(DATA)
Read a 32-bit unsigned value from EtherCAT data.
Definition: ecrt.h:2570
struct list_head fmmu_configs
FMMU configurations contained.
Definition: domain.h:60
#define EC_MASTER_WARN(master, fmt, args...)
Convenience macro for printing master-specific warnings to syslog.
Definition: master.h:92
void ec_fmmu_set_domain_offset_size(ec_fmmu_config_t *fmmu, uint32_t logical_domain_offset, unsigned data_size)
Definition: fmmu_config.c:69
unsigned int ec_domain_fmmu_count(const ec_domain_t *domain)
Get the number of FMMU configurations of the domain.
Definition: domain.c:408
#define EC_MASTER_ERR(master, fmt, args...)
Convenience macro for printing master-specific errors to syslog.
Definition: master.h:80
void ec_master_queue_datagram(ec_master_t *master, ec_datagram_t *datagram)
Places a datagram in the datagram queue.
Definition: master.c:1105
Values read by the master.
Definition: ecrt.h:439
ec_origin_t data_origin
Origin of the data memory.
Definition: domain.h:63
void ec_print_data(const uint8_t *, size_t)
Outputs frame contents for debugging purposes.
Definition: module.c:355
uint16_t working_counter[EC_MAX_NUM_DEVICES]
Last working counter values.
Definition: domain.h:68
uint32_t logical_base_address
Logical offset address of the process data.
Definition: domain.h:64
uint16_t expected_working_counter
Expected working counter.
Definition: domain.h:70
unsigned int redundancy_active
Non-zero, if redundancy is in use.
Definition: domain.h:73
uint8_t allow_overlapping_pdos
Allow input PDOs use the same frame space as output PDOs.
Definition: slave_config.h:133
int ecrt_slave_config_reg_pdo_entry(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, ec_domain_t *domain, unsigned int *bit_position)
Registers a PDO entry for process data exchange in a domain.
Definition: slave_config.c:870
ec_lock_t master_sem
Master semaphore.
Definition: master.h:217
const ec_slave_config_t * sc_in_work
slave_config which is actively being registered in this domain (i.e.
Definition: domain.h:77
int ec_datagram_pair_init(ec_datagram_pair_t *pair, ec_domain_t *domain, uint32_t logical_offset, uint8_t *data, size_t data_size, const unsigned int used[])
Datagram pair constructor.
Definition: datagram_pair.c:48
void ec_domain_add_fmmu_config(ec_domain_t *domain, ec_fmmu_config_t *fmmu)
Adds an FMMU configuration to the domain.
Definition: domain.c:131
Number of directions.
Definition: ecrt.h:441
struct list_head list
List header.
Definition: datagram_pair.h:50
uint8_t * ecrt_domain_data(ec_domain_t *domain)
Returns the domain&#39;s process data.
Definition: domain.c:527
List record type for PDO entry mass-registration.
Definition: ecrt.h:515
EtherCAT domain structure.
No registered process data were exchanged.
Definition: ecrt.h:414
All registered process data were exchanged.
Definition: ecrt.h:417
EtherCAT datagram pair structure.
const char * ec_datagram_type_string(const ec_datagram_t *datagram)
Returns a string describing the datagram type.
Definition: datagram.c:667
uint8_t * data
Datagram payload.
Definition: datagram.h:95
EtherCAT slave configuration.
Definition: slave_config.h:118
ec_datagram_t datagrams[EC_MAX_NUM_DEVICES]
Datagrams.
Definition: datagram_pair.h:52
EtherCAT slave configuration structure.
ec_slave_config_t * ecrt_master_slave_config_err(ec_master_t *master, uint16_t alias, uint16_t position, uint32_t vendor_id, uint32_t product_code)
Same as ecrt_master_slave_config(), but with ERR_PTR() return value.
Definition: master.c:3107
unsigned int * offset
Pointer to a variable to store the PDO entry&#39;s (byte-)offset in the process data. ...
Definition: ecrt.h:522
void ecrt_domain_state(const ec_domain_t *domain, ec_domain_state_t *state)
Reads the state of a domain.
Definition: domain.c:752
uint8_t address[EC_ADDR_LEN]
Recipient address.
Definition: datagram.h:94
void ecrt_domain_process(ec_domain_t *domain)
Determines the states of the domain&#39;s datagrams.
Definition: domain.c:534
void ec_domain_init(ec_domain_t *domain, ec_master_t *master, unsigned int index)
Domain constructor.
Definition: domain.c:63
ec_direction_t dir
FMMU direction.
Definition: fmmu_config.h:51
Backup device.
Definition: globals.h:238
static int shall_count(const ec_fmmu_config_t *cur_fmmu, const ec_fmmu_config_t *first_fmmu)
Domain finish helper function.
Definition: domain.c:235
Values written by the master.
Definition: ecrt.h:438
struct list_head datagram_pairs
Datagrams pairs (main/backup) for process data exchange.
Definition: domain.h:66
void ecrt_domain_queue(ec_domain_t *domain)
(Re-)queues all domain datagrams in the master&#39;s datagram queue.
Definition: domain.c:722
#define EC_MASTER_INFO(master, fmt, args...)
Convenience macro for printing master-specific information to syslog.
Definition: master.h:68
uint32_t product_code
Slave product code.
Definition: ecrt.h:519
EtherCAT master.
Definition: master.h:202
unsigned long notify_jiffies
Time of last notification.
Definition: domain.h:74
int ec_domain_add_datagram_pair(ec_domain_t *domain, uint32_t logical_offset, size_t data_size, uint8_t *data, const unsigned int used[])
Allocates a domain datagram pair and appends it to the list.
Definition: domain.c:187
EtherCAT domain.
Definition: domain.h:54
ec_master_t * master
EtherCAT master owning the domain.
Definition: domain.h:57
#define EC_MAX_DATA_SIZE
Resulting maximum data size of a single datagram in a frame.
Definition: globals.h:95
const ec_fmmu_config_t * ec_domain_find_fmmu(const ec_domain_t *domain, unsigned int pos)
Get a certain FMMU configuration via its position in the list.
Definition: domain.c:426