Changed unit of ec_eeprom_write_request_t from word to byte.
authorFlorian Pose <fp@igh-essen.com>
Mon, 24 Sep 2007 07:54:51 +0000
changeset 754 0b47b49c5976
parent 753 7ba5f9cd8f7e
child 755 178353fc47e5
Changed unit of ec_eeprom_write_request_t from word to byte.
master/fsm_master.c
master/fsm_master.h
master/fsm_sii.c
master/fsm_sii.h
master/slave.c
--- a/master/fsm_master.c	Mon Sep 24 07:39:02 2007 +0000
+++ b/master/fsm_master.c	Mon Sep 24 07:54:51 2007 +0000
@@ -346,8 +346,8 @@
                     slave->ring_position);
         fsm->eeprom_request = request;
         fsm->eeprom_index = 0;
-        ec_fsm_sii_write(&fsm->fsm_sii, request->slave, request->offset,
-                request->words, EC_FSM_SII_NODE);
+        ec_fsm_sii_write(&fsm->fsm_sii, request->slave, request->word_offset,
+                request->data, EC_FSM_SII_NODE);
         fsm->state = ec_fsm_master_state_write_eeprom;
         fsm->state(fsm); // execute immediately
         return 1;
@@ -971,10 +971,10 @@
     }
 
     fsm->eeprom_index++;
-    if (fsm->eeprom_index < request->size) {
+    if (fsm->eeprom_index < request->word_size) {
         ec_fsm_sii_write(&fsm->fsm_sii, slave,
-                request->offset + fsm->eeprom_index,
-                request->words + fsm->eeprom_index,
+                request->word_offset + fsm->eeprom_index,
+                request->data + fsm->eeprom_index * 2,
                 EC_FSM_SII_NODE);
         ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately
         return;
@@ -983,7 +983,7 @@
     // finished writing EEPROM
     if (master->debug_level)
         EC_DBG("Finished writing %u words of EEPROM data to slave %u.\n",
-                request->size, slave->ring_position);
+                request->word_size, slave->ring_position);
     request->state = EC_REQUEST_COMPLETE;
     wake_up(&master->eeprom_queue);
 
--- a/master/fsm_master.h	Mon Sep 24 07:39:02 2007 +0000
+++ b/master/fsm_master.h	Mon Sep 24 07:54:51 2007 +0000
@@ -60,9 +60,9 @@
 {
     struct list_head list;
     ec_slave_t *slave;
-    off_t offset;
-    size_t size;
-    const uint16_t *words;
+    off_t word_offset;
+    size_t word_size;
+    const uint8_t *data;
     ec_request_state_t state;
 }
 ec_eeprom_write_request_t;
--- a/master/fsm_sii.c	Mon Sep 24 07:39:02 2007 +0000
+++ b/master/fsm_sii.c	Mon Sep 24 07:54:51 2007 +0000
@@ -105,7 +105,7 @@
 void ec_fsm_sii_write(ec_fsm_sii_t *fsm, /**< finite state machine */
                       ec_slave_t *slave, /**< slave to read from */
                       uint16_t offset, /**< offset to read from */
-                      const uint16_t *value, /**< pointer to 2 bytes of data */
+                      const uint8_t *value, /**< pointer to 2 bytes of data */
                       ec_fsm_sii_addressing_t mode /**< addressing scheme */
                       )
 {
@@ -127,7 +127,8 @@
 {
     fsm->state(fsm);
 
-    return fsm->state != ec_fsm_sii_state_end && fsm->state != ec_fsm_sii_state_error;
+    return fsm->state != ec_fsm_sii_state_end
+		&& fsm->state != ec_fsm_sii_state_error;
 }
 
 /*****************************************************************************/
@@ -143,7 +144,7 @@
 }
 
 /******************************************************************************
- *  SII state machine
+ * state functions
  *****************************************************************************/
 
 /**
@@ -151,7 +152,9 @@
    Starts reading the slave information interface.
 */
 
-void ec_fsm_sii_state_start_reading(ec_fsm_sii_t *fsm /**< finite state machine */)
+void ec_fsm_sii_state_start_reading(
+		ec_fsm_sii_t *fsm /**< finite state machine */
+		)
 {
     ec_datagram_t *datagram = fsm->datagram;
 
@@ -179,7 +182,9 @@
    Checks, if the SII-read-datagram has been sent and issues a fetch datagram.
 */
 
-void ec_fsm_sii_state_read_check(ec_fsm_sii_t *fsm /**< finite state machine */)
+void ec_fsm_sii_state_read_check(
+		ec_fsm_sii_t *fsm /**< finite state machine */
+		)
 {
     ec_datagram_t *datagram = fsm->datagram;
 
@@ -226,7 +231,9 @@
    Fetches the result of an SII-read datagram.
 */
 
-void ec_fsm_sii_state_read_fetch(ec_fsm_sii_t *fsm /**< finite state machine */)
+void ec_fsm_sii_state_read_fetch(
+		ec_fsm_sii_t *fsm /**< finite state machine */
+		)
 {
     ec_datagram_t *datagram = fsm->datagram;
 
@@ -302,7 +309,9 @@
    Starts reading the slave information interface.
 */
 
-void ec_fsm_sii_state_start_writing(ec_fsm_sii_t *fsm /**< finite state machine */)
+void ec_fsm_sii_state_start_writing(
+		ec_fsm_sii_t *fsm /**< finite state machine */
+		)
 {
     ec_datagram_t *datagram = fsm->datagram;
 
@@ -323,7 +332,9 @@
    SII state: WRITE CHECK.
 */
 
-void ec_fsm_sii_state_write_check(ec_fsm_sii_t *fsm /**< finite state machine */)
+void ec_fsm_sii_state_write_check(
+		ec_fsm_sii_t *fsm /**< finite state machine */
+		)
 {
     ec_datagram_t *datagram = fsm->datagram;
 
@@ -361,7 +372,9 @@
    SII state: WRITE CHECK 2.
 */
 
-void ec_fsm_sii_state_write_check2(ec_fsm_sii_t *fsm /**< finite state machine */)
+void ec_fsm_sii_state_write_check2(
+		ec_fsm_sii_t *fsm /**< finite state machine */
+		)
 {
     ec_datagram_t *datagram = fsm->datagram;
 
@@ -417,7 +430,9 @@
    State: ERROR.
 */
 
-void ec_fsm_sii_state_error(ec_fsm_sii_t *fsm /**< finite state machine */)
+void ec_fsm_sii_state_error(
+		ec_fsm_sii_t *fsm /**< finite state machine */
+		)
 {
 }
 
@@ -427,8 +442,10 @@
    State: END.
 */
 
-void ec_fsm_sii_state_end(ec_fsm_sii_t *fsm /**< finite state machine */)
-{
-}
-
-/*****************************************************************************/
+void ec_fsm_sii_state_end(
+		ec_fsm_sii_t *fsm /**< finite state machine */
+		)
+{
+}
+
+/*****************************************************************************/
--- a/master/fsm_sii.h	Mon Sep 24 07:39:02 2007 +0000
+++ b/master/fsm_sii.h	Mon Sep 24 07:54:51 2007 +0000
@@ -85,7 +85,7 @@
 void ec_fsm_sii_read(ec_fsm_sii_t *, ec_slave_t *,
                      uint16_t, ec_fsm_sii_addressing_t);
 void ec_fsm_sii_write(ec_fsm_sii_t *, ec_slave_t *, uint16_t,
-        const uint16_t *, ec_fsm_sii_addressing_t);
+        const uint8_t *, ec_fsm_sii_addressing_t);
 
 int ec_fsm_sii_exec(ec_fsm_sii_t *);
 int ec_fsm_sii_success(ec_fsm_sii_t *);
--- a/master/slave.c	Mon Sep 24 07:39:02 2007 +0000
+++ b/master/slave.c	Mon Sep 24 07:54:51 2007 +0000
@@ -978,11 +978,11 @@
     // init EEPROM write request
     INIT_LIST_HEAD(&request.list);
     request.slave = slave;
-    request.words = (const uint16_t *) data;
-    request.offset = 0;
-    request.size = size / 2;
-
-    if (request.size < 0x0041) {
+    request.data = data;
+    request.word_offset = 0;
+    request.word_size = size / 2;
+
+    if (request.word_size < 0x0041) {
         EC_ERR("EEPROM data too short! Dropping.\n");
         return -EINVAL;
     }
@@ -993,15 +993,18 @@
         EC_WARN("EEPROM CRC incorrect. Must be 0x%02x.\n", crc);
     }
 
-    cat_header = request.words + EC_FIRST_EEPROM_CATEGORY_OFFSET;
+    cat_header = (const uint16_t *) request.data
+		+ EC_FIRST_EEPROM_CATEGORY_OFFSET;
     cat_type = EC_READ_U16(cat_header);
     while (cat_type != 0xFFFF) { // cycle through categories
-        if (cat_header + 1 > request.words + request.size) {
+        if (cat_header + 1 >
+				(const uint16_t *) request.data + request.word_size) {
             EC_ERR("EEPROM data corrupted! Dropping.\n");
             return -EINVAL;
         }
         cat_size = EC_READ_U16(cat_header + 1);
-        if (cat_header + cat_size + 2 > request.words + request.size) {
+        if (cat_header + cat_size + 2 >
+				(const uint16_t *) request.data + request.word_size) {
             EC_ERR("EEPROM data corrupted! Dropping.\n");
             return -EINVAL;
         }
@@ -1030,9 +1033,9 @@
 {
     ec_eeprom_write_request_t request;
     char *remainder;
-    uint16_t alias, words[8];
+    uint16_t alias;
     int ret;
-    uint8_t crc;
+    uint8_t eeprom_data[16], crc;
 
     if (slave->master->mode != EC_MASTER_MODE_IDLE) { // FIXME
         EC_ERR("Writing to EEPROM is only allowed in idle mode!\n");
@@ -1052,21 +1055,21 @@
     }
 
     // copy first 7 words of recent EEPROM contents
-    memcpy(words, slave->eeprom_data, 14);
+    memcpy(eeprom_data, slave->eeprom_data, 14);
     
-    // write new alias address
-    EC_WRITE_U16(words + 4, alias);
+    // write new alias address in word 4
+    EC_WRITE_U16(eeprom_data + 8, alias);
 
     // calculate new checksum over words 0 to 6
-    crc = ec_slave_eeprom_crc((const uint8_t *) words, 14);
-    EC_WRITE_U16(words + 7, crc);
+    crc = ec_slave_eeprom_crc(eeprom_data, 14);
+    EC_WRITE_U16(eeprom_data + 14, crc);
 
     // init EEPROM write request
     INIT_LIST_HEAD(&request.list);
     request.slave = slave;
-    request.words = words;
-    request.offset = 0x0000;
-    request.size = 8;
+    request.data = eeprom_data;
+    request.word_offset = 0x0000;
+    request.word_size = 8;
 
     if ((ret = ec_slave_schedule_eeprom_writing(&request)))
         return ret; // error code