commit 7b6ab4bf0f782faaccbc081ccb69bf5dbace8600
Author: Cung Sang <csang@techfak.uni-bielefeld.de>
Date:   Mon Feb 11 13:18:22 2019 +0100

    fixed the DW1000Driver struct issued in uinttest v1

diff --git a/unittests/periphery-lld/src/ut_alld_dw1000_v1.c b/unittests/periphery-lld/src/ut_alld_dw1000_v1.c
index 7e9d3e1..9a710ee 100755
--- a/unittests/periphery-lld/src/ut_alld_dw1000_v1.c
+++ b/unittests/periphery-lld/src/ut_alld_dw1000_v1.c
@@ -63,46 +63,32 @@ int dr_mode = 0;
 int chan, tagaddr, ancaddr;
 int instance_mode = ANCHOR;
 
-DW1000Driver* spiDrv;
-
 
 /******************************************************************************/
 /* LOCAL FUNCTIONS                                                            */
 /******************************************************************************/
 
-/*! @brief Change the SPI speed configuration  on the fly */
-void setHighSpeed_SPI(bool speedValue){
+/*! @brief Change the SPI speed configuration on the fly */
+void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv){
 
-  spiStop(&MODULE_HAL_SPI_UWB);
+  spiStop(drv->spid);
   //  spiAcquireBus(&MODULE_HAL_SPI_UWB);
 
   if (speedValue == FALSE){
-    spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbLsConfig);  // low speed spi configuration
+    spiStart(drv->spid, &moduleHalSpiUwbLsConfig);  // low speed spi configuration
   }
   else{
-    spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbHsConfig); // high speed spi configuration
+    spiStart(drv->spid, &moduleHalSpiUwbHsConfig); // high speed spi configuration
   }
 }
-/* void setHighSpeed_SPI(bool speedValue){
-
-  spiStop(spiDrv->spid);
-  //  spiAcquireBus(&MODULE_HAL_SPI_UWB);
-
-  if (speedValue == FALSE){
-    spiStart(spiDrv->spid, &moduleHalSpiUwbLsConfig);  // low speed spi configuration
-  }
-  else{
-    spiStart(spiDrv->spid, &moduleHalSpiUwbHsConfig); // high speed spi configuration
-  }
-} */
 
 /*! @brief Manually set the chip select pin of the SPI */
-void port_SPIx_set_chip_select(void){
+void set_SPI_chip_select(void){
   apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_HIGH);
 }
 
 /*! @brief Manually reset the chip select pin of the SPI */
-void port_SPIx_clear_chip_select(void){
+void clear_SPI_chip_select(void){
   apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW);
 }
 
@@ -122,9 +108,7 @@ void reset_DW1000(void){
 }
 
 
-/*! @brief Configure instance tag/anchor/etc... addresses
- *
- * */
+/*! @brief Configure instance tag/anchor/etc... addresses */
 void addressconfigure(uint8_t s1switch, uint8_t mode){
   uint16_t instAddress ;
 
@@ -146,9 +130,7 @@ void addressconfigure(uint8_t s1switch, uint8_t mode){
 }
 
 
-/*! @brief returns the use case / operational mode
- *
- * */
+/*! @brief returns the use case / operational mode */
 int decarangingmode(uint8_t s1switch){
   int mode = 0;
 
@@ -163,26 +145,24 @@ int decarangingmode(uint8_t s1switch){
   return mode;
 }
 
-/*! @brief Check connection setting and initialize DW1000 module
- *
- **/
-uint32_t inittestapplication(uint8_t s1switch){
+/*! @brief Check connection setting and initialize DW1000 module */
+uint32_t inittestapplication(uint8_t s1switch, DW1000Driver* drv){
   uint32_t devID ;
   int result;
 
-  setHighSpeed_SPI(FALSE);          //low speed spi max. ~4M
+  setHighSpeed_SPI(FALSE, drv);          //low speed spi max. ~4M
   devID = instancereaddeviceid() ;
 
   if(DWT_DEVICE_ID != devID) {
-    port_SPIx_clear_chip_select();
+    clear_SPI_chip_select();
     Sleep(1);
-    port_SPIx_set_chip_select();
+    set_SPI_chip_select();
     Sleep(7);
     devID = instancereaddeviceid() ;
     if(DWT_DEVICE_ID != devID){
-      return(-1) ;  // SPI not working or Unsupported Device ID
+      return(-1) ;
     }    
-    dwt_softreset();//clear the sleep bit - so that after the hard reset below the DW does not go into sleep
+    dwt_softreset();
   }
 
     reset_DW1000();  //reset the DW1000 by driving the RSTn line low
@@ -194,14 +174,14 @@ uint32_t inittestapplication(uint8_t s1switch){
     instance_mode = ANCHOR;
   }
 
-  result = instance_init(spiDrv) ; // TODO
+  result = instance_init(drv) ; // TODO
 //  result = instance_init() ;
 
   if (0 > result){
     return(-1) ;
   }
 
-  setHighSpeed_SPI(TRUE);               // high speed spi max. ~ 20M
+  setHighSpeed_SPI(TRUE, drv);             // high speed spi max. ~ 20M
   devID = instancereaddeviceid() ;
 
   if (DWT_DEVICE_ID != devID){
@@ -217,25 +197,24 @@ uint32_t inittestapplication(uint8_t s1switch){
   instancesetrole(instance_mode) ;       // Set this instance role
   dr_mode = decarangingmode(s1switch);
   chan = chConfig[dr_mode].channelNumber ;
-  instance_config(&chConfig[dr_mode], &sfConfig[dr_mode]) ;
+  instance_config(&chConfig[dr_mode], &sfConfig[dr_mode], drv) ;
 
   return devID;
 }
 
-/*! @brief Main Entry point to Initialization of UWB DW1000 configuration
- *
- * */
+
+/*! @brief Main Entry point to Initialization of UWB DW1000 configuration  */
 #pragma GCC optimize ("O3")
-int UWB_Init(void){
+int UWB_Init(DW1000Driver* drv){
 
   /*! Software defined Configurartion for TAG, ANC, and other settings as needed */
-  s1switch = S1_SWITCH_OFF << 1 // is_switch_on(TA_SW1_2) << 2  // (on = 6.8 Mbps, off = 110 kbps)
-                              | S1_SWITCH_OFF << 2  // (on = CH5, off = CH2)
-                              | S1_SWITCH_OFF << 3  // (on = Anchor, off = TAG)
-                              | S1_SWITCH_OFF << 4  // (configure Tag or anchor ID no.)
-                              | S1_SWITCH_OFF << 5  // (configure Tag or anchor ID no.)
-                              | S1_SWITCH_OFF << 6  // (configure Tag or anchor ID no.)
-                              | S1_SWITCH_OFF << 7; // Not use in this demo
+  s1switch = S1_SWITCH_OFF << 1  // (on = 6.8 Mbps, off = 110 kbps)
+           | S1_SWITCH_OFF << 2  // (on = CH5, off = CH2)
+           | S1_SWITCH_OFF << 3  // (on = Anchor, off = TAG)
+           | S1_SWITCH_OFF << 4  // (configure Tag or anchor ID no.)
+           | S1_SWITCH_OFF << 5  // (configure Tag or anchor ID no.)
+           | S1_SWITCH_OFF << 6  // (configure Tag or anchor ID no.)
+           | S1_SWITCH_OFF << 7; // Not use in this demo
 
 
   port_DisableEXT_IRQ();           //disable ScenSor IRQ until we configure the device
@@ -245,7 +224,7 @@ int UWB_Init(void){
   }
   else{
     //run RTLS application
-    if(inittestapplication(s1switch) == (uint32_t)-1) {
+    if(inittestapplication(s1switch, drv) == (uint32_t)-1) {
       return 0; //error
     }
 
@@ -269,21 +248,21 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
 
   aos_utresult_t result = {0, 0};
 
+  chprintf(stream, "init DW1000...\n");
+  dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
+  aosThdMSleep(5);
 
-  /*! Unit Test snippets for DW1000.
-     * @Note: Passed all 4 unit tests. Event IRQ should be tested separately
-     */
+
+/*! Unit Test snippets for DW1000.
+ * @Note: Passed all 4 unit tests. Event IRQ should be tested separately
+ */
 #ifdef UNIT_TEST_SNIPPETS_DW1000
 
   uint32_t actual_deviceId;
 
-  chprintf(stream, "init DW1000...\n");
-  dwt_initialise(DWT_LOADUCODE, (DW1000Driver*) ut->data);
-  aosThdMSleep(5);
-
   port_DisableEXT_IRQ();
 
-  setHighSpeed_SPI(false);
+  setHighSpeed_SPI(false, (DW1000Driver*) ut->data);
   chprintf(stream, "expected device ID (LS SPI): 0xDECA0130 \n");
   aosThdMSleep(5);
   actual_deviceId = instancereaddeviceid();
@@ -311,7 +290,7 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
     dwt_softreset();
   }
 
-  /*! Low speed SPI unit test result */
+  /*! UT1: Low speed SPI result */
   if (actual_deviceId == DWT_DEVICE_ID){
     aosUtPassed(stream, &result);
   } else {
@@ -336,7 +315,7 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
   }
 
 
-  /* Initialization unit test result */
+  /*! UT2: Initialization  result*/
   if (x_init == 0){
     aosUtPassed(stream, &result);
   } else {
@@ -344,14 +323,14 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
   }
 
 
-  setHighSpeed_SPI(true);
+  setHighSpeed_SPI(true, (DW1000Driver*) ut->data);
 
   chprintf(stream, "expected device ID (HS SPI): 0xDECA0130\n");
   actual_deviceId = instancereaddeviceid();
   chprintf(stream, "actual read ID: 0x%x\n", actual_deviceId);
   aosThdMSleep(5);
 
-  /* High speed SPI unit test result */
+  /*! UT3: High speed SPI result*/
   if (actual_deviceId == DWT_DEVICE_ID){
     aosUtPassed(stream, &result);
   } else {
@@ -362,11 +341,10 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
   reset_DW1000();
 
 
-
   chprintf(stream, " Initialise the configuration for UWB application \n");
   aosThdSleep(5);
 
-  int uwb_init = UWB_Init();
+  int uwb_init = UWB_Init((DW1000Driver*) ut->data);
 
   if (0 != uwb_init){
     chprintf(stream, "UWB config error with return value: %d \n", uwb_init);
@@ -377,7 +355,7 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
     aosThdSleep(5);
   }
 
-  /* UWB configuration unit test.
+  /*! UT4: UWB configuration result
    * If all the four unit tests are passed, the module is ready to run.
    * Note that the interrupt IRQn should be tested separately.
    */
@@ -396,8 +374,8 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
   chprintf(stream, " Initialise the State Machine \n");
   aosThdSleep(2);
 
-  /* Initialize UWB system with the configuration provided in module_uwb_conf.c */
-  int uwb_init = UWB_Init();
+  /* Initialize UWB system with user defined configuration  */
+  int uwb_init = UWB_Init((DW1000Driver*) ut->data);
 
   if (0 != uwb_init){
     chprintf(stream, "UWB config error with return value: %d \n", uwb_init);
