commit 33f542133dd484ad1904f87d0e837020e4f31433
Author: Cung Sang <csang@techfak.uni-bielefeld.de>
Date:   Fri Feb 8 18:30:40 2019 +0100

    Moved DW1000 config struct into driver and made minor changes

diff --git a/include/DW1000/alld_DW1000.h b/include/DW1000/alld_DW1000.h
index a0e7f5a..d33b27a 100644
--- a/include/DW1000/alld_DW1000.h
+++ b/include/DW1000/alld_DW1000.h
@@ -32,8 +32,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #if (AMIROLLD_CFG_DW1000 == 1)
     #include "v1/alld_dw1000_v1.h"
-    #include "v1/alld_dw1000_regs_v1.h"
-    #include "v1/deca_instance_v1.h"
 #elif (AMIROLLD_CFG_DW1000 == 0)
     #error "DW1000 LLD implementation for v0 is not ready yet."
 #else
diff --git a/include/DW1000/v1/alld_dw1000_v1.h b/include/DW1000/v1/alld_dw1000_v1.h
index 9d17bc5..0a333b0 100755
--- a/include/DW1000/v1/alld_dw1000_v1.h
+++ b/include/DW1000/v1/alld_dw1000_v1.h
@@ -477,8 +477,8 @@ void dwt_setgpiovalue(uint32_t gpioNum, uint32_t value);
  *
  * returns DWT_SUCCESS for success, or DWT_ERROR for error
  */
-int dwt_initialise(uint16_t config) ;   // TODO
-//int dwt_initialise(uint16_t config, DW1000Driver* drv) ;
+//int dwt_initialise(uint16_t config) ;   // TODO
+int dwt_initialise(uint16_t config, DW1000Driver* drv) ;
 
 /*! ------------------------------------------------------------------------------------------------------------------
  * @fn dwt_configure()
@@ -1728,54 +1728,6 @@ void dwt_write8bitoffsetreg(int regFileID, int regOffset, uint8_t regval);
  ****************************************************************************************************************************************************/
 
 
-/*! ------------------------------------------------------------------------------------------------------------------
- * @fn writetospi()
- *
- * @brief
- * NB: In porting this to a particular microprocessor, the implementer needs to define the two low
- * level abstract functions to write to and read from the SPI.
- * Low level abstract function to write to the SPI
- * Takes two separate byte buffers for write header and write data
- * returns 0 for success, or -1 for error
- *
- * Note: The body of this function is platform specific
- *
- * input parameters:
- * @param headerLength  - number of bytes header being written
- * @param headerBuffer  - pointer to buffer containing the 'headerLength' bytes of header to be written
- * @param bodylength    - number of bytes data being written
- * @param bodyBuffer    - pointer to buffer containing the 'bodylength' bytes od data to be written
- *
- * output parameters
- *
- * returns DWT_SUCCESS for success, or DWT_ERROR for error
- */
-extern int writetospi(uint16_t headerLength, const uint8_t *headerBuffer, uint32_t bodylength, const uint8_t *bodyBuffer);
-
-/*! ------------------------------------------------------------------------------------------------------------------
- * @fn readfromspi()
- *
- * @brief
- * NB: In porting this to a particular microprocessor, the implementer needs to define the two low
- * level abstract functions to write to and read from the SPI.
- * Low level abstract function to write to the SPI
- * Takes two separate byte buffers for write header and write data
- * returns 0 for success, or -1 for error
- *
- * Note: The body of this function is platform specific
- *
- * input parameters:
- * @param headerLength  - number of bytes header to write
- * @param headerBuffer  - pointer to buffer containing the 'headerLength' bytes of header to write
- * @param readlength    - number of bytes data being read
- * @param readBuffer    - pointer to buffer containing to return the data (NB: size required = headerLength + readlength)
- *
- * output parameters
- *
- * returns DWT_SUCCESS for success (and the position in the buffer at which data begins), or DWT_ERROR for error
- */
-extern int readfromspi(uint16_t headerLength, const uint8_t *headerBuffer, uint32_t readlength, uint8_t *readBuffer);
-
 // ---------------------------------------------------------------------------
 //
 // NB: The purpose of the deca_mutex.c file is to provide for microprocessor interrupt enable/disable, this is used for
@@ -1845,7 +1797,8 @@ void Sleep(unsigned int time_ms);
 
 void port_EnableEXT_IRQ(void);
 void port_DisableEXT_IRQ(void);
-ITStatus port_GetEXT_IRQStatus(void);
+decaIrqStatus_t port_GetEXT_IRQStatus(void);
+//ITStatus port_GetEXT_IRQStatus(void);
 
 void port_set_dw1000_slowrate(void);
 void port_set_dw1000_fastrate(void);
@@ -1859,23 +1812,6 @@ uint32_t portGetTickCnt(void);
 #define DW1000_EXTI_IRQn    EXTI15_10_IRQn
 
 
-/**
- * @brief   Flag to switch between two SPI speeds on the fly
- */
-extern bool isHighSpeedSpi;
-
-
-/**
- * @brief   Configuration for the Low Speed SPI interface driver to communicate with DW1000
- */
-//extern SPIConfig moduleHalSpiUwbLsConfig;
-
-
-/**
- * @brief   Configuration for the High Speed SPI interface driver to communicate with DW1000
- */
-//extern SPIConfig moduleHalSpiUwbHsConfig;
-
 #endif /* defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1) */
 
 #endif //AMIROLLD_DW1000_V1_H
diff --git a/include/DW1000/v1/deca_instance_v1.h b/include/DW1000/v1/deca_instance_v1.h
index a861f1e..6553106 100755
--- a/include/DW1000/v1/deca_instance_v1.h
+++ b/include/DW1000/v1/deca_instance_v1.h
@@ -470,7 +470,9 @@ extern event_data_t dw_event_g;   // TODO
   void instance_close(void);
   // Call init, then call config, then call run. call close when finished
   // initialise the instance (application) structures and DW1000 device
-  int instance_init(void);
+//  int instance_init(void);
+  int instance_init(DW1000Driver* drv);     //TODO
+
   // configure the instance and DW1000 device
   void instance_config(instanceConfig_t *config, sfConfig_t *sfconfig) ;
 
@@ -528,15 +530,23 @@ extern event_data_t dw_event_g;   // TODO
   uint64_t convertmicrosectodevicetimeu (double microsecu);
   double convertdevicetimetosec(int32_t dt);
 
-#define DWT_PRF_64M_RFDLY   (514.462f)
-#define DWT_PRF_16M_RFDLY   (513.9067f)
 
-  /* Extern declaration while defining the data in .c file */
+  // -------------------------------------------------------------------------------------------------------------------
+  // Deca Calibration Values
+  // -------------------------------------------------------------------------------------------------------------------
+
+  #define DWT_PRF_64M_RFDLY   (514.462f)
+  #define DWT_PRF_16M_RFDLY   (513.9067f)
+
+  /* Extern declaration while defining them in .c file */
   extern const uint16_t rfDelays[2];
   extern const uint16_t rfDelaysTREK[2];
   extern const tx_struct txSpectrumConfig[8];
   extern instance_data_t instance_data[NUM_INST] ;
 
+  extern sfConfig_t sfConfig[4];
+  extern instanceConfig_t chConfig[4];
+
 
   int instance_peekevent(void);
 
@@ -579,6 +589,8 @@ extern event_data_t dw_event_g;   // TODO
 
   int instance_starttxtest(int framePeriod);
 
+
+
 #endif /* defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1) */
 
 #ifdef __cplusplus
diff --git a/source/DW1000/v1/alld_dw1000_v1.c b/source/DW1000/v1/alld_dw1000_v1.c
index 8accea9..70460ce 100755
--- a/source/DW1000/v1/alld_dw1000_v1.c
+++ b/source/DW1000/v1/alld_dw1000_v1.c
@@ -28,11 +28,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
 
-
 #include <alld_DW1000.h>
 
 #if (defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)) || defined(__DOXYGEN__)
 
+#include <v1/alld_dw1000_regs_v1.h>
+
 #include <aos_thread.h>
 #include <assert.h>
 #include <string.h>
@@ -40,6 +41,18 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <math.h>
 
 
+// HW dependent implementation (see bottom of file)
+static int writetospi(uint16_t headerLength,
+               const	uint8_t *headerBuffer,
+               uint32_t bodyLength,
+               const	uint8_t *bodyBuffer);
+
+static int readfromspi(uint16_t headerLength,
+                const uint8_t *headerBuffer,
+                uint32_t readlength,
+                uint8_t *readBuffer);
+
+
 // Defines for enable_clocks function
 #define FORCE_SYS_XTI  0
 #define ENABLE_ALL_SEQ 1
@@ -57,19 +70,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define FCTRL_LEN_MAX 2
 
 
-/**
- * Move to the header file <alld_dw1000_v1.h>
-*/
-//#define NUM_BR 3
-//#define NUM_PRF 2
-//#define NUM_PACS 4
-//#define NUM_BW 2            //2 bandwidths are supported
-//#define NUM_SFD 2           //supported number of SFDs - standard = 0, non-standard = 1
-//#define NUM_CH 6            //supported channels are 1, 2, 3, 4, 5, 7
-//#define NUM_CH_SUPPORTED 8  //supported channels are '0', 1, 2, 3, 4, 5, '6', 7
-//#define PCODES 25           //supported preamble codes
-
-
 typedef struct {
     uint32_t lo32;
     uint16_t target[NUM_PRF];
@@ -1013,8 +1013,8 @@ int dwt_setdevicedataptr(unsigned int index)
 #define VTEMP_ADDRESS  (0x09)
 #define XTRIM_ADDRESS  (0x1E)
 
-//int dwt_initialise(const uint16_t config, DW1000Driver* drv)
-int dwt_initialise(const uint16_t config)  // TODO:
+int dwt_initialise(const uint16_t config, DW1000Driver* drv)
+//int dwt_initialise(const uint16_t config)  // TODO:
 {
     uint16_t otp_addr = 0;
     uint32_t ldo_tune = 0;
@@ -1028,7 +1028,7 @@ int dwt_initialise(const uint16_t config)  // TODO:
     pdw1000local->cbRxTo = NULL;
     pdw1000local->cbRxErr = NULL;
 
-//    pdw1000local->driver = drv;  // TODO:
+    pdw1000local->driver = drv;  // TODO:
 
     // Read and validate device ID return -1 if not recognised
     if (DWT_DEVICE_ID != dwt_readdevid()) // MP IC ONLY (i.e. DW1000) FOR THIS CODE
@@ -1813,8 +1813,7 @@ void dwt_writetodevice
     }
 
     // Write it to the SPI
-//    _alld_dw1000_writespi(cnt,header,length,buffer);
-    writetospi(cnt,header,length,buffer);  // TODO
+    writetospi(cnt,header,length,buffer);
 } // end dwt_writetodevice()
 
 /*! ------------------------------------------------------------------------------------------------------------------
@@ -1878,8 +1877,7 @@ void dwt_readfromdevice
     }
 
     // Do the read from the SPI
-//    _alld_dw1000_readspi(cnt, header, length, buffer);  // result is stored in the buffer
-    readfromspi(cnt, header, length, buffer);  // TODO:
+    readfromspi(cnt, header, length, buffer);
 } // end dwt_readfromdevice()
 
 
@@ -4419,9 +4417,11 @@ uint16_t dwt_calcpgcount(uint8_t pgdly)
  *
  ****************************************************************************************************************************************************/
 
-/*
- * DW1000 Hardware dependent functions: SPI, EXTI
- */
+/****************************************************************************//**
+ *
+ * 	alld_dw1000.c					SPI Section
+ *
+ *******************************************************************************/
 
 /*! ------------------------------------------------------------------------------------------------------------------
  * Function: writetospi()
@@ -4431,14 +4431,12 @@ uint16_t dwt_calcpgcount(uint8_t pgdly)
  * returns 0 for success, or -1 for error
  */
 #pragma GCC optimize ("O3")
-int writetospi(uint16_t headerLength,
+static int writetospi(uint16_t headerLength,
                const	uint8_t *headerBuffer,
                uint32_t bodyLength,
                const	uint8_t *bodyBuffer)
 {
 
-    port_SPIx_clear_chip_select();
-
     uint8_t buffer[bodyLength + 3];
     memcpy(buffer, headerBuffer, headerLength); //copy data to buffer
     memcpy(&buffer[headerLength], bodyBuffer, bodyLength); //copy data to buffer
@@ -4447,13 +4445,10 @@ int writetospi(uint16_t headerLength,
                     buffer,
                     bodyLength + headerLength); // send header and data
 
-    port_SPIx_set_chip_select();
-
     return 0;
 } // end writetospi()
 
 
-
 /*! ------------------------------------------------------------------------------------------------------------------
  * Function: readfromspi()
  *
@@ -4463,13 +4458,13 @@ int writetospi(uint16_t headerLength,
  * or returns -1 if there was an error
  */
 #pragma GCC optimize ("O3")
-int readfromspi(uint16_t headerLength,
+static int readfromspi(uint16_t headerLength,
                 const uint8_t *headerBuffer,
                 uint32_t readlength,
                 uint8_t *readBuffer)
 {
 
-    apalSPITransmitAndReceive(&MODULE_HAL_SPI_UWB,
+    apalSPITransmitAndReceive(&MODULE_HAL_SPI_UWB, // TODO: "pdw1000local->driver->spid" fails two spi configs
                               headerBuffer,
                               readBuffer,
                               headerLength,
@@ -4499,14 +4494,14 @@ int readfromspi(uint16_t headerLength,
  *
  * returns the state of the DW1000 interrupt
  */
-decaIrqStatus_t decamutexon(void)           
+decaIrqStatus_t decamutexon(void)
 {
-    decaIrqStatus_t s = port_GetEXT_IRQStatus();
 
-    if(s) {
-        port_DisableEXT_IRQ(); //disable the external interrupt line
-    }
-    return s ;   // return state before disable, value is used to re-enable in decamutexoff call
+  decaIrqStatus_t s = port_GetEXT_IRQStatus();
+  if(s) {
+    port_DisableEXT_IRQ(); //disable the external interrupt line
+  }
+  return s ;   // return state before disable, value is used to re-enable in decamutexoff call
 }
 
 /*! ------------------------------------------------------------------------------------------------------------------
@@ -4526,11 +4521,11 @@ decaIrqStatus_t decamutexon(void)
  */
 void decamutexoff(decaIrqStatus_t s)
 {
-//    (void) s;
-    if(s) { //need to check the port state as we can't use level sensitive interrupt on the STM ARM
-      port_EnableEXT_IRQ();
-    }
-//    return;
+//  (void) s;
+  if(s) { //need to check the port state as we can't use level sensitive interrupt on the STM ARM
+    port_EnableEXT_IRQ();
+  }
+  return;
 }
 
 
@@ -4540,29 +4535,21 @@ void decamutexoff(decaIrqStatus_t s)
 
 void deca_sleep(unsigned int time_ms)
 {
-    aosThdMSleep(time_ms);
+  aosThdMSleep(time_ms);
 }
 
 void Sleep(unsigned int time_ms)
 {
-    aosThdMSleep(time_ms);
+  aosThdMSleep(time_ms);
 }
 
 
-void port_set_dw1000_slowrate(){ // replaced with setHighSpeed_SPI(bool speedValue) implemented in module.c
-    return;
-}
-
-void port_set_dw1000_fastrate(){ // replaced with setHighSpeed_SPI(bool speedValue) implemented in module.c
-    return;
-}
-
 void port_wakeup_dw1000_fast(){ // NOT SUPPORTED
-    return;
+  return;
 }
 
 uint32_t portGetTickCnt(){
-    return chVTGetSystemTimeX();
+  return chVTGetSystemTimeX();
 }
 
 //inline uint32_t portGetTickCnt(){
@@ -4571,30 +4558,27 @@ uint32_t portGetTickCnt(){
 
 
 void port_DisableEXT_IRQ(void){   
-   nvicDisableVector(DW1000_EXTI_IRQn);
+  nvicDisableVector(DW1000_EXTI_IRQn);
 
 }
 
 void port_EnableEXT_IRQ(void){    
-    nvicEnableVector(DW1000_EXTI_IRQn, STM32_IRQ_EXTI10_15_PRIORITY);
+  nvicEnableVector(DW1000_EXTI_IRQn, STM32_IRQ_EXTI10_15_PRIORITY);
 }
 
 
-ITStatus port_GetEXT_IRQStatus(void){
-  ITStatus bitstatus = RESET;
-  //  uint32_t enablestatus = 0;
+decaIrqStatus_t port_GetEXT_IRQStatus(void){
+  decaIrqStatus_t bitstatus = RESET;
 
   if(NVIC_GetActive(DW1000_EXTI_IRQn)|| NVIC_GetPendingIRQ(DW1000_EXTI_IRQn)){
     //  if(NVIC_GetPendingIRQ(EXTI15_10_IRQn)){ //if the interrupt is pending (background )
     bitstatus = SET; //Interrupt is active or panding
   }
   else {
-    bitstatus = RESET; //Currently there is no interrupt IRQ
+    bitstatus = RESET; //No interrupt IRQ at the moment
   }
 
   return bitstatus;
 }
 
-
-
 #endif /* defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1) */
diff --git a/source/DW1000/v1/deca_instance_common_v1.c b/source/DW1000/v1/deca_instance_common_v1.c
index bf6defe..734c2de 100755
--- a/source/DW1000/v1/deca_instance_common_v1.c
+++ b/source/DW1000/v1/deca_instance_common_v1.c
@@ -18,22 +18,113 @@
 #include "module.h"
 #include <string.h>
 #include <math.h>
+#include <v1/deca_instance_v1.h>
+
+
+/*! @brief Software defined configuration settings for RTLS applications */
+/*! Configuration for DecaRangeRTLS TREK Modes (4 default use cases selected by the switch S1 [2,3] on EVB1000, indexed 0 to 3 )*/
+instanceConfig_t chConfig[4] ={
+                               //mode 1 - S1: 2 off, 3 off
+                               {
+                                .channelNumber = 2,             // channel
+                                .preambleCode = 4,              // preambleCode
+                                .pulseRepFreq = DWT_PRF_16M,    // prf
+                                .dataRate = DWT_BR_110K,        // datarate
+                                .preambleLen = DWT_PLEN_1024,   // preambleLength
+                                .pacSize = DWT_PAC32,           // pacSize
+                                .nsSFD = 1,                     // non-standard SFD
+                                .sfdTO = (1025 + 64 - 32)       // SFD timeout
+                               },
+                               //mode 2 - S1: 2 on, 3 off
+                               {
+                                .channelNumber = 2,            // channel
+                                .preambleCode = 4,             // preambleCode
+                                .pulseRepFreq = DWT_PRF_16M,   // prf
+                                .dataRate = DWT_BR_6M8,        // datarate
+                                .preambleLen = DWT_PLEN_128,   // preambleLength
+                                .pacSize = DWT_PAC8,           // pacSize
+                                .nsSFD = 0,                    // non-standard SFD
+                                .sfdTO = (129 + 8 - 8)        // SFD timeout
+                               },
+                               //mode 3 - S1: 2 off, 3 on
+                               {
+                                .channelNumber = 5,             // channel
+                                .preambleCode = 3,              // preambleCode
+                                .pulseRepFreq = DWT_PRF_16M,    // prf
+                                .dataRate = DWT_BR_110K,        // datarate
+                                .preambleLen = DWT_PLEN_1024,   // preambleLength
+                                .pacSize = DWT_PAC32,           // pacSize
+                                .nsSFD = 1,                     // non-standard SFD
+                                .sfdTO = (1025 + 64 - 32)       // SFD timeout
+                               },
+                               //mode 4 - S1: 2 on, 3 on
+                               {
+                                .channelNumber = 5,            // channel
+                                .preambleCode = 3,             // preambleCode
+                                .pulseRepFreq = DWT_PRF_16M,   // prf
+                                .dataRate = DWT_BR_6M8,        // datarate
+                                .preambleLen = DWT_PLEN_128,   // preambleLength
+                                .pacSize = DWT_PAC8,           // pacSize
+                                .nsSFD = 0,                    // non-standard SFD
+                                .sfdTO = (129 + 8 - 8)        // SFD timeout
+                               }
+};
 
 
-extern double dwt_getrangebias(uint8_t chan, float range, uint8_t prf);
-
-extern const uint16_t rfDelays[2];
-extern const uint16_t rfDelaysTREK[2];
-extern const tx_struct txSpectrumConfig[8];
-
-
-
-// -------------------------------------------------------------------------------------------------------------------
-// Deca Calibration Values
-// -------------------------------------------------------------------------------------------------------------------
+/*! Slot and Superframe Configuration for DecaRangeRTLS TREK Modes (4 default use cases selected by the switch S1 [2,3] on EVB1000, indexed 0 to 3 )*/
+sfConfig_t sfConfig[4] ={
+                         //mode 1 - S1: 2 off, 3 off
+                         {
+                          .slotPeriod = (28), //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time
+                          //e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
+                          .numSlots = (10),        //number of slots in the superframe (8 tag slots and 2 used for anchor to anchor ranging),
+                          .sfPeriod = (10*28),  //in ms => 280ms frame means 3.57 Hz location rate
+                          .pollSleepDly = (10*28), //tag period in ms (sleep time + ranging time)
+                          .replyDly = (25000) //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames)
+                         },
+#if (DISCOVERY == 1)
+                         //mode 2 - S1: 2 on, 3 off
+                         {
+                          .slotPeriod = (10), //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time
+                          //e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
+                          .numSlots = (100),        //number of slots in the superframe (98 tag slots and 2 used for anchor to anchor ranging),
+                          .sfPeriod = (10*100),  //in ms => 1000 ms frame means 1 Hz location rate
+                          .pollSleepDly = (10*100), //tag period in ms (sleep time + ranging time)
+                          .replyDly = (2500) //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames)
+
+                         },
+#else
+                         //mode 2 - S1: 2 on, 3 off
+                         {
+                          .slotPeriod = (10), //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time
+                          //e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
+                          .numSlots = (10),        //number of slots in the superframe (8 tag slots and 2 used for anchor to anchor ranging),
+                          .sfPeriod = (10*10),  //in ms => 100 ms frame means 10 Hz location rate
+                          .pollSleepDly = (10*10), //tag period in ms (sleep time + ranging time)
+                          .replyDly = (2500) //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames)
+                         },
+#endif
+                         //mode 3 - S1: 2 off, 3 on
+                         {
+                          .slotPeriod = (28), //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time
+                          //e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
+                          .numSlots = (10),        //number of slots in the superframe (8 tag slots and 2 used for anchor to anchor ranging),
+                          .sfPeriod = (10*28),  //in ms => 280ms frame means 3.57 Hz location rate
+                          .pollSleepDly = (10*28), //tag period in ms (sleep time + ranging time)
+                          .replyDly = (20000) //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames)
+
+                         },
+                         //mode 4 - S1: 2 on, 3 on
+                         {
+                          .slotPeriod = (10), //slot duration in milliseconds (NOTE: the ranging exchange must be able to complete in this time
+                          //e.g. tag sends a poll, 4 anchors send responses and tag sends the final + processing time
+                          .numSlots = (10),        //number of slots in the superframe (8 tag slots and 2 used for anchor to anchor ranging),
+                          .sfPeriod = (10*10),  //in ms => 100 ms frame means 10 Hz location rate
+                          .pollSleepDly = (10*10), //tag period in ms (sleep time + ranging time)
+                          .replyDly = (2500) //poll to final delay in microseconds (needs to be adjusted according to lengths of ranging frames)
+                         }
+};
 
-#define DWT_PRF_64M_RFDLY   (514.462f)
-#define DWT_PRF_16M_RFDLY   (513.9067f)
 
 // -------------------------------------------------------------------------------------------------------------------
 
@@ -341,7 +432,8 @@ void instanceclearcounts(void){
 // function to initialise instance structures
 //
 // Returns 0 on success and -1 on error
-int instance_init(void){
+//int instance_init(void){   // TODO
+int instance_init(DW1000Driver* drv){
   int instance = 0 ;
   int i;
   int result;
@@ -356,7 +448,8 @@ int instance_init(void){
   //dwt_softreset();
 
   //this initialises DW1000 and uses specified configurations from OTP/ROM
-  result = dwt_initialise(DWT_LOADUCODE) ;
+  result = dwt_initialise(DWT_LOADUCODE, drv) ;    // TODO
+//  result = dwt_initialise(DWT_LOADUCODE) ;
 
   //this is platform dependent - only program if DW EVK/EVB
   dwt_setleds(3) ; //configure the GPIOs which control the leds on EVBs
diff --git a/source/DW1000/v1/deca_instance_tag_anchor_v1.c b/source/DW1000/v1/deca_instance_tag_anchor_v1.c
index a1ce3be..a2a415c 100755
--- a/source/DW1000/v1/deca_instance_tag_anchor_v1.c
+++ b/source/DW1000/v1/deca_instance_tag_anchor_v1.c
@@ -15,6 +15,7 @@
 
 #if (defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)) || defined(__DOXYGEN__)
 
+#include <v1/deca_instance_v1.h>
 #include <string.h>
 #include<math.h>
 #include "module.h"
