Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-2 / module.h @ 40b5aa1d

History | View | Annotate | Download (16.361 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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_GPIOEVENTFLAG_SYSSYNC         AOS_GPIOEVENT_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_GPIOEVENTFLAG_SYSWARMRST      AOS_GPIOEVENT_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_GPIOEVENTFLAG_PATHDCSTAT      AOS_GPIOEVENT_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_GPIOEVENTFLAG_SYSPD           AOS_GPIOEVENT_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_GPIOEVENTFLAG_SYSREGEN        AOS_GPIOEVENT_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_GPIOEVENTFLAG_IRINT           AOS_GPIOEVENT_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_GPIOEVENTFLAG_SYSUARTUP       AOS_GPIOEVENT_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_GPIOEVENTFLAG_IMUINT          AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_IMU_INT))
271

    
272
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
273
/**
274
 * @brief   Shell prompt text.
275
 */
276
extern ROMCONST char* moduleShellPrompt;
277
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
278

    
279
/**
280
 * @brief   Interrupt initialization macro.
281
 */
282
#define MODULE_INIT_INTERRUPTS() {                                            \
283
  /* IR_INT */                                                                \
284
  palSetLineCallback(moduleGpioIrInt.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioIrInt.gpio->line);  \
285
  palEnableLineEvent(moduleGpioIrInt.gpio->line, APAL2CH_EDGE(moduleGpioIrInt.meta.edge));                  \
286
  /* IMU_INT */                                                               \
287
  palSetLineCallback(moduleGpioImuInt.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioImuInt.gpio->line);  \
288
  palEnableLineEvent(moduleGpioImuInt.gpio->line, APAL2CH_EDGE(moduleGpioImuInt.meta.edge));                  \
289
  /* PATH_DCSTAT */                                                           \
290
  palSetLineCallback(moduleGpioPathDcStat.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioPathDcStat.gpio->line);  \
291
  palEnableLineEvent(moduleGpioPathDcStat.gpio->line, APAL2CH_EDGE(moduleGpioPathDcStat.meta.edge));                  \
292
  /* SYS_REG_EN */                                                            \
293
  palSetLineCallback(moduleGpioSysRegEn.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioSysRegEn.gpio->line);  \
294
  palEnableLineEvent(moduleGpioSysRegEn.gpio->line, APAL2CH_EDGE(moduleGpioSysRegEn.meta.edge));                  \
295
  /* SYS_WARMRST */                                                           \
296
  palSetLineCallback(moduleGpioSysWarmrst.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioSysWarmrst.gpio->line);  \
297
  palEnableLineEvent(moduleGpioSysWarmrst.gpio->line, APAL2CH_EDGE(moduleGpioSysWarmrst.meta.edge));                  \
298
}
299

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

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

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

    
362
/** @} */
363

    
364
/*===========================================================================*/
365
/**
366
 * @name Startup Shutdown Synchronization Protocol (SSSP)
367
 * @{
368
 */
369
/*===========================================================================*/
370

    
371
#define moduleSsspSignalPD()                    (&moduleGpioSysPd)
372
#define moduleSsspEventflagPD()                 MODULE_OS_GPIOEVENTFLAG_SYSPD
373

    
374
#define moduleSsspSignalS()                     (&moduleGpioSysSync)
375
#define moduleSsspEventflagS()                  MODULE_OS_GPIOEVENTFLAG_SYSSYNC
376

    
377
#define moduleSsspSignalUP()                    (&moduleGpioSysUartUp)
378
#define moduleSsspEventflagUP()                 MODULE_OS_GPIOEVENTFLAG_SYSUARTUP
379

    
380
/** @} */
381

    
382
/*===========================================================================*/
383
/**
384
 * @name Low-level drivers
385
 * @{
386
 */
387
/*===========================================================================*/
388
#include <alld_A3906.h>
389
#include <alld_AT24C01B.h>
390
// TODO: add BNO055 IMU
391
#include <alld_INA219.h>
392
#include <alld_LED.h>
393
#include <alld_LTC4412.h>
394
#include <alld_PCA9544A.h>
395
#include <alld_TPS6211x.h>
396
#include <alld_VCNL4020.h>
397

    
398
/**
399
 * @brief   Motor driver.
400
 */
401
extern A3906Driver moduleLldMotors;
402

    
403
/**
404
 * @brief   EEPROM driver.
405
 */
406
extern AT24C01BDriver moduleLldEeprom;
407

    
408
// TODO: add BNO055 IMU
409

    
410
/**
411
 * @brief   Power monitor (VDD) driver.
412
 */
413
extern INA219Driver moduleLldPowerMonitorVdd;
414

    
415
/**
416
 * @brief   Status LED driver.
417
 */
418
extern LEDDriver moduleLldStatusLed;
419

    
420
/**
421
 * @brief   Power path controler (charging pins) driver.
422
 */
423
extern LTC4412Driver moduleLldPowerPathController;
424

    
425
/**
426
 * @brief   I2C multiplexer driver.
427
 */
428
extern PCA9544ADriver moduleLldI2cMultiplexer;
429

    
430
/**
431
 * @brief   Step down converter (VDRIVE) driver.
432
 */
433
extern TPS6211xDriver moduleLldStepDownConverterVdrive;
434

    
435
/**
436
 * @brief   Proximity sensor driver.
437
 */
438
extern VCNL4020Driver moduleLldProximity;
439

    
440
/** @} */
441

    
442
/*===========================================================================*/
443
/**
444
 * @name Tests
445
 * @{
446
 */
447
/*===========================================================================*/
448
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
449

    
450
/**
451
 * @brief   A3906 (motor driver) test command.
452
 */
453
extern aos_shellcommand_t moduleTestA3906ShellCmd;
454

    
455
/**
456
 * @brief   AT24C01BN-SH-B (EEPROM) test command.
457
 */
458
extern aos_shellcommand_t moduleTestAt24c01bShellCmd;
459

    
460
// TODO: add BNO055
461

    
462
/**
463
 * @brief   INA219 (power monitor) test command.
464
 */
465
extern aos_shellcommand_t moduleTestIna219ShellCmd;
466

    
467
/**
468
 * @brief   Status LED test command.
469
 */
470
extern aos_shellcommand_t moduleTestLedShellCmd;
471

    
472
/**
473
 * @brief   LTC4412 (power path controller) test command.
474
 */
475
extern aos_shellcommand_t moduleTestLtc4412ShellCmd;
476

    
477
/**
478
 * @brief   PCA9544A (I2C multiplexer) test command.
479
 */
480
extern aos_shellcommand_t moduleTestPca9544aShellCmd;
481

    
482
/**
483
 * @brief   TPS62113 (step-down converter) test command.
484
 */
485
extern aos_shellcommand_t moduleTestTps62113ShellCmd;
486

    
487
/**
488
 * @brief   VCNL4020 (proximity sensor) test command.
489
 */
490
extern aos_shellcommand_t moduleTestVcnl4020ShellCmd;
491

    
492
/**
493
 * @brief   Entire module test command.
494
 */
495
extern aos_shellcommand_t moduleTestAllShellCmd;
496

    
497
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
498

    
499
/** @} */
500

    
501
#endif /* AMIROOS_MODULE_H */
502

    
503
/** @} */