Revision 9461fadc os/core/src/aos_system.c

View differences:

os/core/src/aos_system.c
604 604
  aos_timestamp_t uptime;
605 605

  
606 606
  chSysLockFromISR();
607
  // get current uptime
608
  aosSysGetUptimeX(&uptime);
609
  // read signal S
610
  apalControlGpioGet(&moduleSsspGpioSync, &s_state);
611
  // if S was toggled from on to off during SSSP operation phase
612
  if (aos.sssp.stage == AOS_SSSP_OPERATION && s_state == APAL_GPIO_OFF) {
613
    // align the uptime with the synchronization period
614
    if (uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD < AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2) {
615
      _uptime -= uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD;
616
    } else {
617
      _uptime += AMIROOS_CFG_SSSP_SYSSYNCPERIOD - (uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD);
607
  // if the system is in operation phase
608
  if (aos.sssp.stage == AOS_SSSP_OPERATION) {
609
    // read signal S
610
    apalControlGpioGet(&moduleSsspGpioSync, &s_state);
611
    // if S was toggled from on to off
612
    if (s_state == APAL_GPIO_OFF) {
613
      // get current uptime
614
      aosSysGetUptimeX(&uptime);
615
      // align the uptime with the synchronization period
616
      if (uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD < AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2) {
617
        _uptime -= uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD;
618
      } else {
619
        _uptime += AMIROOS_CFG_SSSP_SYSSYNCPERIOD - (uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD);
620
      }
618 621
    }
619 622
  }
620 623
  // broadcast event
......
662 665
  aos_timestamp_t uptime;
663 666

  
664 667
  chSysLockFromISR();
665
  // read and toggle signal S
668
  // toggle and read signal S
669
  apalGpioToggle(moduleSsspGpioSync.gpio);
666 670
  apalControlGpioGet(&moduleSsspGpioSync, &s_state);
667
  s_state = (s_state == APAL_GPIO_ON) ? APAL_GPIO_OFF : APAL_GPIO_ON;
668
  apalControlGpioSet(&moduleSsspGpioSync, s_state);
669 671
  // if S was toggled from off to on
670 672
  if (s_state == APAL_GPIO_ON) {
671 673
    // reconfigure the timer precisely, because the logically falling edge (next interrupt) snychronizes the system time
......
749 751
  // update the system SSSP stage
750 752
  aos.sssp.stage = AOS_SSSP_OPERATION;
751 753

  
754
#if (AMIROOS_CFG_SSSP_MASTER == true)
755
  {
756
    chSysLock();
757
    // start the system synchronization counter
758
    // The first iteration of the timer is set to the next 'center' of a 'slice'.
759
    aos_timestamp_t t;
760
    aosSysGetUptimeX(&t);
761
    t = AMIROOS_CFG_SSSP_SYSSYNCPERIOD - (t % AMIROOS_CFG_SSSP_SYSSYNCPERIOD);
762
    chVTSetI(&_syssynctimer, LL_US2ST((t > (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) ? (t - (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) : (t + (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2))), _sysSyncTimerCallback, NULL);
763
    chSysUnlock();
764
  }
765
#endif
766

  
752 767
  // print system information;
753 768
  _printSystemInfo((BaseSequentialStream*)&aos.iostream);
754 769
  aosprintf("\n");
......
796 811
      f == MODULE_SSSP_EVENTFLAGS_SYNC &&
797 812
      s == APAL_GPIO_OFF) {
798 813
    chSysLock();
799
#if (AMIROOS_CFG_SSSP_MASTER == true)
800
    // start the systen synchronization counter
801
    chVTSetI(&_syssynctimer, LL_US2ST(AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2), &_sysSyncTimerCallback, NULL);
802
#endif
803 814
    // start the uptime counter
804 815
    _synctime = chVTGetSystemTimeX();
805 816
    _uptime = 0;

Also available in: Unified diff