715 |
715 |
716 /*****************************************************************************/ |
716 /*****************************************************************************/ |
717 |
717 |
718 /** |
718 /** |
719 Bestätigt einen Fehler beim Zustandswechsel. |
719 Bestätigt einen Fehler beim Zustandswechsel. |
720 |
|
721 \todo Funktioniert noch nicht... |
|
722 */ |
720 */ |
723 |
721 |
724 void ec_slave_state_ack(ec_slave_t *slave, |
722 void ec_slave_state_ack(ec_slave_t *slave, |
725 /**< Slave, dessen Zustand geändert werden soll */ |
723 /**< Slave, dessen Zustand geändert werden soll */ |
726 uint8_t state |
724 uint8_t state |
733 command = &slave->master->simple_command; |
731 command = &slave->master->simple_command; |
734 |
732 |
735 if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return; |
733 if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return; |
736 EC_WRITE_U16(command->data, state | EC_ACK); |
734 EC_WRITE_U16(command->data, state | EC_ACK); |
737 if (unlikely(ec_master_simple_io(slave->master, command))) { |
735 if (unlikely(ec_master_simple_io(slave->master, command))) { |
738 EC_WARN("State %02X acknowledge failed on slave %i!\n", |
736 EC_WARN("Acknowledge sending failed on slave %i!\n", |
739 state, slave->ring_position); |
737 slave->ring_position); |
740 return; |
738 return; |
741 } |
739 } |
742 |
740 |
743 start = get_cycles(); |
741 start = get_cycles(); |
744 timeout = (cycles_t) 10 * cpu_khz; // 10ms |
742 timeout = (cycles_t) 10 * cpu_khz; // 10ms |
748 udelay(100); // Dem Slave etwas Zeit lassen... |
746 udelay(100); // Dem Slave etwas Zeit lassen... |
749 |
747 |
750 if (ec_command_nprd(command, slave->station_address, 0x0130, 2)) |
748 if (ec_command_nprd(command, slave->station_address, 0x0130, 2)) |
751 return; |
749 return; |
752 if (unlikely(ec_master_simple_io(slave->master, command))) { |
750 if (unlikely(ec_master_simple_io(slave->master, command))) { |
753 EC_WARN("State %02X acknowledge checking failed on slave %i!\n", |
751 EC_WARN("Acknowledge checking failed on slave %i!\n", |
754 state, slave->ring_position); |
|
755 return; |
|
756 } |
|
757 |
|
758 end = get_cycles(); |
|
759 |
|
760 if (unlikely(EC_READ_U8(command->data) != state)) { |
|
761 EC_WARN("Could not acknowledge state %02X on slave %i (code" |
|
762 " %02X)!\n", state, slave->ring_position, |
|
763 EC_READ_U8(command->data)); |
|
764 return; |
|
765 } |
|
766 |
|
767 if (likely(EC_READ_U8(command->data) == state)) { |
|
768 EC_INFO("Acknowleged state %02X on slave %i.\n", state, |
|
769 slave->ring_position); |
752 slave->ring_position); |
770 return; |
753 return; |
771 } |
754 } |
772 |
755 |
|
756 end = get_cycles(); |
|
757 |
|
758 if (likely(EC_READ_U8(command->data) == state)) { |
|
759 EC_INFO("Acknowleged state 0x%02X on slave %i.\n", state, |
|
760 slave->ring_position); |
|
761 return; |
|
762 } |
|
763 |
773 if (unlikely((end - start) >= timeout)) { |
764 if (unlikely((end - start) >= timeout)) { |
774 EC_WARN("Could not check state acknowledgement %02X of slave %i -" |
765 EC_WARN("Failed to check state acknowledgement 0x%02X on slave %i" |
775 " Timeout while checking!\n", state, slave->ring_position); |
766 " - Timeout!\n", state,slave->ring_position); |
776 return; |
767 return; |
777 } |
768 } |
778 } |
769 } |
779 } |
770 } |
780 |
771 |