Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-F103RB / module.h @ 9d8f1b9e

History | View | Annotate | Download (11.188 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 6ff06bbf Thomas Schöpping
#ifndef AMIROOS_MODULE_H
28
#define AMIROOS_MODULE_H
29 f4da707a Thomas Schöpping
30
#include <amiroos.h>
31
32
/*===========================================================================*/
33
/**
34
 * @name Module specific functions
35
 * @{
36
 */
37
/*===========================================================================*/
38
39 7de0cc90 Thomas Schöpping
#if defined(__cplusplus)
40 deaaa47e Cung Sang
extern "C" {
41 7de0cc90 Thomas Schöpping
#endif /* defined(__cplusplus) */
42 deaaa47e Cung Sang
43 8d4d058e Cung Sang
#if (BOARD_DW1000_CONNECTED == true)
44 deaaa47e Cung Sang
void dw1000_spi_init(void);
45 8d4d058e Cung Sang
void process_deca_irq(void);
46
apalGpioState_t port_CheckEXT_IRQ(void) ;
47
#endif /* (BOARD_DW1000_CONNECTED == true) */
48
49
void set_SPI_chip_select(void);
50
void clear_SPI_chip_select(void);
51 3cee92c7 Cung Sang
void reset_DW1000(void);
52 deaaa47e Cung Sang
53 7de0cc90 Thomas Schöpping
#if defined(__cplusplus)
54 deaaa47e Cung Sang
}
55 7de0cc90 Thomas Schöpping
#endif /* defined(__cplusplus) */
56 deaaa47e Cung Sang
57 f4da707a Thomas Schöpping
/** @} */
58
59
/*===========================================================================*/
60
/**
61
 * @name ChibiOS/HAL configuration
62
 * @{
63
 */
64
/*===========================================================================*/
65
66
/**
67
 * @brief   Serial driver of the programmer interface.
68
 */
69
#define MODULE_HAL_PROGIF                       SD2
70
71
/**
72
 * @brief   Configuration for the programmer serial interface driver.
73
 */
74
extern SerialConfig moduleHalProgIfConfig;
75
76
/**
77
 * @brief   Real-Time Clock driver.
78
 */
79
#define MODULE_HAL_RTC                          RTCD1
80
81 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
82 deaaa47e Cung Sang
/**
83
 * @brief   SPI interface driver for the motion sensors (gyroscope and accelerometer).
84
 */
85
#define MODULE_HAL_SPI_UWB                      SPID2
86
87
/**
88
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
89
 */
90
extern SPIConfig moduleHalSpiUwbHsConfig;
91
92
/**
93
 * @brief   Configuration for the SPI interface driver to communicate with the wireless transceiver.
94
 */
95
extern SPIConfig moduleHalSpiUwbLsConfig;
96 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
97 deaaa47e Cung Sang
98 f4da707a Thomas Schöpping
/** @} */
99
100
/*===========================================================================*/
101
/**
102
 * @name GPIO definitions
103
 * @{
104
 */
105
/*===========================================================================*/
106
107
/**
108
 * @brief   LED output signal GPIO.
109
 */
110
extern ROMCONST apalControlGpio_t moduleGpioLed;
111
112 8d4d058e Cung Sang
//#if (BOARD_DW1000_CONNECTED == true)
113 deaaa47e Cung Sang
/**
114
 * @brief   DW1000 reset output signal
115
 * @note    the reset pin should be drived as low by MCU to activate.
116
 *          Then, put back the reset pin as input to MCU (tri-state float on the air
117
 *          is not supported in AMiRo)
118
 */
119
extern ROMCONST apalControlGpio_t moduleGpioDw1000Reset;
120
121
/**
122
 * @brief   DW1000 interrupt IRQn input signal.
123
 */
124
extern ROMCONST apalControlGpio_t moduleGpioDw1000Irqn;
125
126
/**
127
 * @brief   DW1000 SPI chip select  output signal.
128
 */
129
extern ROMCONST apalControlGpio_t moduleGpioSpiChipSelect ;
130 8d4d058e Cung Sang
//#endif /* (BOARD_DW1000_CONNECTED == true) */
131 deaaa47e Cung Sang
132 f4da707a Thomas Schöpping
/**
133
 * @brief   User button input signal.
134
 */
135
extern ROMCONST apalControlGpio_t moduleGpioUserButton;
136
137
/** @} */
138
139
/*===========================================================================*/
140
/**
141
 * @name AMiRo-OS core configurations
142
 * @{
143
 */
144
/*===========================================================================*/
145
146 8d4d058e Cung Sang
//#if (BOARD_DW1000_CONNECTED == true)
147 f4da707a Thomas Schöpping
/**
148 deaaa47e Cung Sang
 * @brief   Event flag to be call dwt_isr() interrupt.
149
 */
150 cda14729 Thomas Schöpping
#define MODULE_OS_GPIOEVENTFLAG_DW1000_IRQn     AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_ARD_D14))
151 8d4d058e Cung Sang
//#endif /* (BOARD_DW1000_CONNECTED == true) */
152 4c72a54c Thomas Schöpping
153 deaaa47e Cung Sang
/**
154 f4da707a Thomas Schöpping
 * @brief   Event flag to be set on a USER_BUTTON interrupt.
155
 */
156 cda14729 Thomas Schöpping
#define MODULE_OS_GPIOEVENTFLAG_USERBUTTON      AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_BUTTON))
157 f4da707a Thomas Schöpping
158 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
159 f4da707a Thomas Schöpping
/**
160
 * @brief   Shell prompt text.
161
 */
162
extern ROMCONST char* moduleShellPrompt;
163 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
164 f4da707a Thomas Schöpping
165
/**
166
 * @brief   Interrupt initialization macro.
167
 */
168
#define MODULE_INIT_INTERRUPTS() {                                            \
169
  /* user button */                                                           \
170 cda14729 Thomas Schöpping
  palSetLineCallback(moduleGpioUserButton.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioUserButton.gpio->line);  \
171 56dc4779 Thomas Schöpping
  palEnableLineEvent(moduleGpioUserButton.gpio->line, APAL2CH_EDGE(moduleGpioUserButton.meta.edge));                  \
172 deaaa47e Cung Sang
  MODULE_INIT_INTERRUPTS_DW1000();                                            \
173 f4da707a Thomas Schöpping
}
174 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
175 deaaa47e Cung Sang
  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
176 cda14729 Thomas Schöpping
    palSetLineCallback(moduleGpioDw1000Irqn.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioDw1000Irqn.gpio->line);  \
177 56dc4779 Thomas Schöpping
    palEnableLineEvent(moduleGpioDw1000Irqn.gpio->line, APAL2CH_EDGE(moduleGpioDw1000Irqn.meta.edge));                  \
178 deaaa47e Cung Sang
  }
179 4c72a54c Thomas Schöpping
#else /* (BOARD_DW1000_CONNECTED == true) */
180 7de0cc90 Thomas Schöpping
  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
181 deaaa47e Cung Sang
  }
182 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
183 deaaa47e Cung Sang
184 f4da707a Thomas Schöpping
185
/**
186 4c72a54c Thomas Schöpping
 * @brief   Test initialization hook.
187 f4da707a Thomas Schöpping
 */
188
#define MODULE_INIT_TESTS() {                                                 \
189 cda14729 Thomas Schöpping
  /* add test commands to shell */                                            \
190 4c72a54c Thomas Schöpping
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
191
  aosShellAddCommand(&aos.shell, &moduleTestButtonShellCmd);                  \
192 deaaa47e Cung Sang
  MODULE_INIT_TESTS_DW1000();                                                 \
193 4c72a54c Thomas Schöpping
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
194 f4da707a Thomas Schöpping
}
195 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
196 deaaa47e Cung Sang
  #define MODULE_INIT_TESTS_DW1000() {                                        \
197 4c72a54c Thomas Schöpping
    aosShellAddCommand(&aos.shell, &moduleTestDw1000ShellCmd);                \
198 deaaa47e Cung Sang
  }
199 4c72a54c Thomas Schöpping
#else /* (BOARD_DW1000_CONNECTED == true) */
200 7de0cc90 Thomas Schöpping
  #define MODULE_INIT_TESTS_DW1000() {                                        \
201 deaaa47e Cung Sang
  }
202 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
203 deaaa47e Cung Sang
204 f4da707a Thomas Schöpping
205
/**
206
 * @brief   Periphery communication interfaces initialization hook.
207
 */
208 4c72a54c Thomas Schöpping
#define MODULE_INIT_PERIPHERY_IF() {                                          \
209 f4da707a Thomas Schöpping
  /* serial driver */                                                         \
210
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
211 4c72a54c Thomas Schöpping
  MODULE_INIT_PERIPHERY_IF_DW1000();                                          \
212 f4da707a Thomas Schöpping
}
213 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
214
  #define MODULE_INIT_PERIPHERY_IF_DW1000() {                                 \
215 deaaa47e Cung Sang
    /* SPI init */                                                            \
216
    dw1000_spi_init();                                                        \
217
    spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbLsConfig);                  \
218
  }
219 4c72a54c Thomas Schöpping
#else /* (BOARD_DW1000_CONNECTED == true) */
220
  #define MODULE_INIT_PERIPHERY_IF_DW1000() {                                 \
221 deaaa47e Cung Sang
  }
222 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
223 deaaa47e Cung Sang
224 f4da707a Thomas Schöpping
225
/**
226
 * @brief   Periphery communication interface deinitialization hook.
227
 */
228 4c72a54c Thomas Schöpping
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
229
  MODULE_SHUTDOWN_PERIPHERY_IF_DW1000();                                      \
230 cda14729 Thomas Schöpping
  /* don't stop the serial driver so messages can still be printed */         \
231 deaaa47e Cung Sang
}
232 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
233
#define MODULE_SHUTDOWN_PERIPHERY_IF_DW1000() {                               \
234 deaaa47e Cung Sang
  /* SPI */                                                                   \
235
  spiStop(&MODULE_HAL_SPI_UWB);                                               \
236 f4da707a Thomas Schöpping
}
237 4c72a54c Thomas Schöpping
#else /* (BOARD_DW1000_CONNECTED == true) */
238
  #define MODULE_SHUTDOWN_PERIPHERY_IF_DW1000() {                             \
239 deaaa47e Cung Sang
  }
240 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
241 f4da707a Thomas Schöpping
242
/**
243 4c72a54c Thomas Schöpping
 * @brief   HOOK to toggle the LEDs when the user button is pressed.
244 f4da707a Thomas Schöpping
 */
245 cda14729 Thomas Schöpping
#define MODULE_MAIN_LOOP_GPIOEVENT(eventflags) {                              \
246
  if (eventflags & MODULE_OS_GPIOEVENTFLAG_USERBUTTON) {                      \
247 f4da707a Thomas Schöpping
    apalControlGpioState_t buttonstate;                                       \
248
    apalControlGpioGet(&moduleGpioUserButton, &buttonstate);                  \
249
    apalControlGpioSet(&moduleGpioLed, buttonstate);                          \
250
  }                                                                           \
251 cda14729 Thomas Schöpping
  MODULE_MAIN_LOOP_GPIOEVENT_DW1000();                                        \
252 f4da707a Thomas Schöpping
}
253 4c72a54c Thomas Schöpping
#if (BOARD_DW1000_CONNECTED == true)
254
  /**
255
   * @brief   HOOK to call process_deca_irq() func when the dw1000 interrupt pin is activated.
256
   */
257 cda14729 Thomas Schöpping
  #define MODULE_MAIN_LOOP_GPIOEVENT_DW1000() {                               \
258
    if(eventflags & MODULE_GPOS_IOEVENTFLAG_DW1000_IRQn) {                    \
259 8d4d058e Cung Sang
      /*apalGpioToggle(moduleGpioLed.gpio);*/ /* just for debug*/             \
260 deaaa47e Cung Sang
      process_deca_irq();                                                     \
261 7de0cc90 Thomas Schöpping
    }                                                                         \
262 deaaa47e Cung Sang
  }
263 4c72a54c Thomas Schöpping
#else /* (BOARD_DW1000_CONNECTED == true) */
264 cda14729 Thomas Schöpping
  #define MODULE_MAIN_LOOP_GPIOEVENT_DW1000() {                               \
265 deaaa47e Cung Sang
  }
266 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
267 f4da707a Thomas Schöpping
268
/** @} */
269
270
/*===========================================================================*/
271
/**
272
 * @name Startup Shutdown Synchronization Protocol (SSSP)
273
 * @{
274
 */
275
/*===========================================================================*/
276
277 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
278 c53ef0b1 Thomas Schöpping
  #error "SSSP is not supported on this module."
279 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
280
281 f4da707a Thomas Schöpping
/** @} */
282
283
/*===========================================================================*/
284
/**
285
 * @name Low-level drivers
286
 * @{
287
 */
288
/*===========================================================================*/
289 4c72a54c Thomas Schöpping
#include <alld_LED.h>
290
#include <alld_button.h>
291
292
/**
293
 * @brief   LED driver.
294
 */
295
extern LEDDriver moduleLldLed;
296
297
/**
298
 * @brief   Button driver.
299
 */
300
extern ButtonDriver moduleLldUserButton;
301
302
303 8d4d058e Cung Sang
/**
304
 * @brief   DW1000 driver.
305
 */
306 deaaa47e Cung Sang
#include <alld_DW1000.h>
307 8d4d058e Cung Sang
void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv);
308 deaaa47e Cung Sang
309 8d4d058e Cung Sang
#if (BOARD_DW1000_CONNECTED == true)
310 deaaa47e Cung Sang
extern DW1000Driver moduleLldDw1000;
311 4c72a54c Thomas Schöpping
#endif /* (BOARD_DW1000_CONNECTED == true) */
312 f4da707a Thomas Schöpping
313
/** @} */
314
315
/*===========================================================================*/
316
/**
317 4c72a54c Thomas Schöpping
 * @name Tests
318 f4da707a Thomas Schöpping
 * @{
319
 */
320
/*===========================================================================*/
321
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
322
323 4c72a54c Thomas Schöpping
/**
324
 * @brief   LED test command.
325
 */
326
extern aos_shellcommand_t moduleTestLedShellCmd;
327
328
/**
329
 * @brief   User button test command.
330
 */
331
extern aos_shellcommand_t moduleTestButtonShellCmd;
332
333
#if (BOARD_DW1000_CONNECTED == true)
334 deaaa47e Cung Sang
/**
335 4c72a54c Thomas Schöpping
 * @brief   DW1000 (UWB transmitter) test command.
336 deaaa47e Cung Sang
 */
337 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestDw1000ShellCmd;
338
#endif /* (BOARD_DW1000_CONNECTED == true) */
339
340
/**
341
 * @brief   Entire module test command.
342
 */
343
extern aos_shellcommand_t moduleTestAllShellCmd;
344 deaaa47e Cung Sang
345 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
346 f4da707a Thomas Schöpping
347
/** @} */
348
349 6ff06bbf Thomas Schöpping
#endif /* AMIROOS_MODULE_H */
350 f4da707a Thomas Schöpping
351
/** @} */