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; |
245 return; |
245 return; |
246 } |
246 } |
247 |
247 |
248 if (datagram->working_counter != 1) { |
248 if (datagram->working_counter != 1) { |
249 char req_state[EC_STATE_STRING_SIZE]; |
249 char req_state[EC_STATE_STRING_SIZE]; |
250 ec_state_string(fsm->requested_state, req_state); |
250 ec_state_string(fsm->requested_state, req_state, 0); |
251 fsm->state = ec_fsm_change_state_error; |
251 fsm->state = ec_fsm_change_state_error; |
252 EC_ERR("Failed to check state %s on slave %u: ", |
252 EC_ERR("Failed to check state %s on slave %u: ", |
253 req_state, slave->ring_position); |
253 req_state, slave->ring_position); |
254 ec_datagram_print_wc_error(datagram); |
254 ec_datagram_print_wc_error(datagram); |
255 return; |
255 return; |
269 } |
269 } |
270 |
270 |
271 if (slave->current_state != fsm->old_state) { // state changed |
271 if (slave->current_state != fsm->old_state) { // state changed |
272 char req_state[EC_STATE_STRING_SIZE], cur_state[EC_STATE_STRING_SIZE]; |
272 char req_state[EC_STATE_STRING_SIZE], cur_state[EC_STATE_STRING_SIZE]; |
273 |
273 |
274 ec_state_string(slave->current_state, cur_state); |
274 ec_state_string(slave->current_state, cur_state, 0); |
275 |
275 |
276 if ((slave->current_state & 0x0F) != (fsm->old_state & 0x0F)) { |
276 if ((slave->current_state & 0x0F) != (fsm->old_state & 0x0F)) { |
277 // Slave spontaneously changed its state just before the new state |
277 // Slave spontaneously changed its state just before the new state |
278 // was written. Accept current state as old state and wait for |
278 // was written. Accept current state as old state and wait for |
279 // state change |
279 // state change |
285 } |
285 } |
286 |
286 |
287 // state change error |
287 // state change error |
288 |
288 |
289 slave->error_flag = 1; |
289 slave->error_flag = 1; |
290 ec_state_string(fsm->requested_state, req_state); |
290 ec_state_string(fsm->requested_state, req_state, 0); |
291 |
291 |
292 EC_ERR("Failed to set %s state, slave %u refused state change (%s).\n", |
292 EC_ERR("Failed to set %s state, slave %u refused state change (%s).\n", |
293 req_state, slave->ring_position, cur_state); |
293 req_state, slave->ring_position, cur_state); |
294 // fetch AL status error code |
294 // fetch AL status error code |
295 ec_datagram_fprd(datagram, slave->station_address, 0x0134, 2); |
295 ec_datagram_fprd(datagram, slave->station_address, 0x0134, 2); |
302 // still old state |
302 // still old state |
303 |
303 |
304 if (datagram->jiffies_received - fsm->jiffies_start >= HZ) { // 1s |
304 if (datagram->jiffies_received - fsm->jiffies_start >= HZ) { // 1s |
305 // timeout while checking |
305 // timeout while checking |
306 char state_str[EC_STATE_STRING_SIZE]; |
306 char state_str[EC_STATE_STRING_SIZE]; |
307 ec_state_string(fsm->requested_state, state_str); |
307 ec_state_string(fsm->requested_state, state_str, 0); |
308 fsm->state = ec_fsm_change_state_error; |
308 fsm->state = ec_fsm_change_state_error; |
309 EC_ERR("Timeout while setting state %s on slave %u.\n", |
309 EC_ERR("Timeout while setting state %s on slave %u.\n", |
310 state_str, slave->ring_position); |
310 state_str, slave->ring_position); |
311 return; |
311 return; |
312 } |
312 } |
324 Application layer status messages. |
324 Application layer status messages. |
325 */ |
325 */ |
326 |
326 |
327 const ec_code_msg_t al_status_messages[] = { |
327 const ec_code_msg_t al_status_messages[] = { |
328 {0x0001, "Unspecified error"}, |
328 {0x0001, "Unspecified error"}, |
329 {0x0011, "Invalud requested state change"}, |
329 {0x0011, "Invalid requested state change"}, |
330 {0x0012, "Unknown requested state"}, |
330 {0x0012, "Unknown requested state"}, |
331 {0x0013, "Bootstrap not supported"}, |
331 {0x0013, "Bootstrap not supported"}, |
332 {0x0014, "No valid firmware"}, |
332 {0x0014, "No valid firmware"}, |
333 {0x0015, "Invalid mailbox configuration"}, |
333 {0x0015, "Invalid mailbox configuration"}, |
334 {0x0016, "Invalid mailbox configuration"}, |
334 {0x0016, "Invalid mailbox configuration"}, |
496 |
496 |
497 slave->current_state = EC_READ_U8(datagram->data); |
497 slave->current_state = EC_READ_U8(datagram->data); |
498 |
498 |
499 if (!(slave->current_state & EC_SLAVE_STATE_ACK_ERR)) { |
499 if (!(slave->current_state & EC_SLAVE_STATE_ACK_ERR)) { |
500 char state_str[EC_STATE_STRING_SIZE]; |
500 char state_str[EC_STATE_STRING_SIZE]; |
501 ec_state_string(slave->current_state, state_str); |
501 ec_state_string(slave->current_state, state_str, 0); |
502 if (fsm->mode == EC_FSM_CHANGE_MODE_FULL) { |
502 if (fsm->mode == EC_FSM_CHANGE_MODE_FULL) { |
503 fsm->state = ec_fsm_change_state_error; |
503 fsm->state = ec_fsm_change_state_error; |
504 } |
504 } |
505 else { // EC_FSM_CHANGE_MODE_ACK_ONLY |
505 else { // EC_FSM_CHANGE_MODE_ACK_ONLY |
506 fsm->state = ec_fsm_change_state_end; |
506 fsm->state = ec_fsm_change_state_end; |
511 } |
511 } |
512 |
512 |
513 if (datagram->jiffies_received - fsm->jiffies_start >= HZ) { // 1s |
513 if (datagram->jiffies_received - fsm->jiffies_start >= HZ) { // 1s |
514 // timeout while checking |
514 // timeout while checking |
515 char state_str[EC_STATE_STRING_SIZE]; |
515 char state_str[EC_STATE_STRING_SIZE]; |
516 ec_state_string(slave->current_state, state_str); |
516 ec_state_string(slave->current_state, state_str, 0); |
517 fsm->state = ec_fsm_change_state_error; |
517 fsm->state = ec_fsm_change_state_error; |
518 EC_ERR("Timeout while acknowledging state %s on slave %u.\n", |
518 EC_ERR("Timeout while acknowledging state %s on slave %u.\n", |
519 state_str, slave->ring_position); |
519 state_str, slave->ring_position); |
520 return; |
520 return; |
521 } |
521 } |