Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-F103RB / module.c @ ed19a68b

History | View | Annotate | Download (7.567 KB)

1 f4da707a Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed 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 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 General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
/**
20
 * @file
21
 * @brief   Structures and constant for the NUCLEO-F103RB module.
22
 *
23
 * @addtogroup NUCLEO-F103RB_module
24
 * @{
25
 */
26
27
#include "module.h"
28
29
/*===========================================================================*/
30
/**
31
 * @name Module specific functions
32
 * @{
33
 */
34
/*===========================================================================*/
35
36
/** @} */
37
38
/*===========================================================================*/
39
/**
40
 * @name ChibiOS/HAL configuration
41
 * @{
42
 */
43
/*===========================================================================*/
44
45
SerialConfig moduleHalProgIfConfig = {
46
  /* bit rate */ 115200,
47
  /* CR1      */ 0,
48
  /* CR1      */ 0,
49
  /* CR1      */ 0,
50
};
51
52 deaaa47e Cung Sang
#ifdef AMIROLLD_CFG_DW1000
53
54
/*! SPI (high and low speed) configuration for DW1000 */
55
SPIConfig moduleHalSpiUwbHsConfig = {
56
  /* circular buffer mode        */ false,
57
  /* callback function pointer   */ NULL,
58
  /* chip select line port       */ GPIOB,
59
  /* chip select line pad number */ GPIOB_PIN12,
60
  /* CR1                         */ 0,
61
  /* CR2                         */ 0,
62
};
63
64
SPIConfig moduleHalSpiUwbLsConfig = {
65
  /* circular buffer mode        */ false,
66
  /* callback function pointer   */ NULL,
67
  /* chip select line port       */ GPIOB,
68
  /* chip select line pad number */ GPIOB_PIN12,
69
  /* CR1                         */ SPI_CR1_BR_1 | SPI_CR1_BR_0,
70
  /* CR2                         */ 0,
71
};
72
73
#endif
74
75 f4da707a Thomas Schöpping
/** @} */
76
77
/*===========================================================================*/
78
/**
79
 * @name GPIO definitions
80
 * @{
81
 */
82
/*===========================================================================*/
83
84
/**
85
 * @brief   LED output signal GPIO.
86
 */
87
static apalGpio_t _gpioLed = {
88
  /* port */ GPIOA,
89
  /* pad  */ GPIOA_LED_GREEN,
90
};
91
ROMCONST apalControlGpio_t moduleGpioLed = {
92
  /* GPIO */ &_gpioLed,
93
  /* meta */ {
94
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
95
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
96
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
97
  },
98
};
99
100 deaaa47e Cung Sang
#ifdef AMIROLLD_CFG_DW1000
101
102
/**
103
 * @brief   DW1000 reset output signal GPIO.
104
 */
105
static apalGpio_t _gpioDw1000Reset = {
106
  /* port */ GPIOA,
107
  /* pad  */ GPIOA_ARD_A0,   // PIN0
108
};
109
ROMCONST apalControlGpio_t moduleGpioDw1000Reset = {
110
  /* GPIO */ &_gpioDw1000Reset,
111
  /* meta */ {
112
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
113
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
114
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
115
  },
116
};
117
118
119
/**
120
 * @brief   DW1000 interrrupt input signal GPIO.
121
 */
122
static apalGpio_t _gpioDw1000Irqn = {
123
  /* port */ GPIOB,
124
  /* pad  */ GPIOB_ARD_D6,  // GPIOB_PIN10
125
};
126
ROMCONST apalControlGpio_t moduleGpioDw1000Irqn = {
127
  /* GPIO */ &_gpioDw1000Irqn,
128
  /* meta */ {
129
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
130
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
131
    /* interrupt edge */ APAL_GPIO_EDGE_RISING,
132
  },
133
};
134
135
136
/**
137
 * @brief   DW1000 SPI chip select output signal GPIO.
138
 */
139
static apalGpio_t _gpioSpiChipSelect = {
140
  /* port */ GPIOB,
141
  /* pad  */ GPIOB_PIN12,  // GPIOB_PIN10
142
};
143
ROMCONST apalControlGpio_t moduleGpioSpiChipSelect = {
144
  /* GPIO */ &_gpioSpiChipSelect,
145
  /* meta */ {
146
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
147
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
148
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
149
  },
150
};
151
152
#endif /* AMIROLLD_CFG_DW1000 */
153
154 f4da707a Thomas Schöpping
/**
155
 * @brief   User button input signal GPIO.
156
 */
157
static apalGpio_t _gpioUserButton = {
158
  /* port */ GPIOC,
159
  /* pad  */ GPIOC_BUTTON,
160
};
161
ROMCONST apalControlGpio_t moduleGpioUserButton = {
162
  /* GPIO */ &_gpioUserButton,
163
  /* meta */ {
164
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
165
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
166
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
167
  },
168
};
169
170
/** @} */
171
172
/*===========================================================================*/
173
/**
174
 * @name AMiRo-OS core configurations
175
 * @{
176
 */
177
/*===========================================================================*/
178
179
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
180
ROMCONST char* moduleShellPrompt = "NUCLEO-F103RB";
181
#endif
182
183
/** @} */
184
185
/*===========================================================================*/
186
/**
187
 * @name Startup Shutdown Synchronization Protocol (SSSP)
188
 * @{
189
 */
190
/*===========================================================================*/
191
192 deaaa47e Cung Sang
193
/*===========================================================================*/
194
/**
195
 * @name Hardware specific wrappers Functions
196
 * @{
197
 */
198
/*===========================================================================*/
199
200
#ifdef AMIROLLD_CFG_DW1000
201
202
/*! @brief entry point to the IRQn event in DW1000 module
203
 *
204
 * */
205
void process_deca_irq(void){
206
  do{
207
    dwt_isr();
208
    //while IRS line active (ARM can only do edge sensitive interrupts)
209
  }while(port_CheckEXT_IRQ() == 1);
210
}
211
212
213
/*! @brief Check the current value of GPIO pin and return the value */
214
apalGpioState_t port_CheckEXT_IRQ(void) {
215
  apalGpioState_t  val;
216
  apalGpioRead(moduleGpioDw1000Irqn.gpio, &val);
217
  return val;
218
}
219
220
221
/*! @brief TODO: Manual implementation of SPI configuration. Somehow, it is necessary in NUCLEO-F103RB  */
222
void dw1000_spi_init(void){
223
  palSetPadMode(GPIOB, GPIOB_PIN13, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
224
  palSetPadMode(GPIOB, GPIOB_PIN14, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
225
  palSetPadMode(GPIOB, GPIOB_PIN15, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
226
  palSetPadMode(moduleGpioSpiChipSelect.gpio->port, moduleGpioSpiChipSelect.gpio->pad, PAL_MODE_OUTPUT_PUSHPULL);
227
  apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW);
228
}
229
230
#endif /* AMIROLLD_CFG_DW1000 */
231 f4da707a Thomas Schöpping
/** @} */
232
233
/*===========================================================================*/
234
/**
235
 * @name Low-level drivers
236
 * @{
237
 */
238
/*===========================================================================*/
239
240 deaaa47e Cung Sang
#ifdef AMIROLLD_CFG_DW1000
241
242
DW1000Driver moduleLldDw1000 = {
243
  /* SPI driver         */ &MODULE_HAL_SPI_UWB,
244
  /* ext interrupt      */ &moduleGpioDw1000Irqn,
245
  /* RESET DW1000       */ &moduleGpioDw1000Reset,
246
};
247
248
#endif /* AMIROLLD_CFG_DW1000 */
249 f4da707a Thomas Schöpping
/** @} */
250
251
/*===========================================================================*/
252
/**
253
 * @name Unit tests (UT)
254
 * @{
255
 */
256
/*===========================================================================*/
257
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
258
259 deaaa47e Cung Sang
#ifdef AMIROLLD_CFG_DW1000
260
261
/*
262
 * UwB Driver (DW1000)
263
 */
264
static int _utShellCmdCb_Dw1000(BaseSequentialStream* stream, int argc, char* argv[])
265
{
266
  (void)argc;
267
  (void)argv;
268
  aosUtRun(stream, &moduleUtAlldDw1000, NULL);
269
  return AOS_OK;
270
}
271
aos_unittest_t moduleUtAlldDw1000 = {
272
  /* info           */ "DW1000",
273
  /* name           */ "UWB System",
274
  /* test function  */ utAlldDw1000Func,
275
  /* shell command  */ {
276
    /* name     */ "unittest:Uwb",
277
    /* callback */ _utShellCmdCb_Dw1000,
278
    /* next     */ NULL,
279
  },
280
  /* data           */ &moduleLldDw1000,
281
};
282
#endif /* AMIROLLD_CFG_DW1000 */
283
284 f4da707a Thomas Schöpping
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
285
286
/** @} */
287
/** @} */