Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-F103RB / module.c @ 7e674331

History | View | Annotate | Download (9.851 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 4c72a54c Thomas Schöpping
#include <amiroos.h>
28 f4da707a Thomas Schöpping
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 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
53 deaaa47e Cung Sang
/*! SPI (high and low speed) configuration for DW1000 */
54
SPIConfig moduleHalSpiUwbHsConfig = {
55
  /* circular buffer mode        */ false,
56
  /* callback function pointer   */ NULL,
57
  /* chip select line port       */ GPIOB,
58
  /* chip select line pad number */ GPIOB_PIN12,
59
  /* CR1                         */ 0,
60
  /* CR2                         */ 0,
61
};
62
63
SPIConfig moduleHalSpiUwbLsConfig = {
64
  /* circular buffer mode        */ false,
65
  /* callback function pointer   */ NULL,
66
  /* chip select line port       */ GPIOB,
67
  /* chip select line pad number */ GPIOB_PIN12,
68
  /* CR1                         */ SPI_CR1_BR_1 | SPI_CR1_BR_0,
69
  /* CR2                         */ 0,
70
};
71 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
72 deaaa47e Cung Sang
73 f4da707a Thomas Schöpping
/** @} */
74
75
/*===========================================================================*/
76
/**
77
 * @name GPIO definitions
78
 * @{
79
 */
80
/*===========================================================================*/
81
82
/**
83
 * @brief   LED output signal GPIO.
84
 */
85
static apalGpio_t _gpioLed = {
86 4c72a54c Thomas Schöpping
  /* line */ LINE_LED_GREEN,
87 f4da707a Thomas Schöpping
};
88
ROMCONST apalControlGpio_t moduleGpioLed = {
89
  /* GPIO */ &_gpioLed,
90
  /* meta */ {
91
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
92
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
93
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
94
  },
95
};
96
97 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
98 deaaa47e Cung Sang
/**
99
 * @brief   DW1000 reset output signal GPIO.
100
 */
101
static apalGpio_t _gpioDw1000Reset = {
102 8d4d058e Cung Sang
  /* line */ LINE_ARD_D15, //PAL_LINE(GPIOA, GPIOA_ARD_A0)
103 deaaa47e Cung Sang
};
104
ROMCONST apalControlGpio_t moduleGpioDw1000Reset = {
105
  /* GPIO */ &_gpioDw1000Reset,
106
  /* meta */ {
107
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
108
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
109
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
110
  },
111
};
112
113
114
/**
115
 * @brief   DW1000 interrrupt input signal GPIO.
116
 */
117
static apalGpio_t _gpioDw1000Irqn = {
118 8d4d058e Cung Sang
  /* line */ LINE_ARD_D14,  // PAL_LINE(GPIOB, GPIOB_ARD_D6)
119 deaaa47e Cung Sang
};
120
ROMCONST apalControlGpio_t moduleGpioDw1000Irqn = {
121
  /* GPIO */ &_gpioDw1000Irqn,
122
  /* meta */ {
123
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
124
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
125
    /* interrupt edge */ APAL_GPIO_EDGE_RISING,
126
  },
127
};
128
129
130
/**
131
 * @brief   DW1000 SPI chip select output signal GPIO.
132
 */
133
static apalGpio_t _gpioSpiChipSelect = {
134 3106e8cc Thomas Schöpping
  /* line */ PAL_LINE(GPIOB, GPIOB_PIN12),
135 deaaa47e Cung Sang
};
136
ROMCONST apalControlGpio_t moduleGpioSpiChipSelect = {
137
  /* GPIO */ &_gpioSpiChipSelect,
138
  /* meta */ {
139
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
140
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
141
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
142
  },
143
};
144 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
145 deaaa47e Cung Sang
146 f4da707a Thomas Schöpping
/**
147
 * @brief   User button input signal GPIO.
148
 */
149
static apalGpio_t _gpioUserButton = {
150 4c72a54c Thomas Schöpping
  /* line */ LINE_BUTTON,
151 f4da707a Thomas Schöpping
};
152
ROMCONST apalControlGpio_t moduleGpioUserButton = {
153
  /* GPIO */ &_gpioUserButton,
154
  /* meta */ {
155
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
156
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
157
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
158
  },
159
};
160
161
/** @} */
162
163
/*===========================================================================*/
164
/**
165
 * @name AMiRo-OS core configurations
166
 * @{
167
 */
168
/*===========================================================================*/
169
170
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
171
ROMCONST char* moduleShellPrompt = "NUCLEO-F103RB";
172 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
173 f4da707a Thomas Schöpping
174
/** @} */
175
176
/*===========================================================================*/
177
/**
178
 * @name Startup Shutdown Synchronization Protocol (SSSP)
179
 * @{
180
 */
181
/*===========================================================================*/
182
183 4c72a54c Thomas Schöpping
/** @} */
184 deaaa47e Cung Sang
185
/*===========================================================================*/
186
/**
187
 * @name Hardware specific wrappers Functions
188
 * @{
189
 */
190
/*===========================================================================*/
191
192 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
193 deaaa47e Cung Sang
/*! @brief TODO: Manual implementation of SPI configuration. Somehow, it is necessary in NUCLEO-F103RB  */
194
void dw1000_spi_init(void){
195
  palSetPadMode(GPIOB, GPIOB_PIN13, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
196
  palSetPadMode(GPIOB, GPIOB_PIN14, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
197
  palSetPadMode(GPIOB, GPIOB_PIN15, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
198 3106e8cc Thomas Schöpping
  palSetLineMode(moduleGpioSpiChipSelect.gpio->line, PAL_MODE_OUTPUT_PUSHPULL);
199 deaaa47e Cung Sang
  apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW);
200
}
201
202 8d4d058e Cung Sang
/*! @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
/*! @brief Check the current value of GPIO pin and return the value */
213
apalGpioState_t port_CheckEXT_IRQ(void) {
214
  apalGpioState_t  val;
215
  apalGpioRead(moduleGpioDw1000Irqn.gpio, &val);
216
  return val;
217
}
218
219
/*! @brief Manually set the chip select pin of the SPI */
220
void set_SPI_chip_select(void){
221
  apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_HIGH);
222
}
223
224
/*! @brief Manually reset the chip select pin of the SPI */
225
void clear_SPI_chip_select(void){
226
  apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW);
227
}
228
229
/*! @brief Change the SPI speed configuration on the fly */
230
void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv){
231
232
  spiStop(drv->spid);
233
234
  if (speedValue == FALSE){
235
    spiStart(drv->spid, &moduleHalSpiUwbLsConfig);  // low speed spi configuration
236
  }
237
  else{
238
    spiStart(drv->spid, &moduleHalSpiUwbHsConfig); // high speed spi configuration
239
  }
240
}
241 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
242 f4da707a Thomas Schöpping
/** @} */
243
244
/*===========================================================================*/
245
/**
246
 * @name Low-level drivers
247
 * @{
248
 */
249
/*===========================================================================*/
250
251 4c72a54c Thomas Schöpping
LEDDriver moduleLldLed = {
252
  /* LED enable Gpio */ &moduleGpioLed,
253
};
254
255
ButtonDriver moduleLldUserButton = {
256
  /* Button Gpio  */ &moduleGpioUserButton,
257
};
258
259
#if (BOARD_DW1000_CONNECTED == true)
260 deaaa47e Cung Sang
DW1000Driver moduleLldDw1000 = {
261
  /* SPI driver         */ &MODULE_HAL_SPI_UWB,
262
  /* ext interrupt      */ &moduleGpioDw1000Irqn,
263
  /* RESET DW1000       */ &moduleGpioDw1000Reset,
264
};
265 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
266
267 f4da707a Thomas Schöpping
/** @} */
268
269
/*===========================================================================*/
270
/**
271 4c72a54c Thomas Schöpping
 * @name Tests
272 f4da707a Thomas Schöpping
 * @{
273
 */
274
/*===========================================================================*/
275
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
276
277 4c72a54c Thomas Schöpping
/*
278
 * LED
279
 */
280
#include <module_test_LED.h>
281
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
282
{
283
  return moduleTestLedShellCb(stream, argc, argv, NULL);
284
}
285
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:LED", _testLedShellCmdCb);
286
287
/*
288
 * User button
289
 */
290
#include <module_test_button.h>
291
static int _testButtonShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
292
{
293
  return moduleTestButtonShellCb(stream, argc, argv, NULL);
294
}
295
AOS_SHELL_COMMAND(moduleTestButtonShellCmd, "test:button", _testButtonShellCmdCb);
296
297
#if (BOARD_DW1000_CONNECTED == true) || defined(__DOXYGEN__)
298 deaaa47e Cung Sang
/*
299
 * UwB Driver (DW1000)
300
 */
301 8d4d058e Cung Sang
#include <module_test_DW1000.h>
302
static int _testDw1000ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
303 deaaa47e Cung Sang
{
304 8d4d058e Cung Sang
  return moduleTestDw1000ShellCb(stream, argc, argv, NULL);
305 deaaa47e Cung Sang
}
306 8d4d058e Cung Sang
AOS_SHELL_COMMAND(moduleTestDw1000ShellCmd, "test:DW1000", _testDw1000ShellCmdCb);
307 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
308
309
/*
310
 * entire module
311
 */
312
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
313
{
314
  (void)argc;
315
  (void)argv;
316
317
  int status = AOS_OK;
318
  char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL};
319
  aos_testresult_t result_test = {0, 0};
320
  aos_testresult_t result_total = {0, 0};
321
322
  /* LED */
323
  status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
324
  result_total = aosTestResultAdd(result_total, result_test);
325
326
  /* User button */
327
  status |= moduleTestButtonShellCb(stream, 0, targv, &result_test);
328
  result_total = aosTestResultAdd(result_total, result_test);
329
330 8d4d058e Cung Sang
#if (BOARD_DW1000_CONNECTED == true) || defined(__DOXYGEN__)
331 4c72a54c Thomas Schöpping
  /* DW1000 */
332 8d4d058e Cung Sang
  status |= moduleTestDw1000ShellCb(stream, 0, targv, &result_test);
333
  result_total = aosTestResultAdd(result_total, result_test);
334
#endif /* (BOARD_DW1000_CONNECTED == true) */
335 4c72a54c Thomas Schöpping
336
  // print total result
337
  chprintf(stream, "\n");
338
  aosTestResultPrintSummary(stream, &result_total, "entire module");
339
340
  return status;
341
}
342
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
343 deaaa47e Cung Sang
344 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
345 f4da707a Thomas Schöpping
346
/** @} */
347
/** @} */