Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-1 / module.c @ 98949060

History | View | Annotate | Download (19.563 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 84f0ce9e Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 e545e620 Thomas Schöpping

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 53710ca3 Marc Rothmann
/**
20 acc97cbf Thomas Schöpping
 * @file
21 53710ca3 Marc Rothmann
 * @brief   Structures and constant for the DiWheelDrive module.
22
 *
23
 * @addtogroup diwheeldrive_module
24
 * @{
25
 */
26
27 c53ef0b1 Thomas Schöpping
#include <amiroos.h>
28
29
#include <string.h>
30 e545e620 Thomas Schöpping
31
/*===========================================================================*/
32
/**
33
 * @name Module specific functions
34
 * @{
35
 */
36
/*===========================================================================*/
37
38
/** @} */
39
40
/*===========================================================================*/
41
/**
42
 * @name ChibiOS/HAL configuration
43
 * @{
44
 */
45
/*===========================================================================*/
46
47
CANConfig moduleHalCanConfig = {
48
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
49
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
50
};
51
52
I2CConfig moduleHalI2cCompassConfig = {
53
  /* I²C mode   */ OPMODE_I2C,
54
  /* frequency  */ 400000,
55
  /* duty cycle */ FAST_DUTY_CYCLE_2,
56
};
57
58
I2CConfig moduleHalI2cProxEepromPwrmtrConfig = {
59
  /* I²C mode   */ OPMODE_I2C,
60
  /* frequency  */ 400000,
61
  /* duty cycle */ FAST_DUTY_CYCLE_2,
62
};
63
64
PWMConfig moduleHalPwmDriveConfig = {
65
  /* frequency              */ 7200000,
66
  /* period                 */ 360,
67
  /* callback               */ NULL,
68
  /* channel configurations */ {
69
    /* channel 0              */ {
70
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
71
      /* callback               */ NULL
72
    },
73
    /* channel 1              */ {
74
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
75
      /* callback               */ NULL
76
    },
77
    /* channel 2              */ {
78
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
79
      /* callback               */ NULL
80
    },
81
    /* channel 3              */ {
82
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
83
      /* callback               */ NULL
84
    },
85
  },
86
  /* TIM CR2 register       */ 0,
87 7de0cc90 Thomas Schöpping
#if (STM32_PWM_USE_ADVANCED == TRUE)
88 e545e620 Thomas Schöpping
  /* TIM BDTR register      */ 0,
89 7de0cc90 Thomas Schöpping
#endif /* (STM32_PWM_USE_ADVANCED == TRUE) */
90 e545e620 Thomas Schöpping
  /* TIM DIER register      */ 0
91
};
92
93
QEIConfig moduleHalQeiConfig = {
94
  /* mode           */ QEI_COUNT_BOTH,
95
  /* channel config */ {
96
    /* channel 0 */ {
97
      /* input mode */ QEI_INPUT_NONINVERTED,
98
    },
99
    /* channel 1 */ {
100
      /* input mode */ QEI_INPUT_NONINVERTED,
101
    },
102
  },
103
  /* encoder range  */  0x10000u,
104
};
105
106
SerialConfig moduleHalProgIfConfig = {
107
  /* bit rate */ 115200,
108
  /* CR1      */ 0,
109
  /* CR1      */ 0,
110
  /* CR1      */ 0,
111
};
112
113
SPIConfig moduleHalSpiAccelerometerConfig = {
114 0128be0f Marc Rothmann
  /* circular buffer mode         */ false,
115 e545e620 Thomas Schöpping
  /* callback function pointer    */ NULL,
116 3106e8cc Thomas Schöpping
  /* chip select line port        */ PAL_PORT(LINE_ACCEL_SS_N),
117
  /* chip select line pad number  */ PAL_PAD(LINE_ACCEL_SS_N),
118 e545e620 Thomas Schöpping
  /* CR1                          */ SPI_CR1_BR_0,
119
  /* CR2                          */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
120
};
121
122
SPIConfig moduleHalSpiGyroscopeConfig = {
123 0128be0f Marc Rothmann
  /* circular buffer mode         */ false,
124 e545e620 Thomas Schöpping
  /* callback function pointer    */ NULL,
125 3106e8cc Thomas Schöpping
  /* chip select line port        */ PAL_PORT(LINE_GYRO_SS_N),
126
  /* chip select line pad number  */ PAL_PAD(LINE_GYRO_SS_N),
127 e545e620 Thomas Schöpping
  /* CR1                          */ SPI_CR1_BR_0,
128
  /* CR2                          */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
129
};
130
131
/** @} */
132
133
/*===========================================================================*/
134
/**
135
 * @name GPIO definitions
136
 * @{
137
 */
138
/*===========================================================================*/
139
140 1e5f7648 Thomas Schöpping
/**
141
 * @brief   LED output signal GPIO.
142
 */
143
static apalGpio_t _gpioLed = {
144 3106e8cc Thomas Schöpping
  /* line */ LINE_LED,
145 e545e620 Thomas Schöpping
};
146 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLed = {
147 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioLed,
148
  /* meta */ {
149
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
150 4c72a54c Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
151 1e5f7648 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
152
  },
153
};
154 e545e620 Thomas Schöpping
155 1e5f7648 Thomas Schöpping
/**
156
 * @brief   POWER_EN output signal GPIO.
157
 */
158
static apalGpio_t _gpioPowerEn = {
159 3106e8cc Thomas Schöpping
  /* line */ LINE_POWER_EN,
160 e545e620 Thomas Schöpping
};
161 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPowerEn = {
162 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPowerEn,
163
  /* meta */ {
164
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
165
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
166
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
167
  },
168
};
169 e545e620 Thomas Schöpping
170 1e5f7648 Thomas Schöpping
/**
171
 * @brief   COMPASS_DRDY output signal GPIO.
172
 */
173
static apalGpio_t _gpioCompassDrdy = {
174 3106e8cc Thomas Schöpping
  /* line */ LINE_COMPASS_DRDY,
175 e545e620 Thomas Schöpping
};
176 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioCompassDrdy = {
177 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioCompassDrdy,
178
  /* meta */ {
179
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
180
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
181
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
182
  },
183
};
184 e545e620 Thomas Schöpping
185 1e5f7648 Thomas Schöpping
/**
186
 * @brief   IR_INT input signal GPIO.
187
 */
188
static apalGpio_t _gpioIrInt = {
189 3106e8cc Thomas Schöpping
  /* line */ LINE_IR_INT,
190 e545e620 Thomas Schöpping
};
191 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioIrInt = {
192 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioIrInt,
193
  /* meta */ {
194
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
195
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
196
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
197
  },
198
};
199 e545e620 Thomas Schöpping
200 1e5f7648 Thomas Schöpping
/**
201
 * @brief   GYRO_DRDY input signal GPIO.
202
 */
203
static apalGpio_t _gpioGyroDrdy = {
204 3106e8cc Thomas Schöpping
  /* line */ LINE_GYRO_DRDY,
205 e545e620 Thomas Schöpping
};
206 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGyroDrdy = {
207 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioGyroDrdy,
208
  /* meta */ {
209
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
210
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
211
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
212
  },
213
};
214 e545e620 Thomas Schöpping
215 1e5f7648 Thomas Schöpping
/**
216
 * @brief   SYS_UART_UP bidirectional signal GPIO.
217
 */
218
static apalGpio_t _gpioSysUartUp = {
219 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_UART_UP,
220 e545e620 Thomas Schöpping
};
221 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
222 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysUartUp,
223
  /* meta */ {
224
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
225
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
226
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
227
  },
228
};
229 e545e620 Thomas Schöpping
230 1e5f7648 Thomas Schöpping
/**
231
 * @brief   ACCEL_INT input signal GPIO.
232
 */
233
static apalGpio_t _gpioAccelInt = {
234 3106e8cc Thomas Schöpping
  /* line */ LINE_ACCEL_INT_N,
235 e545e620 Thomas Schöpping
};
236 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioAccelInt = {
237 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioAccelInt,
238
  /* meta */ {
239
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
240
    /* active state   */ (LIS331DLH_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
241
    /* interrupt edge */ LIS331DLH_LLD_INT_EDGE,
242
  },
243
};
244 e545e620 Thomas Schöpping
245 1e5f7648 Thomas Schöpping
/**
246
 * @brief   SYS_SNYC bidirectional signal GPIO.
247
 */
248
static apalGpio_t _gpioSysSync = {
249 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_INT_N,
250 e545e620 Thomas Schöpping
};
251 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t  moduleGpioSysSync = {
252 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysSync,
253
  /* meta */ {
254
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
255
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
256
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
257
  },
258
};
259 e545e620 Thomas Schöpping
260 1e5f7648 Thomas Schöpping
/**
261
 * @brief   PATH_DCSTAT input signal GPIO.
262
 */
263
static apalGpio_t _gpioPathDcStat = {
264 3106e8cc Thomas Schöpping
  /* line */ LINE_PATH_DCSTAT,
265 e545e620 Thomas Schöpping
};
266 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPathDcStat = {
267 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPathDcStat,
268
  /* meta */ {
269
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
270
    /* active state   */ LTC4412_LLD_STAT_ACTIVE_STATE,
271
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
272
  },
273
};
274 e545e620 Thomas Schöpping
275 1e5f7648 Thomas Schöpping
/**
276
 * @brief   PATH_DCEN output signal GPIO.
277
 */
278
static apalGpio_t _gpioPathDcEn = {
279 3106e8cc Thomas Schöpping
  /* line */ LINE_PATH_DCEN,
280 e545e620 Thomas Schöpping
};
281 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPathDcEn = {
282 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPathDcEn,
283
  /* meta */ {
284
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
285
    /* active state   */ LTC4412_LLD_CTRL_ACTIVE_STATE,
286
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
287
  },
288
};
289 e545e620 Thomas Schöpping
290 1e5f7648 Thomas Schöpping
/**
291
 * @brief   SYS_PD bidirectional signal GPIO.
292
 */
293
static apalGpio_t _gpioSysPd = {
294 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_PD_N,
295 e545e620 Thomas Schöpping
};
296 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysPd = {
297 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysPd,
298
  /* meta */ {
299
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
300
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
301
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
302
  },
303
};
304 e545e620 Thomas Schöpping
305 1e5f7648 Thomas Schöpping
/**
306
 * @brief   SYS_REG_EN input signal GPIO.
307
 */
308
static apalGpio_t _gpioSysRegEn = {
309 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_REG_EN,
310 e545e620 Thomas Schöpping
};
311 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysRegEn = {
312 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysRegEn,
313
  /* meta */ {
314
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
315
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
316
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
317
  },
318
};
319 e545e620 Thomas Schöpping
320 1e5f7648 Thomas Schöpping
/**
321
 * @brief   SYS_WARMRST bidirectional signal GPIO.
322
 */
323
static apalGpio_t _gpioSysWarmrst = {
324 3106e8cc Thomas Schöpping
  /* line */ LINE_SYS_WARMRST_N,
325 e545e620 Thomas Schöpping
};
326 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysWarmrst = {
327 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysWarmrst,
328
  /* meta */ {
329
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
330
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
331
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
332
  },
333
};
334 e545e620 Thomas Schöpping
335
/** @} */
336
337
/*===========================================================================*/
338
/**
339
 * @name AMiRo-OS core configurations
340
 * @{
341
 */
342
/*===========================================================================*/
343
344 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
345 acc97cbf Thomas Schöpping
ROMCONST char* moduleShellPrompt = "DiWheelDrive";
346 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
347 6b53f6bf Thomas Schöpping
348
/** @} */
349
350
/*===========================================================================*/
351
/**
352
 * @name Startup Shutdown Synchronization Protocol (SSSP)
353
 * @{
354
 */
355
/*===========================================================================*/
356
357 c53ef0b1 Thomas Schöpping
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true)) || defined(__DOXYGEN__)
358
359
/* some local definitions */
360
// maximum number of bytes per CAN frame
361
#define CAN_BYTES_PER_FRAME                     8
362
// identifier (as dominant as possible)
363
#define MSI_BCBMSG_CANID                        0
364
365
aos_ssspbcbstatus_t moduleSsspBcbTransmit(const uint8_t* buffer, size_t length)
366
{
367
  aosDbgCheck(buffer != NULL);
368
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
369
370
  // local variables
371
  CANTxFrame frame;
372
373
  // setup the common parts of the message frame
374
  frame.DLC = (uint8_t)length;
375
  frame.RTR = CAN_RTR_DATA;
376
  frame.IDE = CAN_IDE_STD;
377
  frame.SID = MSI_BCBMSG_CANID;
378
  memcpy(frame.data8, buffer, length);
379
380
  // sent the frame and return
381
  return (canTransmitTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) ? AOS_SSSP_BCB_SUCCESS : AOS_SSSP_BCB_ERROR;
382
}
383
384
aos_ssspbcbstatus_t moduleSsspBcbReceive(uint8_t* buffer, size_t length)
385
{
386
  aosDbgCheck(buffer != NULL);
387
  aosDbgCheck(length > 0 && length <= CAN_BYTES_PER_FRAME);
388
389
  // local variables
390
  CANRxFrame frame;
391
392
  // receive a frame and check for errors
393
  if (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE) == MSG_OK) {
394
    // a correct frame was received
395
    if (frame.DLC == length &&
396
        frame.RTR == CAN_RTR_DATA &&
397
        frame.IDE == CAN_IDE_STD &&
398
        frame.SID == MSI_BCBMSG_CANID) {
399
      // success: fetch the data and return
400
      memcpy(buffer, frame.data8, length);
401
      return AOS_SSSP_BCB_SUCCESS;
402
    }
403
    // an unexpected frame was received
404
    else {
405
      return AOS_SSSP_BCB_INVALIDMSG;
406
    }
407
  } else {
408
    // failure: return with error
409
    return AOS_SSSP_BCB_ERROR;
410
  }
411
}
412
413
#undef MSI_BCBMSG_CANID
414
#undef CAN_BYTES_PER_FRAME
415
416
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MSI == true) */
417
418 e545e620 Thomas Schöpping
/** @} */
419
420
/*===========================================================================*/
421
/**
422
 * @name Low-level drivers
423
 * @{
424
 */
425
/*===========================================================================*/
426
427
A3906Driver moduleLldMotors = {
428 1e5f7648 Thomas Schöpping
  /* power enable GPIO  */ &moduleGpioPowerEn,
429 e545e620 Thomas Schöpping
};
430
431 ddf34c3d Thomas Schöpping
AT24C01BDriver moduleLldEeprom = {
432 e545e620 Thomas Schöpping
  /* I2C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
433 ddf34c3d Thomas Schöpping
  /* I²C address  */ AT24C01B_LLD_I2C_ADDR_FIXED,
434 e545e620 Thomas Schöpping
};
435
436
HMC5883LDriver moduleLldCompass = {
437
  /* I²C Driver */ &MODULE_HAL_I2C_COMPASS,
438
};
439
440
INA219Driver moduleLldPowerMonitorVdd = {
441
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
442
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
443
  /* current LSB (uA) */ 0x00u,
444
  /* configuration    */ NULL,
445
};
446
447
L3G4200DDriver moduleLldGyroscope = {
448
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
449
};
450
451
LEDDriver moduleLldStatusLed = {
452 1e5f7648 Thomas Schöpping
  /* LED enable Gpio */ &moduleGpioLed,
453 e545e620 Thomas Schöpping
};
454
455
LIS331DLHDriver moduleLldAccelerometer = {
456
  /* SPI Driver */ &MODULE_HAL_SPI_MOTION,
457
};
458
459
LTC4412Driver moduleLldPowerPathController = {
460 1e5f7648 Thomas Schöpping
  /* Control GPIO */ &moduleGpioPathDcEn,
461
  /* Status GPIO  */ &moduleGpioPathDcStat,
462 e545e620 Thomas Schöpping
};
463
464
PCA9544ADriver moduleLldI2cMultiplexer = {
465
  /* I²C driver   */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
466
  /* I²C address  */ PCA9544A_LLD_I2C_ADDR_FIXED | PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
467
};
468
469 ddf34c3d Thomas Schöpping
TPS6211xDriver moduleLldStepDownConverterVdrive = {
470 1e5f7648 Thomas Schöpping
  /* Power enable Gpio */ &moduleGpioPowerEn,
471 e545e620 Thomas Schöpping
};
472
473
VCNL4020Driver moduleLldProximity = {
474
  /* I²C Driver */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
475
};
476
477
/** @} */
478
479
/*===========================================================================*/
480
/**
481 4c72a54c Thomas Schöpping
 * @name Tests
482 e545e620 Thomas Schöpping
 * @{
483
 */
484
/*===========================================================================*/
485
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
486
487 8be006e0 Thomas Schöpping
/*
488
 * A3906 (motor driver)
489
 */
490 4c72a54c Thomas Schöpping
#include <module_test_A3906.h>
491
static int _testA3906ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
492 e545e620 Thomas Schöpping
{
493 4c72a54c Thomas Schöpping
  return moduleTestA3906ShellCb(stream, argc, argv, NULL);
494 e545e620 Thomas Schöpping
}
495 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestA3906ShellCmd, "test:MotorDriver", _testA3906ShellCmdCb);
496 e545e620 Thomas Schöpping
497 8be006e0 Thomas Schöpping
/*
498 4c72a54c Thomas Schöpping
 * AT24C01BN-SH-B (EEPROM)
499 8be006e0 Thomas Schöpping
 */
500 4c72a54c Thomas Schöpping
#include <module_test_AT24C01B.h>
501
static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
502 e545e620 Thomas Schöpping
{
503 4c72a54c Thomas Schöpping
  return moduleTestAt24c01bShellCb(stream, argc, argv, NULL);
504 e545e620 Thomas Schöpping
}
505 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
506 e545e620 Thomas Schöpping
507 8be006e0 Thomas Schöpping
/*
508
 * HMC5883L (compass)
509
 */
510 4c72a54c Thomas Schöpping
#include <module_test_HMC5883L.h>
511
static int _testHmc5883lShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
512 e545e620 Thomas Schöpping
{
513 4c72a54c Thomas Schöpping
  return moduleTestHmc5883lShellCb(stream, argc, argv, NULL);
514 e545e620 Thomas Schöpping
}
515 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestHmc5883lShellCmd, "test:Compass", _testHmc5883lShellCmdCb);
516 e545e620 Thomas Schöpping
517 8be006e0 Thomas Schöpping
/*
518
 * INA219 (power monitor)
519
 */
520 4c72a54c Thomas Schöpping
#include <module_test_INA219.h>
521
static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
522 e545e620 Thomas Schöpping
{
523 4c72a54c Thomas Schöpping
  return moduleTestIna219ShellCb(stream, argc, argv, NULL);
524 e545e620 Thomas Schöpping
}
525 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
526 e545e620 Thomas Schöpping
527 8be006e0 Thomas Schöpping
/*
528
 * L3G4200D (gyroscope)
529
 */
530 4c72a54c Thomas Schöpping
#include <module_test_L3G4200D.h>
531
static int _testL3g4200dShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
532 e545e620 Thomas Schöpping
{
533 4c72a54c Thomas Schöpping
  return moduleTestL3g4200dShellCb(stream, argc, argv, NULL);
534 e545e620 Thomas Schöpping
}
535 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestL3g4200dShellCmd, "test:Gyroscope", _testL3g4200dShellCmdCb);
536 e545e620 Thomas Schöpping
537 8be006e0 Thomas Schöpping
/*
538
 * Status LED
539
 */
540 4c72a54c Thomas Schöpping
#include <module_test_LED.h>
541
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
542 e545e620 Thomas Schöpping
{
543 4c72a54c Thomas Schöpping
  return moduleTestLedShellCb(stream, argc, argv, NULL);
544 e545e620 Thomas Schöpping
}
545 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
546 e545e620 Thomas Schöpping
547 8be006e0 Thomas Schöpping
/*
548
 * LIS331DLH (accelerometer)
549
 */
550 4c72a54c Thomas Schöpping
#include <module_test_LIS331DLH.h>
551
static int _testLis331dlhShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
552 e545e620 Thomas Schöpping
{
553 4c72a54c Thomas Schöpping
  return moduleTestLis331dlhShellCb(stream, argc, argv, NULL);
554 e545e620 Thomas Schöpping
}
555 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestLis331dlhShellCmd, "test:Accelerometer", _testLis331dlhShellCmdCb);
556 e545e620 Thomas Schöpping
557 8be006e0 Thomas Schöpping
/*
558
 * LTC4412 (power path controller)
559
 */
560 4c72a54c Thomas Schöpping
#include <module_test_LTC4412.h>
561
static int _testLtc4412ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
562 e545e620 Thomas Schöpping
{
563 4c72a54c Thomas Schöpping
  return moduleTestLtc4412ShellCb(stream, argc, argv, NULL);
564 e545e620 Thomas Schöpping
}
565 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestLtc4412ShellCmd, "test:PowerPathController", _testLtc4412ShellCmdCb);
566 e545e620 Thomas Schöpping
567 8be006e0 Thomas Schöpping
/*
568
 * PCA9544A (I2C multiplexer)
569
 */
570 4c72a54c Thomas Schöpping
#include <module_test_PCA9544A.h>
571
static int _testPca9544aShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
572 e545e620 Thomas Schöpping
{
573 4c72a54c Thomas Schöpping
  return moduleTestPca9544aShellCb(stream, argc, argv, NULL);
574 e545e620 Thomas Schöpping
}
575 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestPca9544aShellCmd, "test:I2CMultiplexer", _testPca9544aShellCmdCb);
576 e545e620 Thomas Schöpping
577 8be006e0 Thomas Schöpping
/*
578
 * TPS62113 (step-down converter)
579
 */
580 4c72a54c Thomas Schöpping
#include <module_test_TPS6211x.h>
581
static int _testTps6211xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
582 e545e620 Thomas Schöpping
{
583 4c72a54c Thomas Schöpping
  return moduleTestTps6211xShellCb(stream, argc, argv, NULL);
584 e545e620 Thomas Schöpping
}
585 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestTps62113ShellCmd, "test:StepDownConverter", _testTps6211xShellCmdCb);
586 e545e620 Thomas Schöpping
587 8be006e0 Thomas Schöpping
/*
588
 * VCNL4020 (proximity sensor)
589
 */
590 4c72a54c Thomas Schöpping
#include <module_test_VCNL4020.h>
591
static int _testVcnl4020ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
592 e545e620 Thomas Schöpping
{
593 4c72a54c Thomas Schöpping
  return moduleTestVcnl4020ShellCb(stream, argc, argv, NULL);
594 e545e620 Thomas Schöpping
}
595 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestVcnl4020ShellCmd, "test:ProximitySensor", _testVcnl4020ShellCmdCb);
596
597
/*
598
 * entire module
599
 */
600
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
601 e545e620 Thomas Schöpping
{
602 4c72a54c Thomas Schöpping
  (void)argc;
603
  (void)argv;
604
605
  int status = AOS_OK;
606
  char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL};
607
  aos_testresult_t result_test = {0, 0};
608
  aos_testresult_t result_total = {0, 0};
609
610
  /* A3906 (motor driver) */
611
  status |= moduleTestA3906ShellCb(stream, 0, targv, &result_test);
612
  result_total = aosTestResultAdd(result_total, result_test);
613
614
  /* AT24C01B (EEPROM) */
615
  status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
616
  result_total = aosTestResultAdd(result_total, result_test);
617
618
  /* HMC5883L (compass) */
619
  status |= moduleTestHmc5883lShellCb(stream, 0, targv, &result_test);
620
  result_total = aosTestResultAdd(result_total, result_test);
621
622
  /* INA219 (power monitor) */
623
  status |= moduleTestIna219ShellCb(stream, 0, targv, &result_test);
624
  result_total = aosTestResultAdd(result_total, result_test);
625
626
  /* L3G4200D (gyroscope) */
627
  status |= moduleTestL3g4200dShellCb(stream, 0, targv, &result_test);
628
  result_total = aosTestResultAdd(result_total, result_test);
629
630
  /* Status LED */
631
  status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
632
  result_total = aosTestResultAdd(result_total, result_test);
633
634
  /* LIS331DLH (accelerometer) */
635
  status |= moduleTestLis331dlhShellCb(stream, 0, targv, &result_test);
636
  result_total = aosTestResultAdd(result_total, result_test);
637
638
  /* LTC4412 (power path controller) */
639
  status |= moduleTestLtc4412ShellCb(stream, 0, targv, &result_test);
640
  result_total = aosTestResultAdd(result_total, result_test);
641
642
  /* PCA9544A (I2C multiplexer) */
643
  status |= moduleTestPca9544aShellCb(stream, 0, targv, &result_test);
644
  result_total = aosTestResultAdd(result_total, result_test);
645
646
  /* TPS62113 (step-down converter) */
647
  status |= moduleTestTps6211xShellCb(stream, 0, targv, &result_test);
648
  result_total = aosTestResultAdd(result_total, result_test);
649
650
  /* VCNL4020 (proximity sensor) */
651
  // wheel left
652
  targv[1] = "-wl";
653
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
654
  result_total = aosTestResultAdd(result_total, result_test);
655
  // front left
656
  targv[1] = "-fl";
657
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
658
  result_total = aosTestResultAdd(result_total, result_test);
659
  // front right
660
  targv[1] = "-fr";
661
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
662
  result_total = aosTestResultAdd(result_total, result_test);
663
  // wheel right
664
  targv[1] = "-wr";
665
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
666
  result_total = aosTestResultAdd(result_total, result_test);
667
  targv[1] = "";
668
669
  // print total result
670
  chprintf(stream, "\n");
671
  aosTestResultPrintSummary(stream, &result_total, "entire module");
672
673
  return status;
674 e545e620 Thomas Schöpping
}
675 4c72a54c Thomas Schöpping
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
676 e545e620 Thomas Schöpping
677 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
678 e545e620 Thomas Schöpping
679
/** @} */
680 53710ca3 Marc Rothmann
/** @} */