Read current AL status of slaves while scanning bus.
authorFlorian Pose <fp@igh-essen.com>
Fri, 19 May 2006 14:05:58 +0000
changeset 255 6b916cce7f27
parent 254 986afccca9ea
child 256 dc71aee17f8a
Read current AL status of slaves while scanning bus.
master/fsm.c
--- a/master/fsm.c	Fri May 19 13:58:15 2006 +0000
+++ b/master/fsm.c	Fri May 19 14:05:58 2006 +0000
@@ -58,6 +58,7 @@
 void ec_fsm_master_conf(ec_fsm_t *);
 
 void ec_fsm_slave_start_reading(ec_fsm_t *);
+void ec_fsm_slave_read_status(ec_fsm_t *);
 void ec_fsm_slave_read_base(ec_fsm_t *);
 void ec_fsm_slave_read_dl(ec_fsm_t *);
 void ec_fsm_slave_prepare_sii(ec_fsm_t *);
@@ -425,16 +426,16 @@
     ec_command_apwr(command, fsm->slave->ring_position, 0x0010, 2);
     EC_WRITE_U16(command->data, fsm->slave->station_address);
     ec_master_queue_command(fsm->master, command);
-    fsm->slave_state = ec_fsm_slave_read_base;
-}
-
-/*****************************************************************************/
-
-/**
-   Slave state: Read base.
-*/
-
-void ec_fsm_slave_read_base(ec_fsm_t *fsm)
+    fsm->slave_state = ec_fsm_slave_read_status;
+}
+
+/*****************************************************************************/
+
+/**
+   Slave state: Read status.
+*/
+
+void ec_fsm_slave_read_status(ec_fsm_t *fsm)
 {
     ec_command_t *command = &fsm->command;
 
@@ -445,6 +446,37 @@
         return;
     }
 
+    // read AL status
+    ec_command_nprd(command, fsm->slave->station_address, 0x0130, 2);
+    ec_master_queue_command(fsm->master, command);
+    fsm->slave_state = ec_fsm_slave_read_base;
+}
+
+/*****************************************************************************/
+
+/**
+   Slave state: Read base.
+*/
+
+void ec_fsm_slave_read_base(ec_fsm_t *fsm)
+{
+    ec_command_t *command = &fsm->command;
+    ec_slave_t *slave = fsm->slave;
+
+    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
+        EC_ERR("FSM failed to read AL status of slave %i.\n",
+               fsm->slave->ring_position);
+        fsm->slave_state = ec_fsm_slave_end;
+        return;
+    }
+
+    slave->current_state = EC_READ_U8(command->data);
+    if (slave->current_state & EC_ACK) {
+        EC_WARN("Slave %i has status error bit set (0x%02X)!\n",
+                slave->ring_position, slave->current_state);
+        slave->current_state &= 0x0F;
+    }
+
     // read base data
     ec_command_nprd(command, fsm->slave->station_address, 0x0000, 6);
     ec_master_queue_command(fsm->master, command);