3 * s l a v e . c |
3 * s l a v e . c |
4 * |
4 * |
5 * EtherCAT slave methods. |
5 * EtherCAT slave methods. |
6 * |
6 * |
7 * $Id$ |
7 * $Id$ |
|
8 * |
|
9 * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
|
10 * |
|
11 * This file is part of the IgH EtherCAT Master. |
|
12 * |
|
13 * The IgH EtherCAT Master is free software; you can redistribute it |
|
14 * and/or modify it under the terms of the GNU General Public License |
|
15 * as published by the Free Software Foundation; version 2 of the License. |
|
16 * |
|
17 * The IgH EtherCAT Master is distributed in the hope that it will be |
|
18 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 * GNU General Public License for more details. |
|
21 * |
|
22 * You should have received a copy of the GNU General Public License |
|
23 * along with the IgH EtherCAT Master; if not, write to the Free Software |
|
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
8 * |
25 * |
9 *****************************************************************************/ |
26 *****************************************************************************/ |
10 |
27 |
11 #include <linux/module.h> |
28 #include <linux/module.h> |
12 #include <linux/delay.h> |
29 #include <linux/delay.h> |
63 /*****************************************************************************/ |
80 /*****************************************************************************/ |
64 |
81 |
65 /** |
82 /** |
66 Slave constructor. |
83 Slave constructor. |
67 \return 0 in case of success, else < 0 |
84 \return 0 in case of success, else < 0 |
|
85 \ingroup Slave |
68 */ |
86 */ |
69 |
87 |
70 int ec_slave_init(ec_slave_t *slave, /**< EtherCAT slave */ |
88 int ec_slave_init(ec_slave_t *slave, /**< EtherCAT slave */ |
71 ec_master_t *master, /**< EtherCAT master */ |
89 ec_master_t *master, /**< EtherCAT master */ |
72 uint16_t ring_position, /**< ring position */ |
90 uint16_t ring_position, /**< ring position */ |
199 /*****************************************************************************/ |
218 /*****************************************************************************/ |
200 |
219 |
201 /** |
220 /** |
202 Reads all necessary information from a slave. |
221 Reads all necessary information from a slave. |
203 \return 0 in case of success, else < 0 |
222 \return 0 in case of success, else < 0 |
|
223 \ingroup Slave |
204 */ |
224 */ |
205 |
225 |
206 int ec_slave_fetch(ec_slave_t *slave /**< EtherCAT slave */) |
226 int ec_slave_fetch(ec_slave_t *slave /**< EtherCAT slave */) |
207 { |
227 { |
208 ec_command_t *command; |
228 ec_command_t *command; |
276 /*****************************************************************************/ |
296 /*****************************************************************************/ |
277 |
297 |
278 /** |
298 /** |
279 Reads 16 bit from the slave information interface (SII). |
299 Reads 16 bit from the slave information interface (SII). |
280 \return 0 in case of success, else < 0 |
300 \return 0 in case of success, else < 0 |
|
301 \ingroup Slave |
281 */ |
302 */ |
282 |
303 |
283 int ec_slave_sii_read16(ec_slave_t *slave, |
304 int ec_slave_sii_read16(ec_slave_t *slave, |
284 /**< EtherCAT slave */ |
305 /**< EtherCAT slave */ |
285 uint16_t offset, |
306 uint16_t offset, |
336 /*****************************************************************************/ |
357 /*****************************************************************************/ |
337 |
358 |
338 /** |
359 /** |
339 Reads 32 bit from the slave information interface (SII). |
360 Reads 32 bit from the slave information interface (SII). |
340 \return 0 in case of success, else < 0 |
361 \return 0 in case of success, else < 0 |
|
362 \ingroup Slave |
341 */ |
363 */ |
342 |
364 |
343 int ec_slave_sii_read32(ec_slave_t *slave, |
365 int ec_slave_sii_read32(ec_slave_t *slave, |
344 /**< EtherCAT slave */ |
366 /**< EtherCAT slave */ |
345 uint16_t offset, |
367 uint16_t offset, |
396 /*****************************************************************************/ |
418 /*****************************************************************************/ |
397 |
419 |
398 /** |
420 /** |
399 Writes 16 bit of data to the slave information interface (SII). |
421 Writes 16 bit of data to the slave information interface (SII). |
400 \return 0 in case of success, else < 0 |
422 \return 0 in case of success, else < 0 |
|
423 \ingroup Slave |
401 */ |
424 */ |
402 |
425 |
403 int ec_slave_sii_write16(ec_slave_t *slave, |
426 int ec_slave_sii_write16(ec_slave_t *slave, |
404 /**< EtherCAT slave */ |
427 /**< EtherCAT slave */ |
405 uint16_t offset, |
428 uint16_t offset, |
466 /*****************************************************************************/ |
489 /*****************************************************************************/ |
467 |
490 |
468 /** |
491 /** |
469 Fetches data from slave's EEPROM. |
492 Fetches data from slave's EEPROM. |
470 \return 0 in case of success, else < 0 |
493 \return 0 in case of success, else < 0 |
|
494 \ingroup Slave |
471 */ |
495 */ |
472 |
496 |
473 int ec_slave_fetch_categories(ec_slave_t *slave /**< EtherCAT slave */) |
497 int ec_slave_fetch_categories(ec_slave_t *slave /**< EtherCAT slave */) |
474 { |
498 { |
475 uint16_t word_offset, cat_type, word_count; |
499 uint16_t word_offset, cat_type, word_count; |
558 /*****************************************************************************/ |
582 /*****************************************************************************/ |
559 |
583 |
560 /** |
584 /** |
561 Fetches data from a STRING category. |
585 Fetches data from a STRING category. |
562 \return 0 in case of success, else < 0 |
586 \return 0 in case of success, else < 0 |
|
587 \ingroup Slave |
563 */ |
588 */ |
564 |
589 |
565 int ec_slave_fetch_strings(ec_slave_t *slave, /**< EtherCAT slave */ |
590 int ec_slave_fetch_strings(ec_slave_t *slave, /**< EtherCAT slave */ |
566 const uint8_t *data /**< category data */ |
591 const uint8_t *data /**< category data */ |
567 ) |
592 ) |
596 /*****************************************************************************/ |
621 /*****************************************************************************/ |
597 |
622 |
598 /** |
623 /** |
599 Fetches data from a GENERAL category. |
624 Fetches data from a GENERAL category. |
600 \return 0 in case of success, else < 0 |
625 \return 0 in case of success, else < 0 |
|
626 \ingroup Slave |
601 */ |
627 */ |
602 |
628 |
603 int ec_slave_fetch_general(ec_slave_t *slave, /**< EtherCAT slave */ |
629 int ec_slave_fetch_general(ec_slave_t *slave, /**< EtherCAT slave */ |
604 const uint8_t *data /**< category data */ |
630 const uint8_t *data /**< category data */ |
605 ) |
631 ) |
623 /*****************************************************************************/ |
649 /*****************************************************************************/ |
624 |
650 |
625 /** |
651 /** |
626 Fetches data from a SYNC MANAGER category. |
652 Fetches data from a SYNC MANAGER category. |
627 \return 0 in case of success, else < 0 |
653 \return 0 in case of success, else < 0 |
|
654 \ingroup Slave |
628 */ |
655 */ |
629 |
656 |
630 int ec_slave_fetch_sync(ec_slave_t *slave, /**< EtherCAT slave */ |
657 int ec_slave_fetch_sync(ec_slave_t *slave, /**< EtherCAT slave */ |
631 const uint8_t *data, /**< category data */ |
658 const uint8_t *data, /**< category data */ |
632 size_t word_count /**< number of words */ |
659 size_t word_count /**< number of words */ |
659 /*****************************************************************************/ |
686 /*****************************************************************************/ |
660 |
687 |
661 /** |
688 /** |
662 Fetches data from a [RT]XPDO category. |
689 Fetches data from a [RT]XPDO category. |
663 \return 0 in case of success, else < 0 |
690 \return 0 in case of success, else < 0 |
|
691 \ingroup Slave |
664 */ |
692 */ |
665 |
693 |
666 int ec_slave_fetch_pdo(ec_slave_t *slave, /**< EtherCAT slave */ |
694 int ec_slave_fetch_pdo(ec_slave_t *slave, /**< EtherCAT slave */ |
667 const uint8_t *data, /**< category data */ |
695 const uint8_t *data, /**< category data */ |
668 size_t word_count, /**< number of words */ |
696 size_t word_count, /**< number of words */ |
720 /*****************************************************************************/ |
748 /*****************************************************************************/ |
721 |
749 |
722 /** |
750 /** |
723 Searches the string list for an index and allocates a new string. |
751 Searches the string list for an index and allocates a new string. |
724 \return 0 in case of success, else < 0 |
752 \return 0 in case of success, else < 0 |
725 */ |
753 \ingroup Slave |
726 |
754 \todo documentation |
727 int ec_slave_locate_string(ec_slave_t *slave, unsigned int index, char **ptr) |
755 */ |
|
756 |
|
757 int ec_slave_locate_string(ec_slave_t *slave, /**< EtherCAT slave */ |
|
758 unsigned int index, /**< string index */ |
|
759 char **ptr /**< Address of the string pointer */ |
|
760 ) |
728 { |
761 { |
729 ec_eeprom_string_t *string; |
762 ec_eeprom_string_t *string; |
730 char *err_string; |
763 char *err_string; |
731 |
764 |
732 // Erst alten Speicher freigeben |
765 // Erst alten Speicher freigeben |
765 |
798 |
766 /*****************************************************************************/ |
799 /*****************************************************************************/ |
767 |
800 |
768 /** |
801 /** |
769 Acknowledges an error after a state transition. |
802 Acknowledges an error after a state transition. |
|
803 \ingroup Slave |
770 */ |
804 */ |
771 |
805 |
772 void ec_slave_state_ack(ec_slave_t *slave, /**< EtherCAT slave */ |
806 void ec_slave_state_ack(ec_slave_t *slave, /**< EtherCAT slave */ |
773 uint8_t state /**< previous state */ |
807 uint8_t state /**< previous state */ |
774 ) |
808 ) |
820 /*****************************************************************************/ |
854 /*****************************************************************************/ |
821 |
855 |
822 /** |
856 /** |
823 Reads the AL status code of a slave and displays it. |
857 Reads the AL status code of a slave and displays it. |
824 If the AL status code is not supported, or if no error occurred (both |
858 If the AL status code is not supported, or if no error occurred (both |
825 resulting in code=0), nothing is displayed. |
859 resulting in code = 0), nothing is displayed. |
|
860 \ingroup Slave |
826 */ |
861 */ |
827 |
862 |
828 void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT slave */) |
863 void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT slave */) |
829 { |
864 { |
830 ec_command_t *command; |
865 ec_command_t *command; |
856 /*****************************************************************************/ |
891 /*****************************************************************************/ |
857 |
892 |
858 /** |
893 /** |
859 Does a state transition. |
894 Does a state transition. |
860 \return 0 in case of success, else < 0 |
895 \return 0 in case of success, else < 0 |
|
896 \ingroup Slave |
861 */ |
897 */ |
862 |
898 |
863 int ec_slave_state_change(ec_slave_t *slave, /**< EtherCAT slave */ |
899 int ec_slave_state_change(ec_slave_t *slave, /**< EtherCAT slave */ |
864 uint8_t state /**< new state */ |
900 uint8_t state /**< new state */ |
865 ) |
901 ) |
925 of the corresponding sync manager is covered. Seperate FMMUs arce configured |
961 of the corresponding sync manager is covered. Seperate FMMUs arce configured |
926 for each domain. |
962 for each domain. |
927 If the FMMU configuration is already prepared, the function returns with |
963 If the FMMU configuration is already prepared, the function returns with |
928 success. |
964 success. |
929 \return 0 in case of success, else < 0 |
965 \return 0 in case of success, else < 0 |
|
966 \ingroup Slave |
930 */ |
967 */ |
931 |
968 |
932 int ec_slave_prepare_fmmu(ec_slave_t *slave, /**< EtherCAT slave */ |
969 int ec_slave_prepare_fmmu(ec_slave_t *slave, /**< EtherCAT slave */ |
933 const ec_domain_t *domain, /**< domain */ |
970 const ec_domain_t *domain, /**< domain */ |
934 const ec_sync_t *sync /**< sync manager */ |
971 const ec_sync_t *sync /**< sync manager */ |
963 Outputs all information about a certain slave. |
1000 Outputs all information about a certain slave. |
964 Verbosity: |
1001 Verbosity: |
965 - 0: Only slave types and addresses |
1002 - 0: Only slave types and addresses |
966 - 1: with EEPROM information |
1003 - 1: with EEPROM information |
967 - >1: with SDO dictionaries |
1004 - >1: with SDO dictionaries |
|
1005 \ingroup Slave |
968 */ |
1006 */ |
969 |
1007 |
970 void ec_slave_print(const ec_slave_t *slave, /**< EtherCAT slave */ |
1008 void ec_slave_print(const ec_slave_t *slave, /**< EtherCAT slave */ |
971 unsigned int verbosity /**< verbosity level */ |
1009 unsigned int verbosity /**< verbosity level */ |
972 ) |
1010 ) |
1124 /*****************************************************************************/ |
1162 /*****************************************************************************/ |
1125 |
1163 |
1126 /** |
1164 /** |
1127 Outputs the values of the CRC faoult counters and resets them. |
1165 Outputs the values of the CRC faoult counters and resets them. |
1128 \return 0 in case of success, else < 0 |
1166 \return 0 in case of success, else < 0 |
|
1167 \ingroup Slave |
1129 */ |
1168 */ |
1130 |
1169 |
1131 int ec_slave_check_crc(ec_slave_t *slave /**< EtherCAT slave */) |
1170 int ec_slave_check_crc(ec_slave_t *slave /**< EtherCAT slave */) |
1132 { |
1171 { |
1133 ec_command_t *command; |
1172 ec_command_t *command; |
1179 /*****************************************************************************/ |
1218 /*****************************************************************************/ |
1180 |
1219 |
1181 /** |
1220 /** |
1182 Writes the "configured station alias" to the slave's EEPROM. |
1221 Writes the "configured station alias" to the slave's EEPROM. |
1183 \return 0 in case of success, else < 0 |
1222 \return 0 in case of success, else < 0 |
1184 */ |
1223 \ingroup Slave |
1185 |
1224 */ |
1186 int ecrt_slave_write_alias(ec_slave_t *slave, /** EtherCAT slave */ |
1225 |
1187 uint16_t alias /** new alias */ |
1226 int ecrt_slave_write_alias(ec_slave_t *slave, /**< EtherCAT slave */ |
|
1227 uint16_t alias /**< new alias */ |
1188 ) |
1228 ) |
1189 { |
1229 { |
1190 return ec_slave_sii_write16(slave, 0x0004, alias); |
1230 return ec_slave_sii_write16(slave, 0x0004, alias); |
1191 } |
1231 } |
1192 |
1232 |
1193 /*****************************************************************************/ |
1233 /*****************************************************************************/ |
1194 |
1234 |
1195 /** |
1235 /** |
1196 Formats attribute data for SysFS read access. |
1236 Formats attribute data for SysFS read access. |
1197 \return number of bytes to read |
1237 \return number of bytes to read |
|
1238 \ingroup Slave |
1198 */ |
1239 */ |
1199 |
1240 |
1200 ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< slave's kobject */ |
1241 ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< slave's kobject */ |
1201 struct attribute *attr, /**< attribute */ |
1242 struct attribute *attr, /**< attribute */ |
1202 char *buffer /**< memory to store data */ |
1243 char *buffer /**< memory to store data */ |