353 |
353 |
354 // slave responded |
354 // slave responded |
355 new_state = EC_READ_U8(command->data); |
355 new_state = EC_READ_U8(command->data); |
356 if (!slave->online) { // slave was offline before |
356 if (!slave->online) { // slave was offline before |
357 slave->online = 1; |
357 slave->online = 1; |
358 slave->state_error = 0; |
358 slave->error_flag = 0; // clear error flag |
359 slave->current_state = new_state; |
359 slave->current_state = new_state; |
360 EC_INFO("Slave %i: online (", slave->ring_position); |
360 EC_INFO("Slave %i: online (", slave->ring_position); |
361 ec_print_states(new_state); |
361 ec_print_states(new_state); |
362 printk(").\n"); |
362 printk(").\n"); |
363 } |
363 } |
385 ec_master_t *master = fsm->master; |
385 ec_master_t *master = fsm->master; |
386 ec_slave_t *slave; |
386 ec_slave_t *slave; |
387 |
387 |
388 // check if any slaves are not in the state, they're supposed to be |
388 // check if any slaves are not in the state, they're supposed to be |
389 list_for_each_entry(slave, &master->slaves, list) { |
389 list_for_each_entry(slave, &master->slaves, list) { |
390 if (slave->state_error || !slave->online || |
390 if (slave->error_flag || |
|
391 !slave->online || |
391 slave->requested_state == EC_SLAVE_STATE_UNKNOWN || |
392 slave->requested_state == EC_SLAVE_STATE_UNKNOWN || |
392 slave->current_state == slave->requested_state) continue; |
393 slave->current_state == slave->requested_state) continue; |
393 |
394 |
394 EC_INFO("Changing state of slave %i from ", slave->ring_position); |
395 EC_INFO("Changing state of slave %i from ", slave->ring_position); |
395 ec_print_states(slave->current_state); |
396 ec_print_states(slave->current_state); |
441 ec_slave_t *slave = fsm->slave; |
442 ec_slave_t *slave = fsm->slave; |
442 |
443 |
443 fsm->sii_state(fsm); // execute SII state machine |
444 fsm->sii_state(fsm); // execute SII state machine |
444 |
445 |
445 if (fsm->sii_state == ec_fsm_sii_error) { |
446 if (fsm->sii_state == ec_fsm_sii_error) { |
|
447 fsm->slave->error_flag = 1; |
446 EC_ERR("Failed to validate vendor ID of slave %i.\n", |
448 EC_ERR("Failed to validate vendor ID of slave %i.\n", |
447 slave->ring_position); |
449 slave->ring_position); |
448 fsm->master_state = ec_fsm_master_start; |
450 fsm->master_state = ec_fsm_master_start; |
449 fsm->master_state(fsm); // execute immediately |
451 fsm->master_state(fsm); // execute immediately |
450 return; |
452 return; |
479 ec_slave_t *slave = fsm->slave; |
481 ec_slave_t *slave = fsm->slave; |
480 |
482 |
481 fsm->sii_state(fsm); // execute SII state machine |
483 fsm->sii_state(fsm); // execute SII state machine |
482 |
484 |
483 if (fsm->sii_state == ec_fsm_sii_error) { |
485 if (fsm->sii_state == ec_fsm_sii_error) { |
|
486 fsm->slave->error_flag = 1; |
484 EC_ERR("Failed to validate product code of slave %i.\n", |
487 EC_ERR("Failed to validate product code of slave %i.\n", |
485 slave->ring_position); |
488 slave->ring_position); |
486 fsm->master_state = ec_fsm_master_start; |
489 fsm->master_state = ec_fsm_master_start; |
487 fsm->master_state(fsm); // execute immediately |
490 fsm->master_state(fsm); // execute immediately |
488 return; |
491 return; |
645 if (master->mode == EC_MASTER_MODE_RUNNING) |
648 if (master->mode == EC_MASTER_MODE_RUNNING) |
646 slave->requested_state = EC_SLAVE_STATE_PREOP; |
649 slave->requested_state = EC_SLAVE_STATE_PREOP; |
647 else |
650 else |
648 slave->requested_state = EC_SLAVE_STATE_INIT; |
651 slave->requested_state = EC_SLAVE_STATE_INIT; |
649 } |
652 } |
650 slave->state_error = 0; |
653 slave->error_flag = 0; |
651 |
654 |
652 // calculate coupler-based slave address |
655 // calculate coupler-based slave address |
653 slave->coupler_index = current_coupler_index; |
656 slave->coupler_index = current_coupler_index; |
654 slave->coupler_subindex = coupler_subindex; |
657 slave->coupler_subindex = coupler_subindex; |
655 coupler_subindex++; |
658 coupler_subindex++; |
697 ec_slave_t *slave = fsm->slave; |
700 ec_slave_t *slave = fsm->slave; |
698 |
701 |
699 fsm->sii_state(fsm); // execute SII state machine |
702 fsm->sii_state(fsm); // execute SII state machine |
700 |
703 |
701 if (fsm->sii_state == ec_fsm_sii_error) { |
704 if (fsm->sii_state == ec_fsm_sii_error) { |
|
705 fsm->slave->error_flag = 1; |
702 EC_ERR("Failed to write EEPROM contents to slave %i.\n", |
706 EC_ERR("Failed to write EEPROM contents to slave %i.\n", |
703 slave->ring_position); |
707 slave->ring_position); |
704 kfree(slave->new_eeprom_data); |
708 kfree(slave->new_eeprom_data); |
705 slave->new_eeprom_data = NULL; |
709 slave->new_eeprom_data = NULL; |
706 fsm->master_state = ec_fsm_master_start; |
710 fsm->master_state = ec_fsm_master_start; |
783 { |
787 { |
784 ec_command_t *command = &fsm->command; |
788 ec_command_t *command = &fsm->command; |
785 ec_slave_t *slave = fsm->slave; |
789 ec_slave_t *slave = fsm->slave; |
786 |
790 |
787 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
791 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
|
792 fsm->slave->error_flag = 1; |
788 EC_ERR("FSM failed to read AL status of slave %i.\n", |
793 EC_ERR("FSM failed to read AL status of slave %i.\n", |
789 fsm->slave->ring_position); |
794 fsm->slave->ring_position); |
790 fsm->slave_state = ec_fsm_slave_end; |
795 fsm->slave_state = ec_fsm_slave_end; |
791 return; |
796 return; |
792 } |
797 } |
814 { |
819 { |
815 ec_command_t *command = &fsm->command; |
820 ec_command_t *command = &fsm->command; |
816 ec_slave_t *slave = fsm->slave; |
821 ec_slave_t *slave = fsm->slave; |
817 |
822 |
818 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
823 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
|
824 fsm->slave->error_flag = 1; |
819 EC_ERR("FSM failed to read base data of slave %i.\n", |
825 EC_ERR("FSM failed to read base data of slave %i.\n", |
820 slave->ring_position); |
826 slave->ring_position); |
821 fsm->slave_state = ec_fsm_slave_end; |
827 fsm->slave_state = ec_fsm_slave_end; |
822 return; |
828 return; |
823 } |
829 } |
850 ec_slave_t *slave = fsm->slave; |
856 ec_slave_t *slave = fsm->slave; |
851 uint16_t dl_status; |
857 uint16_t dl_status; |
852 unsigned int i; |
858 unsigned int i; |
853 |
859 |
854 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
860 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
|
861 fsm->slave->error_flag = 1; |
855 EC_ERR("FSM failed to read DL status of slave %i.\n", |
862 EC_ERR("FSM failed to read DL status of slave %i.\n", |
856 slave->ring_position); |
863 slave->ring_position); |
857 fsm->slave_state = ec_fsm_slave_end; |
864 fsm->slave_state = ec_fsm_slave_end; |
858 return; |
865 return; |
859 } |
866 } |
887 |
894 |
888 // execute SII state machine |
895 // execute SII state machine |
889 fsm->sii_state(fsm); |
896 fsm->sii_state(fsm); |
890 |
897 |
891 if (fsm->sii_state == ec_fsm_sii_error) { |
898 if (fsm->sii_state == ec_fsm_sii_error) { |
|
899 fsm->slave->error_flag = 1; |
892 fsm->slave_state = ec_fsm_slave_end; |
900 fsm->slave_state = ec_fsm_slave_end; |
893 EC_ERR("Failed to read EEPROM size of slave %i.\n", |
901 EC_ERR("Failed to read EEPROM size of slave %i.\n", |
894 slave->ring_position); |
902 slave->ring_position); |
895 return; |
903 return; |
896 } |
904 } |
915 kfree(slave->eeprom_data); |
923 kfree(slave->eeprom_data); |
916 } |
924 } |
917 |
925 |
918 if (!(slave->eeprom_data = |
926 if (!(slave->eeprom_data = |
919 (uint8_t *) kmalloc(slave->eeprom_size, GFP_ATOMIC))) { |
927 (uint8_t *) kmalloc(slave->eeprom_size, GFP_ATOMIC))) { |
|
928 fsm->slave->error_flag = 1; |
920 EC_ERR("Failed to allocate EEPROM data on slave %i.\n", |
929 EC_ERR("Failed to allocate EEPROM data on slave %i.\n", |
921 slave->ring_position); |
930 slave->ring_position); |
922 fsm->slave_state = ec_fsm_slave_end; |
931 fsm->slave_state = ec_fsm_slave_end; |
923 return; |
932 return; |
924 } |
933 } |
945 |
954 |
946 // execute SII state machine |
955 // execute SII state machine |
947 fsm->sii_state(fsm); |
956 fsm->sii_state(fsm); |
948 |
957 |
949 if (fsm->sii_state == ec_fsm_sii_error) { |
958 if (fsm->sii_state == ec_fsm_sii_error) { |
|
959 fsm->slave->error_flag = 1; |
950 fsm->slave_state = ec_fsm_slave_end; |
960 fsm->slave_state = ec_fsm_slave_end; |
951 EC_ERR("Failed to fetch EEPROM contents of slave %i.\n", |
961 EC_ERR("Failed to fetch EEPROM contents of slave %i.\n", |
952 slave->ring_position); |
962 slave->ring_position); |
953 return; |
963 return; |
954 } |
964 } |
1052 ec_command_t *command = &fsm->command; |
1063 ec_command_t *command = &fsm->command; |
1053 |
1064 |
1054 fsm->change_state(fsm); // execute state change state machine |
1065 fsm->change_state(fsm); // execute state change state machine |
1055 |
1066 |
1056 if (fsm->change_state == ec_fsm_change_error) { |
1067 if (fsm->change_state == ec_fsm_change_error) { |
|
1068 slave->error_flag = 1; |
1057 fsm->slave_state = ec_fsm_slave_end; |
1069 fsm->slave_state = ec_fsm_slave_end; |
1058 return; |
1070 return; |
1059 } |
1071 } |
1060 |
1072 |
1061 if (fsm->change_state != ec_fsm_change_end) return; |
1073 if (fsm->change_state != ec_fsm_change_end) return; |
1104 ec_eeprom_sync_t *eeprom_sync, mbox_sync; |
1116 ec_eeprom_sync_t *eeprom_sync, mbox_sync; |
1105 |
1117 |
1106 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1118 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1107 EC_ERR("Failed to reset FMMUs of slave %i.\n", |
1119 EC_ERR("Failed to reset FMMUs of slave %i.\n", |
1108 slave->ring_position); |
1120 slave->ring_position); |
1109 slave->state_error = 1; |
1121 slave->error_flag = 1; |
1110 fsm->slave_state = ec_fsm_slave_end; |
1122 fsm->slave_state = ec_fsm_slave_end; |
1111 return; |
1123 return; |
1112 } |
1124 } |
1113 |
1125 |
1114 if (!slave->base_sync_count) { // no sync managers |
1126 if (!slave->base_sync_count) { // no sync managers |
1136 // does it supply sync manager configurations in its EEPROM? |
1148 // does it supply sync manager configurations in its EEPROM? |
1137 if (!list_empty(&slave->eeprom_syncs)) { |
1149 if (!list_empty(&slave->eeprom_syncs)) { |
1138 list_for_each_entry(eeprom_sync, &slave->eeprom_syncs, list) { |
1150 list_for_each_entry(eeprom_sync, &slave->eeprom_syncs, list) { |
1139 if (eeprom_sync->index >= slave->base_sync_count) { |
1151 if (eeprom_sync->index >= slave->base_sync_count) { |
1140 EC_ERR("Invalid sync manager configuration found!"); |
1152 EC_ERR("Invalid sync manager configuration found!"); |
|
1153 fsm->slave->error_flag = 1; |
1141 fsm->slave_state = ec_fsm_slave_end; |
1154 fsm->slave_state = ec_fsm_slave_end; |
1142 return; |
1155 return; |
1143 } |
1156 } |
1144 ec_eeprom_sync_config(eeprom_sync, |
1157 ec_eeprom_sync_config(eeprom_sync, |
1145 command->data + EC_SYNC_SIZE |
1158 command->data + EC_SYNC_SIZE |
1186 ec_slave_t *slave = fsm->slave; |
1199 ec_slave_t *slave = fsm->slave; |
1187 |
1200 |
1188 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1201 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1189 EC_ERR("Failed to set sync managers on slave %i.\n", |
1202 EC_ERR("Failed to set sync managers on slave %i.\n", |
1190 slave->ring_position); |
1203 slave->ring_position); |
1191 slave->state_error = 1; |
1204 slave->error_flag = 1; |
1192 fsm->slave_state = ec_fsm_slave_end; |
1205 fsm->slave_state = ec_fsm_slave_end; |
1193 return; |
1206 return; |
1194 } |
1207 } |
1195 |
1208 |
1196 fsm->change_new = EC_SLAVE_STATE_PREOP; |
1209 fsm->change_new = EC_SLAVE_STATE_PREOP; |
1266 |
1280 |
1267 if (fsm->slave->base_fmmu_count && (command->state != EC_CMD_RECEIVED || |
1281 if (fsm->slave->base_fmmu_count && (command->state != EC_CMD_RECEIVED || |
1268 command->working_counter != 1)) { |
1282 command->working_counter != 1)) { |
1269 EC_ERR("FSM failed to set FMMUs on slave %i.\n", |
1283 EC_ERR("FSM failed to set FMMUs on slave %i.\n", |
1270 fsm->slave->ring_position); |
1284 fsm->slave->ring_position); |
1271 fsm->slave->state_error = 1; |
1285 fsm->slave->error_flag = 1; |
1272 fsm->slave_state = ec_fsm_slave_end; |
1286 fsm->slave_state = ec_fsm_slave_end; |
1273 return; |
1287 return; |
1274 } |
1288 } |
1275 |
1289 |
1276 // set state to SAVEOP |
1290 // set state to SAVEOP |
1290 void ec_fsm_slave_op(ec_fsm_t *fsm /**< finite state machine */) |
1304 void ec_fsm_slave_op(ec_fsm_t *fsm /**< finite state machine */) |
1291 { |
1305 { |
1292 fsm->change_state(fsm); // execute state change state machine |
1306 fsm->change_state(fsm); // execute state change state machine |
1293 |
1307 |
1294 if (fsm->change_state == ec_fsm_change_error) { |
1308 if (fsm->change_state == ec_fsm_change_error) { |
|
1309 fsm->slave->error_flag = 1; |
1295 fsm->slave_state = ec_fsm_slave_end; |
1310 fsm->slave_state = ec_fsm_slave_end; |
1296 return; |
1311 return; |
1297 } |
1312 } |
1298 |
1313 |
1299 if (fsm->change_state != ec_fsm_change_end) return; |
1314 if (fsm->change_state != ec_fsm_change_end) return; |
1321 void ec_fsm_slave_op2(ec_fsm_t *fsm /**< finite state machine */) |
1336 void ec_fsm_slave_op2(ec_fsm_t *fsm /**< finite state machine */) |
1322 { |
1337 { |
1323 fsm->change_state(fsm); // execute state change state machine |
1338 fsm->change_state(fsm); // execute state change state machine |
1324 |
1339 |
1325 if (fsm->change_state == ec_fsm_change_error) { |
1340 if (fsm->change_state == ec_fsm_change_error) { |
|
1341 fsm->slave->error_flag = 1; |
1326 fsm->slave_state = ec_fsm_slave_end; |
1342 fsm->slave_state = ec_fsm_slave_end; |
1327 return; |
1343 return; |
1328 } |
1344 } |
1329 |
1345 |
1330 if (fsm->change_state != ec_fsm_change_end) return; |
1346 if (fsm->change_state != ec_fsm_change_end) return; |
1593 ec_slave_t *slave = fsm->slave; |
1609 ec_slave_t *slave = fsm->slave; |
1594 |
1610 |
1595 if (command->state != EC_CMD_RECEIVED) { |
1611 if (command->state != EC_CMD_RECEIVED) { |
1596 EC_ERR("Failed to send state command to slave %i!\n", |
1612 EC_ERR("Failed to send state command to slave %i!\n", |
1597 fsm->slave->ring_position); |
1613 fsm->slave->ring_position); |
1598 slave->state_error = 1; |
|
1599 fsm->change_state = ec_fsm_change_error; |
1614 fsm->change_state = ec_fsm_change_error; |
1600 return; |
1615 return; |
1601 } |
1616 } |
1602 |
1617 |
1603 if (command->working_counter != 1) { |
1618 if (command->working_counter != 1) { |
1604 EC_ERR("Failed to set state 0x%02X on slave %i: Slave did not" |
1619 EC_ERR("Failed to set state 0x%02X on slave %i: Slave did not" |
1605 " respond.\n", fsm->change_new, fsm->slave->ring_position); |
1620 " respond.\n", fsm->change_new, fsm->slave->ring_position); |
1606 slave->state_error = 1; |
|
1607 fsm->change_state = ec_fsm_change_error; |
1621 fsm->change_state = ec_fsm_change_error; |
1608 return; |
1622 return; |
1609 } |
1623 } |
1610 |
1624 |
1611 fsm->change_start = get_cycles(); |
1625 fsm->change_start = get_cycles(); |
1628 ec_slave_t *slave = fsm->slave; |
1642 ec_slave_t *slave = fsm->slave; |
1629 |
1643 |
1630 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1644 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1631 EC_ERR("Failed to check state 0x%02X on slave %i.\n", |
1645 EC_ERR("Failed to check state 0x%02X on slave %i.\n", |
1632 fsm->change_new, slave->ring_position); |
1646 fsm->change_new, slave->ring_position); |
1633 slave->state_error = 1; |
|
1634 fsm->change_state = ec_fsm_change_error; |
1647 fsm->change_state = ec_fsm_change_error; |
1635 return; |
1648 return; |
1636 } |
1649 } |
1637 |
1650 |
1638 slave->current_state = EC_READ_U8(command->data); |
1651 slave->current_state = EC_READ_U8(command->data); |
1656 return; |
1669 return; |
1657 } |
1670 } |
1658 |
1671 |
1659 if (get_cycles() - fsm->change_start >= (cycles_t) 10 * cpu_khz) { |
1672 if (get_cycles() - fsm->change_start >= (cycles_t) 10 * cpu_khz) { |
1660 // timeout while checking |
1673 // timeout while checking |
1661 slave->state_error = 1; |
|
1662 fsm->change_state = ec_fsm_change_error; |
1674 fsm->change_state = ec_fsm_change_error; |
1663 EC_ERR("Timeout while setting state 0x%02X on slave %i.\n", |
1675 EC_ERR("Timeout while setting state 0x%02X on slave %i.\n", |
1664 fsm->change_new, slave->ring_position); |
1676 fsm->change_new, slave->ring_position); |
1665 return; |
1677 return; |
1666 } |
1678 } |
1709 uint32_t code; |
1721 uint32_t code; |
1710 const ec_code_msg_t *al_msg; |
1722 const ec_code_msg_t *al_msg; |
1711 |
1723 |
1712 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1724 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1713 EC_ERR("Reception of AL status code command failed.\n"); |
1725 EC_ERR("Reception of AL status code command failed.\n"); |
1714 slave->state_error = 1; |
|
1715 fsm->change_state = ec_fsm_change_error; |
1726 fsm->change_state = ec_fsm_change_error; |
1716 return; |
1727 return; |
1717 } |
1728 } |
1718 |
1729 |
1719 if ((code = EC_READ_U16(command->data))) { |
1730 if ((code = EC_READ_U16(command->data))) { |
1745 ec_command_t *command = &fsm->command; |
1756 ec_command_t *command = &fsm->command; |
1746 ec_slave_t *slave = fsm->slave; |
1757 ec_slave_t *slave = fsm->slave; |
1747 |
1758 |
1748 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1759 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1749 EC_ERR("Reception of state ack command failed.\n"); |
1760 EC_ERR("Reception of state ack command failed.\n"); |
1750 slave->state_error = 1; |
|
1751 fsm->change_state = ec_fsm_change_error; |
1761 fsm->change_state = ec_fsm_change_error; |
1752 return; |
1762 return; |
1753 } |
1763 } |
1754 |
1764 |
1755 // read new AL status |
1765 // read new AL status |
1770 ec_command_t *command = &fsm->command; |
1780 ec_command_t *command = &fsm->command; |
1771 ec_slave_t *slave = fsm->slave; |
1781 ec_slave_t *slave = fsm->slave; |
1772 |
1782 |
1773 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1783 if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) { |
1774 EC_ERR("Reception of state ack check command failed.\n"); |
1784 EC_ERR("Reception of state ack check command failed.\n"); |
1775 slave->state_error = 1; |
|
1776 fsm->change_state = ec_fsm_change_error; |
1785 fsm->change_state = ec_fsm_change_error; |
1777 return; |
1786 return; |
1778 } |
1787 } |
1779 |
1788 |
1780 slave->current_state = EC_READ_U8(command->data); |
1789 slave->current_state = EC_READ_U8(command->data); |
1781 |
1790 |
1782 if (slave->current_state == fsm->change_new) { |
1791 if (slave->current_state == fsm->change_new) { |
1783 EC_INFO("Acknowleged state 0x%02X on slave %i.\n", |
1792 EC_INFO("Acknowleged state 0x%02X on slave %i.\n", |
1784 slave->current_state, slave->ring_position); |
1793 slave->current_state, slave->ring_position); |
1785 slave->state_error = 1; |
|
1786 fsm->change_state = ec_fsm_change_error; |
1794 fsm->change_state = ec_fsm_change_error; |
1787 return; |
1795 return; |
1788 } |
1796 } |
1789 |
1797 |
1790 EC_WARN("Failed to acknowledge state 0x%02X on slave %i" |
1798 EC_WARN("Failed to acknowledge state 0x%02X on slave %i" |
1791 " - Timeout!\n", fsm->change_new, slave->ring_position); |
1799 " - Timeout!\n", fsm->change_new, slave->ring_position); |
1792 slave->state_error = 1; |
|
1793 fsm->change_state = ec_fsm_change_error; |
1800 fsm->change_state = ec_fsm_change_error; |
1794 } |
1801 } |
1795 |
1802 |
1796 /*****************************************************************************/ |
1803 /*****************************************************************************/ |
1797 |
1804 |