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/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
