257 \return 0 in case of success, else < 0 |
257 \return 0 in case of success, else < 0 |
258 */ |
258 */ |
259 |
259 |
260 int ec_slave_fetch(ec_slave_t *slave /**< EtherCAT slave */) |
260 int ec_slave_fetch(ec_slave_t *slave /**< EtherCAT slave */) |
261 { |
261 { |
262 ec_command_t *command; |
262 ec_datagram_t *datagram; |
263 unsigned int i; |
263 unsigned int i; |
264 uint16_t dl_status; |
264 uint16_t dl_status; |
265 |
265 |
266 command = &slave->master->simple_command; |
266 datagram = &slave->master->simple_datagram; |
267 |
267 |
268 // read base data |
268 // read base data |
269 if (ec_command_nprd(command, slave->station_address, 0x0000, 6)) return -1; |
269 if (ec_datagram_nprd(datagram, slave->station_address, 0x0000, 6)) |
270 if (unlikely(ec_master_simple_io(slave->master, command))) { |
270 return -1; |
|
271 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
271 EC_ERR("Reading base data from slave %i failed!\n", |
272 EC_ERR("Reading base data from slave %i failed!\n", |
272 slave->ring_position); |
273 slave->ring_position); |
273 return -1; |
274 return -1; |
274 } |
275 } |
275 |
276 |
276 slave->base_type = EC_READ_U8 (command->data); |
277 slave->base_type = EC_READ_U8 (datagram->data); |
277 slave->base_revision = EC_READ_U8 (command->data + 1); |
278 slave->base_revision = EC_READ_U8 (datagram->data + 1); |
278 slave->base_build = EC_READ_U16(command->data + 2); |
279 slave->base_build = EC_READ_U16(datagram->data + 2); |
279 slave->base_fmmu_count = EC_READ_U8 (command->data + 4); |
280 slave->base_fmmu_count = EC_READ_U8 (datagram->data + 4); |
280 slave->base_sync_count = EC_READ_U8 (command->data + 5); |
281 slave->base_sync_count = EC_READ_U8 (datagram->data + 5); |
281 |
282 |
282 if (slave->base_fmmu_count > EC_MAX_FMMUS) |
283 if (slave->base_fmmu_count > EC_MAX_FMMUS) |
283 slave->base_fmmu_count = EC_MAX_FMMUS; |
284 slave->base_fmmu_count = EC_MAX_FMMUS; |
284 |
285 |
285 // read data link status |
286 // read data link status |
286 if (ec_command_nprd(command, slave->station_address, 0x0110, 2)) return -1; |
287 if (ec_datagram_nprd(datagram, slave->station_address, 0x0110, 2)) |
287 if (unlikely(ec_master_simple_io(slave->master, command))) { |
288 return -1; |
|
289 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
288 EC_ERR("Reading DL status from slave %i failed!\n", |
290 EC_ERR("Reading DL status from slave %i failed!\n", |
289 slave->ring_position); |
291 slave->ring_position); |
290 return -1; |
292 return -1; |
291 } |
293 } |
292 |
294 |
293 dl_status = EC_READ_U16(command->data); |
295 dl_status = EC_READ_U16(datagram->data); |
294 for (i = 0; i < 4; i++) { |
296 for (i = 0; i < 4; i++) { |
295 slave->dl_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0; |
297 slave->dl_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0; |
296 slave->dl_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0; |
298 slave->dl_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0; |
297 slave->dl_signal[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0; |
299 slave->dl_signal[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0; |
298 } |
300 } |
340 /**< address of the SII register to read */ |
342 /**< address of the SII register to read */ |
341 uint16_t *target |
343 uint16_t *target |
342 /**< target memory */ |
344 /**< target memory */ |
343 ) |
345 ) |
344 { |
346 { |
345 ec_command_t *command; |
347 ec_datagram_t *datagram; |
346 cycles_t start, end, timeout; |
348 cycles_t start, end, timeout; |
347 |
349 |
348 command = &slave->master->simple_command; |
350 datagram = &slave->master->simple_datagram; |
349 |
351 |
350 // initiate read operation |
352 // initiate read operation |
351 if (ec_command_npwr(command, slave->station_address, 0x502, 6)) return -1; |
353 if (ec_datagram_npwr(datagram, slave->station_address, 0x502, 6)) |
352 EC_WRITE_U8 (command->data, 0x00); // read-only access |
354 return -1; |
353 EC_WRITE_U8 (command->data + 1, 0x01); // request read operation |
355 EC_WRITE_U8 (datagram->data, 0x00); // read-only access |
354 EC_WRITE_U32(command->data + 2, offset); |
356 EC_WRITE_U8 (datagram->data + 1, 0x01); // request read operation |
355 if (unlikely(ec_master_simple_io(slave->master, command))) { |
357 EC_WRITE_U32(datagram->data + 2, offset); |
|
358 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
356 EC_ERR("SII-read failed on slave %i!\n", slave->ring_position); |
359 EC_ERR("SII-read failed on slave %i!\n", slave->ring_position); |
357 return -1; |
360 return -1; |
358 } |
361 } |
359 |
362 |
360 start = get_cycles(); |
363 start = get_cycles(); |
362 |
365 |
363 while (1) |
366 while (1) |
364 { |
367 { |
365 udelay(10); |
368 udelay(10); |
366 |
369 |
367 if (ec_command_nprd(command, slave->station_address, 0x502, 10)) |
370 if (ec_datagram_nprd(datagram, slave->station_address, 0x502, 10)) |
368 return -1; |
371 return -1; |
369 if (unlikely(ec_master_simple_io(slave->master, command))) { |
372 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
370 EC_ERR("Getting SII-read status failed on slave %i!\n", |
373 EC_ERR("Getting SII-read status failed on slave %i!\n", |
371 slave->ring_position); |
374 slave->ring_position); |
372 return -1; |
375 return -1; |
373 } |
376 } |
374 |
377 |
375 end = get_cycles(); |
378 end = get_cycles(); |
376 |
379 |
377 // check for "busy bit" |
380 // check for "busy bit" |
378 if (likely((EC_READ_U8(command->data + 1) & 0x81) == 0)) { |
381 if (likely((EC_READ_U8(datagram->data + 1) & 0x81) == 0)) { |
379 *target = EC_READ_U16(command->data + 6); |
382 *target = EC_READ_U16(datagram->data + 6); |
380 return 0; |
383 return 0; |
381 } |
384 } |
382 |
385 |
383 if (unlikely((end - start) >= timeout)) { |
386 if (unlikely((end - start) >= timeout)) { |
384 EC_ERR("SII-read. Slave %i timed out!\n", slave->ring_position); |
387 EC_ERR("SII-read. Slave %i timed out!\n", slave->ring_position); |
400 /**< address of the SII register to read */ |
403 /**< address of the SII register to read */ |
401 uint32_t *target |
404 uint32_t *target |
402 /**< target memory */ |
405 /**< target memory */ |
403 ) |
406 ) |
404 { |
407 { |
405 ec_command_t *command; |
408 ec_datagram_t *datagram; |
406 cycles_t start, end, timeout; |
409 cycles_t start, end, timeout; |
407 |
410 |
408 command = &slave->master->simple_command; |
411 datagram = &slave->master->simple_datagram; |
409 |
412 |
410 // initiate read operation |
413 // initiate read operation |
411 if (ec_command_npwr(command, slave->station_address, 0x502, 6)) return -1; |
414 if (ec_datagram_npwr(datagram, slave->station_address, 0x502, 6)) |
412 EC_WRITE_U8 (command->data, 0x00); // read-only access |
415 return -1; |
413 EC_WRITE_U8 (command->data + 1, 0x01); // request read operation |
416 EC_WRITE_U8 (datagram->data, 0x00); // read-only access |
414 EC_WRITE_U32(command->data + 2, offset); |
417 EC_WRITE_U8 (datagram->data + 1, 0x01); // request read operation |
415 if (unlikely(ec_master_simple_io(slave->master, command))) { |
418 EC_WRITE_U32(datagram->data + 2, offset); |
|
419 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
416 EC_ERR("SII-read failed on slave %i!\n", slave->ring_position); |
420 EC_ERR("SII-read failed on slave %i!\n", slave->ring_position); |
417 return -1; |
421 return -1; |
418 } |
422 } |
419 |
423 |
420 start = get_cycles(); |
424 start = get_cycles(); |
422 |
426 |
423 while (1) |
427 while (1) |
424 { |
428 { |
425 udelay(10); |
429 udelay(10); |
426 |
430 |
427 if (ec_command_nprd(command, slave->station_address, 0x502, 10)) |
431 if (ec_datagram_nprd(datagram, slave->station_address, 0x502, 10)) |
428 return -1; |
432 return -1; |
429 if (unlikely(ec_master_simple_io(slave->master, command))) { |
433 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
430 EC_ERR("Getting SII-read status failed on slave %i!\n", |
434 EC_ERR("Getting SII-read status failed on slave %i!\n", |
431 slave->ring_position); |
435 slave->ring_position); |
432 return -1; |
436 return -1; |
433 } |
437 } |
434 |
438 |
435 end = get_cycles(); |
439 end = get_cycles(); |
436 |
440 |
437 // check "busy bit" |
441 // check "busy bit" |
438 if (likely((EC_READ_U8(command->data + 1) & 0x81) == 0)) { |
442 if (likely((EC_READ_U8(datagram->data + 1) & 0x81) == 0)) { |
439 *target = EC_READ_U32(command->data + 6); |
443 *target = EC_READ_U32(datagram->data + 6); |
440 return 0; |
444 return 0; |
441 } |
445 } |
442 |
446 |
443 if (unlikely((end - start) >= timeout)) { |
447 if (unlikely((end - start) >= timeout)) { |
444 EC_ERR("SII-read. Slave %i timed out!\n", slave->ring_position); |
448 EC_ERR("SII-read. Slave %i timed out!\n", slave->ring_position); |
460 /**< address of the SII register to write */ |
464 /**< address of the SII register to write */ |
461 uint16_t value |
465 uint16_t value |
462 /**< new value */ |
466 /**< new value */ |
463 ) |
467 ) |
464 { |
468 { |
465 ec_command_t *command; |
469 ec_datagram_t *datagram; |
466 cycles_t start, end, timeout; |
470 cycles_t start, end, timeout; |
467 |
471 |
468 command = &slave->master->simple_command; |
472 datagram = &slave->master->simple_datagram; |
469 |
473 |
470 EC_INFO("SII-write (slave %i, offset 0x%04X, value 0x%04X)\n", |
474 EC_INFO("SII-write (slave %i, offset 0x%04X, value 0x%04X)\n", |
471 slave->ring_position, offset, value); |
475 slave->ring_position, offset, value); |
472 |
476 |
473 // initiate write operation |
477 // initiate write operation |
474 if (ec_command_npwr(command, slave->station_address, 0x502, 8)) return -1; |
478 if (ec_datagram_npwr(datagram, slave->station_address, 0x502, 8)) |
475 EC_WRITE_U8 (command->data, 0x01); // enable write access |
479 return -1; |
476 EC_WRITE_U8 (command->data + 1, 0x02); // request write operation |
480 EC_WRITE_U8 (datagram->data, 0x01); // enable write access |
477 EC_WRITE_U32(command->data + 2, offset); |
481 EC_WRITE_U8 (datagram->data + 1, 0x02); // request write operation |
478 EC_WRITE_U16(command->data + 6, value); |
482 EC_WRITE_U32(datagram->data + 2, offset); |
479 if (unlikely(ec_master_simple_io(slave->master, command))) { |
483 EC_WRITE_U16(datagram->data + 6, value); |
|
484 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
480 EC_ERR("SII-write failed on slave %i!\n", slave->ring_position); |
485 EC_ERR("SII-write failed on slave %i!\n", slave->ring_position); |
481 return -1; |
486 return -1; |
482 } |
487 } |
483 |
488 |
484 start = get_cycles(); |
489 start = get_cycles(); |
486 |
491 |
487 while (1) |
492 while (1) |
488 { |
493 { |
489 udelay(10); |
494 udelay(10); |
490 |
495 |
491 if (ec_command_nprd(command, slave->station_address, 0x502, 2)) |
496 if (ec_datagram_nprd(datagram, slave->station_address, 0x502, 2)) |
492 return -1; |
497 return -1; |
493 if (unlikely(ec_master_simple_io(slave->master, command))) { |
498 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
494 EC_ERR("Getting SII-write status failed on slave %i!\n", |
499 EC_ERR("Getting SII-write status failed on slave %i!\n", |
495 slave->ring_position); |
500 slave->ring_position); |
496 return -1; |
501 return -1; |
497 } |
502 } |
498 |
503 |
499 end = get_cycles(); |
504 end = get_cycles(); |
500 |
505 |
501 // check "busy bit" |
506 // check "busy bit" |
502 if (likely((EC_READ_U8(command->data + 1) & 0x82) == 0)) { |
507 if (likely((EC_READ_U8(datagram->data + 1) & 0x82) == 0)) { |
503 if (EC_READ_U8(command->data + 1) & 0x40) { |
508 if (EC_READ_U8(datagram->data + 1) & 0x40) { |
504 EC_ERR("SII-write failed!\n"); |
509 EC_ERR("SII-write failed!\n"); |
505 return -1; |
510 return -1; |
506 } |
511 } |
507 else { |
512 else { |
508 EC_INFO("SII-write succeeded!\n"); |
513 EC_INFO("SII-write succeeded!\n"); |
832 |
837 |
833 void ec_slave_state_ack(ec_slave_t *slave, /**< EtherCAT slave */ |
838 void ec_slave_state_ack(ec_slave_t *slave, /**< EtherCAT slave */ |
834 uint8_t state /**< previous state */ |
839 uint8_t state /**< previous state */ |
835 ) |
840 ) |
836 { |
841 { |
837 ec_command_t *command; |
842 ec_datagram_t *datagram; |
838 cycles_t start, end, timeout; |
843 cycles_t start, end, timeout; |
839 |
844 |
840 command = &slave->master->simple_command; |
845 datagram = &slave->master->simple_datagram; |
841 |
846 |
842 if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return; |
847 if (ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2)) return; |
843 EC_WRITE_U16(command->data, state | EC_ACK); |
848 EC_WRITE_U16(datagram->data, state | EC_ACK); |
844 if (unlikely(ec_master_simple_io(slave->master, command))) { |
849 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
845 EC_WARN("Acknowledge sending failed on slave %i!\n", |
850 EC_WARN("Acknowledge sending failed on slave %i!\n", |
846 slave->ring_position); |
851 slave->ring_position); |
847 return; |
852 return; |
848 } |
853 } |
849 |
854 |
852 |
857 |
853 while (1) |
858 while (1) |
854 { |
859 { |
855 udelay(100); // wait a little bit... |
860 udelay(100); // wait a little bit... |
856 |
861 |
857 if (ec_command_nprd(command, slave->station_address, 0x0130, 2)) |
862 if (ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2)) |
858 return; |
863 return; |
859 if (unlikely(ec_master_simple_io(slave->master, command))) { |
864 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
860 slave->current_state = EC_SLAVE_STATE_UNKNOWN; |
865 slave->current_state = EC_SLAVE_STATE_UNKNOWN; |
861 EC_WARN("Acknowledge checking failed on slave %i!\n", |
866 EC_WARN("Acknowledge checking failed on slave %i!\n", |
862 slave->ring_position); |
867 slave->ring_position); |
863 return; |
868 return; |
864 } |
869 } |
865 |
870 |
866 end = get_cycles(); |
871 end = get_cycles(); |
867 |
872 |
868 if (likely(EC_READ_U8(command->data) == state)) { |
873 if (likely(EC_READ_U8(datagram->data) == state)) { |
869 slave->current_state = state; |
874 slave->current_state = state; |
870 EC_INFO("Acknowleged state 0x%02X on slave %i.\n", state, |
875 EC_INFO("Acknowleged state 0x%02X on slave %i.\n", state, |
871 slave->ring_position); |
876 slave->ring_position); |
872 return; |
877 return; |
873 } |
878 } |
889 resulting in code = 0), nothing is displayed. |
894 resulting in code = 0), nothing is displayed. |
890 */ |
895 */ |
891 |
896 |
892 void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT slave */) |
897 void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT slave */) |
893 { |
898 { |
894 ec_command_t *command; |
899 ec_datagram_t *datagram; |
895 uint16_t code; |
900 uint16_t code; |
896 const ec_code_msg_t *al_msg; |
901 const ec_code_msg_t *al_msg; |
897 |
902 |
898 command = &slave->master->simple_command; |
903 datagram = &slave->master->simple_datagram; |
899 |
904 |
900 if (ec_command_nprd(command, slave->station_address, 0x0134, 2)) return; |
905 if (ec_datagram_nprd(datagram, slave->station_address, 0x0134, 2)) return; |
901 if (unlikely(ec_master_simple_io(slave->master, command))) { |
906 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
902 EC_WARN("Failed to read AL status code on slave %i!\n", |
907 EC_WARN("Failed to read AL status code on slave %i!\n", |
903 slave->ring_position); |
908 slave->ring_position); |
904 return; |
909 return; |
905 } |
910 } |
906 |
911 |
907 if (!(code = EC_READ_U16(command->data))) return; |
912 if (!(code = EC_READ_U16(datagram->data))) return; |
908 |
913 |
909 for (al_msg = al_status_messages; al_msg->code; al_msg++) { |
914 for (al_msg = al_status_messages; al_msg->code; al_msg++) { |
910 if (al_msg->code == code) { |
915 if (al_msg->code == code) { |
911 EC_ERR("AL status message 0x%04X: \"%s\".\n", |
916 EC_ERR("AL status message 0x%04X: \"%s\".\n", |
912 al_msg->code, al_msg->message); |
917 al_msg->code, al_msg->message); |
926 |
931 |
927 int ec_slave_state_change(ec_slave_t *slave, /**< EtherCAT slave */ |
932 int ec_slave_state_change(ec_slave_t *slave, /**< EtherCAT slave */ |
928 uint8_t state /**< new state */ |
933 uint8_t state /**< new state */ |
929 ) |
934 ) |
930 { |
935 { |
931 ec_command_t *command; |
936 ec_datagram_t *datagram; |
932 cycles_t start, end, timeout; |
937 cycles_t start, end, timeout; |
933 |
938 |
934 command = &slave->master->simple_command; |
939 datagram = &slave->master->simple_datagram; |
935 |
940 |
936 slave->requested_state = state; |
941 slave->requested_state = state; |
937 |
942 |
938 if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return -1; |
943 if (ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2)) |
939 EC_WRITE_U16(command->data, state); |
944 return -1; |
940 if (unlikely(ec_master_simple_io(slave->master, command))) { |
945 EC_WRITE_U16(datagram->data, state); |
|
946 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
941 EC_ERR("Failed to set state 0x%02X on slave %i!\n", |
947 EC_ERR("Failed to set state 0x%02X on slave %i!\n", |
942 state, slave->ring_position); |
948 state, slave->ring_position); |
943 return -1; |
949 return -1; |
944 } |
950 } |
945 |
951 |
948 |
954 |
949 while (1) |
955 while (1) |
950 { |
956 { |
951 udelay(100); // wait a little bit |
957 udelay(100); // wait a little bit |
952 |
958 |
953 if (ec_command_nprd(command, slave->station_address, 0x0130, 2)) |
959 if (ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2)) |
954 return -1; |
960 return -1; |
955 if (unlikely(ec_master_simple_io(slave->master, command))) { |
961 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
956 slave->current_state = EC_SLAVE_STATE_UNKNOWN; |
962 slave->current_state = EC_SLAVE_STATE_UNKNOWN; |
957 EC_ERR("Failed to check state 0x%02X on slave %i!\n", |
963 EC_ERR("Failed to check state 0x%02X on slave %i!\n", |
958 state, slave->ring_position); |
964 state, slave->ring_position); |
959 return -1; |
965 return -1; |
960 } |
966 } |
961 |
967 |
962 end = get_cycles(); |
968 end = get_cycles(); |
963 |
969 |
964 if (unlikely(EC_READ_U8(command->data) & 0x10)) { // state change error |
970 if (unlikely(EC_READ_U8(datagram->data) & 0x10)) { |
|
971 // state change error |
965 EC_ERR("Failed to set state 0x%02X - Slave %i refused state change" |
972 EC_ERR("Failed to set state 0x%02X - Slave %i refused state change" |
966 " (code 0x%02X)!\n", state, slave->ring_position, |
973 " (code 0x%02X)!\n", state, slave->ring_position, |
967 EC_READ_U8(command->data)); |
974 EC_READ_U8(datagram->data)); |
968 slave->current_state = EC_READ_U8(command->data); |
975 slave->current_state = EC_READ_U8(datagram->data); |
969 state = slave->current_state & 0x0F; |
976 state = slave->current_state & 0x0F; |
970 ec_slave_read_al_status_code(slave); |
977 ec_slave_read_al_status_code(slave); |
971 ec_slave_state_ack(slave, state); |
978 ec_slave_state_ack(slave, state); |
972 return -1; |
979 return -1; |
973 } |
980 } |
974 |
981 |
975 if (likely(EC_READ_U8(command->data) == (state & 0x0F))) { |
982 if (likely(EC_READ_U8(datagram->data) == (state & 0x0F))) { |
976 slave->current_state = state; |
983 slave->current_state = state; |
977 return 0; // state change successful |
984 return 0; // state change successful |
978 } |
985 } |
979 |
986 |
980 if (unlikely((end - start) >= timeout)) { |
987 if (unlikely((end - start) >= timeout)) { |
1203 \return 0 in case of success, else < 0 |
1210 \return 0 in case of success, else < 0 |
1204 */ |
1211 */ |
1205 |
1212 |
1206 int ec_slave_check_crc(ec_slave_t *slave /**< EtherCAT slave */) |
1213 int ec_slave_check_crc(ec_slave_t *slave /**< EtherCAT slave */) |
1207 { |
1214 { |
1208 ec_command_t *command; |
1215 ec_datagram_t *datagram; |
1209 |
1216 |
1210 command = &slave->master->simple_command; |
1217 datagram = &slave->master->simple_datagram; |
1211 |
1218 |
1212 if (ec_command_nprd(command, slave->station_address, 0x0300, 4)) return -1; |
1219 if (ec_datagram_nprd(datagram, slave->station_address, 0x0300, 4)) |
1213 if (unlikely(ec_master_simple_io(slave->master, command))) { |
1220 return -1; |
|
1221 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
1214 EC_WARN("Reading CRC fault counters failed on slave %i!\n", |
1222 EC_WARN("Reading CRC fault counters failed on slave %i!\n", |
1215 slave->ring_position); |
1223 slave->ring_position); |
1216 return -1; |
1224 return -1; |
1217 } |
1225 } |
1218 |
1226 |
1219 if (!EC_READ_U32(command->data)) return 0; // no CRC faults |
1227 if (!EC_READ_U32(datagram->data)) return 0; // no CRC faults |
1220 |
1228 |
1221 if (EC_READ_U8(command->data)) |
1229 if (EC_READ_U8(datagram->data)) |
1222 EC_WARN("%3i RX-error%s on slave %i, channel A.\n", |
1230 EC_WARN("%3i RX-error%s on slave %i, channel A.\n", |
1223 EC_READ_U8(command->data), |
1231 EC_READ_U8(datagram->data), |
1224 EC_READ_U8(command->data) == 1 ? "" : "s", |
1232 EC_READ_U8(datagram->data) == 1 ? "" : "s", |
1225 slave->ring_position); |
1233 slave->ring_position); |
1226 if (EC_READ_U8(command->data + 1)) |
1234 if (EC_READ_U8(datagram->data + 1)) |
1227 EC_WARN("%3i invalid frame%s on slave %i, channel A.\n", |
1235 EC_WARN("%3i invalid frame%s on slave %i, channel A.\n", |
1228 EC_READ_U8(command->data + 1), |
1236 EC_READ_U8(datagram->data + 1), |
1229 EC_READ_U8(command->data + 1) == 1 ? "" : "s", |
1237 EC_READ_U8(datagram->data + 1) == 1 ? "" : "s", |
1230 slave->ring_position); |
1238 slave->ring_position); |
1231 if (EC_READ_U8(command->data + 2)) |
1239 if (EC_READ_U8(datagram->data + 2)) |
1232 EC_WARN("%3i RX-error%s on slave %i, channel B.\n", |
1240 EC_WARN("%3i RX-error%s on slave %i, channel B.\n", |
1233 EC_READ_U8(command->data + 2), |
1241 EC_READ_U8(datagram->data + 2), |
1234 EC_READ_U8(command->data + 2) == 1 ? "" : "s", |
1242 EC_READ_U8(datagram->data + 2) == 1 ? "" : "s", |
1235 slave->ring_position); |
1243 slave->ring_position); |
1236 if (EC_READ_U8(command->data + 3)) |
1244 if (EC_READ_U8(datagram->data + 3)) |
1237 EC_WARN("%3i invalid frame%s on slave %i, channel B.\n", |
1245 EC_WARN("%3i invalid frame%s on slave %i, channel B.\n", |
1238 EC_READ_U8(command->data + 3), |
1246 EC_READ_U8(datagram->data + 3), |
1239 EC_READ_U8(command->data + 3) == 1 ? "" : "s", |
1247 EC_READ_U8(datagram->data + 3) == 1 ? "" : "s", |
1240 slave->ring_position); |
1248 slave->ring_position); |
1241 |
1249 |
1242 // reset CRC counters |
1250 // reset CRC counters |
1243 if (ec_command_npwr(command, slave->station_address, 0x0300, 4)) return -1; |
1251 if (ec_datagram_npwr(datagram, slave->station_address, 0x0300, 4)) |
1244 EC_WRITE_U32(command->data, 0x00000000); |
1252 return -1; |
1245 if (unlikely(ec_master_simple_io(slave->master, command))) { |
1253 EC_WRITE_U32(datagram->data, 0x00000000); |
|
1254 if (unlikely(ec_master_simple_io(slave->master, datagram))) { |
1246 EC_WARN("Resetting CRC fault counters failed on slave %i!\n", |
1255 EC_WARN("Resetting CRC fault counters failed on slave %i!\n", |
1247 slave->ring_position); |
1256 slave->ring_position); |
1248 return -1; |
1257 return -1; |
1249 } |
1258 } |
1250 |
1259 |