Revision 1d3e002f core/src/aos_main.cpp

View differences:

core/src/aos_main.cpp
78 78
 */
79 79
#define SSSP_STACKINIT_CANMSGID_ABORT           0x001
80 80

  
81
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
81
#else /* AMIROOS_CFG_SSSP_ENABLE == false */
82

  
83
/**
84
 * @brief   Default shutdown mode if SSSP is unavailable.
85
 */
86
#define AOS_SHUTDOWN_DEFAULT                    AOS_SHUTDOWN_DEEPSLEEP
87

  
88
#endif /* AMIROOS_CFG_SSSP_ENABLE */
82 89

  
83 90
/**
84 91
 * @brief   CAN message identifier for calender synchronization message.
......
106 113
 * @brief   I/O shell channel for the programmer interface.
107 114
 */
108 115
static AosShellChannel _stdshellchannel;
109
#endif
110
#endif
116
#endif /* AMIROOS_CFG_SHELL_ENABLE == true */
117
#endif /* defined(MODULE_HAL_PROGIF) */
111 118

  
112 119
/*
113 120
 * hook to add further static variables
......
283 290
  aos_shutdown_t shutdown = AOS_SHUTDOWN_NONE;
284 291
  sssp_modulestackinitstage_t stage = STAGE_3_1;
285 292
  eventmask_t eventmask = 0;
286
  eventflags_t ioflags;
293
  eventflags_t ioflags = 0;
287 294
  event_source_t eventSourceTimeout;
288 295
  event_source_t eventSourceDelay;
289 296
  event_listener_t eventListenerTimeout;
......
297 304
  aos_ssspmoduleid_t lastid = 0;
298 305
#endif
299 306
  flags_t flags;
307
  aos_timestamp_t uptime;
300 308

  
301 309
  // initialize local varibles
302 310
  chEvtObjectInit(&eventSourceTimeout);
......
379 387
    // reset wfe flag for the next iteration
380 388
    flags.wfe_next = true;
381 389

  
382
    // waiting for events may be skipped
390
    // waiting for events (may be skipped)
383 391
    if (flags.wfe) {
384 392
      // wait for any event to occur
385 393
      aosDbgPrintf("WFE...");
......
387 395
      aosDbgPrintf("\t0x%08X", eventmask);
388 396
    } else {
389 397
      aosDbgPrintf("WFE skipped");
398
      eventmask = 0;
390 399
    }
391
    aos_timestamp_t uptime;
392 400
    aosSysGetUptime(&uptime);
393
    aosDbgPrintf("\t%04ums\n", (uint32_t)(uptime / 1000));
401
    aosDbgPrintf("\t%04ums\n", (uint32_t)(uptime / MICROSECONDS_PER_MILLISECOND));
394 402

  
395 403
    /*
396 404
     * execute some general tasks and high priority events
......
410 418
      if (ioflags & MODULE_SSSP_EVENTFLAGS_PD) {
411 419
        aosDbgPrintf("PD evt\n");
412 420
        // deactivate S and UP
421
        aosDbgPrintf("disabling S\n");
413 422
        apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
414 423
#if (AMIROOS_CFG_SSSP_STACK_END != true)
424
        aosDbgPrintf("disabling UP\n");
415 425
        apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
416 426
#endif
417 427
        // set shutdown flag and exit the loop
......
422 432
      if (ioflags & MODULE_SSSP_EVENTFLAGS_SYNC) {
423 433
        apalControlGpioState_t sstate;
424 434
        apalControlGpioGet(&moduleSsspGpioSync, &sstate);
425
        if (sstate == APAL_GPIO_OFF) {
426
          aosDbgPrintf("-S evt\n");
435
        if (sstate == APAL_GPIO_ON) {
436
          aosDbgPrintf("S evt (enabled)\n");
437
        } else {
438
          aosDbgPrintf("S evt (disabled)\n");
427 439
          // either finish or abort
428 440
          if ((stage == STAGE_3_3_WAITFORID) && (aos.sssp.moduleId != 0)) {
429 441
            stage = STAGE_3_4_FINISH;
......
447 459
    }
448 460
    // if a CAN event occurred
449 461
    if ((eventmask & eventListenerCan.events)) {
462
      aosDbgPrintf("CAN evt\n");
450 463
      // fetch message
451 464
      if (flags.wfe) {
452 465
        canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE);
......
465 478
    }
466 479
    // if a timeout event occurred
467 480
    if (eventmask & eventListenerTimeout.events) {
481
      aosDbgPrintf("timeout evt\n");
468 482
      // is handled at the end of the loop (or must be cleared by FSM)
469 483
    }
470 484
    // if a delay event occurred
471 485
    if (eventmask & eventListenerDelay.events) {
486
      aosDbgPrintf("delay evt\n");
472 487
      // is handled by FSM
473 488
    }
474 489

  
......
492 507
            break;
493 508
          }
494 509
          // activate S
495
          aosDbgPrintf("S+\n");
510
          aosDbgPrintf("enabling S\n");
496 511
          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
497 512
#if (AMIROOS_CFG_SSSP_STACK_START == true)
498 513
          // proceed immediately
......
524 539
            chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
525 540
            eventmask &= ~(eventListenerTimeout.events);
526 541
            // activate S
527
            aosDbgPrintf("S+\n");
542
            aosDbgPrintf("enabling S\n");
528 543
            apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
529 544
#if (AMIROOS_CFG_SSSP_STACK_START == true)
530 545
            // proceed
......
567 582
#if (AMIROOS_CFG_SSSP_STACK_END == true)
568 583
          // sequence is already over
569 584
          // deactivate S
570
          aosDbgPrintf("S-\n");
585
          aosDbgPrintf("disabling S\n");
571 586
          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
572 587
          // proceed
573 588
          stage = STAGE_3_3_WAITFORID;
......
580 595
        // if a delay event occurred
581 596
        if (eventmask & eventListenerDelay.events) {
582 597
          // activate UP
583
          aosDbgPrintf("UP+\n");
598
          aosDbgPrintf("enabling UP\n");
584 599
          apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
585 600
          // deactivate S
586
          aosDbgPrintf("S-\n");
601
          aosDbgPrintf("disabling S\n");
587 602
          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
588 603
          // explicitely clear timeout event flag
589 604
          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
......
665 680

  
666 681
        // if an IO event was received (DN signal)
667 682
        if ((eventmask & _eventListenerIO.events) && (ioflags & MODULE_SSSP_EVENTFLAGS_DN)) {
668
          aosDbgPrintf("DN <-\n");
683
          aosDbgPrintf("DN evt\n");
669 684
          // reset timeout timer
670 685
          chVTReset(&timerTimeout);
671 686
          chEvtWaitAnyTimeout(eventListenerTimeout.events, TIME_IMMEDIATE);
......
688 703
        if (eventmask & eventListenerDelay.events) {
689 704
#if (AMIROOS_CFG_SSSP_STACK_END != true)
690 705
          // activate UP
691
          aosDbgPrintf("UP+\n");
706
          aosDbgPrintf("enabling UP\n");
692 707
          apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_ON);
693 708
#endif
694 709
          // deactivate S
695
          aosDbgPrintf("S-\n");
710
          aosDbgPrintf("disabling S\n");
696 711
          apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
697 712
          // reset the timeout timer
698 713
          chVTSet(&timerTimeout, chTimeUS2I(AOS_SYSTEM_SSSP_TIMEOUT), _ssspTimerCallback, &eventSourceTimeout);
......
794 809
        aos.sssp.stage = AOS_SSSP_STARTUP_3_4;
795 810

  
796 811
        // deactivate S
797
        aosDbgPrintf("S-\n");
812
        aosDbgPrintf("disabling SYNC\n");
798 813
        apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
799 814
        // invalidate module ID
800 815
        aos.sssp.moduleId = 0;
......
808 823

  
809 824
        break;
810 825
      } /* end of STAGE_3_4_ABORT */
811
    }
826
    } /* end of switch(stage) */
812 827

  
813 828
    // fetch pending CAN message (if any)
814 829
    if ((eventmask & eventListenerCan.events) && (canReceiveTimeout(&MODULE_HAL_CAN, CAN_ANY_MAILBOX, &canRxFrame, TIME_IMMEDIATE) == MSG_OK)) {
......
827 842
    // apply wfe value for next iteration
828 843
    flags.wfe = flags.wfe_next;
829 844
  } /* end of FSM loop */
830
  aosDbgPrintf("\n");
831 845

  
832 846
  // unregister all events (timeout, delay, CAN receive)
833 847
  chEvtUnregister(&eventSourceTimeout, &eventListenerTimeout);
......
838 852

  
839 853
  // reset all control signals
840 854
#if (AMIROOS_CFG_SSSP_STACK_END != true)
855
  aosDbgPrintf("disabling UP\n");
841 856
  apalControlGpioSet(&moduleSsspGpioUp, APAL_GPIO_OFF);
842 857
#endif
858
  aosDbgPrintf("disabling S\n");
843 859
  apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_OFF);
860
  aosSysGetUptime(&uptime);
861
  aosDbgPrintf("done\t%04ums\n", (uint32_t)(uptime / MICROSECONDS_PER_MILLISECOND));
844 862

  
845 863
  return shutdown;
846 864
}
......
947 965
#else
948 966
  chEvtRegisterMaskWithFlags(&aos.events.io, &_eventListenerIO, IOEVENT_MASK, MODULE_SSSP_EVENTFLAGS_PD | MODULE_SSSP_EVENTFLAGS_SYNC | MODULE_SSSP_EVENTFLAGS_DN | MODULE_SSSP_EVENTFLAGS_UP);
949 967
#endif
950
#else /* AMIROOS_CFG_SSSP_ENABLE == false */
951
  chEvtRegisterMask(&aos.events.io, &_eventListenerIO, IOEVENT_MASK);
952
#endif /* AMIROOS_CFG_SSSP_ENABLE */
968
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
953 969
  chEvtRegisterMask(&aos.events.os, &_eventListenerOS, OSEVENT_MASK);
954 970

  
955 971
#if defined(AMIROOS_CFG_MAIN_INIT_HOOK_5)
......
1186 1202
        // evaluate flags
1187 1203
        eventflags = chEvtGetAndClearFlags(&_eventListenerOS);
1188 1204
        switch (eventflags) {
1205
#if (AMIROOS_CFG_SSSP_ENABLE == true)
1189 1206
          case AOS_SYSTEM_EVENTFLAGS_HIBERNATE:
1190 1207
            shutdown = AOS_SHUTDOWN_HIBERNATE;
1191 1208
            break;
......
1198 1215
          case AOS_SYSTEM_EVENTFLAGS_RESTART:
1199 1216
            shutdown = AOS_SHUTDOWN_RESTART;
1200 1217
            break;
1218
#else /* AMIROOS_CFG_SSSP_ENABLE == false */
1219
          case AOS_SYSTEM_EVENTFLAGS_SHUTDOWN:
1220
            shutdown = AOS_SHUTDOWN_DEFAULT;
1221
            break;
1222
#endif /* AMIROOS_CFG_SSSP_ENABLE */
1201 1223
          default:
1202 1224
            _unexpectedEventError(eventmask, eventflags);
1203 1225
            break;

Also available in: Unified diff