Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-2 / module.h @ c7cd988c

History | View | Annotate | Download (16.8 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 LightRing module.
22
 *
23
 * @addtogroup lightring_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
/** @} */
40

    
41
/*===========================================================================*/
42
/**
43
 * @name ChibiOS/HAL configuration
44
 * @{
45
 */
46
/*===========================================================================*/
47

    
48
/**
49
 * @brief   CAN driver to use.
50
 */
51
#define MODULE_HAL_CAN                          CAND1
52

    
53
/**
54
 * @brief   Configuration for the CAN driver.
55
 */
56
extern CANConfig moduleHalCanConfig;
57

    
58
/**
59
 * @brief   I2C driver to access the EEPROM, power monitor and the breakout header.
60
 */
61
#define MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT   I2CD2
62

    
63
/**
64
 * @brief   Configuration for the EEPROM, power monitor and breakout I2C driver.
65
 */
66
extern I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig;
67

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

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

    
78
/**
79
 * @brief   SPI interface driver for the motion sensors (gyroscope and accelerometer).
80
 */
81
#define MODULE_HAL_SPI_LIGHT                    SPID1
82

    
83
/**
84
 * @brief   Configuration for the SPI interface driver to communicate with the LED driver.
85
 */
86
extern SPIConfig moduleHalSpiLightConfig;
87

    
88
/**
89
 * @brief   SPI interface driver for the breakout header.
90
 */
91
#define MODULE_HAL_SPI_BREAKOUT                 SPID2
92

    
93
/**
94
 * @brief   UART interface driver for the breakout header (alternative to serial).
95
 */
96
#define MODULE_HAL_UART_BREAKOUT                UARTD2
97

    
98
/**
99
 * @brief   Real-Time Clock driver.
100
 */
101
#define MODULE_HAL_RTC                          RTCD1
102

    
103
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) || defined(__DOXYGEN__)
104

    
105
/**
106
 * @brief   SPI interface driver for UWB DW1000 module.
107
 */
108
#define MODULE_HAL_SPI_UWB                      MODULE_HAL_SPI_BREAKOUT
109

    
110
/**
111
 * @brief   Configuration for the high-speed SPI interface driver of DW1000 module.
112
 */
113
extern SPIConfig moduleHalSpiUwbHsConfig;
114

    
115
/**
116
 * @brief   Configuration for the low-speed SPI interface driver of DW1000 module.
117
 */
118
extern SPIConfig moduleHalSpiUwbLsConfig;
119

    
120
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */
121

    
122
/** @} */
123

    
124
/*===========================================================================*/
125
/**
126
 * @name GPIO definitions
127
 * @{
128
 */
129
/*===========================================================================*/
130

    
131
/**
132
 * @brief   LIGHT_BANK output signal GPIO.
133
 */
134
extern ROMCONST apalControlGpio_t moduleGpioLightBlank;
135

    
136
/**
137
 * @brief   RS232_R_EN_N output signal GPIO.
138
 */
139
extern ROMCONST apalControlGpio_t moduleGpioRs232En;
140

    
141
/**
142
 * @brief   SW_V33_EN output signal GPIO.
143
 */
144
extern ROMCONST apalControlGpio_t moduleGpioSwV33En;
145

    
146
// The 4.2V switch is disabled due to a hardware bug.
147
///**
148
// * @brief   SW_V42_EN output signal GPIO.
149
// */
150
//extern ROMCONST apalControlGpio_t moduleGpioSwV42En;
151

    
152
/**
153
 * @brief   SW_V50_EN output signal GPIO.
154
 */
155
extern ROMCONST apalControlGpio_t moduleGpioSwV50En;
156

    
157
/**
158
 * @brief   IO_3 breakout signal GPIO.
159
 */
160
extern apalControlGpio_t moduleGpioBreakoutIo3;
161

    
162
/**
163
 * @brief   IO_5 breakout signal GPIO.
164
 */
165
extern apalControlGpio_t moduleGpioBreakoutIo5;
166

    
167
/**
168
 * @brief   IO_6 breakout signal GPIO.
169
 */
170
extern apalControlGpio_t moduleGpioBreakoutIo6;
171

    
172
/**
173
 * @brief   SYS_UART_DN bidirectional signal GPIO.
174
 */
175
extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
176

    
177
/**
178
 * @brief   IO_7 breakout signal GPIO.
179
 */
180
extern apalControlGpio_t moduleGpioBreakoutIo7;
181

    
182
/**
183
 * @brief   IO_8 breakout signal GPIO.
184
 */
185
extern apalControlGpio_t moduleGpioBreakoutIo8;
186

    
187
/**
188
 * @brief   IO_4 breakout signal GPIO.
189
 */
190
extern apalControlGpio_t moduleGpioBreakoutIo4;
191

    
192
/**
193
 * @brief   IO_1 breakout signal GPIO.
194
 */
195
extern apalControlGpio_t moduleGpioBreakoutIo1;
196

    
197
/**
198
 * @brief   IO_2 breakout signal GPIO.
199
 */
200
extern apalControlGpio_t moduleGpioBreakoutIo2;
201

    
202
/**
203
 * @brief   LED output signal GPIO.
204
 */
205
extern ROMCONST apalControlGpio_t moduleGpioLed;
206

    
207
/**
208
 * @brief   LIGHT_XLAT output signal.
209
 */
210
extern ROMCONST apalControlGpio_t moduleGpioLightXlat;
211

    
212
/**
213
 * @brief   SW_V18_EN output signal GPIO.
214
 */
215
extern ROMCONST apalControlGpio_t moduleGpioSwV18En;
216

    
217
/**
218
 * @brief   SW_VSYS_EN output signal GPIO.
219
 */
220
extern ROMCONST apalControlGpio_t moduleGpioSwVsysEn;
221

    
222
/**
223
 * @brief   SYS_UART_UP bidirectional signal GPIO.
224
 */
225
extern ROMCONST apalControlGpio_t moduleGpioSysUartUp;
226

    
227
/**
228
 * @brief   SYS_PD bidirectional signal GPIO.
229
 */
230
extern ROMCONST apalControlGpio_t moduleGpioSysPd;
231

    
232
/**
233
 * @brief   SYS_SYNC bidirectional signal GPIO.
234
 */
235
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
236

    
237
/** @} */
238

    
239
/*===========================================================================*/
240
/**
241
 * @name AMiRo-OS core configurations
242
 * @{
243
 */
244
/*===========================================================================*/
245

    
246
/**
247
 * @brief   Event flag to be set on a IO_4 (breakout) interrupt.
248
 */
249
#define MODULE_OS_GPIOEVENTFLAG_BREAKOUTIO4     AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_IO_4))
250

    
251
/**
252
 * @brief   Event flag to be set on a IO_1 (breakout) interrupt.
253
 */
254
#define MODULE_OS_GPIOEVENTFLAG_BREAKOUTIO1     AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_IO_1))
255

    
256
/**
257
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
258
 */
259
#define MODULE_OS_GPIOEVENTFLAG_SYSSYNC         AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_SYS_INT_N))
260

    
261
/**
262
 * @brief   Event flag to be set on a IO_3 (breakout) interrupt.
263
 */
264
#define MODULE_OS_GPIOEVENTFLAG_BREAKOUTIO3     AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_IO_3))
265

    
266
/**
267
 * @brief   Event flag to be set on a IO_5 (breakout) interrupt.
268
 */
269
#define MODULE_OS_GPIOEVENTFLAG_BREAKOUTIO5     AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_IO_5))
270

    
271
/**
272
 * @brief   Event flag to be set on a IO_6 (breakout) interrupt.
273
 */
274
#define MODULE_OS_GPIOEVENTFLAG_BREAKOUTIO6     AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_IO_6))
275

    
276
/**
277
 * @brief   Event flag to be set on a SYS_UART_DN interrupt.
278
 */
279
#define MODULE_OS_GPIOEVENTFLAG_SYSUARTDN       AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_DN))
280

    
281
/**
282
 * @brief   Event flag to be set on a SYS_UART_UP interrupt.
283
 */
284
#define MODULE_OS_GPIOEVENTFLAG_SYSUARTUP       AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_UP))
285

    
286
/**
287
 * @brief   Event flag to be set on a IO_7 (breakout) interrupt.
288
 */
289
#define MODULE_OS_GPIOEVENTFLAG_BREAKOUTIO7     AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_IO_7))
290

    
291
/**
292
 * @brief   Event flag to be set on a IO_8 (breakout) interrupt.
293
 */
294
#define MODULE_OS_GPIOEVENTFLAG_BREAKOUTIO8     AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_IO_8))
295

    
296
/**
297
 * @brief   Event flag to be set on a SYS_PD interrupt.
298
 */
299
#define MODULE_OS_GPIOEVENTFLAG_SYSPD           AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
300

    
301
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) || defined(__DOXYGEN__)
302

    
303
/**
304
 * @brief   Event flag to be set on a DW1000 interrupt.
305
 */
306
#define MODULE_OS_GPIOEVENTFLAG_DW1000          MODULE_OS_GPIOEVENTFLAGS_BREAKOUTIO8
307

    
308
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */
309

    
310
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
311
/**
312
 * @brief   Shell prompt text.
313
 */
314
extern ROMCONST char* moduleShellPrompt;
315
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
316

    
317
/**
318
 * @brief   Interrupt initialization macro.
319
 */
320
#define MODULE_INIT_INTERRUPTS() {                                            \
321
  /* breakout interrupts must be enabled explicitely */                       \
322
  MODULE_INIT_INTERRUPTS_BREAKOUT();                                          \
323
}
324
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
325
  #define MODULE_INIT_INTERRUPTS_BREAKOUT() {                                 \
326
    palSetLineCallback(moduleLldDw1000.gpio_exti->gpio->line, aosSysGetStdGpioCallback(), &moduleLldDw1000.gpio_exti->gpio->line);  \
327
    palEnableLineEvent(moduleLldDw1000.gpio_exti->gpio->line, APAL2CH_EDGE(moduleLldDw1000.gpio_exti->meta.edge));                  \
328
  }
329
#elif (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_NONE)
330
  #define MODULE_INIT_INTERRUPTS_BREAKOUT() {                                 \
331
  }
332
#endif
333

    
334
/**
335
 * @brief   Test initialization hook.
336
 */
337
#define MODULE_INIT_TESTS() {                                                 \
338
  /* add test commands to shell */                                            \
339
  aosShellAddCommand(&aos.shell, &moduleTestAt24c01bShellCmd);                \
340
  aosShellAddCommand(&aos.shell, &moduleTestIna219ShellCmd);                  \
341
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
342
  aosShellAddCommand(&aos.shell, &moduleTestMic9404xShellCmd);                \
343
  aosShellAddCommand(&aos.shell, &moduleTestTlc5947ShellCmd);                 \
344
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
345
  MODULE_INIT_TESTS_BREAKOUT();                                               \
346
}
347
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
348
  #define MODULE_INIT_TESTS_BREAKOUT() {                                      \
349
    aosShellAddCommand(&aos.shell, &moduleTestDw1000ShellCmd);                \
350
  }
351
#elif (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_NONE)
352
  #define MODULE_INIT_TESTS_BREAKOUT() {                                      \
353
  }
354
#endif
355

    
356
/**
357
 * @brief   Periphery communication interfaces initialization hook.
358
 */
359
#define MODULE_INIT_PERIPHERY_IF() {                                          \
360
  /* serial driver */                                                         \
361
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
362
  /* I2C */                                                                   \
363
  moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed; \
364
  moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed; \
365
  moduleHalI2cEepromPwrmtrBreakoutConfig.duty_cycle = (moduleHalI2cEepromPwrmtrBreakoutConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
366
  i2cStart(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT, &moduleHalI2cEepromPwrmtrBreakoutConfig);  \
367
  /* SPI */                                                                   \
368
  spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig);                  \
369
  /* CAN */                                                                   \
370
  canStart(&MODULE_HAL_CAN, &moduleHalCanConfig);                             \
371
  /* breakout module */                                                       \
372
  MODULE_INIT_PERIPHERY_COMM_BREAKOUT();                                      \
373
}
374
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
375
  #define MODULE_INIT_PERIPHERY_COMM_BREAKOUT() {                             \
376
    spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbLsConfig);                  \
377
  }
378
#elif (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_NONE)
379
  #define MODULE_INIT_PERIPHERY_COMM_BREAKOUT() {                             \
380
  }
381
#endif
382

    
383
/**
384
 * @brief   Periphery communication interface deinitialization hook.
385
 */
386
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
387
  /* breakout module */                                                       \
388
  MODULE_SHUTDOWN_PERIPHERY_COMM_BREAKOUT();                                  \
389
  /* CAN */                                                                   \
390
  canStop(&MODULE_HAL_CAN);                                                   \
391
  /* SPI */                                                                   \
392
  spiStop(&MODULE_HAL_SPI_LIGHT);                                             \
393
  /* I2C */                                                                   \
394
  i2cStop(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT);                            \
395
  /* don't stop the serial driver so messages can still be printed */         \
396
}
397
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
398
  #define MODULE_SHUTDOWN_PERIPHERY_COMM_BREAKOUT() {                         \
399
    /* SPI */                                                                 \
400
    spiStop(&MODULE_HAL_SPI_UWB);                                             \
401
  }
402
#elif (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_NONE)
403
  #define MODULE_SHUTDOWN_PERIPHERY_COMM_BREAKOUT() {                         \
404
  }
405
#endif
406

    
407
/** @} */
408

    
409
/*===========================================================================*/
410
/**
411
 * @name Startup Shutdown Synchronization Protocol (SSSP)
412
 * @{
413
 */
414
/*===========================================================================*/
415

    
416
#define moduleSsspSignalPD()                    (&moduleGpioSysPd)
417
#define moduleSsspEventflagPD()                 MODULE_OS_GPIOEVENTFLAG_SYSPD
418

    
419
#define moduleSsspSignalS()                     (&moduleGpioSysSync)
420
#define moduleSsspEventflagS()                  MODULE_OS_GPIOEVENTFLAG_SYSSYNC
421

    
422
#define moduleSsspSignalDN()                    (&moduleGpioSysUartDn)
423
#define moduleSsspEventflagDN()                 MODULE_OS_GPIOEVENTFLAG_SYSUARTDN
424

    
425
/** @} */
426

    
427
/*===========================================================================*/
428
/**
429
 * @name Low-level drivers
430
 * @{
431
 */
432
/*===========================================================================*/
433
#include <alld_AT24C01B.h>
434
#include <alld_INA219.h>
435
#include <alld_LED.h>
436
#include <alld_MIC9404x.h>
437
// TODO: add SNx5C3221E
438
#include <alld_TLC5947.h>
439

    
440
/**
441
 * @brief   EEPROM driver.
442
 */
443
extern AT24C01BDriver moduleLldEeprom;
444

    
445
/**
446
 * @brief   Power monitor (VLED 4.2) driver.
447
 */
448
extern INA219Driver moduleLldPowerMonitorVled;
449

    
450
/**
451
 * @brief   Status LED driver.
452
 */
453
extern LEDDriver moduleLldStatusLed;
454

    
455
/**
456
 * @brief   Power switch driver (1.8V).
457
 */
458
extern MIC9404xDriver moduleLldPowerSwitchV18;
459

    
460
/**
461
 * @brief   Power switch driver (3.3V).
462
 */
463
extern MIC9404xDriver moduleLldPowerSwitchV33;
464

    
465
/**
466
 * @brief   Power switch driver (4.2V).
467
 */
468
extern MIC9404xDriver moduleLldPowerSwitchV42;
469

    
470
/**
471
 * @brief   Power switch driver (5.0V).
472
 */
473
extern MIC9404xDriver moduleLldPowerSwitchV50;
474

    
475
/**
476
 * @brief   Pseudo power switch driver (VSYS).
477
 * @details There is no actual MIC9040x device, but the swicthable circuit behaves analogous.
478
 */
479
extern MIC9404xDriver moduleLldPowerSwitchVsys;
480

    
481
// TODO: add SNx5C3221E
482

    
483
/**
484
 * @brief   24 channel PWM LED driver.
485
 */
486
extern TLC5947Driver moduleLldLedPwm;
487

    
488
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) || defined(__DOXYGEN__)
489

    
490
#include <alld_DW1000.h>
491

    
492
/**
493
 * @brief   Alias for the DW1000 driver object.
494
 * @note    The dw1000 struct is defined as external variable (singleton) by the
495
 *          driver, since the Decawave software stacks assumes no more than a
496
 *          single device in a system.
497
 */
498
#define moduleLldDw1000                         dw1000
499

    
500
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */
501

    
502
/** @} */
503

    
504
/*===========================================================================*/
505
/**
506
 * @name Tests
507
 * @{
508
 */
509
/*===========================================================================*/
510
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
511

    
512
/**
513
 * @brief   AT24C01BN-SH-B (EEPROM) test command.
514
 */
515
extern aos_shellcommand_t moduleTestAt24c01bShellCmd;
516

    
517
/**
518
 * @brief   INA219 (power monitor) test command.
519
 */
520
extern aos_shellcommand_t moduleTestIna219ShellCmd;
521

    
522
/**
523
 * @brief   Status LED test command.
524
 */
525
extern aos_shellcommand_t moduleTestLedShellCmd;
526

    
527
/**
528
 * @brief   MIC9404x (power switch) test command.
529
 */
530
extern aos_shellcommand_t moduleTestMic9404xShellCmd;
531

    
532
// TODO: add SNx5C3221E
533

    
534
/**
535
 * @brief   TLC5947 (24 channel PWM LED driver) test command.
536
 */
537
extern aos_shellcommand_t moduleTestTlc5947ShellCmd;
538

    
539
/**
540
 * @brief   Entire module test command.
541
 */
542
extern aos_shellcommand_t moduleTestAllShellCmd;
543

    
544

    
545
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) || defined(__DOXYGEN__)
546

    
547
/**
548
 * @brief   DW1000 (UWB transmitter) test command.
549
 */
550
extern aos_shellcommand_t moduleTestDw1000ShellCmd;
551

    
552
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */
553

    
554
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
555

    
556
/** @} */
557

    
558
#endif /* AMIROOS_MODULE_H */
559

    
560
/** @} */