Revision 4c72a54c modules/DiWheelDrive_1-2/module.c

View differences:

modules/DiWheelDrive_1-2/module.c
127 127
  /* GPIO */ &_gpioLed,
128 128
  /* meta */ {
129 129
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
130
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
130
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
131 131
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
132 132
  },
133 133
};
......
367 367
  /* I²C address  */ AT24C01B_LLD_I2C_ADDR_FIXED,
368 368
};
369 369

  
370
// TODO: BNO055
371

  
370 372
INA219Driver moduleLldPowerMonitorVdd = {
371 373
  /* I2C Driver       */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
372 374
  /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
......
400 402

  
401 403
/*===========================================================================*/
402 404
/**
403
 * @name Unit tests (UT)
405
 * @name Tests
404 406
 * @{
405 407
 */
406 408
/*===========================================================================*/
407 409
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
408
#include <string.h>
409 410

  
410 411
/*
411 412
 * A3906 (motor driver)
412 413
 */
413
static int _utShellCmdCb_AlldA3906(BaseSequentialStream* stream, int argc, char* argv[])
414
#include <module_test_A3906.h>
415
static int _testA3906ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
414 416
{
415
  (void)argc;
416
  (void)argv;
417
  aosUtRun(stream, &moduleUtAlldA3906, NULL);
418
  return AOS_OK;
417
  return moduleTestA3906ShellCb(stream, argc, argv, NULL);
419 418
}
420
static ut_a3906data_t _utA3906Data = {
421
  /* driver           */ &moduleLldMotors,
422
  /* PWM information  */ {
423
    /* driver   */ &MODULE_HAL_PWM_DRIVE,
424
    /* channels */ {
425
      /* left wheel forward   */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD,
426
      /* left wheel backward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD,
427
      /* right wheel forward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD,
428
      /* right wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD,
429
    },
430
  },
431
  /* QEI information  */ {
432
    /* left wheel               */ &MODULE_HAL_QEI_LEFT_WHEEL,
433
    /* right wheel              */ &MODULE_HAL_QEI_RIGHT_WHEEL,
434
    /* increment per revolution */ MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION,
435
  },
436
  /* Wheel diameter   */ {
437
    /* left wheel   */ 0.05571f,
438
    /* right wheel  */ 0.05571f,
439
  },
440
  /* timeout          */ 10 * MICROSECONDS_PER_SECOND,
441
};
442
aos_unittest_t moduleUtAlldA3906  = {
443
  /* name           */ "A3906",
444
  /* info           */ "motor driver",
445
  /* test function  */ utAlldA3906Func,
446
  /* shell command  */ {
447
    /* name     */ "unittest:MotorDriver",
448
    /* callback */ _utShellCmdCb_AlldA3906,
449
    /* next     */ NULL,
450
  },
451
  /* data           */ &_utA3906Data,
452
};
419
AOS_SHELL_COMMAND(moduleTestA3906ShellCmd, "test:MotorDriver", _testA3906ShellCmdCb);
453 420

  
454 421
/*
455
 * AT24C01B (EEPROM)
422
 * AT24C01BN-SH-B (EEPROM)
456 423
 */
457
static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
424
#include <module_test_AT24C01B.h>
425
static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
458 426
{
459
  (void)argc;
460
  (void)argv;
461
  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
462
  return AOS_OK;
427
  return moduleTestAt24c01bShellCb(stream, argc, argv, NULL);
463 428
}
464
static ut_at24c01bdata_t _utAlldAt24c01bData = {
465
  /* driver   */ &moduleLldEeprom,
466
  /* timeout  */ MICROSECONDS_PER_SECOND,
467
};
468
aos_unittest_t moduleUtAlldAt24c01b = {
469
  /* name           */ "AT24C01B",
470
  /* info           */ "1kbit EEPROM",
471
  /* test function  */ utAlldAt24c01bFunc,
472
  /* shell command  */ {
473
    /* name     */ "unittest:EEPROM",
474
    /* callback */ _utShellCmdCb_AlldAt24c01b,
475
    /* next     */ NULL,
476
  },
477
  /* data           */ &_utAlldAt24c01bData,
478
};
429
AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
430

  
431
// TODO: BNO055
479 432

  
480 433
/*
481 434
 * INA219 (power monitor)
482 435
 */
483
static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
436
#include <module_test_INA219.h>
437
static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
484 438
{
485
  (void)argc;
486
  (void)argv;
487
  aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
488
  return AOS_OK;
439
  return moduleTestIna219ShellCb(stream, argc, argv, NULL);
489 440
}
490
static ut_ina219data_t _utIna219Data = {
491
  /* driver           */ &moduleLldPowerMonitorVdd,
492
  /* expected voltage */ 3.3f,
493
  /* tolerance        */ 0.05f,
494
  /* timeout */ MICROSECONDS_PER_SECOND,
495
};
496
aos_unittest_t moduleUtAlldIna219 = {
497
  /* name           */ "INA219",
498
  /* info           */ "power monitor",
499
  /* test function  */ utAlldIna219Func,
500
  /* shell command  */ {
501
    /* name     */ "unittest:PowerMonitor",
502
    /* callback */ _utShellCmdCb_AlldIna219,
503
    /* next     */ NULL,
504
  },
505
  /* data           */ &_utIna219Data,
506
};
441
AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
507 442

  
508 443
/*
509 444
 * Status LED
510 445
 */
511
static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
446
#include <module_test_LED.h>
447
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
512 448
{
513
  (void)argc;
514
  (void)argv;
515
  aosUtRun(stream, &moduleUtAlldLed, NULL);
516
  return AOS_OK;
449
  return moduleTestLedShellCb(stream, argc, argv, NULL);
517 450
}
518
aos_unittest_t moduleUtAlldLed = {
519
  /* name           */ "LED",
520
  /* info           */ NULL,
521
  /* test function  */ utAlldLedFunc,
522
  /* shell command  */ {
523
    /* name     */ "unittest:StatusLED",
524
    /* callback */ _utShellCmdCb_AlldLed,
525
    /* next     */ NULL,
526
  },
527
  /* data           */ &moduleLldStatusLed,
528
};
451
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
529 452

  
530 453
/*
531 454
 * LTC4412 (power path controller)
532 455
 */
533
static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[])
456
#include <module_test_LTC4412.h>
457
static int _testLtc4412ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
534 458
{
535
  (void)argc;
536
  (void)argv;
537
  aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
538
  return AOS_OK;
459
  return moduleTestLtc4412ShellCb(stream, argc, argv, NULL);
539 460
}
540
aos_unittest_t moduleUtAlldLtc4412 = {
541
  /* name           */ "LTC4412",
542
  /* info           */ "Power path controller",
543
  /* test function  */ utAlldLtc4412Func,
544
  /* shell command  */ {
545
    /* name     */ "unittest:PowerPathController",
546
    /* callback */ _utShellCmdCb_AlldLtc4412,
547
    /* next     */ NULL,
548
  },
549
  /* data           */ &moduleLldPowerPathController,
550
};
461
AOS_SHELL_COMMAND(moduleTestLtc4412ShellCmd, "test:PowerPathController", _testLtc4412ShellCmdCb);
551 462

  
552 463
/*
553 464
 * PCA9544A (I2C multiplexer)
554 465
 */
555
static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[])
466
#include <module_test_PCA9544A.h>
467
static int _testPca9544aShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
556 468
{
557
  (void)argc;
558
  (void)argv;
559
  aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
560
  return AOS_OK;
469
  return moduleTestPca9544aShellCb(stream, argc, argv, NULL);
561 470
}
562
static ut_pca9544adata_t _utPca9544aData = {
563
  /* driver  */ &moduleLldI2cMultiplexer,
564
  /* timeout */ MICROSECONDS_PER_SECOND,
565
};
566
aos_unittest_t moduleUtAlldPca9544a = {
567
  /* name           */ "PCA9544A",
568
  /* info           */ "I2C multiplexer",
569
  /* test function  */ utAlldPca9544aFunc,
570
  /* shell command  */ {
571
    /* name     */ "unittest:I2CMultiplexer",
572
    /* callback */ _utShellCmdCb_AlldPca9544a,
573
    /* next     */ NULL,
574
  },
575
  /* data           */ &_utPca9544aData,
576
};
471
AOS_SHELL_COMMAND(moduleTestPca9544aShellCmd, "test:I2CMultiplexer", _testPca9544aShellCmdCb);
577 472

  
578 473
/*
579 474
 * TPS62113 (step-down converter)
580 475
 */
581
static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
476
#include <module_test_TPS6211x.h>
477
static int _testTps6211xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
582 478
{
583
  (void)argc;
584
  (void)argv;
585
  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
586
  return AOS_OK;
479
  return moduleTestTps6211xShellCb(stream, argc, argv, NULL);
587 480
}
588
aos_unittest_t moduleUtAlldTps62113 = {
589
  /* name           */ "TPS62113",
590
  /* info           */ "Step down converter",
591
  /* test function  */ utAlldTps6211xFunc,
592
  /* shell command  */ {
593
    /* name     */ "unittest:StepDownConverter",
594
    /* callback */ _utShellCmdCb_AlldTps62113,
595
    /* next     */ NULL,
596
  },
597
  /* data           */ &moduleLldStepDownConverterVdrive,
598
};
481
AOS_SHELL_COMMAND(moduleTestTps62113ShellCmd, "test:StepDownConverter", _testTps6211xShellCmdCb);
599 482

  
600 483
/*
601 484
 * VCNL4020 (proximity sensor)
602 485
 */
603
static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
486
#include <module_test_VCNL4020.h>
487
static int _testVcnl4020ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
604 488
{
605
  uint8_t intstatus;
606
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
607
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
608
  if (intstatus) {
609
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
610
  }
611
  return;
489
  return moduleTestVcnl4020ShellCb(stream, argc, argv, NULL);
612 490
}
613
static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
491
AOS_SHELL_COMMAND(moduleTestVcnl4020ShellCmd, "test:ProximitySensor", _testVcnl4020ShellCmdCb);
492

  
493
/*
494
 * entire module
495
 */
496
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
614 497
{
615
  enum {
616
    UNKNOWN,
617
    FL, FR, WL, WR,
618
  } sensor = UNKNOWN;
619
  // evaluate arguments
620
  if (argc == 2) {
621
    if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) {
622
      sensor = FL;
623
    } else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) {
624
      sensor = FR;
625
    } else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) {
626
      sensor = WL;
627
    } else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) {
628
      sensor = WR;
629
    }
630
  }
631
  if (sensor != UNKNOWN) {
632
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
633
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
634
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
635
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
636
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
637
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
638
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
639
    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
640
    switch (sensor) {
641
      case FL:
642
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
643
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front left sensor");
644
        break;
645
      case FR:
646
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
647
        aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
648
        break;
649
      case WL:
650
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
651
        aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
652
        break;
653
      case WR:
654
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
655
        aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
656
        break;
657
      default:
658
        break;
659
    }
660
    return AOS_OK;
661
  }
662
  // print help
663
  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
664
  chprintf(stream, "Options:\n");
665
  chprintf(stream, "  --frontleft, -fl\n");
666
  chprintf(stream, "    Test front left proximity sensor.\n");
667
  chprintf(stream, "  --frontrigt, -fr\n");
668
  chprintf(stream, "    Test front right proximity sensor.\n");
669
  chprintf(stream, "  --wheelleft, -wl\n");
670
  chprintf(stream, "    Test left wheel proximity sensor.\n");
671
  chprintf(stream, "  --wheelright, -wr\n");
672
  chprintf(stream, "    Test right wheel proximity sensor.\n");
673
  return AOS_INVALIDARGUMENTS;
498
  (void)argc;
499
  (void)argv;
500

  
501
  int status = AOS_OK;
502
  char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL};
503
  aos_testresult_t result_test = {0, 0};
504
  aos_testresult_t result_total = {0, 0};
505

  
506
  /* A3906 (motor driver) */
507
  status |= moduleTestA3906ShellCb(stream, 0, targv, &result_test);
508
  result_total = aosTestResultAdd(result_total, result_test);
509

  
510
  /* AT24C01B (EEPROM) */
511
  status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
512
  result_total = aosTestResultAdd(result_total, result_test);
513

  
514
  // TODO: BNO055
515

  
516
  /* INA219 (power monitor) */
517
  status |= moduleTestIna219ShellCb(stream, 0, targv, &result_test);
518
  result_total = aosTestResultAdd(result_total, result_test);
519

  
520
  /* Status LED */
521
  status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
522
  result_total = aosTestResultAdd(result_total, result_test);
523

  
524
  /* LTC4412 (power path controller) */
525
  status |= moduleTestLtc4412ShellCb(stream, 0, targv, &result_test);
526
  result_total = aosTestResultAdd(result_total, result_test);
527

  
528
  /* PCA9544A (I2C multiplexer) */
529
  status |= moduleTestPca9544aShellCb(stream, 0, targv, &result_test);
530
  result_total = aosTestResultAdd(result_total, result_test);
531

  
532
  /* TPS62113 (step-down converter) */
533
  status |= moduleTestTps6211xShellCb(stream, 0, targv, &result_test);
534
  result_total = aosTestResultAdd(result_total, result_test);
535

  
536
  /* VCNL4020 (proximity sensor) */
537
  // wheel left
538
  targv[1] = "-wl";
539
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
540
  result_total = aosTestResultAdd(result_total, result_test);
541
  // front left
542
  targv[1] = "-fl";
543
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
544
  result_total = aosTestResultAdd(result_total, result_test);
545
  // front right
546
  targv[1] = "-fr";
547
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
548
  result_total = aosTestResultAdd(result_total, result_test);
549
  // wheel right
550
  targv[1] = "-wr";
551
  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
552
  result_total = aosTestResultAdd(result_total, result_test);
553
  targv[1] = "";
554

  
555
  // print total result
556
  chprintf(stream, "\n");
557
  aosTestResultPrintSummary(stream, &result_total, "entire module");
558

  
559
  return status;
674 560
}
675
static ut_vcnl4020data_t _utVcnl4020Data = {
676
  /* driver       */ &moduleLldProximity,
677
  /* timeout      */ MICROSECONDS_PER_SECOND,
678
  /* event source */ &aos.events.io,
679
  /* event flags  */ MODULE_OS_IOEVENTFLAGS_IRINT,
680
};
681
aos_unittest_t moduleUtAlldVcnl4020 = {
682
  /* name           */ "VCNL4020",
683
  /* info           */ "proximity sensor",
684
  /* test function  */ utAlldVcnl4020Func,
685
  /* shell command  */ {
686
    /* name     */ "unittest:Proximity",
687
    /* callback */ _utShellCmdCb_AlldVcnl4020,
688
    /* next     */ NULL,
689
  },
690
  /* data           */ &_utVcnl4020Data,
691
};
561
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
692 562

  
693 563
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
694 564

  

Also available in: Unified diff