From e59e94114aba85e9a2c4ea9d5235f3b2597fc0f8 Mon Sep 17 00:00:00 2001
From: wierenga <sdos@astron.nl>
Date: Fri, 7 Jul 2006 15:55:56 +0000
Subject: [PATCH] BugID: 778 Improved initialisation sequence by keeping tight
 tab on initialisation states. Still not working properly, is the firmware at
 fault?

---
 MAC/APL/PIC/RSPDriver/src/BSWrite.cc          |  15 ++-
 MAC/APL/PIC/RSPDriver/src/BSWrite.h           |   1 -
 MAC/APL/PIC/RSPDriver/src/InitState.cc        | 120 ++++++++++++++++++
 MAC/APL/PIC/RSPDriver/src/InitState.h         | 103 +++++++++++++++
 MAC/APL/PIC/RSPDriver/src/Makefile.am         |   2 +
 MAC/APL/PIC/RSPDriver/src/RSUWrite.cc         |  30 +++--
 MAC/APL/PIC/RSPDriver/src/RSUWrite.h          |   6 +-
 .../PIC/RSPDriver/src/RemoteStation.conf.in   |   2 +-
 MAC/APL/PIC/RSPDriver/src/SyncAction.cc       |  20 ++-
 MAC/APL/PIC/RSPDriver/src/SyncAction.h        |  11 ++
 MAC/APL/PIC/RSPDriver/src/TDSProtocolWrite.cc |  10 ++
 MAC/APL/PIC/RSPDriver/src/TDSResultRead.cc    |  39 ++----
 MAC/APL/PIC/RSPDriver/src/TDSResultRead.h     |   1 -
 13 files changed, 302 insertions(+), 58 deletions(-)
 create mode 100644 MAC/APL/PIC/RSPDriver/src/InitState.cc
 create mode 100644 MAC/APL/PIC/RSPDriver/src/InitState.h

diff --git a/MAC/APL/PIC/RSPDriver/src/BSWrite.cc b/MAC/APL/PIC/RSPDriver/src/BSWrite.cc
index 346009459da..2871027689b 100644
--- a/MAC/APL/PIC/RSPDriver/src/BSWrite.cc
+++ b/MAC/APL/PIC/RSPDriver/src/BSWrite.cc
@@ -30,6 +30,7 @@
 #include "StationSettings.h"
 #include "BSWrite.h"
 #include "Cache.h"
+#include "InitState.h"
 
 // nof seconds to wait with next action in init sequence
 #define DELAY_NEXT ((long)0)
@@ -38,13 +39,15 @@ using namespace LOFAR;
 using namespace RSP;
 using namespace EPA_Protocol;
 using namespace RTC;
+using namespace blitz;
 
 BSWrite::BSWrite(GCFPortInterface& board_port, int board_id, int blp, const Scheduler& scheduler)
   : SyncAction(board_port, board_id, 1), m_blp(blp), m_scheduler(scheduler)
 {
-  m_mark.resize(StationSettings::instance()->nrRspBoards());
-  m_mark = Timestamp(0,0);
   memset(&m_hdr, 0, sizeof(MEPHeader));
+
+  // this action should be performed at initialisation
+  doAtInit();
 }
 
 BSWrite::~BSWrite()
@@ -54,14 +57,12 @@ BSWrite::~BSWrite()
 
 void BSWrite::sendrequest()
 {
+  if (InitState::instance().getState() == InitState::WRITE_RCUENABLE) {
 
-  // force read/write if DELAY_NEXT seconds after time mark
-  if (m_mark(getBoardId()) != Timestamp(0,0) && (m_mark(getBoardId()) + DELAY_NEXT <= m_scheduler.getCurrentTime())) {
-    
     Cache::getInstance().reset(); // reset all cache values to default
     Cache::getInstance().getState().force(); // force read/write of all register after clear
 
-    m_mark(getBoardId()) = Timestamp(0,0); // reset mark
+    InitState::instance().setRCUEnableDone((getBoardId() * StationSettings::instance()->nrBlpsPerBoard()) + m_blp);
   }
 
   // skip update if the neither of the RCU's settings have been modified
@@ -111,7 +112,7 @@ GCFEvent::TResult BSWrite::handleack(GCFEvent& event, GCFPortInterface& /*port*/
   // change state to indicate that it has been applied in the hardware
   Cache::getInstance().getState().bs().write_ack((getBoardId() * StationSettings::instance()->nrBlpsPerBoard()) + m_blp);
 
-  m_mark(getBoardId()) = m_scheduler.getCurrentTime();
+  InitState::instance().setBSDone((getBoardId() * StationSettings::instance()->nrBlpsPerBoard()) + m_blp);
 
   return GCFEvent::HANDLED;
 }
diff --git a/MAC/APL/PIC/RSPDriver/src/BSWrite.h b/MAC/APL/PIC/RSPDriver/src/BSWrite.h
index 4b42fcca789..cdc0547c8e0 100644
--- a/MAC/APL/PIC/RSPDriver/src/BSWrite.h
+++ b/MAC/APL/PIC/RSPDriver/src/BSWrite.h
@@ -63,7 +63,6 @@ namespace LOFAR {
       EPA_Protocol::MEPHeader m_hdr;
       int m_blp;
       const Scheduler&               m_scheduler; // for getCurrentTime
-      blitz::Array<RTC::Timestamp,1> m_mark;      // mark time for each board
     };
   };
 };
diff --git a/MAC/APL/PIC/RSPDriver/src/InitState.cc b/MAC/APL/PIC/RSPDriver/src/InitState.cc
new file mode 100644
index 00000000000..b0924dad375
--- /dev/null
+++ b/MAC/APL/PIC/RSPDriver/src/InitState.cc
@@ -0,0 +1,120 @@
+//#  InitState.cc: class to keep track of initialiation state
+//#  of the RSPDriver for a LOFAR station
+//#
+//#  Copyright (C) 2002-2004
+//#  ASTRON (Netherlands Foundation for Research in Astronomy)
+//#  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//#
+//#  This program is free software; you can redistribute it and/or modify
+//#  it under the terms of the GNU General Public License as published by
+//#  the Free Software Foundation; either version 2 of the License, or
+//#  (at your option) any later version.
+//#
+//#  This program is distributed in the hope that it will be useful,
+//#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//#  GNU General Public License for more details.
+//#
+//#  You should have received a copy of the GNU General Public License
+//#  along with this program; if not, write to the Free Software
+//#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//#
+//#  $Id$
+
+#include <lofar_config.h>
+#include <Common/LofarLogger.h>
+
+#include "InitState.h"
+#include "StationSettings.h"
+#include <blitz/array.h>
+
+using namespace LOFAR;
+using namespace RSP;
+using namespace blitz;
+
+/*
+ * Instance pointer for the InitState singleton class.
+ */
+InitState* InitState::m_instance = 0;
+
+InitState::~InitState()
+{
+}
+
+InitState& InitState::instance()
+{
+  if (0 == m_instance) {
+    m_instance = new InitState();
+  }
+   
+  return *m_instance;
+}
+
+InitState::InitState()
+{
+  m_tds_done.resize(StationSettings::instance()->nrRspBoards());
+  m_rsu_done.resize(StationSettings::instance()->nrRspBoards());
+  m_bs_done.resize(StationSettings::instance()->nrBlps());
+  m_rcuenable_done.resize(StationSettings::instance()->nrBlps());
+
+  init();
+}
+
+void InitState::init(CurrentState state)
+{
+  m_tds_done       = false;
+  m_rsu_done       = false;
+  m_bs_done        = false;
+  m_rcuenable_done = false;
+  m_state          = state;
+}
+
+void InitState::setTDSDone(int boardid, bool value)
+{
+  ASSERT(boardid >= 0 && boardid < StationSettings::instance()->nrRspBoards());
+  m_tds_done(boardid) = value;
+  if (isTDSDone()) m_state = WRITE_RSU;
+}
+
+void InitState::setRSUDone(int boardid, bool value)
+{
+  ASSERT(boardid >= 0 && boardid < StationSettings::instance()->nrRspBoards());
+  m_rsu_done(boardid) = value;
+  if (isRSUDone()) m_state = WRITE_BS;
+}
+
+void InitState::setBSDone(int blpid, bool value)
+{
+  ASSERT(blpid >= 0 && blpid < StationSettings::instance()->nrBlps());
+  m_bs_done(blpid) = value;
+  if (isBSDone()) m_state = WRITE_RCUENABLE;
+}
+
+void InitState::setRCUEnableDone(int blpid, bool value)
+{
+  ASSERT(blpid >= 0 && blpid < StationSettings::instance()->nrBlps());
+  m_rcuenable_done(blpid) = value;
+  if (isRCUEnableDone()) {
+    init();
+  }
+}
+
+bool InitState::isTDSDone() const
+{
+  return (m_state == WRITE_TDS) && (sum(where(m_tds_done == true, 1, 0)) == StationSettings::instance()->nrRspBoards());
+}
+
+bool InitState::isRSUDone() const
+{
+  return (m_state == WRITE_RSU) && (sum(where(m_rsu_done == true, 1, 0)) == StationSettings::instance()->nrRspBoards());
+}
+
+bool InitState::isBSDone() const
+{
+  return (m_state == WRITE_BS) && (sum(where(m_bs_done == true, 1, 0)) == StationSettings::instance()->nrBlps());
+}
+
+bool InitState::isRCUEnableDone() const
+{
+  return (m_state == WRITE_RCUENABLE) && (sum(where(m_rcuenable_done == true, 1, 0)) == StationSettings::instance()->nrBlps());
+}
diff --git a/MAC/APL/PIC/RSPDriver/src/InitState.h b/MAC/APL/PIC/RSPDriver/src/InitState.h
new file mode 100644
index 00000000000..e34d33259cf
--- /dev/null
+++ b/MAC/APL/PIC/RSPDriver/src/InitState.h
@@ -0,0 +1,103 @@
+//#  -*- mode: c++ -*-
+//#
+//#  InitState.h: class to control initialization of all RSP boards
+//#
+//#  Copyright (C) 2002-2004
+//#  ASTRON (Netherlands Foundation for Research in Astronomy)
+//#  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//#
+//#  This program is free software; you can redistribute it and/or modify
+//#  it under the terms of the GNU General Public License as published by
+//#  the Free Software Foundation; either version 2 of the License, or
+//#  (at your option) any later version.
+//#
+//#  This program is distributed in the hope that it will be useful,
+//#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//#  GNU General Public License for more details.
+//#
+//#  You should have received a copy of the GNU General Public License
+//#  along with this program; if not, write to the Free Software
+//#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//#
+//#  $Id$
+
+#ifndef INITSTATE_H_
+#define INITSTATE_H_
+
+#include <blitz/array.h>
+
+namespace LOFAR {
+  namespace RSP {
+
+    /**
+     * Singleton class to control station initialization
+     */
+    class InitState
+    {
+    public:
+
+      typedef enum {
+	INIT = 0,
+	WRITE_TDS,
+	WRITE_RSU,
+	WRITE_BS,
+	WRITE_RCUENABLE,
+      } CurrentState;
+
+      /*@{*/
+      /**
+       * Constructor/destructor
+       */
+      static InitState& instance();
+      virtual ~InitState();
+      /*@}*/
+
+      void init(CurrentState state = INIT); // initialise the class
+
+      /*
+       * Get state.
+       */
+      CurrentState getState() const { return m_state; }
+
+      void setTDSDone(int boardid, bool value = true);
+      void setRSUDone(int boardid, bool value = true);
+      void setBSDone(int blpid, bool value = true);
+      void setRCUEnableDone(int blpid, bool value = true);
+
+      bool isTDSDone() const;
+      bool isRSUDone() const;
+      bool isBSDone() const;
+      bool isRCUEnableDone() const;
+
+    private:
+
+      /**
+       * Direct construction not allowed.
+       */
+      InitState();
+
+      /*
+       * The current state we're in
+       */
+      CurrentState m_state;
+
+
+      /*
+       * Keep tab on each RSPBoard whether
+       * initialization has completed.
+       */
+      blitz::Array<bool, 1> m_tds_done;
+      blitz::Array<bool, 1> m_rsu_done;
+      blitz::Array<bool, 1> m_bs_done;
+      blitz::Array<bool, 1> m_rcuenable_done;
+
+      /**
+       * Singleton class.
+       */
+      static InitState* m_instance;
+    };
+  };
+};
+     
+#endif /* INITSTATE_H_ */
diff --git a/MAC/APL/PIC/RSPDriver/src/Makefile.am b/MAC/APL/PIC/RSPDriver/src/Makefile.am
index d39424ee354..4949aa6505f 100644
--- a/MAC/APL/PIC/RSPDriver/src/Makefile.am
+++ b/MAC/APL/PIC/RSPDriver/src/Makefile.am
@@ -133,6 +133,8 @@ RSPDriver_SOURCES = \
 	\
 	SyncAction.h \
 	SyncAction.cc \
+	InitState.h \
+	InitState.cc \
 	WriteReg.h \
 	WriteReg.cc \
 	ReadReg.h \
diff --git a/MAC/APL/PIC/RSPDriver/src/RSUWrite.cc b/MAC/APL/PIC/RSPDriver/src/RSUWrite.cc
index 45f9b6977c9..6dec1561d0a 100644
--- a/MAC/APL/PIC/RSPDriver/src/RSUWrite.cc
+++ b/MAC/APL/PIC/RSPDriver/src/RSUWrite.cc
@@ -34,6 +34,7 @@
 #include "StationSettings.h"
 #include "RSUWrite.h"
 #include "Cache.h"
+#include "InitState.h"
 
 // nof seconds to wait with writing BS register after RSU clear
 #define WAIT_AFTER ((long)3)
@@ -52,9 +53,11 @@ static const EPA_Protocol::RSUReset  g_RSU_RESET_NONE  = { 0, 0, 0, 0 }; // No a
 RSUWrite::RSUWrite(GCFPortInterface& board_port, int board_id, const Scheduler& scheduler)
   : SyncAction(board_port, board_id, 1), m_scheduler(scheduler)
 {
-  m_mark.resize(StationSettings::instance()->nrRspBoards());
-  m_mark = Timestamp(0,0);
   memset(&m_hdr, 0, sizeof(MEPHeader));
+  m_mark = Timestamp(0,0);
+
+  // this action should be performed at initialisation
+  doAtInit();
 }
 
 RSUWrite::~RSUWrite()
@@ -67,18 +70,17 @@ void RSUWrite::sendrequest()
   
   reset.hdr.set(MEPHeader::RSU_RESET_HDR);
 
-  // force read/write if WAIT_AFTER seconds after time mark
-  if (m_mark(getBoardId()) != Timestamp(0,0) && (m_mark(getBoardId()) + WAIT_AFTER <= m_scheduler.getCurrentTime())) {
-    
+  if (InitState::instance().getState() == InitState::WRITE_BS &&
+      m_mark != Timestamp(0,0) && m_mark + ((long)3) <= m_scheduler.getCurrentTime()) {
+
     // next write all BS registers on all AP's of this board
     for (int blp = 0; blp < StationSettings::instance()->nrBlpsPerBoard(); blp++) {
       Cache::getInstance().getState().bs().reset((getBoardId() * StationSettings::instance()->nrBlpsPerBoard()) + blp);
       Cache::getInstance().getState().bs().write_force((getBoardId() * StationSettings::instance()->nrBlpsPerBoard()) + blp);
     }
-    m_mark(getBoardId()) = Timestamp(0,0); // reset mark
   }
 
-  // cache modified?
+  // cache modified, or initialising and clock update has completed
   if (RTC::RegisterState::WRITE != Cache::getInstance().getState().rsuclear().get(getBoardId())) {
     Cache::getInstance().getState().rsuclear().unmodified(getBoardId());
 
@@ -86,6 +88,11 @@ void RSUWrite::sendrequest()
     return;
   }
 
+  if (InitState::instance().getState() == InitState::INIT) {
+    // indicate that we're initialising the hardware
+    InitState::instance().init(InitState::WRITE_RSU);
+  }
+
   // read values from cache
   RSUSettings& s = Cache::getInstance().getBack().getRSUSettings();
   if (s()(getBoardId()).getSync()) {
@@ -129,12 +136,9 @@ GCFEvent::TResult RSUWrite::handleack(GCFEvent& event, GCFPortInterface& /*port*
   }
 
   Cache::getInstance().getState().rsuclear().write_ack(getBoardId());
-  
-  // mark time if needed
-  RSUSettings& s = Cache::getInstance().getBack().getRSUSettings();
-  if (s()(getBoardId()).getClear() || s()(getBoardId()).getReset()) {
-    m_mark(getBoardId()) = m_scheduler.getCurrentTime();
-  }
+
+  InitState::instance().setRSUDone(getBoardId());
+  m_mark = m_scheduler.getCurrentTime();
 
   Cache::getInstance().getBack().getRSUSettings()()(getBoardId()).setRaw(0); // clear the flags
 
diff --git a/MAC/APL/PIC/RSPDriver/src/RSUWrite.h b/MAC/APL/PIC/RSPDriver/src/RSUWrite.h
index 7b20138ed0c..fafc3e9bcb5 100644
--- a/MAC/APL/PIC/RSPDriver/src/RSUWrite.h
+++ b/MAC/APL/PIC/RSPDriver/src/RSUWrite.h
@@ -62,9 +62,9 @@ namespace LOFAR {
       virtual GCFEvent::TResult handleack(GCFEvent& event, GCFPortInterface& port);
 
     private:
-      EPA_Protocol::MEPHeader         m_hdr;
-      const Scheduler&                m_scheduler; // for getCurrentTime
-      blitz::Array<RTC::Timestamp, 1> m_mark;      // mark time for all boards
+      EPA_Protocol::MEPHeader  m_hdr;
+      const Scheduler&         m_scheduler; // for getCurrentTime
+      RTC::Timestamp           m_mark;      // mark time
     };
   };
 };
diff --git a/MAC/APL/PIC/RSPDriver/src/RemoteStation.conf.in b/MAC/APL/PIC/RSPDriver/src/RemoteStation.conf.in
index 8f6b4be07a3..868f30bc108 100644
--- a/MAC/APL/PIC/RSPDriver/src/RemoteStation.conf.in
+++ b/MAC/APL/PIC/RSPDriver/src/RemoteStation.conf.in
@@ -5,7 +5,7 @@
 #
 # Number of RSP boards
 #
-RS.N_RSPBOARDS=1
+RS.N_RSPBOARDS=2
 
 #
 # Number of BLP's per RSP board
diff --git a/MAC/APL/PIC/RSPDriver/src/SyncAction.cc b/MAC/APL/PIC/RSPDriver/src/SyncAction.cc
index 1c5076593ee..1ff7f266a07 100644
--- a/MAC/APL/PIC/RSPDriver/src/SyncAction.cc
+++ b/MAC/APL/PIC/RSPDriver/src/SyncAction.cc
@@ -25,6 +25,8 @@
 #include <APL/RSP_Protocol/EPA_Protocol.ph>
 
 #include "SyncAction.h"
+#include "Cache.h"
+#include "InitState.h"
 
 using namespace LOFAR;
 using namespace RSP;
@@ -40,7 +42,8 @@ SyncAction::SyncAction(GCFPortInterface& board_port, int board_id, int n_indices
     m_continue(false),
     m_n_indices(n_indices),
     m_current_index(0),
-    m_retries(0)
+    m_retries(0),
+    m_atinit(false)
 {
 }
 
@@ -91,9 +94,18 @@ GCFEvent::TResult SyncAction::sendrequest_state(GCFEvent& event, GCFPortInterfac
     case F_ENTRY:
     {
       for (;;) {
-	// send initial request
-	setContinue(false); // initialize on each entry
-	sendrequest();
+
+	if (!m_atinit && (InitState::instance().getState() != InitState::INIT)) {
+
+	  // skip this action and continue with the next
+	  setContinue(true); // continue with next action
+
+	} else {
+
+	  // send initial request
+	  setContinue(false); // initialize on each entry
+	  sendrequest();
+	}
 
 	// if sendrequest calls setContinue(true), then no event
 	// has been sent, move on to next index
diff --git a/MAC/APL/PIC/RSPDriver/src/SyncAction.h b/MAC/APL/PIC/RSPDriver/src/SyncAction.h
index 091a260af91..1bd2b29a25e 100644
--- a/MAC/APL/PIC/RSPDriver/src/SyncAction.h
+++ b/MAC/APL/PIC/RSPDriver/src/SyncAction.h
@@ -91,6 +91,16 @@ namespace LOFAR {
        */
       void reset();
 
+      /*
+       * doAtInit
+       *
+       * When passed true, this action is marked as an
+       * initialization action and it is executed during
+       * the initialisation phase. If set to false this action
+       * is skipped during the initialisation phase.
+       */
+      void doAtInit(bool atinit = true) { m_atinit = atinit; }
+
     protected:
       /*@{*/
       /**
@@ -112,6 +122,7 @@ namespace LOFAR {
       int               m_n_indices;
       int               m_current_index;
       int               m_retries;
+      bool              m_atinit;
     };
   };
 };
diff --git a/MAC/APL/PIC/RSPDriver/src/TDSProtocolWrite.cc b/MAC/APL/PIC/RSPDriver/src/TDSProtocolWrite.cc
index da846dbd7e6..bbcb05b0e5e 100644
--- a/MAC/APL/PIC/RSPDriver/src/TDSProtocolWrite.cc
+++ b/MAC/APL/PIC/RSPDriver/src/TDSProtocolWrite.cc
@@ -30,6 +30,7 @@
 #include "TDSProtocolWrite.h"
 #include "TDSi2cdefs.h"
 #include "Cache.h"
+#include "InitState.h"
 
 #include <netinet/in.h>
 
@@ -121,6 +122,9 @@ TDSProtocolWrite::TDSProtocolWrite(GCFPortInterface& board_port, int board_id)
 {
   memset(&m_hdr, 0, sizeof(MEPHeader));
 
+  // this action should be performed at initialisation
+  doAtInit();
+
 #if 0
   // patch the tds_160MHz sequence and its result to check programming PLL
   for (int i = 3; i < TDS_PROGRAMPLLS_SIZE; i += 7) printf("%c", (tds_160MHz[i] & 0x80 ? '#' : '_'));
@@ -152,6 +156,11 @@ void TDSProtocolWrite::sendrequest()
     return;
   }
 
+  // indicate that we're initialising the hardware
+  if (InitState::instance().getState() == InitState::INIT) {
+    InitState::instance().init(InitState::WRITE_TDS);
+  }
+
   uint32 tds_control = 0;
   sscanf(GET_CONFIG_STRING("RSPDriver.TDS_CONTROL"), "%x", &tds_control);
 
@@ -167,6 +176,7 @@ void TDSProtocolWrite::sendrequest()
     //
     Cache::getInstance().getState().tds().write_ack(getBoardId());
     setContinue(true);
+
     return;
   }
 
diff --git a/MAC/APL/PIC/RSPDriver/src/TDSResultRead.cc b/MAC/APL/PIC/RSPDriver/src/TDSResultRead.cc
index ff569754b51..a6e3eeb836b 100644
--- a/MAC/APL/PIC/RSPDriver/src/TDSResultRead.cc
+++ b/MAC/APL/PIC/RSPDriver/src/TDSResultRead.cc
@@ -30,6 +30,7 @@
 #include "TDSResultRead.h"
 #include "TDSi2cdefs.h"
 #include "Cache.h"
+#include "InitState.h"
 #include "StationSettings.h"
 
 #include <netinet/in.h>
@@ -42,14 +43,14 @@ using namespace blitz;
 using namespace RTC;
 
 #define DELAY_NEXT ((long)0)
-/*#define TDSRESULTREAD_DELAY 2*/
 
 TDSResultRead::TDSResultRead(GCFPortInterface& board_port, int board_id, const Scheduler& scheduler)
   : SyncAction(board_port, board_id, 1), m_delay(0), m_scheduler(scheduler)
 {
-  m_mark.resize(StationSettings::instance()->nrRspBoards());
-  m_mark = Timestamp(0,0);
   memset(&m_hdr, 0, sizeof(MEPHeader));
+
+  // this action should be performed at initialisation
+  doAtInit();
 }
 
 TDSResultRead::~TDSResultRead()
@@ -59,8 +60,9 @@ TDSResultRead::~TDSResultRead()
 
 void TDSResultRead::sendrequest()
 {
-  // force read/write if WAIT_AFTER seconds after time mark
-  if (m_mark(getBoardId()) != Timestamp(0,0) && (m_mark(getBoardId()) + DELAY_NEXT <= m_scheduler.getCurrentTime())) {
+  if (InitState::instance().getState() == InitState::WRITE_RSU) {
+
+    cerr << "CLOCK CHANGE COMPLETED ON ALL BOARDS" << endl;
     
     // After changing the clock an RSP clear is required.
 
@@ -72,26 +74,16 @@ void TDSResultRead::sendrequest()
     // signal that the register has changed
     Cache::getInstance().getState().rsuclear().reset(getBoardId());
     Cache::getInstance().getState().rsuclear().write_force(getBoardId());
-
-    m_mark(getBoardId()) = Timestamp(0,0); // reset mark
   }
 
   // skip update if the Clocks settings have not been modified
   if (RTC::RegisterState::READ != Cache::getInstance().getState().tds().get(getBoardId()))
   {
+    InitState::instance().setTDSDone(getBoardId()); // mark done
     setContinue(true);
     return;
   }
 
-  /*
-  // delay TDSRESULTREAD_DELAY periods
-  if (m_delay++ < TDSRESULTREAD_DELAY) {
-    setContinue(true);
-    return;
-  }
-  m_delay = 0;
-  */
-
   EPAReadEvent tdsresult;
   tdsresult.hdr.set(MEPHeader::TDS_RESULT_HDR);
 
@@ -160,10 +152,7 @@ GCFEvent::TResult TDSResultRead::handleack(GCFEvent& event, GCFPortInterface& /*
     idiff = imemcmp(tds_160MHz_result, ack.result, sizeof(tds_160MHz_result));
     if (-1 == idiff) {
       Cache::getInstance().getState().tds().read_ack(getBoardId());
-
-      // mark completion of clock change
-      m_mark(getBoardId()) = m_scheduler.getCurrentTime();
-
+      InitState::instance().setTDSDone(getBoardId());
     } else {
       LOG_ERROR(formatString("TDSResultRead::handleack (160MHz): unexpected I2C result response, first mismatch @ %d", idiff));
 
@@ -178,10 +167,7 @@ GCFEvent::TResult TDSResultRead::handleack(GCFEvent& event, GCFPortInterface& /*
     idiff = imemcmp(tds_200MHz_result, ack.result, sizeof(tds_200MHz_result));
     if (-1 == idiff) {
       Cache::getInstance().getState().tds().read_ack(getBoardId());
-
-      // mark completion of clock change
-      m_mark(getBoardId()) = m_scheduler.getCurrentTime();
-
+      InitState::instance().setTDSDone(getBoardId());
     } else {
       LOG_ERROR(formatString("TDSResultRead::handleack (200MHz): unexpected I2C result response, first mismatch @ %d", idiff));
 
@@ -196,10 +182,7 @@ GCFEvent::TResult TDSResultRead::handleack(GCFEvent& event, GCFPortInterface& /*
     idiff = imemcmp(tds_off_result, ack.result, sizeof(tds_off_result));
     if (-1 == idiff) {
       Cache::getInstance().getState().tds().read_ack(getBoardId());
-
-      // mark completion of clock change
-      m_mark(getBoardId()) = m_scheduler.getCurrentTime();
-
+      InitState::instance().setTDSDone(getBoardId());
     } else {
       LOG_ERROR(formatString("TDSResultRead::handleack (OFF): unexpected I2C result response, first mismatch @ %d", idiff));
 
diff --git a/MAC/APL/PIC/RSPDriver/src/TDSResultRead.h b/MAC/APL/PIC/RSPDriver/src/TDSResultRead.h
index f4f3544ba60..41540c09bc0 100644
--- a/MAC/APL/PIC/RSPDriver/src/TDSResultRead.h
+++ b/MAC/APL/PIC/RSPDriver/src/TDSResultRead.h
@@ -64,7 +64,6 @@ namespace LOFAR {
       int m_delay; // used to delay reading back results
 
       const Scheduler&                m_scheduler; // for getCurrentTime
-      blitz::Array<RTC::Timestamp, 1> m_mark;      // mark time
     };
   };
 };
-- 
GitLab