Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-2 / module.h @ 4c72a54c

History | View | Annotate | Download (16.643 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 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
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC          AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_INT_N))
236

    
237
/**
238
 * @brief   Event flag to be set on a SYS_WARMRST interrupt.
239
 */
240
#define MODULE_OS_IOEVENTFLAGS_SYSWARMRST       AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_WARMRST_N))
241

    
242
/**
243
 * @brief   Event flag to be set on a PATH_DCSTAT interrupt.
244
 */
245
#define MODULE_OS_IOEVENTFLAGS_PATHDCSTAT       AOS_IOEVENT_FLAG(PAL_PAD(LINE_PATH_DCEN))
246

    
247
/**
248
 * @brief   Event flag to be set on a SYS_PD interrupt.
249
 */
250
#define MODULE_OS_IOEVENTFLAGS_SYSPD            AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
251

    
252
/**
253
 * @brief   Event flag to be set on a SYS_REG_EN interrupt.
254
 */
255
#define MODULE_OS_IOEVENTFLAGS_SYSREGEN         AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_REG_EN))
256

    
257
/**
258
 * @brief   Event flag to be set on a IR_INT interrupt.
259
 */
260
#define MODULE_OS_IOEVENTFLAGS_IRINT            AOS_IOEVENT_FLAG(PAL_PAD(LINE_IR_INT))
261

    
262
/**
263
 * @brief   Event flag to be set on a SYS_UART_UP interrupt.
264
 */
265
#define MODULE_OS_IOEVENTFLAGS_SYSUARTUP        AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_UART_UP))
266

    
267
/**
268
 * @brief   Event flag to be set on a IMU_INT interrupt.
269
 */
270
#define MODULE_OS_IOEVENTFLAGS_IMUINT         AOS_IOEVENT_FLAG(PAL_PAD(LINE_IMU_INT))
271

    
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
  palSetLineCallback(moduleGpioIrInt.gpio->line, aosSysGetStdIntCallback(), &moduleGpioIrInt.gpio->line); \
293
  palEnableLineEvent(moduleGpioIrInt.gpio->line, APAL2CH_EDGE(moduleGpioIrInt.meta.edge));                \
294
  /* IMU_INT */                                                               \
295
  palSetLineCallback(moduleGpioImuInt.gpio->line, aosSysGetStdIntCallback(), &moduleGpioImuInt.gpio->line); \
296
  palEnableLineEvent(moduleGpioImuInt.gpio->line, APAL2CH_EDGE(moduleGpioImuInt.meta.edge));                \
297
  /* PATH_DCSTAT */                                                           \
298
  palSetLineCallback(moduleGpioPathDcStat.gpio->line, aosSysGetStdIntCallback(), &moduleGpioPathDcStat.gpio->line); \
299
  palEnableLineEvent(moduleGpioPathDcStat.gpio->line, APAL2CH_EDGE(moduleGpioPathDcStat.meta.edge));                \
300
  /* SYS_REG_EN */                                                            \
301
  palSetLineCallback(moduleGpioSysRegEn.gpio->line, aosSysGetStdIntCallback(), &moduleGpioSysRegEn.gpio->line); \
302
  palEnableLineEvent(moduleGpioSysRegEn.gpio->line, APAL2CH_EDGE(moduleGpioSysRegEn.meta.edge));                \
303
  /* SYS_WARMRST */                                                           \
304
  palSetLineCallback(moduleGpioSysWarmrst.gpio->line, aosSysGetStdIntCallback(), &moduleGpioSysWarmrst.gpio->line); \
305
  palEnableLineEvent(moduleGpioSysWarmrst.gpio->line, APAL2CH_EDGE(moduleGpioSysWarmrst.meta.edge));                \
306
}
307

    
308
/**
309
 * @brief   Test initialization hook.
310
 */
311
#define MODULE_INIT_TESTS() {                                                 \
312
  /* initialize tests and add to shell */                                     \
313
  aosShellAddCommand(&aos.shell, &moduleTestA3906ShellCmd);                   \
314
  aosShellAddCommand(&aos.shell, &moduleTestAt24c01bShellCmd);                \
315
  /* TODO: add BNO055 test command */                                         \
316
  aosShellAddCommand(&aos.shell, &moduleTestIna219ShellCmd);                  \
317
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
318
  aosShellAddCommand(&aos.shell, &moduleTestLtc4412ShellCmd);                 \
319
  aosShellAddCommand(&aos.shell, &moduleTestPca9544aShellCmd);                \
320
  aosShellAddCommand(&aos.shell, &moduleTestTps62113ShellCmd);                \
321
  aosShellAddCommand(&aos.shell, &moduleTestVcnl4020ShellCmd);                \
322
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
323
}
324

    
325
/**
326
 * @brief   Periphery communication interfaces initialization hook.
327
 */
328
#define MODULE_INIT_PERIPHERY_IF() {                                          \
329
  /* serial driver */                                                         \
330
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
331
  /* I2C */                                                                   \
332
  /* TODO: calculcate config depending on BNO055 */                           \
333
  i2cStart(&MODULE_HAL_I2C_IMU, &moduleHalI2cImuConfig);                      \
334
  moduleHalI2cProxEepromPwrmtrConfig.clock_speed = (PCA9544A_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxEepromPwrmtrConfig.clock_speed) ? PCA9544A_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxEepromPwrmtrConfig.clock_speed; \
335
  moduleHalI2cProxEepromPwrmtrConfig.clock_speed = (VCNL4020_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxEepromPwrmtrConfig.clock_speed) ? VCNL4020_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxEepromPwrmtrConfig.clock_speed; \
336
  moduleHalI2cProxEepromPwrmtrConfig.clock_speed = (AT24C01B_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxEepromPwrmtrConfig.clock_speed) ? AT24C01B_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxEepromPwrmtrConfig.clock_speed; \
337
  moduleHalI2cProxEepromPwrmtrConfig.clock_speed = (INA219_LLD_I2C_MAXFREQUENCY < moduleHalI2cProxEepromPwrmtrConfig.clock_speed) ? INA219_LLD_I2C_MAXFREQUENCY : moduleHalI2cProxEepromPwrmtrConfig.clock_speed; \
338
  moduleHalI2cProxEepromPwrmtrConfig.duty_cycle = (moduleHalI2cProxEepromPwrmtrConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2;  \
339
  i2cStart(&MODULE_HAL_I2C_PROX_EEPROM_PWRMTR, &moduleHalI2cProxEepromPwrmtrConfig);  \
340
  /* PWM */                                                                   \
341
  pwmStart(&MODULE_HAL_PWM_DRIVE, &moduleHalPwmDriveConfig);                  \
342
  /* QEI */                                                                   \
343
  qeiStart(&MODULE_HAL_QEI_LEFT_WHEEL, &moduleHalQeiConfig);                  \
344
  qeiStart(&MODULE_HAL_QEI_RIGHT_WHEEL, &moduleHalQeiConfig);                 \
345
  qeiEnable(&MODULE_HAL_QEI_LEFT_WHEEL);                                      \
346
  qeiEnable(&MODULE_HAL_QEI_RIGHT_WHEEL);                                     \
347
}
348

    
349
/**
350
 * @brief   Periphery communication interface deinitialization hook.
351
 */
352
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
353
  /* PWM */                                                                   \
354
  pwmStop(&MODULE_HAL_PWM_DRIVE);                                             \
355
  /* QEI */                                                                   \
356
  qeiDisable(&MODULE_HAL_QEI_LEFT_WHEEL);                                     \
357
  qeiDisable(&MODULE_HAL_QEI_RIGHT_WHEEL);                                    \
358
  qeiStop(&MODULE_HAL_QEI_LEFT_WHEEL);                                        \
359
  qeiStop(&MODULE_HAL_QEI_RIGHT_WHEEL);                                       \
360
  /* I2C */                                                                   \
361
  i2cStop(&MODULE_HAL_I2C_IMU);                                               \
362
  i2cStop(&MODULE_HAL_I2C_PROX_EEPROM_PWRMTR);                                \
363
  /* don't stop the serial driver so messages can still be printed */         \
364
}
365

    
366
/** @} */
367

    
368
/*===========================================================================*/
369
/**
370
 * @name Startup Shutdown Synchronization Protocol (SSSP)
371
 * @{
372
 */
373
/*===========================================================================*/
374

    
375
/**
376
 * @brief   PD signal GPIO.
377
 */
378
#define moduleSsspGpioPd                        moduleGpioSysPd
379

    
380
/**
381
 * @brief   SYNC signal GPIO.
382
 */
383
#define moduleSsspGpioSync                      moduleGpioSysSync
384

    
385
/**
386
 * @brief   UP signal GPIO.
387
 */
388
#define moduleSsspGpioUp                        moduleGpioSysUartUp
389

    
390
/**
391
 * @brief   Event flags for PD signal events.
392
 */
393
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
394

    
395
/**
396
 * @brief   Event flags for SYNC signal events.
397
 */
398
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
399

    
400
/**
401
 * @brief   Event flags for UP signal events.
402
 */
403
#define MODULE_SSSP_EVENTFLAGS_UP               MODULE_OS_IOEVENTFLAGS_SYSUARTUP
404

    
405
/** @} */
406

    
407
/*===========================================================================*/
408
/**
409
 * @name Low-level drivers
410
 * @{
411
 */
412
/*===========================================================================*/
413
#include <alld_A3906.h>
414
#include <alld_AT24C01B.h>
415
// TODO: add BNO055 IMU
416
#include <alld_INA219.h>
417
#include <alld_LED.h>
418
#include <alld_LTC4412.h>
419
#include <alld_PCA9544A.h>
420
#include <alld_TPS6211x.h>
421
#include <alld_VCNL4020.h>
422

    
423
/**
424
 * @brief   Motor driver.
425
 */
426
extern A3906Driver moduleLldMotors;
427

    
428
/**
429
 * @brief   EEPROM driver.
430
 */
431
extern AT24C01BDriver moduleLldEeprom;
432

    
433
// TODO: add BNO055 IMU
434

    
435
/**
436
 * @brief   Power monitor (VDD) driver.
437
 */
438
extern INA219Driver moduleLldPowerMonitorVdd;
439

    
440
/**
441
 * @brief   Status LED driver.
442
 */
443
extern LEDDriver moduleLldStatusLed;
444

    
445
/**
446
 * @brief   Power path controler (charging pins) driver.
447
 */
448
extern LTC4412Driver moduleLldPowerPathController;
449

    
450
/**
451
 * @brief   I2C multiplexer driver.
452
 */
453
extern PCA9544ADriver moduleLldI2cMultiplexer;
454

    
455
/**
456
 * @brief   Step down converter (VDRIVE) driver.
457
 */
458
extern TPS6211xDriver moduleLldStepDownConverterVdrive;
459

    
460
/**
461
 * @brief   Proximity sensor driver.
462
 */
463
extern VCNL4020Driver moduleLldProximity;
464

    
465
/** @} */
466

    
467
/*===========================================================================*/
468
/**
469
 * @name Tests
470
 * @{
471
 */
472
/*===========================================================================*/
473
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
474

    
475
/**
476
 * @brief   A3906 (motor driver) test command.
477
 */
478
extern aos_shellcommand_t moduleTestA3906ShellCmd;
479

    
480
/**
481
 * @brief   AT24C01BN-SH-B (EEPROM) test command.
482
 */
483
extern aos_shellcommand_t moduleTestAt24c01bShellCmd;
484

    
485
// TODO: add BNO055
486

    
487
/**
488
 * @brief   INA219 (power monitor) test command.
489
 */
490
extern aos_shellcommand_t moduleTestIna219ShellCmd;
491

    
492
/**
493
 * @brief   Status LED test command.
494
 */
495
extern aos_shellcommand_t moduleTestLedShellCmd;
496

    
497
/**
498
 * @brief   LTC4412 (power path controller) test command.
499
 */
500
extern aos_shellcommand_t moduleTestLtc4412ShellCmd;
501

    
502
/**
503
 * @brief   PCA9544A (I2C multiplexer) test command.
504
 */
505
extern aos_shellcommand_t moduleTestPca9544aShellCmd;
506

    
507
/**
508
 * @brief   TPS62113 (step-down converter) test command.
509
 */
510
extern aos_shellcommand_t moduleTestTps62113ShellCmd;
511

    
512
/**
513
 * @brief   VCNL4020 (proximity sensor) test command.
514
 */
515
extern aos_shellcommand_t moduleTestVcnl4020ShellCmd;
516

    
517
/**
518
 * @brief   Entire module test command.
519
 */
520
extern aos_shellcommand_t moduleTestAllShellCmd;
521

    
522
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
523

    
524
/** @} */
525

    
526
#endif /* AMIROOS_MODULE_H */
527

    
528
/** @} */