496 ec_command_t *command /**< command */ |
496 ec_command_t *command /**< command */ |
497 ) |
497 ) |
498 { |
498 { |
499 unsigned int response_tries_left; |
499 unsigned int response_tries_left; |
500 |
500 |
501 response_tries_left = 10; |
501 response_tries_left = 10000; |
502 |
502 |
503 while (1) |
503 while (1) |
504 { |
504 { |
505 ec_master_queue_command(master, command); |
505 ec_master_queue_command(master, command); |
506 ecrt_master_sync_io(master); |
506 ecrt_master_sync_io(master); |
746 Initializes a sync manager configuration page. |
746 Initializes a sync manager configuration page. |
747 The referenced memory (\a data) must be at least EC_SYNC_SIZE bytes. |
747 The referenced memory (\a data) must be at least EC_SYNC_SIZE bytes. |
748 */ |
748 */ |
749 |
749 |
750 void ec_sync_config(const ec_sync_t *sync, /**< sync manager */ |
750 void ec_sync_config(const ec_sync_t *sync, /**< sync manager */ |
|
751 const ec_slave_t *slave, /**< EtherCAT slave */ |
751 uint8_t *data /**> configuration memory */ |
752 uint8_t *data /**> configuration memory */ |
752 ) |
753 ) |
753 { |
754 { |
|
755 size_t sync_size; |
|
756 |
|
757 sync_size = ec_slave_calc_sync_size(slave, sync); |
|
758 |
754 EC_WRITE_U16(data, sync->physical_start_address); |
759 EC_WRITE_U16(data, sync->physical_start_address); |
755 EC_WRITE_U16(data + 2, sync->size); |
760 EC_WRITE_U16(data + 2, sync_size); |
756 EC_WRITE_U8 (data + 4, sync->control_byte); |
761 EC_WRITE_U8 (data + 4, sync->control_byte); |
757 EC_WRITE_U8 (data + 5, 0x00); // status byte (read only) |
762 EC_WRITE_U8 (data + 5, 0x00); // status byte (read only) |
758 EC_WRITE_U16(data + 6, 0x0001); // enable |
763 EC_WRITE_U16(data + 6, 0x0001); // enable |
759 } |
764 } |
760 |
765 |
782 Initializes an FMMU configuration page. |
787 Initializes an FMMU configuration page. |
783 The referenced memory (\a data) must be at least EC_FMMU_SIZE bytes. |
788 The referenced memory (\a data) must be at least EC_FMMU_SIZE bytes. |
784 */ |
789 */ |
785 |
790 |
786 void ec_fmmu_config(const ec_fmmu_t *fmmu, /**< FMMU */ |
791 void ec_fmmu_config(const ec_fmmu_t *fmmu, /**< FMMU */ |
|
792 const ec_slave_t *slave, /**< EtherCAT slave */ |
787 uint8_t *data /**> configuration memory */ |
793 uint8_t *data /**> configuration memory */ |
788 ) |
794 ) |
789 { |
795 { |
|
796 size_t sync_size; |
|
797 |
|
798 sync_size = ec_slave_calc_sync_size(slave, fmmu->sync); |
|
799 |
790 EC_WRITE_U32(data, fmmu->logical_start_address); |
800 EC_WRITE_U32(data, fmmu->logical_start_address); |
791 EC_WRITE_U16(data + 4, fmmu->sync->size); |
801 EC_WRITE_U16(data + 4, sync_size); // size of fmmu |
792 EC_WRITE_U8 (data + 6, 0x00); // logical start bit |
802 EC_WRITE_U8 (data + 6, 0x00); // logical start bit |
793 EC_WRITE_U8 (data + 7, 0x07); // logical end bit |
803 EC_WRITE_U8 (data + 7, 0x07); // logical end bit |
794 EC_WRITE_U16(data + 8, fmmu->sync->physical_start_address); |
804 EC_WRITE_U16(data + 8, fmmu->sync->physical_start_address); |
795 EC_WRITE_U8 (data + 10, 0x00); // physical start bit |
805 EC_WRITE_U8 (data + 10, 0x00); // physical start bit |
796 EC_WRITE_U8 (data + 11, (fmmu->sync->control_byte & 0x04) ? 0x02 : 0x01); |
806 EC_WRITE_U8 (data + 11, (fmmu->sync->control_byte & 0x04) ? 0x02 : 0x01); |
1131 for (j = 0; type->sync_managers[j] && j < EC_MAX_SYNC; j++) { |
1141 for (j = 0; type->sync_managers[j] && j < EC_MAX_SYNC; j++) { |
1132 sync = type->sync_managers[j]; |
1142 sync = type->sync_managers[j]; |
1133 if (ec_command_npwr(command, slave->station_address, |
1143 if (ec_command_npwr(command, slave->station_address, |
1134 0x0800 + j * EC_SYNC_SIZE, EC_SYNC_SIZE)) |
1144 0x0800 + j * EC_SYNC_SIZE, EC_SYNC_SIZE)) |
1135 return -1; |
1145 return -1; |
1136 ec_sync_config(sync, command->data); |
1146 ec_sync_config(sync, slave, command->data); |
|
1147 EC_INFO("configuring sync.\n"); |
1137 if (unlikely(ec_master_simple_io(master, command))) { |
1148 if (unlikely(ec_master_simple_io(master, command))) { |
1138 EC_ERR("Setting sync manager %i failed on slave %i!\n", |
1149 EC_ERR("Setting sync manager %i failed on slave %i!\n", |
1139 j, slave->ring_position); |
1150 j, slave->ring_position); |
1140 return -1; |
1151 return -1; |
1141 } |
1152 } |
1209 for (j = 0; j < slave->fmmu_count; j++) { |
1220 for (j = 0; j < slave->fmmu_count; j++) { |
1210 fmmu = &slave->fmmus[j]; |
1221 fmmu = &slave->fmmus[j]; |
1211 if (ec_command_npwr(command, slave->station_address, |
1222 if (ec_command_npwr(command, slave->station_address, |
1212 0x0600 + j * EC_FMMU_SIZE, EC_FMMU_SIZE)) |
1223 0x0600 + j * EC_FMMU_SIZE, EC_FMMU_SIZE)) |
1213 return -1; |
1224 return -1; |
1214 ec_fmmu_config(fmmu, command->data); |
1225 ec_fmmu_config(fmmu, slave, command->data); |
|
1226 EC_INFO("configuring fmmu.\n"); |
1215 if (unlikely(ec_master_simple_io(master, command))) { |
1227 if (unlikely(ec_master_simple_io(master, command))) { |
1216 EC_ERR("Setting FMMU %i failed on slave %i!\n", |
1228 EC_ERR("Setting FMMU %i failed on slave %i!\n", |
1217 j, slave->ring_position); |
1229 j, slave->ring_position); |
1218 return -1; |
1230 return -1; |
1219 } |
1231 } |