52 void ec_fsm_master_state_acknowledge(ec_fsm_master_t *); |
54 void ec_fsm_master_state_acknowledge(ec_fsm_master_t *); |
53 void ec_fsm_master_state_validate_vendor(ec_fsm_master_t *); |
55 void ec_fsm_master_state_validate_vendor(ec_fsm_master_t *); |
54 void ec_fsm_master_state_validate_product(ec_fsm_master_t *); |
56 void ec_fsm_master_state_validate_product(ec_fsm_master_t *); |
55 void ec_fsm_master_state_rewrite_addresses(ec_fsm_master_t *); |
57 void ec_fsm_master_state_rewrite_addresses(ec_fsm_master_t *); |
56 void ec_fsm_master_state_configure_slave(ec_fsm_master_t *); |
58 void ec_fsm_master_state_configure_slave(ec_fsm_master_t *); |
|
59 void ec_fsm_master_state_clear_addresses(ec_fsm_master_t *); |
57 void ec_fsm_master_state_scan_slaves(ec_fsm_master_t *); |
60 void ec_fsm_master_state_scan_slaves(ec_fsm_master_t *); |
58 void ec_fsm_master_state_write_eeprom(ec_fsm_master_t *); |
61 void ec_fsm_master_state_write_eeprom(ec_fsm_master_t *); |
59 void ec_fsm_master_state_sdodict(ec_fsm_master_t *); |
62 void ec_fsm_master_state_sdodict(ec_fsm_master_t *); |
60 void ec_fsm_master_state_sdo_request(ec_fsm_master_t *); |
63 void ec_fsm_master_state_sdo_request(ec_fsm_master_t *); |
61 void ec_fsm_master_state_end(ec_fsm_master_t *); |
64 void ec_fsm_master_state_end(ec_fsm_master_t *); |
236 fsm->topology_change_pending = 0; |
239 fsm->topology_change_pending = 0; |
237 fsm->tainted = 0; |
240 fsm->tainted = 0; |
238 fsm->idle = 0; |
241 fsm->idle = 0; |
239 fsm->scan_jiffies = jiffies; |
242 fsm->scan_jiffies = jiffies; |
240 |
243 |
|
244 #ifdef EC_EOE |
241 ec_master_eoe_stop(master); |
245 ec_master_eoe_stop(master); |
242 ec_master_clear_eoe_handlers(master); |
246 ec_master_clear_eoe_handlers(master); |
|
247 #endif |
243 ec_master_destroy_slaves(master); |
248 ec_master_destroy_slaves(master); |
244 |
249 |
245 master->slave_count = datagram->working_counter; |
250 master->slave_count = datagram->working_counter; |
246 |
251 |
247 if (!master->slave_count) { |
252 if (!master->slave_count) { |
274 } |
279 } |
275 |
280 |
276 list_add_tail(&slave->list, &master->slaves); |
281 list_add_tail(&slave->list, &master->slaves); |
277 } |
282 } |
278 |
283 |
279 EC_INFO("Scanning bus.\n"); |
284 if (master->debug_level) |
280 |
285 EC_DBG("Clearing station addresses...\n"); |
281 // begin scanning of slaves |
286 |
282 fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
287 ec_datagram_bwr(datagram, 0x0010, 2); |
283 fsm->state = ec_fsm_master_state_scan_slaves; |
288 EC_WRITE_U16(datagram->data, 0x0000); |
284 ec_fsm_slave_start_scan(&fsm->fsm_slave, fsm->slave); |
289 fsm->retries = EC_FSM_RETRIES; |
285 ec_fsm_slave_exec(&fsm->fsm_slave); // execute immediately |
290 fsm->state = ec_fsm_master_state_clear_addresses; |
286 return; |
291 return; |
287 } |
292 } |
288 } |
293 } |
289 |
294 |
290 // fetch state from each slave |
295 // fetch state from each slave |
585 if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
590 if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
586 return; |
591 return; |
587 |
592 |
588 if (datagram->state != EC_DATAGRAM_RECEIVED) { |
593 if (datagram->state != EC_DATAGRAM_RECEIVED) { |
589 EC_ERR("Failed to receive AL state datagram for slave %i" |
594 EC_ERR("Failed to receive AL state datagram for slave %i" |
590 " (datagram state %i)\n", slave->ring_position, datagram->state); |
595 " (datagram state %i)\n", |
|
596 slave->ring_position, datagram->state); |
591 fsm->state = ec_fsm_master_state_error; |
597 fsm->state = ec_fsm_master_state_error; |
592 return; |
598 return; |
593 } |
599 } |
594 |
600 |
595 // did the slave not respond to its station address? |
601 // did the slave not respond to its station address? |
596 if (datagram->working_counter != 1) { |
602 if (datagram->working_counter == 0) { |
597 ec_slave_set_online_state(slave, EC_SLAVE_OFFLINE); |
603 ec_slave_set_online_state(slave, EC_SLAVE_OFFLINE); |
598 ec_fsm_master_action_next_slave_state(fsm); |
604 ec_fsm_master_action_next_slave_state(fsm); |
599 return; |
605 return; |
600 } |
606 } |
|
607 |
|
608 // FIXME what to to on multiple response? |
601 |
609 |
602 // slave responded |
610 // slave responded |
603 ec_slave_set_state(slave, EC_READ_U8(datagram->data)); // set app state first |
611 ec_slave_set_state(slave, EC_READ_U8(datagram->data)); // set app state first |
604 ec_slave_set_online_state(slave, EC_SLAVE_ONLINE); |
612 ec_slave_set_online_state(slave, EC_SLAVE_ONLINE); |
605 |
613 |
772 fsm->state = ec_fsm_master_state_error; |
780 fsm->state = ec_fsm_master_state_error; |
773 return; |
781 return; |
774 } |
782 } |
775 |
783 |
776 if (datagram->working_counter != 1) { |
784 if (datagram->working_counter != 1) { |
777 EC_ERR("Failed to write station address - slave %i did not respond.\n", |
785 EC_ERR("Failed to write station address of slave %i: ", |
778 slave->ring_position); |
786 slave->ring_position); |
|
787 ec_datagram_print_wc_error(datagram); |
779 fsm->state = ec_fsm_master_state_error; |
788 fsm->state = ec_fsm_master_state_error; |
780 return; |
789 return; |
781 } |
790 } |
782 |
791 |
783 if (fsm->slave->list.next == &fsm->master->slaves) { // last slave? |
792 if (fsm->slave->list.next == &fsm->master->slaves) { // last slave? |
792 } |
801 } |
793 |
802 |
794 /*****************************************************************************/ |
803 /*****************************************************************************/ |
795 |
804 |
796 /** |
805 /** |
|
806 * Master state: CLEAR ADDRESSES. |
|
807 */ |
|
808 |
|
809 void ec_fsm_master_state_clear_addresses( |
|
810 ec_fsm_master_t *fsm /**< master state machine */ |
|
811 ) |
|
812 { |
|
813 ec_master_t *master = fsm->master; |
|
814 ec_datagram_t *datagram = fsm->datagram; |
|
815 |
|
816 if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
|
817 return; |
|
818 |
|
819 if (datagram->state != EC_DATAGRAM_RECEIVED) { |
|
820 EC_ERR("Failed to receive address clearing datagram (state %i).\n", |
|
821 datagram->state); |
|
822 fsm->state = ec_fsm_master_state_error; |
|
823 return; |
|
824 } |
|
825 |
|
826 if (datagram->working_counter != master->slave_count) { |
|
827 EC_WARN("Failed to clear all station addresses: Cleared %u of %u", |
|
828 datagram->working_counter, master->slave_count); |
|
829 } |
|
830 |
|
831 EC_INFO("Scanning bus.\n"); |
|
832 |
|
833 // begin scanning of slaves |
|
834 fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
|
835 fsm->state = ec_fsm_master_state_scan_slaves; |
|
836 ec_fsm_slave_start_scan(&fsm->fsm_slave, fsm->slave); |
|
837 ec_fsm_slave_exec(&fsm->fsm_slave); // execute immediately |
|
838 } |
|
839 |
|
840 /*****************************************************************************/ |
|
841 |
|
842 /** |
797 * Master state: SCAN SLAVES. |
843 * Master state: SCAN SLAVES. |
798 * Executes the sub-statemachine for the scanning of a slave. |
844 * Executes the sub-statemachine for the scanning of a slave. |
799 */ |
845 */ |
800 |
846 |
801 void ec_fsm_master_state_scan_slaves( |
847 void ec_fsm_master_state_scan_slaves( |
806 ec_slave_t *slave = fsm->slave; |
852 ec_slave_t *slave = fsm->slave; |
807 |
853 |
808 if (ec_fsm_slave_exec(&fsm->fsm_slave)) // execute slave state machine |
854 if (ec_fsm_slave_exec(&fsm->fsm_slave)) // execute slave state machine |
809 return; |
855 return; |
810 |
856 |
|
857 #ifdef EC_EOE |
811 if (slave->sii_mailbox_protocols & EC_MBOX_EOE) { |
858 if (slave->sii_mailbox_protocols & EC_MBOX_EOE) { |
812 // create EoE handler for this slave |
859 // create EoE handler for this slave |
813 ec_eoe_t *eoe; |
860 ec_eoe_t *eoe; |
814 if (!(eoe = kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) { |
861 if (!(eoe = kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) { |
815 EC_ERR("Failed to allocate EoE handler memory for slave %u!\n", |
862 EC_ERR("Failed to allocate EoE handler memory for slave %u!\n", |
822 } |
869 } |
823 else { |
870 else { |
824 list_add_tail(&eoe->list, &master->eoe_handlers); |
871 list_add_tail(&eoe->list, &master->eoe_handlers); |
825 } |
872 } |
826 } |
873 } |
|
874 #endif |
827 |
875 |
828 // another slave to fetch? |
876 // another slave to fetch? |
829 if (slave->list.next != &master->slaves) { |
877 if (slave->list.next != &master->slaves) { |
830 fsm->slave = list_entry(slave->list.next, ec_slave_t, list); |
878 fsm->slave = list_entry(slave->list.next, ec_slave_t, list); |
831 ec_fsm_slave_start_scan(&fsm->fsm_slave, fsm->slave); |
879 ec_fsm_slave_start_scan(&fsm->fsm_slave, fsm->slave); |
834 } |
882 } |
835 |
883 |
836 EC_INFO("Bus scanning completed in %u ms.\n", |
884 EC_INFO("Bus scanning completed in %u ms.\n", |
837 (u32) (jiffies - fsm->scan_jiffies) * 1000 / HZ); |
885 (u32) (jiffies - fsm->scan_jiffies) * 1000 / HZ); |
838 |
886 |
|
887 #ifdef EC_EOE |
839 // check if EoE processing has to be started |
888 // check if EoE processing has to be started |
840 ec_master_eoe_start(master); |
889 ec_master_eoe_start(master); |
|
890 #endif |
841 |
891 |
842 master->scan_state = EC_REQUEST_COMPLETE; |
892 master->scan_state = EC_REQUEST_COMPLETE; |
843 wake_up_interruptible(&master->scan_queue); |
893 wake_up_interruptible(&master->scan_queue); |
844 |
894 |
845 fsm->state = ec_fsm_master_state_end; |
895 fsm->state = ec_fsm_master_state_end; |