185 } |
185 } |
186 |
186 |
187 if (datagram->working_counter == 0) { |
187 if (datagram->working_counter == 0) { |
188 if (datagram->jiffies_received - fsm->jiffies_start >= 3 * HZ) { |
188 if (datagram->jiffies_received - fsm->jiffies_start >= 3 * HZ) { |
189 char state_str[EC_STATE_STRING_SIZE]; |
189 char state_str[EC_STATE_STRING_SIZE]; |
190 ec_state_string(fsm->requested_state, state_str); |
190 ec_state_string(fsm->requested_state, state_str, 0); |
191 fsm->state = ec_fsm_change_state_error; |
191 fsm->state = ec_fsm_change_state_error; |
192 EC_ERR("Failed to set state %s on slave %u: ", |
192 EC_ERR("Failed to set state %s on slave %u: ", |
193 state_str, fsm->slave->ring_position); |
193 state_str, fsm->slave->ring_position); |
194 ec_datagram_print_wc_error(datagram); |
194 ec_datagram_print_wc_error(datagram); |
195 return; |
195 return; |
202 return; |
202 return; |
203 } |
203 } |
204 |
204 |
205 if (unlikely(datagram->working_counter > 1)) { |
205 if (unlikely(datagram->working_counter > 1)) { |
206 char state_str[EC_STATE_STRING_SIZE]; |
206 char state_str[EC_STATE_STRING_SIZE]; |
207 ec_state_string(fsm->requested_state, state_str); |
207 ec_state_string(fsm->requested_state, state_str, 0); |
208 fsm->state = ec_fsm_change_state_error; |
208 fsm->state = ec_fsm_change_state_error; |
209 EC_ERR("Failed to set state %s on slave %u: ", |
209 EC_ERR("Failed to set state %s on slave %u: ", |
210 state_str, fsm->slave->ring_position); |
210 state_str, fsm->slave->ring_position); |
211 ec_datagram_print_wc_error(datagram); |
211 ec_datagram_print_wc_error(datagram); |
212 return; |
212 return; |
244 return; |
244 return; |
245 } |
245 } |
246 |
246 |
247 if (datagram->working_counter != 1) { |
247 if (datagram->working_counter != 1) { |
248 char req_state[EC_STATE_STRING_SIZE]; |
248 char req_state[EC_STATE_STRING_SIZE]; |
249 ec_state_string(fsm->requested_state, req_state); |
249 ec_state_string(fsm->requested_state, req_state, 0); |
250 fsm->state = ec_fsm_change_state_error; |
250 fsm->state = ec_fsm_change_state_error; |
251 EC_ERR("Failed to check state %s on slave %u: ", |
251 EC_ERR("Failed to check state %s on slave %u: ", |
252 req_state, slave->ring_position); |
252 req_state, slave->ring_position); |
253 ec_datagram_print_wc_error(datagram); |
253 ec_datagram_print_wc_error(datagram); |
254 return; |
254 return; |
268 } |
268 } |
269 |
269 |
270 if (slave->current_state != fsm->old_state) { // state changed |
270 if (slave->current_state != fsm->old_state) { // state changed |
271 char req_state[EC_STATE_STRING_SIZE], cur_state[EC_STATE_STRING_SIZE]; |
271 char req_state[EC_STATE_STRING_SIZE], cur_state[EC_STATE_STRING_SIZE]; |
272 |
272 |
273 ec_state_string(slave->current_state, cur_state); |
273 ec_state_string(slave->current_state, cur_state, 0); |
274 |
274 |
275 if ((slave->current_state & 0x0F) != (fsm->old_state & 0x0F)) { |
275 if ((slave->current_state & 0x0F) != (fsm->old_state & 0x0F)) { |
276 // Slave spontaneously changed its state just before the new state |
276 // Slave spontaneously changed its state just before the new state |
277 // was written. Accept current state as old state and wait for |
277 // was written. Accept current state as old state and wait for |
278 // state change |
278 // state change |
284 } |
284 } |
285 |
285 |
286 // state change error |
286 // state change error |
287 |
287 |
288 slave->error_flag = 1; |
288 slave->error_flag = 1; |
289 ec_state_string(fsm->requested_state, req_state); |
289 ec_state_string(fsm->requested_state, req_state, 0); |
290 |
290 |
291 EC_ERR("Failed to set %s state, slave %u refused state change (%s).\n", |
291 EC_ERR("Failed to set %s state, slave %u refused state change (%s).\n", |
292 req_state, slave->ring_position, cur_state); |
292 req_state, slave->ring_position, cur_state); |
293 // fetch AL status error code |
293 // fetch AL status error code |
294 ec_datagram_fprd(datagram, slave->station_address, 0x0134, 2); |
294 ec_datagram_fprd(datagram, slave->station_address, 0x0134, 2); |
300 // still old state |
300 // still old state |
301 |
301 |
302 if (datagram->jiffies_received - fsm->jiffies_start >= HZ) { // 1s |
302 if (datagram->jiffies_received - fsm->jiffies_start >= HZ) { // 1s |
303 // timeout while checking |
303 // timeout while checking |
304 char state_str[EC_STATE_STRING_SIZE]; |
304 char state_str[EC_STATE_STRING_SIZE]; |
305 ec_state_string(fsm->requested_state, state_str); |
305 ec_state_string(fsm->requested_state, state_str, 0); |
306 fsm->state = ec_fsm_change_state_error; |
306 fsm->state = ec_fsm_change_state_error; |
307 EC_ERR("Timeout while setting state %s on slave %u.\n", |
307 EC_ERR("Timeout while setting state %s on slave %u.\n", |
308 state_str, slave->ring_position); |
308 state_str, slave->ring_position); |
309 return; |
309 return; |
310 } |
310 } |
321 Application layer status messages. |
321 Application layer status messages. |
322 */ |
322 */ |
323 |
323 |
324 const ec_code_msg_t al_status_messages[] = { |
324 const ec_code_msg_t al_status_messages[] = { |
325 {0x0001, "Unspecified error"}, |
325 {0x0001, "Unspecified error"}, |
326 {0x0011, "Invalud requested state change"}, |
326 {0x0011, "Invalid requested state change"}, |
327 {0x0012, "Unknown requested state"}, |
327 {0x0012, "Unknown requested state"}, |
328 {0x0013, "Bootstrap not supported"}, |
328 {0x0013, "Bootstrap not supported"}, |
329 {0x0014, "No valid firmware"}, |
329 {0x0014, "No valid firmware"}, |
330 {0x0015, "Invalid mailbox configuration"}, |
330 {0x0015, "Invalid mailbox configuration"}, |
331 {0x0016, "Invalid mailbox configuration"}, |
331 {0x0016, "Invalid mailbox configuration"}, |
492 |
492 |
493 slave->current_state = EC_READ_U8(datagram->data); |
493 slave->current_state = EC_READ_U8(datagram->data); |
494 |
494 |
495 if (!(slave->current_state & EC_SLAVE_STATE_ACK_ERR)) { |
495 if (!(slave->current_state & EC_SLAVE_STATE_ACK_ERR)) { |
496 char state_str[EC_STATE_STRING_SIZE]; |
496 char state_str[EC_STATE_STRING_SIZE]; |
497 ec_state_string(slave->current_state, state_str); |
497 ec_state_string(slave->current_state, state_str, 0); |
498 if (fsm->mode == EC_FSM_CHANGE_MODE_FULL) { |
498 if (fsm->mode == EC_FSM_CHANGE_MODE_FULL) { |
499 fsm->state = ec_fsm_change_state_error; |
499 fsm->state = ec_fsm_change_state_error; |
500 } |
500 } |
501 else { // EC_FSM_CHANGE_MODE_ACK_ONLY |
501 else { // EC_FSM_CHANGE_MODE_ACK_ONLY |
502 fsm->state = ec_fsm_change_state_end; |
502 fsm->state = ec_fsm_change_state_end; |
507 } |
507 } |
508 |
508 |
509 if (datagram->jiffies_received - fsm->jiffies_start >= HZ) { // 1s |
509 if (datagram->jiffies_received - fsm->jiffies_start >= HZ) { // 1s |
510 // timeout while checking |
510 // timeout while checking |
511 char state_str[EC_STATE_STRING_SIZE]; |
511 char state_str[EC_STATE_STRING_SIZE]; |
512 ec_state_string(slave->current_state, state_str); |
512 ec_state_string(slave->current_state, state_str, 0); |
513 fsm->state = ec_fsm_change_state_error; |
513 fsm->state = ec_fsm_change_state_error; |
514 EC_ERR("Timeout while acknowledging state %s on slave %u.\n", |
514 EC_ERR("Timeout while acknowledging state %s on slave %u.\n", |
515 state_str, slave->ring_position); |
515 state_str, slave->ring_position); |
516 return; |
516 return; |
517 } |
517 } |