From 2001a7886f0bd3f2ebd1a755591a8485dd850fa1 Mon Sep 17 00:00:00 2001
From: Florian Pose <fp@igh-essen.com>
Date: Fri, 22 Feb 2008 18:25:44 +0000
Subject: [PATCH] CoE state machines raising error, if the slave does not
 support CoE.

---
 master/fsm_coe.c | 18 ++++++++++++++++++
 master/fsm_coe.h |  9 +++------
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/master/fsm_coe.c b/master/fsm_coe.c
index 29392947..e9e30eea 100644
--- a/master/fsm_coe.c
+++ b/master/fsm_coe.c
@@ -249,6 +249,12 @@ void ec_fsm_coe_dict_start(ec_fsm_coe_t *fsm /**< finite state machine */)
     ec_slave_t *slave = fsm->slave;
     uint8_t *data;
 
+    if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)) {
+        EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
+        fsm->state = ec_fsm_coe_error;
+        return;
+    }
+
     if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) {
         fsm->state = ec_fsm_coe_error;
         return;
@@ -955,6 +961,12 @@ void ec_fsm_coe_down_start(ec_fsm_coe_t *fsm /**< finite state machine */)
         EC_DBG("Downloading Sdo 0x%04X:%i to slave %i.\n",
                sdodata->index, sdodata->subindex, slave->ring_position);
 
+    if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)) {
+        EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
+        fsm->state = ec_fsm_coe_error;
+        return;
+    }
+
     if (slave->sii_rx_mailbox_size < 6 + 10 + sdodata->size) {
         EC_ERR("Sdo fragmenting not supported yet!\n");
         fsm->state = ec_fsm_coe_error;
@@ -1170,6 +1182,12 @@ void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */)
         EC_DBG("Uploading Sdo 0x%04X:%i from slave %i.\n",
                entry->sdo->index, entry->subindex, slave->ring_position);
 
+    if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)) {
+        EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
+        fsm->state = ec_fsm_coe_error;
+        return;
+    }
+
     if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) {
         fsm->state = ec_fsm_coe_error;
         return;
diff --git a/master/fsm_coe.h b/master/fsm_coe.h
index fafa241c..3b776cba 100644
--- a/master/fsm_coe.h
+++ b/master/fsm_coe.h
@@ -51,12 +51,9 @@
 
 typedef struct ec_fsm_coe ec_fsm_coe_t; /**< \see ec_fsm_coe */
 
-/**
-   Finite state machine of an EtherCAT master.
-*/
-
-struct ec_fsm_coe
-{
+/** Finite state machines for the CANopen-over-EtherCAT protocol.
+ */
+struct ec_fsm_coe {
     ec_slave_t *slave; /**< slave the FSM runs on */
     ec_datagram_t *datagram; /**< datagram used in the state machine */
     unsigned int retries; /**< retries upon datagram timeout */
-- 
GitLab