Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-0 / module.h @ 5d929a9e

History | View | Annotate | Download (11.424 KB)

1 e545e620 Thomas Schöpping
/*
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 e05848a6 Robin Ewers
static void _alld_dw1000_callback(void* args);
30
31 e545e620 Thomas Schöpping
/** @} */
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 e05848a6 Robin Ewers
 * @brief   SPI interface driver for UWB Module.
78 e545e620 Thomas Schöpping
 */
79 e05848a6 Robin Ewers
#define MODULE_HAL_SPI_UWB                      SPID2
80 e545e620 Thomas Schöpping
81 8399aeae Thomas Schöpping
/**
82 e05848a6 Robin Ewers
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
83 22be62dc Thomas Schöpping
 */
84 e05848a6 Robin Ewers
extern SPIConfig moduleHalSpiLightConfig;
85 22be62dc Thomas Schöpping
86
/**
87 e05848a6 Robin Ewers
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
88 22be62dc Thomas Schöpping
 */
89 e05848a6 Robin Ewers
extern SPIConfig moduleHalSpiUWBConfig;
90 22be62dc Thomas Schöpping
91
/**
92 8399aeae Thomas Schöpping
 * @brief   Real-Time Clock driver.
93
 */
94
#define MODULE_HAL_RTC                          RTCD1
95
96 e545e620 Thomas Schöpping
/** @} */
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 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioLightBlank;
110 e545e620 Thomas Schöpping
111
/**
112
 * @brief   LASER_EN output signal GPIO.
113
 */
114 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioLaserEn;
115 e545e620 Thomas Schöpping
116
/**
117
 * @brief   LASER_OC input signal GPIO.
118
 */
119 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioLaserOc;
120 e545e620 Thomas Schöpping
121
/**
122
 * @brief   SYS_UART_DN bidirectional signal GPIO.
123
 */
124 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioSysUartDn;
125 e545e620 Thomas Schöpping
126
/**
127
 * @brief   WL_GDO2 input signal GPIO.
128
 */
129 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioWlGdo2;
130 e545e620 Thomas Schöpping
131
/**
132
 * @brief   WL_GDO0 input signal GPIO.
133
 */
134 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioWlGdo0;
135 e545e620 Thomas Schöpping
136
/**
137
 * @brief   LIGHT_XLAT output signal GPIO.
138
 */
139 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioLightXlat;
140 e545e620 Thomas Schöpping
141
/**
142
 * @brief   SYS_PD bidirectional signal GPIO.
143
 */
144 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioSysPd;
145 e545e620 Thomas Schöpping
146
/**
147
 * @brief   SYS_SYNC bidirectional signal GPIO.
148
 */
149 1e5f7648 Thomas Schöpping
extern apalControlGpio_t moduleGpioSysSync;
150 e545e620 Thomas Schöpping
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 1e5f7648 Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_LASEROC          ((eventflags_t)1 << GPIOB_LASER_OC_N)
164 e545e620 Thomas Schöpping
165
/**
166
 * @brief   Event flag to be set on a SYS_UART_DN interrupt.
167
 */
168 1e5f7648 Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN        ((eventflags_t)1 << GPIOB_SYS_UART_DN)
169 e545e620 Thomas Schöpping
170
/**
171
 * @brief   Event flag to be set on a WL_GDO2 interrupt.
172
 */
173 1e5f7648 Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_WLGDO2           ((eventflags_t)1 << GPIOB_WL_GDO2)
174 e545e620 Thomas Schöpping
175
/**
176
 * @brief   Event flag to be set on a WL_GDO0 interrupt.
177
 */
178 1e5f7648 Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_WLGDO0           ((eventflags_t)1 << GPIOB_WL_GDO0)
179 e545e620 Thomas Schöpping
180
/**
181
 * @brief   Event flag to be set on a SYS_PD interrupt.
182
 */
183 1e5f7648 Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSPD            ((eventflags_t)1 << GPIOC_SYS_PD_N)
184 e545e620 Thomas Schöpping
185
/**
186
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
187
 */
188 1e5f7648 Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          ((eventflags_t)1 << GPIOD_SYS_INT_N)
189 e545e620 Thomas Schöpping
190 6b53f6bf Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
191 e545e620 Thomas Schöpping
/**
192
 * @brief   Shell prompt text.
193
 */
194
extern const char* moduleShellPrompt;
195 6b53f6bf Thomas Schöpping
#endif
196 e545e620 Thomas Schöpping
197 e05848a6 Robin Ewers
198
199
200 e545e620 Thomas Schöpping
/**
201 1e5f7648 Thomas Schöpping
 * @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 e05848a6 Robin Ewers
  palSetPadCallback(moduleGpioWlGdo2.gpio->port, moduleGpioWlGdo2.gpio->pad, _alld_dw1000_callback, &moduleGpioWlGdo2.gpio->pad);  \
210 1e5f7648 Thomas Schöpping
  palEnablePadEvent(moduleGpioWlGdo2.gpio->port, moduleGpioWlGdo2.gpio->pad, APAL2CH_EDGE(moduleGpioWlGdo2.meta.edge));   \
211
  /* WL_GDO0 */                                                               \
212 e05848a6 Robin Ewers
  palSetPadCallback(moduleGpioWlGdo0.gpio->port, moduleGpioWlGdo0.gpio->pad, _alld_dw1000_callback, &moduleGpioWlGdo0.gpio->pad);  \
213 1e5f7648 Thomas Schöpping
  /*palEnablePadEvent(moduleGpioWlGdo0.gpio->port, moduleGpioWlGdo0.gpio->pad, APAL2CH_EDGE(moduleGpioWlGdo0.meta.edge)); // this is broken for some reason*/   \
214
}
215
216
/**
217 e545e620 Thomas Schöpping
 * @brief   Unit test initialization hook.
218
 */
219
#define MODULE_INIT_TESTS() {                                                 \
220
  /* add unit-test shell commands */                                          \
221 6b53f6bf Thomas Schöpping
  aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01bn.shellcmd);            \
222
  aosShellAddCommand(&aos.shell, &moduleUtAlldTlc5947.shellcmd);              \
223
  aosShellAddCommand(&aos.shell, &moduleUtAlldTps2051bdbv.shellcmd);          \
224 e05848a6 Robin Ewers
  aosShellAddCommand(&aos.shell, &moduleUtAlldDw1000.shellcmd);                \
225 e545e620 Thomas Schöpping
}
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 e05848a6 Robin Ewers
  spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUWBConfig);                      \
240 e545e620 Thomas Schöpping
}
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 e05848a6 Robin Ewers
  spiStop(&MODULE_HAL_SPI_UWB);                                               \
249 e545e620 Thomas Schöpping
  /* 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
/*===========================================================================*/
257
/**
258 6b53f6bf Thomas Schöpping
 * @name Startup Shutdown Synchronization Protocol (SSSP)
259
 * @{
260
 */
261
/*===========================================================================*/
262
263
/**
264
 * @brief   PD signal GPIO.
265
 */
266 1e5f7648 Thomas Schöpping
#define moduleSsspGpioPd                        moduleGpioSysPd
267 6b53f6bf Thomas Schöpping
268
/**
269
 * @brief   SYNC signal GPIO.
270
 */
271 1e5f7648 Thomas Schöpping
#define moduleSsspGpioSync                      moduleGpioSysSync
272 6b53f6bf Thomas Schöpping
273
/**
274 933df08e Thomas Schöpping
 * @brief   DN signal GPIO.
275
 */
276 1e5f7648 Thomas Schöpping
#define moduleSsspGpioDn                        moduleGpioSysUartDn
277 933df08e Thomas Schöpping
278
/**
279 6b53f6bf Thomas Schöpping
 * @brief   Event flags for PD signal events.
280
 */
281
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
282
283
/**
284 933df08e Thomas Schöpping
 * @brief   Event flags for SYNC signal events.
285 6b53f6bf Thomas Schöpping
 */
286
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
287
288
/**
289 933df08e Thomas Schöpping
 * @brief   Event flags for DN signal events.
290
 */
291
#define MODULE_SSSP_EVENTFLAGS_DN               MODULE_OS_IOEVENTFLAGS_SYSUARTDN
292
293 6b53f6bf Thomas Schöpping
/** @} */
294
295
/*===========================================================================*/
296
/**
297 e545e620 Thomas Schöpping
 * @name Low-level drivers
298
 * @{
299
 */
300
/*===========================================================================*/
301
#include <alld_at24c01bn-sh-b.h>
302
#include <alld_tlc5947.h>
303
#include <alld_tps2051bdbv.h>
304 e05848a6 Robin Ewers
#include <alld_dw1000.h>
305 e545e620 Thomas Schöpping
306
/**
307
 * @brief   EEPROM driver.
308
 */
309
extern AT24C01BNDriver moduleLldEeprom;
310
311
/**
312
 * @brief   LED PWM driver.
313
 */
314
extern TLC5947Driver moduleLldLedPwm;
315
316
/**
317
 * @brief   Power switch driver for the laser supply power.
318
 */
319
extern TPS2051BDriver moduleLldPowerSwitchLaser;
320
321 e05848a6 Robin Ewers
/**
322
 * @brief   DW1000 driver for UWB.
323
 */
324
extern DW1000Driver moduleLldDW1000;
325
326
327
328
329
/*! ------------------------------------------------------------------------------------------------------------------
330
 * Function: _alld_dw1000_callback()
331
 *
332
 * Low level abstract function to handle 'reset' adn 'irq' interrupt from DW1000
333
 * Expects arg to be of iopadid_t* type, used to distinguish between irq or reset signal
334
 */
335
static void _alld_dw1000_callback(void* args) {
336
337
    aosDbgCheck(true);
338
339
340
    chSysLockFromISR();
341
    if ((*(iopadid_t*) args) == moduleLldDW1000.gpio_reset->pad)
342
    {
343
        // dw1000 external indicate reset done
344
    }
345
    else if ((*(iopadid_t*) args) == moduleLldDW1000.gpio_exti->pad)
346
    {
347
        dwt_isr();
348
    }
349
    else
350
    {
351
        return;
352
    }
353
    chSysUnlockFromISR();
354
355
}
356
357
358 e545e620 Thomas Schöpping
/** @} */
359
360
/*===========================================================================*/
361
/**
362
 * @name Unit tests (UT)
363
 * @{
364
 */
365
/*===========================================================================*/
366
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
367
#include <ut_alld_at24c01bn-sh-b.h>
368
#include <ut_alld_tlc5947.h>
369
#include <ut_alld_tps2051bdbv.h>
370 e05848a6 Robin Ewers
#include <ut_alld_dw1000.h>
371 e545e620 Thomas Schöpping
372
/**
373
 * @brief   EEPROM unit test object.
374
 */
375
extern aos_unittest_t moduleUtAlldAt24c01bn;
376
377
/**
378
 * @brief   LED PWM driver unit test object.
379
 */
380
extern aos_unittest_t moduleUtAlldTlc5947;
381
382
/**
383
 * @brief   Current-limited power switch (Laser output)
384
 */
385
extern aos_unittest_t moduleUtAlldTps2051bdbv;
386
387 e05848a6 Robin Ewers
/**
388
 * @brief   DW1000 unit test object.
389
 */
390
extern aos_unittest_t moduleUtAlldDw1000;
391
392
393 e545e620 Thomas Schöpping
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
394
395
/** @} */
396
397
#endif /* _AMIROOS_MODULE_H_ */