Revision 33f54213 source/DW1000/v1/alld_dw1000_v1.c

View differences:

source/DW1000/v1/alld_dw1000_v1.c
28 28
 *
29 29
 */
30 30

  
31

  
32 31
#include <alld_DW1000.h>
33 32

  
34 33
#if (defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)) || defined(__DOXYGEN__)
35 34

  
35
#include <v1/alld_dw1000_regs_v1.h>
36

  
36 37
#include <aos_thread.h>
37 38
#include <assert.h>
38 39
#include <string.h>
......
40 41
#include <math.h>
41 42

  
42 43

  
44
// HW dependent implementation (see bottom of file)
45
static int writetospi(uint16_t headerLength,
46
               const	uint8_t *headerBuffer,
47
               uint32_t bodyLength,
48
               const	uint8_t *bodyBuffer);
49

  
50
static int readfromspi(uint16_t headerLength,
51
                const uint8_t *headerBuffer,
52
                uint32_t readlength,
53
                uint8_t *readBuffer);
54

  
55

  
43 56
// Defines for enable_clocks function
44 57
#define FORCE_SYS_XTI  0
45 58
#define ENABLE_ALL_SEQ 1
......
57 70
#define FCTRL_LEN_MAX 2
58 71

  
59 72

  
60
/**
61
 * Move to the header file <alld_dw1000_v1.h>
62
*/
63
//#define NUM_BR 3
64
//#define NUM_PRF 2
65
//#define NUM_PACS 4
66
//#define NUM_BW 2            //2 bandwidths are supported
67
//#define NUM_SFD 2           //supported number of SFDs - standard = 0, non-standard = 1
68
//#define NUM_CH 6            //supported channels are 1, 2, 3, 4, 5, 7
69
//#define NUM_CH_SUPPORTED 8  //supported channels are '0', 1, 2, 3, 4, 5, '6', 7
70
//#define PCODES 25           //supported preamble codes
71

  
72

  
73 73
typedef struct {
74 74
    uint32_t lo32;
75 75
    uint16_t target[NUM_PRF];
......
1013 1013
#define VTEMP_ADDRESS  (0x09)
1014 1014
#define XTRIM_ADDRESS  (0x1E)
1015 1015

  
1016
//int dwt_initialise(const uint16_t config, DW1000Driver* drv)
1017
int dwt_initialise(const uint16_t config)  // TODO:
1016
int dwt_initialise(const uint16_t config, DW1000Driver* drv)
1017
//int dwt_initialise(const uint16_t config)  // TODO:
1018 1018
{
1019 1019
    uint16_t otp_addr = 0;
1020 1020
    uint32_t ldo_tune = 0;
......
1028 1028
    pdw1000local->cbRxTo = NULL;
1029 1029
    pdw1000local->cbRxErr = NULL;
1030 1030

  
1031
//    pdw1000local->driver = drv;  // TODO:
1031
    pdw1000local->driver = drv;  // TODO:
1032 1032

  
1033 1033
    // Read and validate device ID return -1 if not recognised
1034 1034
    if (DWT_DEVICE_ID != dwt_readdevid()) // MP IC ONLY (i.e. DW1000) FOR THIS CODE
......
1813 1813
    }
1814 1814

  
1815 1815
    // Write it to the SPI
1816
//    _alld_dw1000_writespi(cnt,header,length,buffer);
1817
    writetospi(cnt,header,length,buffer);  // TODO
1816
    writetospi(cnt,header,length,buffer);
1818 1817
} // end dwt_writetodevice()
1819 1818

  
1820 1819
/*! ------------------------------------------------------------------------------------------------------------------
......
1878 1877
    }
1879 1878

  
1880 1879
    // Do the read from the SPI
1881
//    _alld_dw1000_readspi(cnt, header, length, buffer);  // result is stored in the buffer
1882
    readfromspi(cnt, header, length, buffer);  // TODO:
1880
    readfromspi(cnt, header, length, buffer);
1883 1881
} // end dwt_readfromdevice()
1884 1882

  
1885 1883

  
......
4419 4417
 *
4420 4418
 ****************************************************************************************************************************************************/
4421 4419

  
4422
/*
4423
 * DW1000 Hardware dependent functions: SPI, EXTI
4424
 */
4420
/****************************************************************************//**
4421
 *
4422
 * 	alld_dw1000.c					SPI Section
4423
 *
4424
 *******************************************************************************/
4425 4425

  
4426 4426
/*! ------------------------------------------------------------------------------------------------------------------
4427 4427
 * Function: writetospi()
......
4431 4431
 * returns 0 for success, or -1 for error
4432 4432
 */
4433 4433
#pragma GCC optimize ("O3")
4434
int writetospi(uint16_t headerLength,
4434
static int writetospi(uint16_t headerLength,
4435 4435
               const	uint8_t *headerBuffer,
4436 4436
               uint32_t bodyLength,
4437 4437
               const	uint8_t *bodyBuffer)
4438 4438
{
4439 4439

  
4440
    port_SPIx_clear_chip_select();
4441

  
4442 4440
    uint8_t buffer[bodyLength + 3];
4443 4441
    memcpy(buffer, headerBuffer, headerLength); //copy data to buffer
4444 4442
    memcpy(&buffer[headerLength], bodyBuffer, bodyLength); //copy data to buffer
......
4447 4445
                    buffer,
4448 4446
                    bodyLength + headerLength); // send header and data
4449 4447

  
4450
    port_SPIx_set_chip_select();
4451

  
4452 4448
    return 0;
4453 4449
} // end writetospi()
4454 4450

  
4455 4451

  
4456

  
4457 4452
/*! ------------------------------------------------------------------------------------------------------------------
4458 4453
 * Function: readfromspi()
4459 4454
 *
......
4463 4458
 * or returns -1 if there was an error
4464 4459
 */
4465 4460
#pragma GCC optimize ("O3")
4466
int readfromspi(uint16_t headerLength,
4461
static int readfromspi(uint16_t headerLength,
4467 4462
                const uint8_t *headerBuffer,
4468 4463
                uint32_t readlength,
4469 4464
                uint8_t *readBuffer)
4470 4465
{
4471 4466

  
4472
    apalSPITransmitAndReceive(&MODULE_HAL_SPI_UWB,
4467
    apalSPITransmitAndReceive(&MODULE_HAL_SPI_UWB, // TODO: "pdw1000local->driver->spid" fails two spi configs
4473 4468
                              headerBuffer,
4474 4469
                              readBuffer,
4475 4470
                              headerLength,
......
4499 4494
 *
4500 4495
 * returns the state of the DW1000 interrupt
4501 4496
 */
4502
decaIrqStatus_t decamutexon(void)           
4497
decaIrqStatus_t decamutexon(void)
4503 4498
{
4504
    decaIrqStatus_t s = port_GetEXT_IRQStatus();
4505 4499

  
4506
    if(s) {
4507
        port_DisableEXT_IRQ(); //disable the external interrupt line
4508
    }
4509
    return s ;   // return state before disable, value is used to re-enable in decamutexoff call
4500
  decaIrqStatus_t s = port_GetEXT_IRQStatus();
4501
  if(s) {
4502
    port_DisableEXT_IRQ(); //disable the external interrupt line
4503
  }
4504
  return s ;   // return state before disable, value is used to re-enable in decamutexoff call
4510 4505
}
4511 4506

  
4512 4507
/*! ------------------------------------------------------------------------------------------------------------------
......
4526 4521
 */
4527 4522
void decamutexoff(decaIrqStatus_t s)
4528 4523
{
4529
//    (void) s;
4530
    if(s) { //need to check the port state as we can't use level sensitive interrupt on the STM ARM
4531
      port_EnableEXT_IRQ();
4532
    }
4533
//    return;
4524
//  (void) s;
4525
  if(s) { //need to check the port state as we can't use level sensitive interrupt on the STM ARM
4526
    port_EnableEXT_IRQ();
4527
  }
4528
  return;
4534 4529
}
4535 4530

  
4536 4531

  
......
4540 4535

  
4541 4536
void deca_sleep(unsigned int time_ms)
4542 4537
{
4543
    aosThdMSleep(time_ms);
4538
  aosThdMSleep(time_ms);
4544 4539
}
4545 4540

  
4546 4541
void Sleep(unsigned int time_ms)
4547 4542
{
4548
    aosThdMSleep(time_ms);
4543
  aosThdMSleep(time_ms);
4549 4544
}
4550 4545

  
4551 4546

  
4552
void port_set_dw1000_slowrate(){ // replaced with setHighSpeed_SPI(bool speedValue) implemented in module.c
4553
    return;
4554
}
4555

  
4556
void port_set_dw1000_fastrate(){ // replaced with setHighSpeed_SPI(bool speedValue) implemented in module.c
4557
    return;
4558
}
4559

  
4560 4547
void port_wakeup_dw1000_fast(){ // NOT SUPPORTED
4561
    return;
4548
  return;
4562 4549
}
4563 4550

  
4564 4551
uint32_t portGetTickCnt(){
4565
    return chVTGetSystemTimeX();
4552
  return chVTGetSystemTimeX();
4566 4553
}
4567 4554

  
4568 4555
//inline uint32_t portGetTickCnt(){
......
4571 4558

  
4572 4559

  
4573 4560
void port_DisableEXT_IRQ(void){   
4574
   nvicDisableVector(DW1000_EXTI_IRQn);
4561
  nvicDisableVector(DW1000_EXTI_IRQn);
4575 4562

  
4576 4563
}
4577 4564

  
4578 4565
void port_EnableEXT_IRQ(void){    
4579
    nvicEnableVector(DW1000_EXTI_IRQn, STM32_IRQ_EXTI10_15_PRIORITY);
4566
  nvicEnableVector(DW1000_EXTI_IRQn, STM32_IRQ_EXTI10_15_PRIORITY);
4580 4567
}
4581 4568

  
4582 4569

  
4583
ITStatus port_GetEXT_IRQStatus(void){
4584
  ITStatus bitstatus = RESET;
4585
  //  uint32_t enablestatus = 0;
4570
decaIrqStatus_t port_GetEXT_IRQStatus(void){
4571
  decaIrqStatus_t bitstatus = RESET;
4586 4572

  
4587 4573
  if(NVIC_GetActive(DW1000_EXTI_IRQn)|| NVIC_GetPendingIRQ(DW1000_EXTI_IRQn)){
4588 4574
    //  if(NVIC_GetPendingIRQ(EXTI15_10_IRQn)){ //if the interrupt is pending (background )
4589 4575
    bitstatus = SET; //Interrupt is active or panding
4590 4576
  }
4591 4577
  else {
4592
    bitstatus = RESET; //Currently there is no interrupt IRQ
4578
    bitstatus = RESET; //No interrupt IRQ at the moment
4593 4579
  }
4594 4580

  
4595 4581
  return bitstatus;
4596 4582
}
4597 4583

  
4598

  
4599

  
4600 4584
#endif /* defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1) */

Also available in: Unified diff