master/fsm.c
branchstable-1.0
changeset 1623 05622513f627
parent 1621 4bbe090553f7
child 1624 9dc190591c0f
--- a/master/fsm.c	Mon Jun 26 15:35:23 2006 +0000
+++ b/master/fsm.c	Mon Jun 26 16:07:07 2006 +0000
@@ -44,10 +44,6 @@
 
 /*****************************************************************************/
 
-const ec_code_msg_t al_status_messages[];
-
-/*****************************************************************************/
-
 void ec_fsm_master_start(ec_fsm_t *);
 void ec_fsm_master_broadcast(ec_fsm_t *);
 void ec_fsm_master_proc_states(ec_fsm_t *);
@@ -1675,123 +1671,6 @@
 /*****************************************************************************/
 
 /**
-   Change state: CODE.
-*/
-
-void ec_fsm_change_code(ec_fsm_t *fsm /**< finite state machine */)
-{
-    ec_command_t *command = &fsm->command;
-    ec_slave_t *slave = fsm->slave;
-    uint32_t code;
-    const ec_code_msg_t *al_msg;
-
-    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
-        EC_ERR("Reception of AL status code command failed.\n");
-        slave->state_error = 1;
-        fsm->change_state = ec_fsm_change_error;
-        return;
-    }
-
-    if ((code = EC_READ_U16(command->data))) {
-        for (al_msg = al_status_messages; al_msg->code; al_msg++) {
-            if (al_msg->code != code) continue;
-            EC_ERR("AL status message 0x%04X: \"%s\".\n",
-                   al_msg->code, al_msg->message);
-            break;
-        }
-        if (!al_msg->code)
-            EC_ERR("Unknown AL status code 0x%04X.\n", code);
-    }
-
-    // acknowledge "old" slave state
-    ec_command_npwr(command, slave->station_address, 0x0120, 2);
-    EC_WRITE_U16(command->data, slave->current_state);
-    ec_master_queue_command(fsm->master, command);
-    fsm->change_state = ec_fsm_change_ack;
-}
-
-/*****************************************************************************/
-
-/**
-   Change state: ACK.
-*/
-
-void ec_fsm_change_ack(ec_fsm_t *fsm /**< finite state machine */)
-{
-    ec_command_t *command = &fsm->command;
-    ec_slave_t *slave = fsm->slave;
-
-    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
-        EC_ERR("Reception of state ack command failed.\n");
-        slave->state_error = 1;
-        fsm->change_state = ec_fsm_change_error;
-        return;
-    }
-
-    // read new AL status
-    ec_command_nprd(command, slave->station_address, 0x0130, 2);
-    ec_master_queue_command(fsm->master, command);
-    fsm->change_state = ec_fsm_change_ack2;
-}
-
-/*****************************************************************************/
-
-/**
-   Change state: ACK.
-   Acknowledge 2.
-*/
-
-void ec_fsm_change_ack2(ec_fsm_t *fsm /**< finite state machine */)
-{
-    ec_command_t *command = &fsm->command;
-    ec_slave_t *slave = fsm->slave;
-
-    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
-        EC_ERR("Reception of state ack check command failed.\n");
-        slave->state_error = 1;
-        fsm->change_state = ec_fsm_change_error;
-        return;
-    }
-
-    slave->current_state = EC_READ_U8(command->data);
-
-    if (slave->current_state == fsm->change_new) {
-        EC_INFO("Acknowleged state 0x%02X on slave %i.\n",
-                slave->current_state, slave->ring_position);
-        slave->state_error = 1;
-        fsm->change_state = ec_fsm_change_error;
-        return;
-    }
-
-    EC_WARN("Failed to acknowledge state 0x%02X on slave %i"
-            " - Timeout!\n", fsm->change_new, slave->ring_position);
-    slave->state_error = 1;
-    fsm->change_state = ec_fsm_change_error;
-}
-
-/*****************************************************************************/
-
-/**
-   Change state: END.
-*/
-
-void ec_fsm_change_end(ec_fsm_t *fsm /**< finite state machine */)
-{
-}
-
-/*****************************************************************************/
-
-/**
-   Change state: ERROR.
-*/
-
-void ec_fsm_change_error(ec_fsm_t *fsm /**< finite state machine */)
-{
-}
-
-/*****************************************************************************/
-
-/**
    Application layer status messages.
 */
 
@@ -1816,3 +1695,120 @@
 };
 
 /*****************************************************************************/
+
+/**
+   Change state: CODE.
+*/
+
+void ec_fsm_change_code(ec_fsm_t *fsm /**< finite state machine */)
+{
+    ec_command_t *command = &fsm->command;
+    ec_slave_t *slave = fsm->slave;
+    uint32_t code;
+    const ec_code_msg_t *al_msg;
+
+    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
+        EC_ERR("Reception of AL status code command failed.\n");
+        slave->state_error = 1;
+        fsm->change_state = ec_fsm_change_error;
+        return;
+    }
+
+    if ((code = EC_READ_U16(command->data))) {
+        for (al_msg = al_status_messages; al_msg->code; al_msg++) {
+            if (al_msg->code != code) continue;
+            EC_ERR("AL status message 0x%04X: \"%s\".\n",
+                   al_msg->code, al_msg->message);
+            break;
+        }
+        if (!al_msg->code)
+            EC_ERR("Unknown AL status code 0x%04X.\n", code);
+    }
+
+    // acknowledge "old" slave state
+    ec_command_npwr(command, slave->station_address, 0x0120, 2);
+    EC_WRITE_U16(command->data, slave->current_state);
+    ec_master_queue_command(fsm->master, command);
+    fsm->change_state = ec_fsm_change_ack;
+}
+
+/*****************************************************************************/
+
+/**
+   Change state: ACK.
+*/
+
+void ec_fsm_change_ack(ec_fsm_t *fsm /**< finite state machine */)
+{
+    ec_command_t *command = &fsm->command;
+    ec_slave_t *slave = fsm->slave;
+
+    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
+        EC_ERR("Reception of state ack command failed.\n");
+        slave->state_error = 1;
+        fsm->change_state = ec_fsm_change_error;
+        return;
+    }
+
+    // read new AL status
+    ec_command_nprd(command, slave->station_address, 0x0130, 2);
+    ec_master_queue_command(fsm->master, command);
+    fsm->change_state = ec_fsm_change_ack2;
+}
+
+/*****************************************************************************/
+
+/**
+   Change state: ACK.
+   Acknowledge 2.
+*/
+
+void ec_fsm_change_ack2(ec_fsm_t *fsm /**< finite state machine */)
+{
+    ec_command_t *command = &fsm->command;
+    ec_slave_t *slave = fsm->slave;
+
+    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
+        EC_ERR("Reception of state ack check command failed.\n");
+        slave->state_error = 1;
+        fsm->change_state = ec_fsm_change_error;
+        return;
+    }
+
+    slave->current_state = EC_READ_U8(command->data);
+
+    if (slave->current_state == fsm->change_new) {
+        EC_INFO("Acknowleged state 0x%02X on slave %i.\n",
+                slave->current_state, slave->ring_position);
+        slave->state_error = 1;
+        fsm->change_state = ec_fsm_change_error;
+        return;
+    }
+
+    EC_WARN("Failed to acknowledge state 0x%02X on slave %i"
+            " - Timeout!\n", fsm->change_new, slave->ring_position);
+    slave->state_error = 1;
+    fsm->change_state = ec_fsm_change_error;
+}
+
+/*****************************************************************************/
+
+/**
+   Change state: END.
+*/
+
+void ec_fsm_change_end(ec_fsm_t *fsm /**< finite state machine */)
+{
+}
+
+/*****************************************************************************/
+
+/**
+   Change state: ERROR.
+*/
+
+void ec_fsm_change_error(ec_fsm_t *fsm /**< finite state machine */)
+{
+}
+
+/*****************************************************************************/