Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-2 / module.h @ 56dc4779

History | View | Annotate | Download (16.4 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   Interrupt initialization macro.
281
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
282
 */
283
#define MODULE_INIT_INTERRUPTS() {                                            \
284
  /* IR_INT */                                                                \
285
  palSetLineCallback(moduleGpioIrInt.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioIrInt.gpio->line);  \
286
  palEnableLineEvent(moduleGpioIrInt.gpio->line, APAL2CH_EDGE(moduleGpioIrInt.meta.edge));                  \
287
  /* IMU_INT */                                                               \
288
  palSetLineCallback(moduleGpioImuInt.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioImuInt.gpio->line);  \
289
  palEnableLineEvent(moduleGpioImuInt.gpio->line, APAL2CH_EDGE(moduleGpioImuInt.meta.edge));                  \
290
  /* PATH_DCSTAT */                                                           \
291
  palSetLineCallback(moduleGpioPathDcStat.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioPathDcStat.gpio->line);  \
292
  palEnableLineEvent(moduleGpioPathDcStat.gpio->line, APAL2CH_EDGE(moduleGpioPathDcStat.meta.edge));                  \
293
  /* SYS_REG_EN */                                                            \
294
  palSetLineCallback(moduleGpioSysRegEn.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioSysRegEn.gpio->line);  \
295
  palEnableLineEvent(moduleGpioSysRegEn.gpio->line, APAL2CH_EDGE(moduleGpioSysRegEn.meta.edge));                  \
296
  /* SYS_WARMRST */                                                           \
297
  palSetLineCallback(moduleGpioSysWarmrst.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioSysWarmrst.gpio->line);  \
298
  palEnableLineEvent(moduleGpioSysWarmrst.gpio->line, APAL2CH_EDGE(moduleGpioSysWarmrst.meta.edge));                  \
299
}
300

    
301
/**
302
 * @brief   Test initialization hook.
303
 */
304
#define MODULE_INIT_TESTS() {                                                 \
305
  /* initialize tests and add to shell */                                     \
306
  aosShellAddCommand(&aos.shell, &moduleTestA3906ShellCmd);                   \
307
  aosShellAddCommand(&aos.shell, &moduleTestAt24c01bShellCmd);                \
308
  /* TODO: add BNO055 test command */                                         \
309
  aosShellAddCommand(&aos.shell, &moduleTestIna219ShellCmd);                  \
310
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
311
  aosShellAddCommand(&aos.shell, &moduleTestLtc4412ShellCmd);                 \
312
  aosShellAddCommand(&aos.shell, &moduleTestPca9544aShellCmd);                \
313
  aosShellAddCommand(&aos.shell, &moduleTestTps62113ShellCmd);                \
314
  aosShellAddCommand(&aos.shell, &moduleTestVcnl4020ShellCmd);                \
315
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
316
}
317

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

    
342
/**
343
 * @brief   Periphery communication interface deinitialization hook.
344
 */
345
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
346
  /* PWM */                                                                   \
347
  pwmStop(&MODULE_HAL_PWM_DRIVE);                                             \
348
  /* QEI */                                                                   \
349
  qeiDisable(&MODULE_HAL_QEI_LEFT_WHEEL);                                     \
350
  qeiDisable(&MODULE_HAL_QEI_RIGHT_WHEEL);                                    \
351
  qeiStop(&MODULE_HAL_QEI_LEFT_WHEEL);                                        \
352
  qeiStop(&MODULE_HAL_QEI_RIGHT_WHEEL);                                       \
353
  /* I2C */                                                                   \
354
  i2cStop(&MODULE_HAL_I2C_IMU);                                               \
355
  i2cStop(&MODULE_HAL_I2C_PROX_EEPROM_PWRMTR);                                \
356
  /* don't stop the serial driver so messages can still be printed */         \
357
}
358

    
359
/** @} */
360

    
361
/*===========================================================================*/
362
/**
363
 * @name Startup Shutdown Synchronization Protocol (SSSP)
364
 * @{
365
 */
366
/*===========================================================================*/
367

    
368
/**
369
 * @brief   PD signal GPIO.
370
 */
371
#define moduleSsspGpioPd                        moduleGpioSysPd
372

    
373
/**
374
 * @brief   SYNC signal GPIO.
375
 */
376
#define moduleSsspGpioSync                      moduleGpioSysSync
377

    
378
/**
379
 * @brief   UP signal GPIO.
380
 */
381
#define moduleSsspGpioUp                        moduleGpioSysUartUp
382

    
383
/**
384
 * @brief   Event flags for PD signal events.
385
 */
386
#define MODULE_SSSP_EVENTFLAGS_PD               MODULE_OS_IOEVENTFLAGS_SYSPD
387

    
388
/**
389
 * @brief   Event flags for SYNC signal events.
390
 */
391
#define MODULE_SSSP_EVENTFLAGS_SYNC             MODULE_OS_IOEVENTFLAGS_SYSSYNC
392

    
393
/**
394
 * @brief   Event flags for UP signal events.
395
 */
396
#define MODULE_SSSP_EVENTFLAGS_UP               MODULE_OS_IOEVENTFLAGS_SYSUARTUP
397

    
398
/** @} */
399

    
400
/*===========================================================================*/
401
/**
402
 * @name Low-level drivers
403
 * @{
404
 */
405
/*===========================================================================*/
406
#include <alld_A3906.h>
407
#include <alld_AT24C01B.h>
408
// TODO: add BNO055 IMU
409
#include <alld_INA219.h>
410
#include <alld_LED.h>
411
#include <alld_LTC4412.h>
412
#include <alld_PCA9544A.h>
413
#include <alld_TPS6211x.h>
414
#include <alld_VCNL4020.h>
415

    
416
/**
417
 * @brief   Motor driver.
418
 */
419
extern A3906Driver moduleLldMotors;
420

    
421
/**
422
 * @brief   EEPROM driver.
423
 */
424
extern AT24C01BDriver moduleLldEeprom;
425

    
426
// TODO: add BNO055 IMU
427

    
428
/**
429
 * @brief   Power monitor (VDD) driver.
430
 */
431
extern INA219Driver moduleLldPowerMonitorVdd;
432

    
433
/**
434
 * @brief   Status LED driver.
435
 */
436
extern LEDDriver moduleLldStatusLed;
437

    
438
/**
439
 * @brief   Power path controler (charging pins) driver.
440
 */
441
extern LTC4412Driver moduleLldPowerPathController;
442

    
443
/**
444
 * @brief   I2C multiplexer driver.
445
 */
446
extern PCA9544ADriver moduleLldI2cMultiplexer;
447

    
448
/**
449
 * @brief   Step down converter (VDRIVE) driver.
450
 */
451
extern TPS6211xDriver moduleLldStepDownConverterVdrive;
452

    
453
/**
454
 * @brief   Proximity sensor driver.
455
 */
456
extern VCNL4020Driver moduleLldProximity;
457

    
458
/** @} */
459

    
460
/*===========================================================================*/
461
/**
462
 * @name Tests
463
 * @{
464
 */
465
/*===========================================================================*/
466
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
467

    
468
/**
469
 * @brief   A3906 (motor driver) test command.
470
 */
471
extern aos_shellcommand_t moduleTestA3906ShellCmd;
472

    
473
/**
474
 * @brief   AT24C01BN-SH-B (EEPROM) test command.
475
 */
476
extern aos_shellcommand_t moduleTestAt24c01bShellCmd;
477

    
478
// TODO: add BNO055
479

    
480
/**
481
 * @brief   INA219 (power monitor) test command.
482
 */
483
extern aos_shellcommand_t moduleTestIna219ShellCmd;
484

    
485
/**
486
 * @brief   Status LED test command.
487
 */
488
extern aos_shellcommand_t moduleTestLedShellCmd;
489

    
490
/**
491
 * @brief   LTC4412 (power path controller) test command.
492
 */
493
extern aos_shellcommand_t moduleTestLtc4412ShellCmd;
494

    
495
/**
496
 * @brief   PCA9544A (I2C multiplexer) test command.
497
 */
498
extern aos_shellcommand_t moduleTestPca9544aShellCmd;
499

    
500
/**
501
 * @brief   TPS62113 (step-down converter) test command.
502
 */
503
extern aos_shellcommand_t moduleTestTps62113ShellCmd;
504

    
505
/**
506
 * @brief   VCNL4020 (proximity sensor) test command.
507
 */
508
extern aos_shellcommand_t moduleTestVcnl4020ShellCmd;
509

    
510
/**
511
 * @brief   Entire module test command.
512
 */
513
extern aos_shellcommand_t moduleTestAllShellCmd;
514

    
515
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
516

    
517
/** @} */
518

    
519
#endif /* AMIROOS_MODULE_H */
520

    
521
/** @} */