48 |
48 |
49 #include "globals.h" |
49 #include "globals.h" |
50 #include "datagram.h" |
50 #include "datagram.h" |
51 #include "pdo.h" |
51 #include "pdo.h" |
52 #include "sync.h" |
52 #include "sync.h" |
53 #include "fmmu.h" |
|
54 |
53 |
55 /*****************************************************************************/ |
54 /*****************************************************************************/ |
56 |
55 |
57 /** maximum number of FMMUs per slave */ |
56 /** State of an EtherCAT slave. |
58 #define EC_MAX_FMMUS 16 |
|
59 |
|
60 /*****************************************************************************/ |
|
61 |
|
62 /** |
|
63 * State of an EtherCAT slave. |
|
64 */ |
57 */ |
65 |
58 typedef enum { |
66 typedef enum |
|
67 { |
|
68 EC_SLAVE_STATE_UNKNOWN = 0x00, |
59 EC_SLAVE_STATE_UNKNOWN = 0x00, |
69 /**< unknown state */ |
60 /**< unknown state */ |
70 EC_SLAVE_STATE_INIT = 0x01, |
61 EC_SLAVE_STATE_INIT = 0x01, |
71 /**< INIT state (no mailbox communication, no IO) */ |
62 /**< INIT state (no mailbox communication, no IO) */ |
72 EC_SLAVE_STATE_PREOP = 0x02, |
63 EC_SLAVE_STATE_PREOP = 0x02, |
75 /**< SAVEOP (mailbox communication and input update) */ |
66 /**< SAVEOP (mailbox communication and input update) */ |
76 EC_SLAVE_STATE_OP = 0x08, |
67 EC_SLAVE_STATE_OP = 0x08, |
77 /**< OP (mailbox communication and input/output update) */ |
68 /**< OP (mailbox communication and input/output update) */ |
78 EC_SLAVE_STATE_ACK_ERR = 0x10 |
69 EC_SLAVE_STATE_ACK_ERR = 0x10 |
79 /**< Acknowledge/Error bit (no actual state) */ |
70 /**< Acknowledge/Error bit (no actual state) */ |
80 } |
71 } ec_slave_state_t; |
81 ec_slave_state_t; |
|
82 |
72 |
83 /*****************************************************************************/ |
73 /*****************************************************************************/ |
84 |
74 |
85 /** |
75 /** EtherCAT slave online state. |
86 * EtherCAT slave online state. |
|
87 */ |
76 */ |
88 |
|
89 typedef enum { |
77 typedef enum { |
90 EC_SLAVE_OFFLINE, |
78 EC_SLAVE_OFFLINE, |
91 EC_SLAVE_ONLINE |
79 EC_SLAVE_ONLINE |
92 } |
80 } ec_slave_online_state_t; |
93 ec_slave_online_state_t; |
|
94 |
81 |
95 /*****************************************************************************/ |
82 /*****************************************************************************/ |
96 |
83 |
97 /** |
84 /** Supported mailbox protocols. |
98 * Supported mailbox protocols. |
|
99 */ |
85 */ |
100 |
86 enum { |
101 enum |
|
102 { |
|
103 EC_MBOX_AOE = 0x01, /**< ADS-over-EtherCAT */ |
87 EC_MBOX_AOE = 0x01, /**< ADS-over-EtherCAT */ |
104 EC_MBOX_EOE = 0x02, /**< Ethernet-over-EtherCAT */ |
88 EC_MBOX_EOE = 0x02, /**< Ethernet-over-EtherCAT */ |
105 EC_MBOX_COE = 0x04, /**< CANopen-over-EtherCAT */ |
89 EC_MBOX_COE = 0x04, /**< CANopen-over-EtherCAT */ |
106 EC_MBOX_FOE = 0x08, /**< File-Access-over-EtherCAT */ |
90 EC_MBOX_FOE = 0x08, /**< File-Access-over-EtherCAT */ |
107 EC_MBOX_SOE = 0x10, /**< Servo-Profile-over-EtherCAT */ |
91 EC_MBOX_SOE = 0x10, /**< Servo-Profile-over-EtherCAT */ |
108 EC_MBOX_VOE = 0x20 /**< Vendor specific */ |
92 EC_MBOX_VOE = 0x20 /**< Vendor specific */ |
109 }; |
93 }; |
110 |
94 |
111 /*****************************************************************************/ |
95 /*****************************************************************************/ |
112 |
96 |
113 /** |
97 /** EtherCAT slave. |
114 * EtherCAT slave. |
|
115 */ |
98 */ |
116 |
|
117 struct ec_slave |
99 struct ec_slave |
118 { |
100 { |
119 struct list_head list; /**< list item */ |
101 struct list_head list; /**< list item */ |
120 struct kobject kobj; /**< kobject */ |
102 struct kobject kobj; /**< kobject */ |
121 ec_master_t *master; /**< master owning the slave */ |
103 ec_master_t *master; /**< master owning the slave */ |
122 |
104 |
123 ec_slave_state_t requested_state; /**< requested application state */ |
|
124 ec_slave_state_t current_state; /**< current application state */ |
|
125 ec_slave_online_state_t online_state; /**< online state */ |
|
126 unsigned int self_configured; /**< slave was configured by this master */ |
|
127 unsigned int error_flag; /**< stop processing after an error */ |
|
128 unsigned int pdos_registered; /**< non-zero, if PDOs were registered */ |
|
129 |
|
130 // addresses |
105 // addresses |
131 uint16_t ring_position; /**< ring position */ |
106 uint16_t ring_position; /**< ring position */ |
132 uint16_t station_address; /**< configured station address */ |
107 uint16_t station_address; /**< configured station address */ |
|
108 |
|
109 // configuration |
|
110 ec_slave_config_t *config; /**< Current configuration. */ |
|
111 ec_slave_state_t requested_state; /**< Requested application state. */ |
|
112 ec_slave_state_t current_state; /**< Current application state. */ |
|
113 ec_slave_online_state_t online_state; /**< online state */ |
|
114 unsigned int self_configured; /**< Slave was configured by this master. */ |
|
115 unsigned int error_flag; /**< Stop processing after an error. */ |
133 |
116 |
134 // base data |
117 // base data |
135 uint8_t base_type; /**< slave type */ |
118 uint8_t base_type; /**< slave type */ |
136 uint8_t base_revision; /**< revision */ |
119 uint8_t base_revision; /**< revision */ |
137 uint16_t base_build; /**< build number */ |
120 uint16_t base_build; /**< build number */ |
167 char *sii_image; /**< slave image name acc. to EEPROM */ |
150 char *sii_image; /**< slave image name acc. to EEPROM */ |
168 char *sii_order; /**< slave order number acc. to EEPROM */ |
151 char *sii_order; /**< slave order number acc. to EEPROM */ |
169 char *sii_name; /**< slave name acc. to EEPROM */ |
152 char *sii_name; /**< slave name acc. to EEPROM */ |
170 int16_t sii_current_on_ebus; /**< power consumption */ |
153 int16_t sii_current_on_ebus; /**< power consumption */ |
171 |
154 |
172 ec_fmmu_t fmmus[EC_MAX_FMMUS]; /**< FMMU configurations */ |
|
173 uint8_t fmmu_count; /**< number of FMMUs used */ |
|
174 |
|
175 struct kobject sdo_kobj; /**< kobject for SDOs */ |
155 struct kobject sdo_kobj; /**< kobject for SDOs */ |
176 struct list_head sdo_dictionary; /**< SDO dictionary list */ |
156 struct list_head sdo_dictionary; /**< SDO dictionary list */ |
177 struct list_head sdo_confs; /**< list of SDO configurations */ |
|
178 uint8_t sdo_dictionary_fetched; /**< dictionary has been fetched */ |
157 uint8_t sdo_dictionary_fetched; /**< dictionary has been fetched */ |
179 unsigned long jiffies_preop; /**< time, the slave went to PREOP */ |
158 unsigned long jiffies_preop; /**< time, the slave went to PREOP */ |
180 |
159 |
181 uint8_t pdo_mapping_fetched; /**< PDO mapping has been fetched */ |
160 uint8_t pdo_mapping_fetched; /**< PDO mapping has been fetched */ |
182 }; |
161 }; |
185 |
164 |
186 // slave construction/destruction |
165 // slave construction/destruction |
187 int ec_slave_init(ec_slave_t *, ec_master_t *, uint16_t, uint16_t); |
166 int ec_slave_init(ec_slave_t *, ec_master_t *, uint16_t, uint16_t); |
188 void ec_slave_destroy(ec_slave_t *); |
167 void ec_slave_destroy(ec_slave_t *); |
189 |
168 |
190 void ec_slave_reset(ec_slave_t *); |
|
191 |
|
192 int ec_slave_prepare_fmmu(ec_slave_t *, const ec_domain_t *, |
|
193 const ec_sync_t *); |
|
194 |
|
195 void ec_slave_request_state(ec_slave_t *, ec_slave_state_t); |
169 void ec_slave_request_state(ec_slave_t *, ec_slave_state_t); |
196 void ec_slave_set_state(ec_slave_t *, ec_slave_state_t); |
170 void ec_slave_set_state(ec_slave_t *, ec_slave_state_t); |
197 void ec_slave_set_online_state(ec_slave_t *, ec_slave_online_state_t); |
171 void ec_slave_set_online_state(ec_slave_t *, ec_slave_online_state_t); |
198 |
172 |
199 // SII categories |
173 // SII categories |
200 int ec_slave_fetch_sii_strings(ec_slave_t *, const uint8_t *, size_t); |
174 int ec_slave_fetch_sii_strings(ec_slave_t *, const uint8_t *, size_t); |
201 int ec_slave_fetch_sii_general(ec_slave_t *, const uint8_t *, size_t); |
175 int ec_slave_fetch_sii_general(ec_slave_t *, const uint8_t *, size_t); |
202 int ec_slave_fetch_sii_syncs(ec_slave_t *, const uint8_t *, size_t); |
176 int ec_slave_fetch_sii_syncs(ec_slave_t *, const uint8_t *, size_t); |
203 int ec_slave_fetch_sii_pdos(ec_slave_t *, const uint8_t *, size_t, |
177 int ec_slave_fetch_sii_pdos(ec_slave_t *, const uint8_t *, size_t, |
204 ec_pdo_type_t); |
178 ec_direction_t); |
205 |
179 |
206 // misc. |
180 // misc. |
207 ec_sync_t *ec_slave_get_pdo_sync(ec_slave_t *, ec_direction_t); |
181 ec_sync_t *ec_slave_get_pdo_sync(ec_slave_t *, ec_direction_t); |
208 int ec_slave_validate(const ec_slave_t *, uint32_t, uint32_t); |
182 int ec_slave_validate(const ec_slave_t *, uint32_t, uint32_t); |
209 void ec_slave_sdo_dict_info(const ec_slave_t *, |
183 void ec_slave_sdo_dict_info(const ec_slave_t *, |