commit 10b520a8b318b31cb1e02dca356b9adda62a2b34
Author: Cung Sang <csang@techfak.uni-bielefeld.de>
Date:   Tue Feb 12 11:22:21 2019 +0100

    DW1000 unit test updated

diff --git a/unittests/periphery-lld/src/ut_alld_dw1000_v1.c b/unittests/periphery-lld/src/ut_alld_dw1000_v1.c
index 9a710ee..e5995e7 100755
--- a/unittests/periphery-lld/src/ut_alld_dw1000_v1.c
+++ b/unittests/periphery-lld/src/ut_alld_dw1000_v1.c
@@ -41,7 +41,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define SWS1_A1A_MODE 0x10  //anchor/tag address A1
 #define SWS1_A2A_MODE 0x20  //anchor/tag address A2
 #define SWS1_A3A_MODE 0x40  //anchor/tag address A3
-#define SWS1_USB2SPI_MODE 0x78  //USB to SPI mode
 
 #define S1_SWITCH_ON  (1)
 #define S1_SWITCH_OFF (0)
@@ -72,7 +71,6 @@ int instance_mode = ANCHOR;
 void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv){
 
   spiStop(drv->spid);
-  //  spiAcquireBus(&MODULE_HAL_SPI_UWB);
 
   if (speedValue == FALSE){
     spiStart(drv->spid, &moduleHalSpiUwbLsConfig);  // low speed spi configuration
@@ -82,6 +80,23 @@ void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv){
   }
 }
 
+/*! @brief entry point to the IRQn event in DW1000 module
+ *
+ * */
+void process_deca_irq(void){
+  do{
+    dwt_isr();
+    //while IRS line active (ARM can only do edge sensitive interrupts)
+  }while(port_CheckEXT_IRQ() == 1);
+}
+
+/*! @brief Check the current value of GPIO pin and return the value */
+apalGpioState_t port_CheckEXT_IRQ(void) {
+  apalGpioState_t  val;
+  apalGpioRead(moduleGpioDw1000Irqn.gpio, &val);
+  return val;
+}
+
 /*! @brief Manually set the chip select pin of the SPI */
 void set_SPI_chip_select(void){
   apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_HIGH);
@@ -107,7 +122,6 @@ void reset_DW1000(void){
   aosThdMSleep(2);
 }
 
-
 /*! @brief Configure instance tag/anchor/etc... addresses */
 void addressconfigure(uint8_t s1switch, uint8_t mode){
   uint16_t instAddress ;
@@ -129,7 +143,6 @@ void addressconfigure(uint8_t s1switch, uint8_t mode){
   instancesetaddresses(instAddress);
 }
 
-
 /*! @brief returns the use case / operational mode */
 int decarangingmode(uint8_t s1switch){
   int mode = 0;
@@ -146,7 +159,7 @@ int decarangingmode(uint8_t s1switch){
 }
 
 /*! @brief Check connection setting and initialize DW1000 module */
-uint32_t inittestapplication(uint8_t s1switch, DW1000Driver* drv){
+int32_t inittestapplication(uint8_t s1switch, DW1000Driver* drv){
   uint32_t devID ;
   int result;
 
@@ -174,14 +187,13 @@ uint32_t inittestapplication(uint8_t s1switch, DW1000Driver* drv){
     instance_mode = ANCHOR;
   }
 
-  result = instance_init(drv) ; // TODO
-//  result = instance_init() ;
+  result = instance_init(drv) ;
 
   if (0 > result){
     return(-1) ;
   }
 
-  setHighSpeed_SPI(TRUE, drv);             // high speed spi max. ~ 20M
+  setHighSpeed_SPI(TRUE, drv);       // high speed spi max. ~ 20M
   devID = instancereaddeviceid() ;
 
   if (DWT_DEVICE_ID != devID){
@@ -199,10 +211,9 @@ uint32_t inittestapplication(uint8_t s1switch, DW1000Driver* drv){
   chan = chConfig[dr_mode].channelNumber ;
   instance_config(&chConfig[dr_mode], &sfConfig[dr_mode], drv) ;
 
-  return devID;
+  return (int32_t)devID;
 }
 
-
 /*! @brief Main Entry point to Initialization of UWB DW1000 configuration  */
 #pragma GCC optimize ("O3")
 int UWB_Init(DW1000Driver* drv){
@@ -219,19 +230,13 @@ int UWB_Init(DW1000Driver* drv){
 
   port_DisableEXT_IRQ();           //disable ScenSor IRQ until we configure the device
 
-  if((s1switch & SWS1_USB2SPI_MODE) == SWS1_USB2SPI_MODE){
-    return 1;
+  if(inittestapplication(s1switch, drv) == -1) {
+    return (-1); //error
   }
-  else{
-    //run RTLS application
-    if(inittestapplication(s1switch, drv) == (uint32_t)-1) {
-      return 0; //error
-    }
 
-    aosThdMSleep(5);
-  }
+  aosThdMSleep(5);
 
-  port_EnableEXT_IRQ();           //enable ScenSor IRQ before starting
+  port_EnableEXT_IRQ();  //enable DW1000 IRQ before starting
 
   return 0;
 }
@@ -254,7 +259,7 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
 
 
 /*! Unit Test snippets for DW1000.
- * @Note: Passed all 4 unit tests. Event IRQ should be tested separately
+ * @Note: Event IRQ for DW1000 should be tested separately
  */
 #ifdef UNIT_TEST_SNIPPETS_DW1000
 
@@ -269,21 +274,20 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
   chprintf(stream, "actual read ID: 0x%x\n", actual_deviceId);
   aosThdMSleep(5);
 
-  if(DWT_DEVICE_ID != actual_deviceId) //if the read of device ID fails, the DW1000 could be asleep
-  {
-    port_SPIx_clear_chip_select();  //CS low
-    aosThdMSleep(1);   //200 us to wake up then waits 5ms for DW1000 XTAL to stabilise
-    port_SPIx_set_chip_select();  //CS high
+  //if the read of device ID fails, the DW1000 could be asleep
+  if(DWT_DEVICE_ID != actual_deviceId){
+
+    clear_SPI_chip_select();
+    aosThdMSleep(1);
+    set_SPI_chip_select();
     aosThdMSleep(7);
     actual_deviceId = instancereaddeviceid() ;
 
-    // SPI not working or Unsupported Device ID
     if(DWT_DEVICE_ID != actual_deviceId){
-      chprintf(stream, "SPI not working or Unsupported Device ID\n");
+      chprintf(stream, "SPI is not working or Unsupported Device ID\n");
       chprintf(stream, "actual device ID is: 0x%x\n", actual_deviceId);
       chprintf(stream, "expected device ID: 0xDECA0130 \n");
       aosThdMSleep(5);
-      //          return(-1) ;
     }
 
     //clear the sleep bit - so that after the hard reset below the DW does not go into sleep
@@ -296,25 +300,23 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
   } else {
     aosUtFailed(stream, &result);
   }
-  reset_DW1000();
 
+  reset_DW1000();
 
-  chprintf(stream, " Initialise instance for DW1000 \n");
-  aosThdSleep(5);
+  chprintf(stream, "initialise instance for DW1000 \n");
+  aosThdSleep(1);
 
-  int x_init = instance_init((DW1000Driver*) ut->data) ;   // TODO
-//  int x_init = instance_init() ;
+  int x_init = instance_init((DW1000Driver*) ut->data) ;
 
   if (0 != x_init){
-    chprintf(stream, "Init error with return value: %d \n", x_init);
-    aosThdSleep(5);
+    chprintf(stream, "init error with return value: %d \n", x_init);
+    aosThdSleep(1);
   }
   else {
-    chprintf(stream, "Init success with return value: %d \n", x_init);
-    aosThdSleep(5);
+    chprintf(stream, "init success with return value: %d \n", x_init);
+    aosThdSleep(1);
   }
 
-
   /*! UT2: Initialization  result*/
   if (x_init == 0){
     aosUtPassed(stream, &result);
@@ -322,13 +324,12 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
     aosUtFailed(stream, &result);
   }
 
-
   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);
+  aosThdMSleep(1);
 
   /*! UT3: High speed SPI result*/
   if (actual_deviceId == DWT_DEVICE_ID){
@@ -340,19 +341,18 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
   port_EnableEXT_IRQ();
   reset_DW1000();
 
-
-  chprintf(stream, " Initialise the configuration for UWB application \n");
-  aosThdSleep(5);
+  chprintf(stream, "initialise the configuration for UWB application \n");
+  aosThdSleep(1);
 
   int uwb_init = UWB_Init((DW1000Driver*) ut->data);
 
   if (0 != uwb_init){
     chprintf(stream, "UWB config error with return value: %d \n", uwb_init);
-    aosThdSleep(5);
+    aosThdSleep(1);
   }
   else {
     chprintf(stream, "UWB config success with return value: %d \n", uwb_init);
-    aosThdSleep(5);
+    aosThdSleep(1);
   }
 
   /*! UT4: UWB configuration result
@@ -369,27 +369,27 @@ aos_utresult_t utAlldDw1000Func(BaseSequentialStream* stream, aos_unittest_t* ut
 
 #else
 
-  // RUN THE STATE MACHINE DEMO APP
 
-  chprintf(stream, " Initialise the State Machine \n");
+  /*! RUN THE STATE MACHINE DEMO APP (RTLS) */
+
+  chprintf(stream, "initialise the State Machine \n");
   aosThdSleep(2);
 
   /* 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);
+    chprintf(stream, "error in UWB config with return value: %d \n", uwb_init);
   }
   else {
-    chprintf(stream, "UWB config success with return value: %d \n", uwb_init);
+    chprintf(stream, "succeed the init of UWB config \n");
   }
   aosThdSleep(1);
 
-  chprintf(stream, " Running the RTLS demo application \n");
+  chprintf(stream, "running the RTLS demo application ... \n");
   aosThdSleep(1);
 
-
-  /* Run the localization system demo app as a thread */
+  /*! Run the localization system demo app as a thread */
   while(1){
     instance_run();
 //    aosThdUSleep(10);
