Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-2 / module.h @ da1c10ac

History | View | Annotate | Download (16.586 KB)

1 abb8b3f4 Thomas Schöpping
/*
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 DiWheelDrive module.
22
 *
23
 * @addtogroup diwheeldrive_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 compass.
60
 */
61
#define MODULE_HAL_I2C_IMU                      I2CD1
62
63
/**
64
 * @brief   Configuration for the compass I2C driver.
65
 */
66
extern I2CConfig moduleHalI2cImuConfig;
67
68
/**
69
 * @brief   I2C driver to access multiplexer, proximity sensors, EEPROM and power monitor.
70
 */
71
#define MODULE_HAL_I2C_PROX_EEPROM_PWRMTR       I2CD2
72
73
/**
74
 * @brief   Configuration for the multiplexer, proximity, EEPROM and power monitor I2C driver.
75
 */
76
extern I2CConfig moduleHalI2cProxEepromPwrmtrConfig;
77
78
/**
79
 * @brief   PWM driver to use.
80
 */
81
#define MODULE_HAL_PWM_DRIVE                    PWMD2
82
83
/**
84
 * @brief   Configuration for the PWM driver.
85
 */
86
extern PWMConfig moduleHalPwmDriveConfig;
87
88
/**
89
 * @brief   Drive PWM channel for the left wheel forward direction.
90
 */
91
#define MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD     ((apalPWMchannel_t)0)
92
93
/**
94
 * @brief   Drive PWM channel for the left wheel backward direction.
95
 */
96
#define MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD    ((apalPWMchannel_t)1)
97
98
/**
99
 * @brief   Drive PWM channel for the right wheel forward direction.
100
 */
101
#define MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD    ((apalPWMchannel_t)2)
102
103
/**
104
 * @brief   Drive PWM channel for the right wheel backward direction.
105
 */
106
#define MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD   ((apalPWMchannel_t)3)
107
108
/**
109
 * @brief   Quadrature encooder for the left wheel.
110
 */
111
#define MODULE_HAL_QEI_LEFT_WHEEL               QEID3
112
113
/**
114
 * @brief   Quadrature encooder for the right wheel.
115
 */
116
#define MODULE_HAL_QEI_RIGHT_WHEEL              QEID4
117
118
/**
119
 * @brief   Configuration for both quadrature encoders.
120
 */
121
extern QEIConfig moduleHalQeiConfig;
122
123
/**
124
 * @brief   QEI increments per wheel revolution.
125
 * @details 2 signal edges per pulse * 2 signals * 16 pulses per motor revolution * 22:1 gearbox
126
 */
127
#define MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION  (apalQEICount_t)(2 * 2 * 16 * 22)
128
129
/**
130
 * @brief   Serial driver of the programmer interface.
131
 */
132
#define MODULE_HAL_PROGIF                       SD1
133
134
/**
135
 * @brief   Configuration for the programmer serial interface driver.
136
 */
137
extern SerialConfig moduleHalProgIfConfig;
138
139
/**
140
 * @brief   Real-Time Clock driver.
141
 */
142
#define MODULE_HAL_RTC                          RTCD1
143
144
/** @} */
145
146
/*===========================================================================*/
147
/**
148
 * @name GPIO definitions
149
 * @{
150
 */
151
/*===========================================================================*/
152
153
/**
154
 * @brief   LED output signal GPIO.
155
 */
156
extern ROMCONST apalControlGpio_t moduleGpioLed;
157
158
/**
159
 * @brief   POWER_EN output signal GPIO.
160
 */
161
extern ROMCONST apalControlGpio_t moduleGpioPowerEn;
162
163
/**
164
 * @brief   IR_INT input signal GPIO.
165
 */
166
extern ROMCONST apalControlGpio_t moduleGpioIrInt;
167
168
/**
169
 * @brief   SYS_UART_UP bidirectional signal GPIO.
170
 */
171
extern ROMCONST apalControlGpio_t moduleGpioSysUartUp;
172
173
/**
174
 * @brief   IMU_INT input signal GPIO.
175
 */
176
extern ROMCONST apalControlGpio_t moduleGpioImuInt;
177
178
/**
179
 * @brief   SYS_SNYC bidirectional signal GPIO.
180
 */
181
extern ROMCONST apalControlGpio_t moduleGpioSysSync;
182
183
/**
184
 * @brief   IMU_RESET output signal GPIO.
185
 */
186
extern ROMCONST apalControlGpio_t moduleGpioImuReset;
187
188
/**
189
 * @brief   PATH_DCSTAT input signal GPIO.
190
 */
191
extern ROMCONST apalControlGpio_t moduleGpioPathDcStat;
192
193
/**
194
 * @brief   PATH_DCEN output signal GPIO.
195
 */
196
extern ROMCONST apalControlGpio_t moduleGpioPathDcEn;
197
198
/**
199
 * @brief   SYS_PD bidirectional signal GPIO.
200
 */
201
extern ROMCONST apalControlGpio_t moduleGpioSysPd;
202
203
/**
204
 * @brief   SYS_REG_EN input signal GPIO.
205
 */
206
extern ROMCONST apalControlGpio_t moduleGpioSysRegEn;
207
208
/**
209
 * @brief   IMU_BOOT_LOAD output signal GPIO.
210
 */
211
extern ROMCONST apalControlGpio_t moduleGpioImuBootLoad;
212
213
/**
214
 * @brief   IMU_BL_IND input signal GPIO.
215
 */
216
extern ROMCONST apalControlGpio_t moduleGpioImuBlInd;
217
218
/**
219
 * @brief   SYS_WARMRST bidirectional signal GPIO.
220
 */
221
extern ROMCONST apalControlGpio_t moduleGpioSysWarmrst;
222
223
/** @} */
224
225
/*===========================================================================*/
226
/**
227
 * @name AMiRo-OS core configurations
228
 * @{
229
 */
230
/*===========================================================================*/
231
232
/**
233
 * @brief   Event flag to be set on a SYS_SYNC interrupt.
234
 */
235 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_INT_N))
236 abb8b3f4 Thomas Schöpping
237
/**
238
 * @brief   Event flag to be set on a SYS_WARMRST interrupt.
239
 */
240 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSWARMRST       AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_WARMRST_N))
241 abb8b3f4 Thomas Schöpping
242
/**
243
 * @brief   Event flag to be set on a PATH_DCSTAT interrupt.
244
 */
245 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_PATHDCSTAT       AOS_IOEVENT_FLAG(PAL_PAD(LINE_PATH_DCEN))
246 abb8b3f4 Thomas Schöpping
247
/**
248
 * @brief   Event flag to be set on a SYS_PD interrupt.
249
 */
250 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSPD            AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
251 abb8b3f4 Thomas Schöpping
252
/**
253
 * @brief   Event flag to be set on a SYS_REG_EN interrupt.
254
 */
255 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSREGEN         AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_REG_EN))
256 abb8b3f4 Thomas Schöpping
257
/**
258
 * @brief   Event flag to be set on a IR_INT interrupt.
259
 */
260 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_IRINT            AOS_IOEVENT_FLAG(PAL_PAD(LINE_IR_INT))
261 abb8b3f4 Thomas Schöpping
262
/**
263
 * @brief   Event flag to be set on a SYS_UART_UP interrupt.
264
 */
265 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_SYSUARTUP        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_UP))
266 abb8b3f4 Thomas Schöpping
267
/**
268
 * @brief   Event flag to be set on a IMU_INT interrupt.
269
 */
270 3106e8cc Thomas Schöpping
#define MODULE_OS_IOEVENTFLAGS_IMUINT         AOS_IOEVENT_FLAG(PAL_PAD(LINE_IMU_INT))
271 abb8b3f4 Thomas Schöpping
272
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
273
/**
274
 * @brief   Shell prompt text.
275
 */
276
extern ROMCONST char* moduleShellPrompt;
277
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
278
279
/**
280
 * @brief   Additional HAL initialization hook.
281
 */
282
#define MODULE_INIT_HAL_EXTRA() {                                             \
283
  qeiInit();                                                                  \
284
}
285
286
/**
287
 * @brief   Interrupt initialization macro.
288
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
289
 */
290
#define MODULE_INIT_INTERRUPTS() {                                            \
291
  /* IR_INT */                                                                \
292 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioIrInt.gpio->line, aosSysGetStdIntCallback(), &moduleGpioIrInt.gpio->line); \
293
  palEnableLineEvent(moduleGpioIrInt.gpio->line, APAL2CH_EDGE(moduleGpioIrInt.meta.edge));                \
294 abb8b3f4 Thomas Schöpping
  /* IMU_INT */                                                               \
295 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioImuInt.gpio->line, aosSysGetStdIntCallback(), &moduleGpioImuInt.gpio->line); \
296
  palEnableLineEvent(moduleGpioImuInt.gpio->line, APAL2CH_EDGE(moduleGpioImuInt.meta.edge));                \
297 abb8b3f4 Thomas Schöpping
  /* PATH_DCSTAT */                                                           \
298 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioPathDcStat.gpio->line, aosSysGetStdIntCallback(), &moduleGpioPathDcStat.gpio->line); \
299
  palEnableLineEvent(moduleGpioPathDcStat.gpio->line, APAL2CH_EDGE(moduleGpioPathDcStat.meta.edge));                \
300 abb8b3f4 Thomas Schöpping
  /* SYS_REG_EN */                                                            \
301 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioSysRegEn.gpio->line, aosSysGetStdIntCallback(), &moduleGpioSysRegEn.gpio->line); \
302
  palEnableLineEvent(moduleGpioSysRegEn.gpio->line, APAL2CH_EDGE(moduleGpioSysRegEn.meta.edge));                \
303 abb8b3f4 Thomas Schöpping
  /* SYS_WARMRST */                                                           \
304 3106e8cc Thomas Schöpping
  palSetLineCallback(moduleGpioSysWarmrst.gpio->line, aosSysGetStdIntCallback(), &moduleGpioSysWarmrst.gpio->line); \
305
  palEnableLineEvent(moduleGpioSysWarmrst.gpio->line, APAL2CH_EDGE(moduleGpioSysWarmrst.meta.edge));                \
306 abb8b3f4 Thomas Schöpping
}
307
308
/**
309
 * @brief   Unit test initialization hook.
310
 */
311
#define MODULE_INIT_TESTS() {                                                 \
312
  /* add unit-test shell commands */                                          \
313
  aosShellAddCommand(&aos.shell, &moduleUtAlldA3906.shellcmd);                \
314
  aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01b.shellcmd);             \
315
  aosShellAddCommand(&aos.shell, &moduleUtAlldIna219.shellcmd);               \
316
  aosShellAddCommand(&aos.shell, &moduleUtAlldLed.shellcmd);                  \
317
  aosShellAddCommand(&aos.shell, &moduleUtAlldLtc4412.shellcmd);              \
318
  aosShellAddCommand(&aos.shell, &moduleUtAlldPca9544a.shellcmd);             \
319
  aosShellAddCommand(&aos.shell, &moduleUtAlldTps62113.shellcmd);             \
320
  aosShellAddCommand(&aos.shell, &moduleUtAlldVcnl4020.shellcmd);             \
321
}
322
323
/**
324
 * @brief   Periphery communication interfaces initialization hook.
325
 */
326
#define MODULE_INIT_PERIPHERY_COMM() {                                        \
327
  /* serial driver */                                                         \
328
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
329
  /* I2C */                                                                   \
330
  /* TODO: calculcate config depending on BNO055 */                           \
331
  i2cStart(&MODULE_HAL_I2C_IMU, &moduleHalI2cImuConfig);                      \
332
  moduleHalI2cProxEepromPwrmtrConfig.clock_speed = (PCA9544A_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxEepromPwrmtrConfig.clock_speed) ? PCA9544A_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxEepromPwrmtrConfig.clock_speed; \
333
  moduleHalI2cProxEepromPwrmtrConfig.clock_speed = (VCNL4020_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxEepromPwrmtrConfig.clock_speed) ? VCNL4020_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxEepromPwrmtrConfig.clock_speed; \
334
  moduleHalI2cProxEepromPwrmtrConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxEepromPwrmtrConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxEepromPwrmtrConfig.clock_speed; \
335
  moduleHalI2cProxEepromPwrmtrConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxEepromPwrmtrConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxEepromPwrmtrConfig.clock_speed; \
336
  moduleHalI2cProxEepromPwrmtrConfig.duty_cycle = (moduleHalI2cProxEepromPwrmtrConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
337
  i2cStart(&MODULE_HAL_I2C_PROX_EEPROM_PWRMTR, &moduleHalI2cProxEepromPwrmtrConfig);  \
338
  /* PWM */                                                                   \
339
  pwmStart(&MODULE_HAL_PWM_DRIVE, &moduleHalPwmDriveConfig);                  \
340
  /* QEI */                                                                   \
341
  qeiStart(&MODULE_HAL_QEI_LEFT_WHEEL, &moduleHalQeiConfig);                  \
342
  qeiStart(&MODULE_HAL_QEI_RIGHT_WHEEL, &moduleHalQeiConfig);                 \
343
  qeiEnable(&MODULE_HAL_QEI_LEFT_WHEEL);                                      \
344
  qeiEnable(&MODULE_HAL_QEI_RIGHT_WHEEL);                                     \
345
}
346
347
/**
348
 * @brief   Periphery communication interface deinitialization hook.
349
 */
350
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
351
  /* PWM */                                                                   \
352
  pwmStop(&MODULE_HAL_PWM_DRIVE);                                             \
353
  /* QEI */                                                                   \
354
  qeiDisable(&MODULE_HAL_QEI_LEFT_WHEEL);                                     \
355
  qeiDisable(&MODULE_HAL_QEI_RIGHT_WHEEL);                                    \
356
  qeiStop(&MODULE_HAL_QEI_LEFT_WHEEL);                                        \
357
  qeiStop(&MODULE_HAL_QEI_RIGHT_WHEEL);                                       \
358
  /* I2C */                                                                   \
359
  i2cStop(&MODULE_HAL_I2C_IMU);                                               \
360
  i2cStop(&MODULE_HAL_I2C_PROX_EEPROM_PWRMTR);                                \
361
  /* don't stop the serial driver so messages can still be printed */         \
362
}
363
364
/** @} */
365
366
/*===========================================================================*/
367
/**
368
 * @name Startup Shutdown Synchronization Protocol (SSSP)
369
 * @{
370
 */
371
/*===========================================================================*/
372
373
/**
374
 * @brief   PD signal GPIO.
375
 */
376
#define moduleSsspGpioPd                        moduleGpioSysPd
377
378
/**
379
 * @brief   SYNC signal GPIO.
380
 */
381
#define moduleSsspGpioSync                      moduleGpioSysSync
382
383
/**
384
 * @brief   UP signal GPIO.
385
 */
386
#define moduleSsspGpioUp                        moduleGpioSysUartUp
387
388
/**
389
 * @brief   Event flags for PD signal events.
390
 */
391
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
392
393
/**
394
 * @brief   Event flags for SYNC signal events.
395
 */
396
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
397
398
/**
399
 * @brief   Event flags for UP signal events.
400
 */
401
#define MODULE_SSSP_EVENTFLAGS_UP               MODULE_OS_IOEVENTFLAGS_SYSUARTUP
402
403
/** @} */
404
405
/*===========================================================================*/
406
/**
407
 * @name Low-level drivers
408
 * @{
409
 */
410
/*===========================================================================*/
411
#include <alld_A3906.h>
412
#include <alld_AT24C01B.h>
413
#include <alld_INA219.h>
414
#include <alld_LED.h>
415
#include <alld_LTC4412.h>
416
#include <alld_PCA9544A.h>
417
#include <alld_TPS6211x.h>
418
#include <alld_VCNL4020.h>
419
420
// TODO: add BNO055 IMU
421
422
/**
423
 * @brief   Motor driver.
424
 */
425
extern A3906Driver moduleLldMotors;
426
427
/**
428
 * @brief   EEPROM driver.
429
 */
430
extern AT24C01BDriver moduleLldEeprom;
431
432
/**
433
 * @brief   Power monitor (VDD) driver.
434
 */
435
extern INA219Driver moduleLldPowerMonitorVdd;
436
437
/**
438
 * @brief   Status LED driver.
439
 */
440
extern LEDDriver moduleLldStatusLed;
441
442
/**
443
 * @brief   Power path controler (charging pins) driver.
444
 */
445
extern LTC4412Driver moduleLldPowerPathController;
446
447
/**
448
 * @brief   I2C multiplexer driver.
449
 */
450
extern PCA9544ADriver moduleLldI2cMultiplexer;
451
452
/**
453
 * @brief   Step down converter (VDRIVE) driver.
454
 */
455
extern TPS6211xDriver moduleLldStepDownConverterVdrive;
456
457
/**
458
 * @brief   Proximity sensor driver.
459
 */
460
extern VCNL4020Driver moduleLldProximity;
461
462
/** @} */
463
464
/*===========================================================================*/
465
/**
466
 * @name Unit tests (UT)
467
 * @{
468
 */
469
/*===========================================================================*/
470
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
471
#include <ut_alld_A3906_v1.h>
472
#include <ut_alld_AT24C01B_v1.h>
473
#include <ut_alld_INA219_v1.h>
474
#include <ut_alld_LED_v1.h>
475
#include <ut_alld_LTC4412_v1.h>
476
#include <ut_alld_PCA9544A_v1.h>
477
#include <ut_alld_TPS6211x_v1.h>
478
#include <ut_alld_VCNL4020_v1.h>
479
480
// TODO: add BNO055 IMU
481
482
/**
483
 * @brief   A3906 (motor driver) unit test object.
484
 */
485
extern aos_unittest_t moduleUtAlldA3906;
486
487
/**
488
 * @brief   AT24C01BN-SH-B (EEPROM) unit test object.
489
 */
490
extern aos_unittest_t moduleUtAlldAt24c01b;
491
492
/**
493
 * @brief   INA219 (power monitor) unit test object.
494
 */
495
extern aos_unittest_t moduleUtAlldIna219;
496
497
/**
498
 * @brief   Status LED unit test object.
499
 */
500
extern aos_unittest_t moduleUtAlldLed;
501
502
/**
503
 * @brief   LTC4412 (power path controller) unit test object.
504
 */
505
extern aos_unittest_t moduleUtAlldLtc4412;
506
507
/**
508
 * @brief   PCA9544A (I2C multiplexer) unit test object.
509
 */
510
extern aos_unittest_t moduleUtAlldPca9544a;
511
512
/**
513
 * @brief   TPS62113 (step-down converter) unit test object.
514
 */
515
extern aos_unittest_t moduleUtAlldTps62113;
516
517
/**
518
 * @brief   VCNL4020 (proximity sensor) unit test object.
519
 */
520
extern aos_unittest_t moduleUtAlldVcnl4020;
521
522
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
523
524
/** @} */
525
526
#endif /* AMIROOS_MODULE_H */
527
528
/** @} */