Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / module.h @ 1ef74af5

History | View | Annotate | Download (11.469 KB)

1 e05848a6 Robin Ewers
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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
#ifndef _AMIROOS_MODULE_H_
20
#define _AMIROOS_MODULE_H_
21
22
/*===========================================================================*/
23
/**
24
 * @name Module specific functions
25
 * @{
26
 */
27
/*===========================================================================*/
28
29
static void _alld_dw1000_callback(void* args);
30
31
/** @} */
32
33
/*===========================================================================*/
34
/**
35
 * @name ChibiOS/HAL configuration
36
 * @{
37
 */
38
/*===========================================================================*/
39
#include <hal.h>
40
41
/**
42
 * @brief   CAN driver to use.
43
 */
44
#define MODULE_HAL_CAN                          CAND1
45
46
/**
47
 * @brief   Configuration for the CAN driver.
48
 */
49
extern CANConfig moduleHalCanConfig;
50
51
/**
52
 * @brief   I2C driver to access the EEPROM.
53
 */
54
#define MODULE_HAL_I2C_EEPROM                   I2CD2
55
56
/**
57
 * @brief   Configuration for the EEPROM I2C driver.
58
 */
59
extern I2CConfig moduleHalI2cEepromConfig;
60
61
/**
62
 * @brief   Serial driver of the programmer interface.
63
 */
64
#define MODULE_HAL_PROGIF                       SD1
65
66
/**
67
 * @brief   Configuration for the programmer serial interface driver.
68
 */
69
extern SerialConfig moduleHalProgIfConfig;
70
71
/**
72
 * @brief   SPI interface driver for the motion sensors (gyroscope and accelerometer).
73
 */
74
#define MODULE_HAL_SPI_LIGHT                    SPID1
75
76
/**
77
 * @brief   SPI interface driver for UWB Module.
78
 */
79
#define MODULE_HAL_SPI_UWB                      SPID2
80
81
/**
82
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
83
 */
84
extern SPIConfig moduleHalSpiLightConfig;
85
86
/**
87
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
88
 */
89
extern SPIConfig moduleHalSpiUWBConfig;
90
91
/**
92
 * @brief   Real-Time Clock driver.
93
 */
94
#define MODULE_HAL_RTC                          RTCD1
95
96
/** @} */
97
98
/*===========================================================================*/
99
/**
100
 * @name GPIO definitions
101
 * @{
102
 */
103
/*===========================================================================*/
104
#include <amiro-lld.h>
105
106
/**
107
 * @brief   LIGHT_BANK output signal GPIO.
108
 */
109
extern apalControlGpio_t moduleGpioLightBlank;
110
111
/**
112
 * @brief   LASER_EN output signal GPIO.
113
 */
114
extern apalControlGpio_t moduleGpioLaserEn;
115
116
/**
117
 * @brief   LASER_OC input signal GPIO.
118
 */
119
extern apalControlGpio_t moduleGpioLaserOc;
120
121
/**
122
 * @brief   SYS_UART_DN bidirectional signal GPIO.
123
 */
124
extern apalControlGpio_t moduleGpioSysUartDn;
125
126
/**
127
 * @brief   WL_GDO2 input signal GPIO.
128
 */
129
extern apalControlGpio_t moduleGpioWlGdo2;
130
131
/**
132
 * @brief   WL_GDO0 input signal GPIO.
133
 */
134
extern apalControlGpio_t moduleGpioWlGdo0;
135
136
/**
137
 * @brief   LIGHT_XLAT output signal GPIO.
138
 */
139
extern apalControlGpio_t moduleGpioLightXlat;
140
141
/**
142
 * @brief   SYS_PD bidirectional signal GPIO.
143
 */
144
extern apalControlGpio_t moduleGpioSysPd;
145
146
/**
147
 * @brief   SYS_SYNC bidirectional signal GPIO.
148
 */
149
extern apalControlGpio_t moduleGpioSysSync;
150
151
/** @} */
152
153
/*===========================================================================*/
154
/**
155
 * @name AMiRo-OS core configurations
156
 * @{
157
 */
158
/*===========================================================================*/
159
160
/**
161
 * @brief   Event flag to be set on a LASER_OC interrupt.
162
 */
163
#define MODULE_OS_IOEVENTFLAGS_LASEROC          ((eventflags_t)1 << GPIOB_LASER_OC_N)
164
165
/**
166
 * @brief   Event flag to be set on a SYS_UART_DN interrupt.
167
 */
168
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN        ((eventflags_t)1 << GPIOB_SYS_UART_DN)
169
170
/**
171
 * @brief   Event flag to be set on a WL_GDO2 interrupt.
172
 */
173
#define MODULE_OS_IOEVENTFLAGS_WLGDO2           ((eventflags_t)1 << GPIOB_WL_GDO2)
174
175
/**
176
 * @brief   Event flag to be set on a WL_GDO0 interrupt.
177
 */
178
#define MODULE_OS_IOEVENTFLAGS_WLGDO0           ((eventflags_t)1 << GPIOB_WL_GDO0)
179
180
/**
181
 * @brief   Event flag to be set on a SYS_PD interrupt.
182
 */
183
#define MODULE_OS_IOEVENTFLAGS_SYSPD            ((eventflags_t)1 << GPIOC_SYS_PD_N)
184
185
/**
186
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
187
 */
188
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          ((eventflags_t)1 << GPIOD_SYS_INT_N)
189
190
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
191
/**
192
 * @brief   Shell prompt text.
193
 */
194
extern const char* moduleShellPrompt;
195
#endif
196
197
198
199
200
/**
201
 * @brief   Interrupt initialization macro.
202
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
203
 */
204
#define MODULE_INIT_INTERRUPTS() {                                            \
205
  /* LASER_OC */                                                              \
206
  palSetPadCallback(moduleGpioLaserOc.gpio->port, moduleGpioLaserOc.gpio->pad, _intCallback, &moduleGpioLaserOc.gpio->pad); \
207
  palEnablePadEvent(moduleGpioLaserOc.gpio->port, moduleGpioLaserOc.gpio->pad, APAL2CH_EDGE(moduleGpioLaserOc.meta.edge));  \
208
  /* WL_GDO2 */                                                               \
209
  palSetPadCallback(moduleGpioWlGdo2.gpio->port, moduleGpioWlGdo2.gpio->pad, _alld_dw1000_callback, &moduleGpioWlGdo2.gpio->pad);  \
210
  palEnablePadEvent(moduleGpioWlGdo2.gpio->port, moduleGpioWlGdo2.gpio->pad, APAL2CH_EDGE(moduleGpioWlGdo2.meta.edge));   \
211
  /* WL_GDO0 */                                                               \
212
  palSetPadCallback(moduleGpioWlGdo0.gpio->port, moduleGpioWlGdo0.gpio->pad, _alld_dw1000_callback, &moduleGpioWlGdo0.gpio->pad);  \
213
  /*palEnablePadEvent(moduleGpioWlGdo0.gpio->port, moduleGpioWlGdo0.gpio->pad, APAL2CH_EDGE(moduleGpioWlGdo0.meta.edge)); // this is broken for some reason*/   \
214
}
215
216
/**
217
 * @brief   Unit test initialization hook.
218
 */
219
#define MODULE_INIT_TESTS() {                                                 \
220
  /* add unit-test shell commands */                                          \
221
  aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01bn.shellcmd);            \
222
  aosShellAddCommand(&aos.shell, &moduleUtAlldTlc5947.shellcmd);              \
223
  aosShellAddCommand(&aos.shell, &moduleUtAlldTps2051bdbv.shellcmd);          \
224
  aosShellAddCommand(&aos.shell, &moduleUtAlldDw1000.shellcmd);                \
225
}
226
227
/**
228
 * @brief   Periphery communication interfaces initialization hook.
229
 */
230
#define MODULE_INIT_PERIPHERY_COMM() {                                        \
231
  /* serial driver */                                                         \
232
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
233
  /* I2C */                                                                   \
234
  moduleHalI2cEepromConfig.clock_speed = (AT24C01BN_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromConfig.clock_speed) ? AT24C01BN_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromConfig.clock_speed; \
235
  moduleHalI2cEepromConfig.duty_cycle = (moduleHalI2cEepromConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
236
  i2cStart(&MODULE_HAL_I2C_EEPROM, &moduleHalI2cEepromConfig);                \
237
  /* SPI */                                                                   \
238
  spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig);                  \
239
  spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUWBConfig);                      \
240
}
241
242
/**
243
 * @brief   Periphery communication interface deinitialization hook.
244
 */
245
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
246
  /* SPI */                                                                   \
247
  spiStop(&MODULE_HAL_SPI_LIGHT);                                             \
248
  spiStop(&MODULE_HAL_SPI_UWB);                                               \
249
  /* I2C */                                                                   \
250
  i2cStop(&MODULE_HAL_I2C_EEPROM);                                            \
251
  /* don't stop the serial driver so messages can still be printed */         \
252
}
253
254
/** @} */
255
256 1ef74af5 Simon Welzel
#if (AMIROOS_CFG_SSSP_ENABLE == true)
257 e05848a6 Robin Ewers
/*===========================================================================*/
258
/**
259
 * @name Startup Shutdown Synchronization Protocol (SSSP)
260
 * @{
261
 */
262
/*===========================================================================*/
263
264
/**
265
 * @brief   PD signal GPIO.
266
 */
267
#define moduleSsspGpioPd                        moduleGpioSysPd
268
269
/**
270
 * @brief   SYNC signal GPIO.
271
 */
272
#define moduleSsspGpioSync                      moduleGpioSysSync
273
274
/**
275
 * @brief   DN signal GPIO.
276
 */
277
#define moduleSsspGpioDn                        moduleGpioSysUartDn
278
279
/**
280
 * @brief   Event flags for PD signal events.
281
 */
282
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
283
284
/**
285
 * @brief   Event flags for SYNC signal events.
286
 */
287
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
288
289
/**
290
 * @brief   Event flags for DN signal events.
291
 */
292
#define MODULE_SSSP_EVENTFLAGS_DN               MODULE_OS_IOEVENTFLAGS_SYSUARTDN
293
294
/** @} */
295
296 1ef74af5 Simon Welzel
#endif
297
298 e05848a6 Robin Ewers
/*===========================================================================*/
299
/**
300
 * @name Low-level drivers
301
 * @{
302
 */
303
/*===========================================================================*/
304
#include <alld_at24c01bn-sh-b.h>
305
#include <alld_tlc5947.h>
306
#include <alld_tps2051bdbv.h>
307
#include <alld_dw1000.h>
308
309
/**
310
 * @brief   EEPROM driver.
311
 */
312
extern AT24C01BNDriver moduleLldEeprom;
313
314
/**
315
 * @brief   LED PWM driver.
316
 */
317
extern TLC5947Driver moduleLldLedPwm;
318
319
/**
320
 * @brief   Power switch driver for the laser supply power.
321
 */
322
extern TPS2051BDriver moduleLldPowerSwitchLaser;
323
324
/**
325
 * @brief   DW1000 driver for UWB.
326
 */
327
extern DW1000Driver moduleLldDW1000;
328
329
330
331
332
/*! ------------------------------------------------------------------------------------------------------------------
333
 * Function: _alld_dw1000_callback()
334
 *
335
 * Low level abstract function to handle 'reset' adn 'irq' interrupt from DW1000
336
 * Expects arg to be of iopadid_t* type, used to distinguish between irq or reset signal
337
 */
338
static void _alld_dw1000_callback(void* args) {
339
340
    aosDbgCheck(true);
341
342
343
    chSysLockFromISR();
344
    if ((*(iopadid_t*) args) == moduleLldDW1000.gpio_reset->pad)
345
    {
346
        // dw1000 external indicate reset done
347
    }
348
    else if ((*(iopadid_t*) args) == moduleLldDW1000.gpio_exti->pad)
349
    {
350
        dwt_isr();
351
    }
352
    else
353
    {
354
        return;
355
    }
356
    chSysUnlockFromISR();
357
358
}
359
360
361
/** @} */
362
363
/*===========================================================================*/
364
/**
365
 * @name Unit tests (UT)
366
 * @{
367
 */
368
/*===========================================================================*/
369
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
370
#include <ut_alld_at24c01bn-sh-b.h>
371
#include <ut_alld_tlc5947.h>
372
#include <ut_alld_tps2051bdbv.h>
373
#include <ut_alld_dw1000.h>
374
375
/**
376
 * @brief   EEPROM unit test object.
377
 */
378
extern aos_unittest_t moduleUtAlldAt24c01bn;
379
380
/**
381
 * @brief   LED PWM driver unit test object.
382
 */
383
extern aos_unittest_t moduleUtAlldTlc5947;
384
385
/**
386
 * @brief   Current-limited power switch (Laser output)
387
 */
388
extern aos_unittest_t moduleUtAlldTps2051bdbv;
389
390
/**
391
 * @brief   DW1000 unit test object.
392
 */
393
extern aos_unittest_t moduleUtAlldDw1000;
394
395
396
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
397
398
/** @} */
399
400
#endif /* _AMIROOS_MODULE_H_ */