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