Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / DW1000 / v2 / alld_DW1000.c @ df051abd

History | View | Annotate | Download (3.661 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
/**
20
 * @file    alld_DW1000.c
21
 * @brief   UWB transceiver function implementations.
22
 *
23
 * @addtogroup lld_uwb
24
 * @{
25
 */
26

    
27
#include <alld_DW1000.h>
28
#include "decadriver/deca_device_api.h"
29
#include <string.h>
30

    
31
/******************************************************************************/
32
/* LOCAL DEFINITIONS                                                          */
33
/******************************************************************************/
34

    
35
/******************************************************************************/
36
/* EXPORTED VARIABLES                                                         */
37
/******************************************************************************/
38

    
39
/******************************************************************************/
40
/* LOCAL TYPES                                                                */
41
/******************************************************************************/
42

    
43
/******************************************************************************/
44
/* LOCAL VARIABLES                                                            */
45
/******************************************************************************/
46

    
47
/******************************************************************************/
48
/* LOCAL FUNCTIONS                                                            */
49
/******************************************************************************/
50

    
51
/******************************************************************************/
52
/* EXPORTED FUNCTIONS                                                         */
53
/******************************************************************************/
54

    
55
int writetospi(uint16 headerLength, const uint8 *headerBuffer, uint32 bodylength, const uint8 *bodyBuffer)
56
{
57
  apalDbgAssert(dw1000.spid != NULL);
58
  apalDbgAssert(headerLength + bodylength <= DW1000_LLD_SPIBUFLEN);
59

    
60
  uint8_t buffer[DW1000_LLD_SPIBUFLEN];
61
  memcpy(&buffer[0], headerBuffer, headerLength);
62
  memcpy(&buffer[headerLength], bodyBuffer, bodylength);
63

    
64
  return (apalSPITransmit(dw1000.spid, buffer, headerLength + bodylength) == APAL_STATUS_OK) ? 0 : -1;
65
}
66

    
67
int readfromspi(uint16 headerLength, const uint8 *headerBuffer, uint32 readlength, uint8 *readBuffer)
68
{
69
  apalDbgAssert(dw1000.spid != NULL);
70

    
71
  return (apalSPITransmitAndReceive(dw1000.spid, headerBuffer, readBuffer, headerLength, readlength) == APAL_STATUS_OK) ? 0 : -1;
72
}
73

    
74
decaIrqStatus_t decamutexon(void)
75
{
76
  apalDbgAssert(dw1000.gpio_exti != NULL);
77

    
78
  bool enabled;
79
  apalGpioIsInterruptEnabled(dw1000.gpio_exti->gpio, &enabled);
80
  if (enabled) {
81
    apalControlGpioSetInterrupt(dw1000.gpio_exti, false);
82
  }
83

    
84
  return enabled;
85
}
86

    
87
void decamutexoff(decaIrqStatus_t s)
88
{
89
  apalDbgAssert(dw1000.gpio_exti != NULL);
90

    
91
  if (s) {
92
    apalControlGpioSetInterrupt(dw1000.gpio_exti, true);
93
  }
94

    
95
  return;
96
}
97

    
98
void deca_sleep(unsigned int time_ms)
99
{
100
  apalSleep((apalTime_t)time_ms * 1000);
101
  return;
102
}
103

    
104
/** @} */
105