Read SDO entry access rights.
authorFlorian Pose <fp@igh-essen.com>
Wed, 08 Apr 2009 08:13:33 +0000
changeset 1382 cb2188d111f3
parent 1381 f592fe7e799d
child 1383 0c88c50c31e3
Read SDO entry access rights.
NEWS
master/cdev.c
master/fsm_coe.c
master/globals.h
master/ioctl.h
master/sdo_entry.c
master/sdo_entry.h
tool/CommandSdos.cpp
--- a/NEWS	Tue Apr 07 12:53:37 2009 +0000
+++ b/NEWS	Wed Apr 08 08:13:33 2009 +0000
@@ -27,6 +27,7 @@
 * Going to the Bootstrap state is now supported by the state machines and the
   command-line tool.
 * Introduced ecrt_master_slave() to get information about a certain slave.
+* SDO entry access rights are shown in 'ethercat sdos'.
 
 Changes in 1.4.0:
 
--- a/master/cdev.c	Tue Apr 07 12:53:37 2009 +0000
+++ b/master/cdev.c	Wed Apr 08 08:13:33 2009 +0000
@@ -720,6 +720,18 @@
 
     data.data_type = entry->data_type;
     data.bit_length = entry->bit_length;
+    data.read_access[EC_SDO_ENTRY_ACCESS_PREOP] =
+        entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP];
+    data.read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
+        entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP];
+    data.read_access[EC_SDO_ENTRY_ACCESS_OP] =
+        entry->read_access[EC_SDO_ENTRY_ACCESS_OP];
+    data.write_access[EC_SDO_ENTRY_ACCESS_PREOP] =
+        entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP];
+    data.write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
+        entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP];
+    data.write_access[EC_SDO_ENTRY_ACCESS_OP] =
+        entry->write_access[EC_SDO_ENTRY_ACCESS_OP];
     ec_cdev_strcpy(data.description, entry->description);
 
     up(&master->master_sem);
--- a/master/fsm_coe.c	Tue Apr 07 12:53:37 2009 +0000
+++ b/master/fsm_coe.c	Wed Apr 08 08:13:33 2009 +0000
@@ -773,7 +773,7 @@
     EC_WRITE_U16(data + 4, 0x0000);
     EC_WRITE_U16(data + 6, sdo->index); // SDO index
     EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex
-    EC_WRITE_U8 (data + 9, 0x00); // value info (no values)
+    EC_WRITE_U8 (data + 9, 0x01); // value info (access rights only)
 
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_coe_dict_entry_request;
@@ -886,6 +886,7 @@
     uint8_t *data, mbox_prot;
     size_t rec_size, data_size;
     ec_sdo_entry_t *entry;
+    u16 word;
 
     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
         return; // FIXME: request again?
@@ -987,6 +988,15 @@
     entry->data_type = EC_READ_U16(data + 10);
     entry->bit_length = EC_READ_U16(data + 12);
 
+    // read access rights
+    word = EC_READ_U16(data + 14);
+    entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = word & 0x0001;
+    entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 1)  & 0x0001;
+    entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 2)  & 0x0001;
+    entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = (word >> 3) & 0x0001;
+    entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 4)  & 0x0001;
+    entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 5)  & 0x0001;
+
     if (data_size) {
         uint8_t *desc;
         if (!(desc = kmalloc(data_size + 1, GFP_KERNEL))) {
--- a/master/globals.h	Tue Apr 07 12:53:37 2009 +0000
+++ b/master/globals.h	Wed Apr 08 08:13:33 2009 +0000
@@ -174,6 +174,17 @@
                port 0 receive time. */
 } ec_slave_dc_range_t;
 
+/** Access states for SDO entries.
+ *
+ * The access rights are managed per AL state.
+ */
+enum {
+    EC_SDO_ENTRY_ACCESS_PREOP, /**< Access rights in PREOP. */
+    EC_SDO_ENTRY_ACCESS_SAFEOP, /**< Access rights in SAFEOP. */
+    EC_SDO_ENTRY_ACCESS_OP, /**< Access rights in OP. */
+    EC_SDO_ENTRY_ACCESS_COUNT /**< Number of states. */
+};
+
 /*****************************************************************************/
 
 /** Convenience macro for printing EtherCAT-specific information to syslog.
--- a/master/ioctl.h	Tue Apr 07 12:53:37 2009 +0000
+++ b/master/ioctl.h	Wed Apr 08 08:13:33 2009 +0000
@@ -288,6 +288,8 @@
     // outputs
     uint16_t data_type;
     uint16_t bit_length;
+    uint8_t read_access[EC_SDO_ENTRY_ACCESS_COUNT];
+    uint8_t write_access[EC_SDO_ENTRY_ACCESS_COUNT];
     int8_t description[EC_IOCTL_STRING_SIZE];
 } ec_ioctl_slave_sdo_entry_t;
 
--- a/master/sdo_entry.c	Tue Apr 07 12:53:37 2009 +0000
+++ b/master/sdo_entry.c	Wed Apr 08 08:13:33 2009 +0000
@@ -52,6 +52,12 @@
     entry->subindex = subindex;
     entry->data_type = 0x0000;
     entry->bit_length = 0;
+    entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = 0;
+    entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = 0;
+    entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = 0;
+    entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = 0;
+    entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = 0;
+    entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = 0;
     entry->description = NULL;
 }
 
--- a/master/sdo_entry.h	Tue Apr 07 12:53:37 2009 +0000
+++ b/master/sdo_entry.h	Wed Apr 08 08:13:33 2009 +0000
@@ -57,6 +57,8 @@
     uint8_t subindex; /**< Subindex. */
     uint16_t data_type; /**< Data type. */
     uint16_t bit_length; /**< Data size in bit. */
+    uint8_t read_access[EC_SDO_ENTRY_ACCESS_COUNT]; /**< Read access. */
+    uint8_t write_access[EC_SDO_ENTRY_ACCESS_COUNT]; /**< Write access. */
     char *description; /**< Description. */
 } ec_sdo_entry_t;
 
--- a/tool/CommandSdos.cpp	Tue Apr 07 12:53:37 2009 +0000
+++ b/tool/CommandSdos.cpp	Wed Apr 08 08:13:33 2009 +0000
@@ -58,11 +58,18 @@
     	<< "   SDO 0x1018, \"Identity object\"" << endl
     	<< endl
     	<< "2) SDO entries - SDO index and SDO entry subindex (both" << endl
-		<< "   hexadecimal) followed by the data type, the length in" << endl
-		<< "   bit, and the description. Example:" << endl
+		<< "   hexadecimal) followed by the access rights (see" << endl
+        << "   below), the data type, the length in bit, and the" << endl
+        << "   description. Example:" << endl
     	<< endl
-    	<< "   0x1018:01, uint32, 32 bit, \"Vendor id\"" << endl
+    	<< "   0x1018:01, rwrwrw, uint32, 32 bit, \"Vendor id\"" << endl
     	<< endl
+        << "The access rights are specified for the AL states PREOP," << endl
+        << "SAFEOP and OP. An 'r' means, that the entry is readable" << endl
+        << "in the corresponding state, an 'w' means writable," << endl
+        << "respectively. If a right is not granted, a dash '-' is" << endl
+        << "shown." << endl
+        << endl
     	<< "If the --quiet option is given, only the SDOs are output."
 		<< endl << endl
     	<< "Command-specific options:" << endl
@@ -133,6 +140,13 @@
             cout << "  0x" << hex << setfill('0')
                 << setw(4) << sdo.sdo_index << ":"
                 << setw(2) << (unsigned int) entry.sdo_entry_subindex
+                << ", "
+                << (entry.read_access[EC_SDO_ENTRY_ACCESS_PREOP] ? "r" : "-")
+                << (entry.write_access[EC_SDO_ENTRY_ACCESS_PREOP] ? "w" : "-")
+                << (entry.read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] ? "r" : "-")
+                << (entry.write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] ? "w" : "-")
+                << (entry.read_access[EC_SDO_ENTRY_ACCESS_OP] ? "r" : "-")
+                << (entry.write_access[EC_SDO_ENTRY_ACCESS_OP] ? "w" : "-")
                 << ", ";
 
             if ((d = findDataType(entry.data_type))) {