Introduced ec_datagram_zero().
authorFlorian Pose <fp@igh-essen.com>
Tue, 30 Sep 2008 07:34:55 +0000
changeset 1225 4d5b739edcb5
parent 1224 784bb76105cd
child 1226 afb189516fcf
Introduced ec_datagram_zero().
NEWS
master/datagram.c
master/datagram.h
master/domain.c
master/fsm_change.c
master/fsm_master.c
master/fsm_sii.c
master/fsm_slave_config.c
master/fsm_slave_scan.c
master/mailbox.c
--- a/NEWS	Mon Sep 29 10:17:33 2008 +0000
+++ b/NEWS	Tue Sep 30 07:34:55 2008 +0000
@@ -7,6 +7,8 @@
 Changes since 1.4.0:
 
 * Added VoE protocol support.
+* Separated datagram initialization from filling the payload with zeros.
+  Introduced new method ec_datagram_zero() for that.
 * Added phy_read and phy_write commands to ethercat tool.
 
 Changes in version 1.4.0-rc2:
--- a/master/datagram.c	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/datagram.c	Tue Sep 30 07:34:55 2008 +0000
@@ -56,7 +56,6 @@
 
 #define EC_FUNC_FOOTER \
     datagram->data_size = data_size; \
-    memset(datagram->data, 0x00, data_size); \
     return 0;
 
 /** \endcond */
@@ -161,6 +160,15 @@
 
 /*****************************************************************************/
 
+/** Fills the datagram payload memory with zeros.
+ */
+void ec_datagram_zero(ec_datagram_t *datagram /**< EtherCAT datagram. */)
+{
+    memset(datagram->data, 0x00, datagram->data_size);
+}
+
+/*****************************************************************************/
+
 /** Initializes an EtherCAT APRD datagram.
  *
  * \return 0 in case of success, else < 0
--- a/master/datagram.h	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/datagram.h	Tue Sep 30 07:34:55 2008 +0000
@@ -125,6 +125,7 @@
 void ec_datagram_init(ec_datagram_t *);
 void ec_datagram_clear(ec_datagram_t *);
 int ec_datagram_prealloc(ec_datagram_t *, size_t);
+void ec_datagram_zero(ec_datagram_t *);
 
 int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t);
 int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t);
--- a/master/domain.c	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/domain.c	Tue Sep 30 07:34:55 2008 +0000
@@ -177,6 +177,7 @@
         domain->expected_working_counter = used[EC_DIR_INPUT];
     }
 
+    ec_datagram_zero(datagram);
     list_add_tail(&datagram->list, &domain->datagrams);
     return 0;
 }
--- a/master/fsm_change.c	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/fsm_change.c	Tue Sep 30 07:34:55 2008 +0000
@@ -223,6 +223,7 @@
 
     // read AL status from slave
     ec_datagram_fprd(datagram, slave->station_address, 0x0130, 2);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
     fsm->spontaneous_change = 0;
     fsm->state = ec_fsm_change_state_status;
@@ -299,6 +300,7 @@
                req_state, slave->ring_position, cur_state);
         // fetch AL status error code
         ec_datagram_fprd(datagram, slave->station_address, 0x0134, 2);
+        ec_datagram_zero(datagram);
         fsm->retries = EC_FSM_RETRIES;
         fsm->state = ec_fsm_change_state_code;
         return;
@@ -319,6 +321,7 @@
  check_again:
     // no timeout yet. check again
     ec_datagram_fprd(datagram, slave->station_address, 0x0130, 2);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
 }
 
@@ -457,6 +460,7 @@
 
     // read new AL status
     ec_datagram_fprd(datagram, slave->station_address, 0x0130, 2);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_change_state_check_ack;
 }
@@ -525,6 +529,7 @@
 
     // reread new AL status
     ec_datagram_fprd(datagram, slave->station_address, 0x0130, 2);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
 }
 
--- a/master/fsm_master.c	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/fsm_master.c	Tue Sep 30 07:34:55 2008 +0000
@@ -165,6 +165,7 @@
 {
     fsm->idle = 1;
     ec_datagram_brd(fsm->datagram, 0x0130, 2);
+    ec_datagram_zero(fsm->datagram);
     fsm->state = ec_fsm_master_state_broadcast;
 }
 
@@ -276,6 +277,7 @@
         fsm->slave = master->slaves;
         ec_datagram_fprd(fsm->datagram, fsm->slave->station_address,
                 0x0130, 2);
+        ec_datagram_zero(datagram);
         fsm->retries = EC_FSM_RETRIES;
         fsm->state = ec_fsm_master_state_read_state;
     } else {
@@ -356,6 +358,7 @@
         if (request->dir == EC_DIR_INPUT) {
             ec_datagram_fprd(fsm->datagram, request->slave->station_address,
                     request->offset, request->length);
+            ec_datagram_zero(fsm->datagram);
         } else {
             if (request->length > fsm->datagram->mem_size) {
                 EC_ERR("Request length (%u) exceeds maximum datagram size (%u)!\n",
@@ -541,6 +544,7 @@
         fsm->idle = 1;
         ec_datagram_fprd(fsm->datagram,
                 fsm->slave->station_address, 0x0130, 2);
+        ec_datagram_zero(fsm->datagram);
         fsm->retries = EC_FSM_RETRIES;
         fsm->state = ec_fsm_master_state_read_state;
         return;
--- a/master/fsm_sii.c	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/fsm_sii.c	Tue Sep 30 07:34:55 2008 +0000
@@ -241,6 +241,7 @@
             break;
     }
 
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_sii_state_read_fetch;
 }
@@ -381,6 +382,7 @@
 
     // issue check datagram
     ec_datagram_fprd(datagram, fsm->slave->station_address, 0x502, 2);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_sii_state_write_check2;
 }
--- a/master/fsm_slave_config.c	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/fsm_slave_config.c	Tue Sep 30 07:34:55 2008 +0000
@@ -218,7 +218,7 @@
     // clear FMMU configurations
     ec_datagram_fpwr(datagram, slave->station_address,
             0x0600, EC_FMMU_PAGE_SIZE * slave->base_fmmu_count);
-    memset(datagram->data, 0x00, EC_FMMU_PAGE_SIZE * slave->base_fmmu_count);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_slave_config_state_clear_fmmus;
 }
@@ -295,8 +295,7 @@
     if (slave->sii.sync_count >= 2) { // mailbox configuration provided
         ec_datagram_fpwr(datagram, slave->station_address, 0x0800,
                 EC_SYNC_PAGE_SIZE * slave->sii.sync_count);
-        memset(datagram->data, 0x00,
-                EC_SYNC_PAGE_SIZE * slave->sii.sync_count);
+        ec_datagram_zero(datagram);
 
         for (i = 0; i < 2; i++) {
             ec_sync_page(&slave->sii.syncs[i], i,
@@ -314,7 +313,7 @@
 
         ec_datagram_fpwr(datagram, slave->station_address, 0x0800,
                 EC_SYNC_PAGE_SIZE * 2);
-        memset(datagram->data, 0x00, EC_SYNC_PAGE_SIZE * 2);
+        ec_datagram_zero(datagram);
 
         ec_sync_init(&sync, slave);
         sync.physical_start_address = slave->sii.rx_mailbox_offset;
@@ -553,7 +552,7 @@
     ec_datagram_fpwr(datagram, slave->station_address,
             0x0800 + EC_SYNC_PAGE_SIZE * offset,
             EC_SYNC_PAGE_SIZE * num_pdo_syncs);
-    memset(datagram->data, 0x00, EC_SYNC_PAGE_SIZE * num_pdo_syncs);
+    ec_datagram_zero(datagram);
 
     for (i = 0; i < num_pdo_syncs; i++) {
         sync_index = i + offset;
@@ -633,7 +632,7 @@
     // configure FMMUs
     ec_datagram_fpwr(datagram, slave->station_address,
                      0x0600, EC_FMMU_PAGE_SIZE * slave->base_fmmu_count);
-    memset(datagram->data, 0x00, EC_FMMU_PAGE_SIZE * slave->base_fmmu_count);
+    ec_datagram_zero(datagram);
     for (i = 0; i < slave->config->used_fmmus; i++) {
         fmmu = &slave->config->fmmu_configs[i];
         if (!(sync = ec_slave_get_sync(slave, fmmu->sync_index))) {
--- a/master/fsm_slave_scan.c	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/fsm_slave_scan.c	Tue Sep 30 07:34:55 2008 +0000
@@ -203,6 +203,7 @@
 
     // Read AL state
     ec_datagram_fprd(datagram, fsm->slave->station_address, 0x0130, 2);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_slave_scan_state_state;
 }
@@ -250,6 +251,7 @@
 
     // read base data
     ec_datagram_fprd(datagram, fsm->slave->station_address, 0x0000, 6);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_slave_scan_state_base;
 }
@@ -299,6 +301,7 @@
 
     // read data link status
     ec_datagram_fprd(datagram, slave->station_address, 0x0110, 2);
+    ec_datagram_zero(datagram);
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_slave_scan_state_datalink;
 }
--- a/master/mailbox.c	Mon Sep 29 10:17:33 2008 +0000
+++ b/master/mailbox.c	Tue Sep 30 07:34:55 2008 +0000
@@ -100,6 +100,7 @@
     if (ec_datagram_fprd(datagram, slave->station_address, 0x808, 8))
         return -1;
 
+    ec_datagram_zero(datagram);
     return 0;
 }
 
@@ -128,7 +129,10 @@
 {
     if (ec_datagram_fprd(datagram, slave->station_address,
                          slave->sii.tx_mailbox_offset,
-                         slave->sii.tx_mailbox_size)) return -1;
+                         slave->sii.tx_mailbox_size))
+        return -1;
+
+    ec_datagram_zero(datagram);
     return 0;
 }