Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-F103RB / module.h @ b23ca7cc

History | View | Annotate | Download (10.854 KB)

1
/*
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
#ifndef AMIROOS_MODULE_H
28
#define AMIROOS_MODULE_H
29

    
30
#include <amiroos.h>
31

    
32
/*===========================================================================*/
33
/**
34
 * @name Module specific functions
35
 * @{
36
 */
37
/*===========================================================================*/
38

    
39
#if (BOARD_DW1000_CONNECTED == true)
40

    
41
#if defined(__cplusplus)
42
extern "C" {
43
#endif /* defined(__cplusplus) */
44

    
45
void dw1000_spi_init(void);
46

    
47
#if defined(__cplusplus)
48
}
49
#endif /* defined(__cplusplus) */
50

    
51
#endif /* (BOARD_DW1000_CONNECTED == true) */
52

    
53

    
54
/** @} */
55

    
56
/*===========================================================================*/
57
/**
58
 * @name ChibiOS/HAL configuration
59
 * @{
60
 */
61
/*===========================================================================*/
62

    
63
/**
64
 * @brief   Serial driver of the programmer interface.
65
 */
66
#define MODULE_HAL_PROGIF                       SD2
67

    
68
/**
69
 * @brief   Configuration for the programmer serial interface driver.
70
 */
71
extern SerialConfig moduleHalProgIfConfig;
72

    
73
/**
74
 * @brief   Real-Time Clock driver.
75
 */
76
#define MODULE_HAL_RTC                          RTCD1
77

    
78
#if (BOARD_DW1000_CONNECTED == true)
79

    
80
/**
81
 * @brief   SPI interface driver for the motion sensors (gyroscope and accelerometer).
82
 */
83
#define MODULE_HAL_SPI_UWB                      SPID2
84

    
85
/**
86
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
87
 */
88
extern SPIConfig moduleHalSpiUwbHsConfig;
89

    
90
/**
91
 * @brief   Configuration for the SPI interface driver to communicate with the wireless transceiver.
92
 */
93
extern SPIConfig moduleHalSpiUwbLsConfig;
94

    
95
#endif /* (BOARD_DW1000_CONNECTED == true) */
96

    
97
/** @} */
98

    
99
/*===========================================================================*/
100
/**
101
 * @name GPIO definitions
102
 * @{
103
 */
104
/*===========================================================================*/
105

    
106
/**
107
 * @brief   LED output signal GPIO.
108
 */
109
extern ROMCONST apalControlGpio_t moduleGpioLed;
110

    
111
#if (BOARD_DW1000_CONNECTED == true)
112

    
113
/**
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

    
131
#endif /* (BOARD_DW1000_CONNECTED == true) */
132

    
133
/**
134
 * @brief   User button input signal.
135
 */
136
extern ROMCONST apalControlGpio_t moduleGpioUserButton;
137

    
138
/** @} */
139

    
140
/*===========================================================================*/
141
/**
142
 * @name AMiRo-OS core configurations
143
 * @{
144
 */
145
/*===========================================================================*/
146

    
147
#if (BOARD_DW1000_CONNECTED == true)
148

    
149
/**
150
 * @brief   Event flag to be call dwt_isr() interrupt.
151
 */
152
#define MODULE_OS_IOEVENTFLAGS_DW1000_IRQn      AOS_IOEVENT_FLAG(PAL_PAD(LINE_ARD_D6))
153

    
154
#endif /* (BOARD_DW1000_CONNECTED == true) */
155

    
156
/**
157
 * @brief   Event flag to be set on a USER_BUTTON interrupt.
158
 */
159
#define MODULE_OS_IOEVENTFLAGS_USERBUTTON       AOS_IOEVENT_FLAG(PAL_PAD(LINE_BUTTON))
160

    
161
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
162
/**
163
 * @brief   Shell prompt text.
164
 */
165
extern ROMCONST char* moduleShellPrompt;
166
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
167

    
168
/**
169
 * @brief   Interrupt initialization macro.
170
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
171
 */
172
#define MODULE_INIT_INTERRUPTS() {                                            \
173
  /* user button */                                                           \
174
  palSetLineCallback(moduleGpioUserButton.gpio->line, aosSysGetStdIntCallback(), &moduleGpioUserButton.gpio->line); \
175
  palEnableLineEvent(moduleGpioUserButton.gpio->line, APAL2CH_EDGE(moduleGpioUserButton.meta.edge));                \
176
  MODULE_INIT_INTERRUPTS_DW1000();                                            \
177
}
178
#if (BOARD_DW1000_CONNECTED == true)
179
  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
180
    palSetLineCallback(moduleGpioDw1000Irqn.gpio->line, aosSysGetStdIntCallback(), &moduleGpioDw1000Irqn.gpio->line); \
181
    palEnableLineEvent(moduleGpioDw1000Irqn.gpio->line, APAL2CH_EDGE(moduleGpioDw1000Irqn.meta.edge));                \
182
  }
183
#else /* (BOARD_DW1000_CONNECTED == true) */
184
  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
185
  }
186
#endif /* (BOARD_DW1000_CONNECTED == true) */
187

    
188

    
189
/**
190
 * @brief   Test initialization hook.
191
 */
192
#define MODULE_INIT_TESTS() {                                                 \
193
  /* initialize tests and add to shell */                                     \
194
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
195
  aosShellAddCommand(&aos.shell, &moduleTestButtonShellCmd);                  \
196
  MODULE_INIT_TESTS_DW1000();                                                 \
197
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
198
}
199
#if (BOARD_DW1000_CONNECTED == true)
200
  #define MODULE_INIT_TESTS_DW1000() {                                        \
201
    aosShellAddCommand(&aos.shell, &moduleTestDw1000ShellCmd);                \
202
  }
203
#else /* (BOARD_DW1000_CONNECTED == true) */
204
  #define MODULE_INIT_TESTS_DW1000() {                                        \
205
  }
206
#endif /* (BOARD_DW1000_CONNECTED == true) */
207

    
208

    
209
/**
210
 * @brief   Periphery communication interfaces initialization hook.
211
 */
212
#define MODULE_INIT_PERIPHERY_IF() {                                          \
213
  /* serial driver */                                                         \
214
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
215
  MODULE_INIT_PERIPHERY_IF_DW1000();                                          \
216
}
217
#if (BOARD_DW1000_CONNECTED == true)
218
  #define MODULE_INIT_PERIPHERY_IF_DW1000() {                                 \
219
    /* SPI init */                                                            \
220
    dw1000_spi_init();                                                        \
221
    spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbLsConfig);                  \
222
  }
223
#else /* (BOARD_DW1000_CONNECTED == true) */
224
  #define MODULE_INIT_PERIPHERY_IF_DW1000() {                                 \
225
  }
226
#endif /* (BOARD_DW1000_CONNECTED == true) */
227

    
228

    
229
/**
230
 * @brief   Periphery communication interface deinitialization hook.
231
 */
232
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
233
  MODULE_SHUTDOWN_PERIPHERY_IF_DW1000();                                      \
234
}
235
#if (BOARD_DW1000_CONNECTED == true)
236
#define MODULE_SHUTDOWN_PERIPHERY_IF_DW1000() {                               \
237
  /* SPI */                                                                   \
238
  spiStop(&MODULE_HAL_SPI_UWB);                                               \
239
}
240
#else /* (BOARD_DW1000_CONNECTED == true) */
241
  #define MODULE_SHUTDOWN_PERIPHERY_IF_DW1000() {                             \
242
  }
243
#endif /* (BOARD_DW1000_CONNECTED == true) */
244

    
245
/**
246
 * @brief   HOOK to toggle the LEDs when the user button is pressed.
247
 */
248
#define MODULE_MAIN_LOOP_IO_EVENT(eventflags) {                               \
249
  if (eventflags & MODULE_OS_IOEVENTFLAGS_USERBUTTON) {                       \
250
    apalControlGpioState_t buttonstate;                                       \
251
    apalControlGpioGet(&moduleGpioUserButton, &buttonstate);                  \
252
    apalControlGpioSet(&moduleGpioLed, buttonstate);                          \
253
  }                                                                           \
254
  MODULE_MAIN_LOOP_IO_EVENT_DW1000();                                         \
255
}
256
#if (BOARD_DW1000_CONNECTED == true)
257
  /**
258
   * @brief   HOOK to call process_deca_irq() func when the dw1000 interrupt pin is activated.
259
   */
260
  #define MODULE_MAIN_LOOP_IO_EVENT_DW1000() {                                \
261
    if(eventflags & MODULE_OS_IOEVENTFLAGS_DW1000_IRQn) {                     \
262
      /*apalGpioToggle(moduleGpioLedGreen.gpio); // just for debug  */        \
263
      process_deca_irq();                                                     \
264
    }                                                                         \
265
  }
266
#else /* (BOARD_DW1000_CONNECTED == true) */
267
  #define MODULE_MAIN_LOOP_IO_EVENT_DW1000() {                                \
268
  }
269
#endif /* (BOARD_DW1000_CONNECTED == true) */
270

    
271
/** @} */
272

    
273
/*===========================================================================*/
274
/**
275
 * @name Startup Shutdown Synchronization Protocol (SSSP)
276
 * @{
277
 */
278
/*===========================================================================*/
279

    
280
/** @} */
281

    
282
/*===========================================================================*/
283
/**
284
 * @name Low-level drivers
285
 * @{
286
 */
287
/*===========================================================================*/
288
#include <alld_LED.h>
289
#include <alld_button.h>
290

    
291
/**
292
 * @brief   LED driver.
293
 */
294
extern LEDDriver moduleLldLed;
295

    
296
/**
297
 * @brief   Button driver.
298
 */
299
extern ButtonDriver moduleLldUserButton;
300

    
301
#if (BOARD_DW1000_CONNECTED == true)
302

    
303
#include <alld_DW1000.h>
304

    
305
extern DW1000Driver moduleLldDw1000;
306

    
307
#endif /* (BOARD_DW1000_CONNECTED == true) */
308

    
309
/** @} */
310

    
311
/*===========================================================================*/
312
/**
313
 * @name Tests
314
 * @{
315
 */
316
/*===========================================================================*/
317
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
318

    
319
/**
320
 * @brief   LED test command.
321
 */
322
extern aos_shellcommand_t moduleTestLedShellCmd;
323

    
324
/**
325
 * @brief   User button test command.
326
 */
327
extern aos_shellcommand_t moduleTestButtonShellCmd;
328

    
329
#if (BOARD_DW1000_CONNECTED == true)
330

    
331
/**
332
 * @brief   DW1000 (UWB transmitter) test command.
333
 */
334
extern aos_shellcommand_t moduleTestDw1000ShellCmd;
335

    
336
#endif /* (BOARD_DW1000_CONNECTED == true) */
337

    
338
/**
339
 * @brief   Entire module test command.
340
 */
341
extern aos_shellcommand_t moduleTestAllShellCmd;
342

    
343
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
344

    
345
/** @} */
346

    
347
#endif /* AMIROOS_MODULE_H */
348

    
349
/** @} */