Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (9.65 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
#ifdef AMIROLLD_CFG_DW1000
40

    
41
#ifdef __cplusplus
42
extern "C" {
43
#endif
44

    
45
apalGpioState_t port_CheckEXT_IRQ(void) ;
46

    
47
void dw1000_spi_init(void);
48

    
49
void process_deca_irq(void);
50

    
51

    
52
#ifdef __cplusplus
53
}
54
#endif
55

    
56
#endif /* AMIROLLD_CFG_DW1000 */
57

    
58

    
59
/** @} */
60

    
61
/*===========================================================================*/
62
/**
63
 * @name ChibiOS/HAL configuration
64
 * @{
65
 */
66
/*===========================================================================*/
67

    
68
/**
69
 * @brief   Serial driver of the programmer interface.
70
 */
71
#define MODULE_HAL_PROGIF                       SD2
72

    
73
/**
74
 * @brief   Configuration for the programmer serial interface driver.
75
 */
76
extern SerialConfig moduleHalProgIfConfig;
77

    
78
/**
79
 * @brief   Real-Time Clock driver.
80
 */
81
#define MODULE_HAL_RTC                          RTCD1
82

    
83

    
84
#ifdef AMIROLLD_CFG_DW1000
85

    
86
/**
87
 * @brief   SPI interface driver for the motion sensors (gyroscope and accelerometer).
88
 */
89
#define MODULE_HAL_SPI_UWB                      SPID2
90

    
91

    
92
/**
93
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
94
 */
95
extern SPIConfig moduleHalSpiUwbHsConfig;
96

    
97
/**
98
 * @brief   Configuration for the SPI interface driver to communicate with the wireless transceiver.
99
 */
100
extern SPIConfig moduleHalSpiUwbLsConfig;
101

    
102
#endif /* AMIROLLD_CFG_DW1000 */
103

    
104
/** @} */
105

    
106

    
107
/*===========================================================================*/
108
/**
109
 * @name GPIO definitions
110
 * @{
111
 */
112
/*===========================================================================*/
113

    
114
/**
115
 * @brief   LED output signal GPIO.
116
 */
117
extern ROMCONST apalControlGpio_t moduleGpioLed;
118

    
119
#ifdef AMIROLLD_CFG_DW1000
120
/**
121
 * @brief   DW1000 reset output signal
122
 * @note    the reset pin should be drived as low by MCU to activate.
123
 *          Then, put back the reset pin as input to MCU (tri-state float on the air
124
 *          is not supported in AMiRo)
125
 */
126
extern ROMCONST apalControlGpio_t moduleGpioDw1000Reset;
127

    
128
/**
129
 * @brief   DW1000 interrupt IRQn input signal.
130
 */
131
extern ROMCONST apalControlGpio_t moduleGpioDw1000Irqn;
132

    
133
/**
134
 * @brief   DW1000 SPI chip select  output signal.
135
 */
136
extern ROMCONST apalControlGpio_t moduleGpioSpiChipSelect ;
137

    
138
#endif /* AMIROLLD_CFG_DW1000 */
139

    
140
/**
141
 * @brief   User button input signal.
142
 */
143
extern ROMCONST apalControlGpio_t moduleGpioUserButton;
144

    
145
/** @} */
146

    
147
/*===========================================================================*/
148
/**
149
 * @name AMiRo-OS core configurations
150
 * @{
151
 */
152
/*===========================================================================*/
153

    
154
/**
155
 * @brief   Event flag to be call dwt_isr() interrupt.
156
 */
157
#define MODULE_OS_IOEVENTFLAGS_DW1000_IRQn      AOS_IOEVENT_FLAG(GPIOB_ARD_D6)
158

    
159
/**
160
 * @brief   Event flag to be set on a USER_BUTTON interrupt.
161
 */
162
#define MODULE_OS_IOEVENTFLAGS_USERBUTTON       AOS_IOEVENT_FLAG(GPIOC_BUTTON)
163

    
164

    
165
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
166
/**
167
 * @brief   Shell prompt text.
168
 */
169
extern ROMCONST char* moduleShellPrompt;
170
#endif
171

    
172

    
173
/**
174
 * @brief   Interrupt initialization macro.
175
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
176
 */
177
#define MODULE_INIT_INTERRUPTS() {                                            \
178
  /* user button */                                                           \
179
  palSetPadCallback(moduleGpioUserButton.gpio->port, moduleGpioUserButton.gpio->pad, _intCallback, &moduleGpioUserButton.gpio->pad);  \
180
  palEnablePadEvent(moduleGpioUserButton.gpio->port, moduleGpioUserButton.gpio->pad, APAL2CH_EDGE(moduleGpioUserButton.meta.edge));   \
181
  MODULE_INIT_INTERRUPTS_DW1000();                                            \
182
}
183
#ifdef AMIROLLD_CFG_DW1000
184
  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
185
    palSetPadCallback(moduleGpioDw1000Irqn.gpio->port, moduleGpioDw1000Irqn.gpio->pad, _intCallback, &moduleGpioDw1000Irqn.gpio->pad);  \
186
    palEnablePadEvent(moduleGpioDw1000Irqn.gpio->port, moduleGpioDw1000Irqn.gpio->pad, APAL2CH_EDGE(moduleGpioDw1000Irqn.meta.edge));   \
187
  }
188
#else
189
  #define MODULE_INIT_INTERRUPTS_DW1000() {                                  \
190
  }
191
#endif /* AMIROLLD_CFG_DW1000 */
192

    
193

    
194
/**
195
 * @brief   Unit test initialization hook.
196
 */
197
#define MODULE_INIT_TESTS() {                                                 \
198
  /* add unit-test shell commands */                                          \
199
  MODULE_INIT_TESTS_DW1000();                                                 \
200
}
201
#ifdef AMIROLLD_CFG_DW1000
202
  #define MODULE_INIT_TESTS_DW1000() {                                        \
203
    aosShellAddCommand(&aos.shell, &moduleUtAlldDw1000.shellcmd);             \
204
  }
205
#else
206
  #define MODULE_INIT_TESTS_DW1000() {                                         \
207
  }
208
#endif /* AMIROLLD_CFG_DW1000 */
209

    
210

    
211
/**
212
 * @brief   Periphery communication interfaces initialization hook.
213
 */
214
#define MODULE_INIT_PERIPHERY_COMM() {                                        \
215
  /* serial driver */                                                         \
216
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
217
  MODULE_INIT_PERIPHERY_COMM_DW1000();                                        \
218
}
219
#ifdef AMIROLLD_CFG_DW1000
220
  #define MODULE_INIT_PERIPHERY_COMM_DW1000() {                               \
221
    /* SPI init */                                                            \
222
    dw1000_spi_init();                                                        \
223
    spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbLsConfig);                  \
224
  }
225
#else
226
  #define MODULE_INIT_PERIPHERY_COMM_DW1000() {                               \
227
  }
228
#endif /* AMIROLLD_CFG_DW1000 */
229

    
230

    
231
/**
232
 * @brief   Periphery communication interface deinitialization hook.
233
 */
234
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
235
  MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000();                                    \
236
}
237
#ifdef AMIROLLD_CFG_DW1000
238
#define MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000() {                             \
239
  /* SPI */                                                                   \
240
  spiStop(&MODULE_HAL_SPI_UWB);                                               \
241
}
242
#else
243
  #define MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000() {                           \
244
  }
245
#endif /* AMIROLLD_CFG_DW1000 */
246

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

    
270
/** @} */
271

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

    
279
/** @} */
280

    
281
/*===========================================================================*/
282
/**
283
 * @name Low-level drivers
284
 * @{
285
 */
286
/*===========================================================================*/
287
#ifdef AMIROLLD_CFG_DW1000
288
#include <alld_DW1000.h>
289

    
290
extern DW1000Driver moduleLldDw1000;
291

    
292
#endif /* AMIROLLD_CFG_DW1000 */
293

    
294
/** @} */
295

    
296
/*===========================================================================*/
297
/**
298
 * @name Unit tests (UT)
299
 * @{
300
 */
301
/*===========================================================================*/
302
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
303

    
304
#if defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)
305
#include<ut_alld_dw1000_v1.h>
306

    
307
/**
308
 * @brief   DW1000 unit test object.
309
 */
310
extern aos_unittest_t moduleUtAlldDw1000;
311

    
312
#endif /* defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1) */
313

    
314
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
315

    
316
/** @} */
317

    
318
#endif /* AMIROOS_MODULE_H */
319

    
320
/** @} */