Beispiel #1
0
/***************************************************************************//**
 * @brief
 *    Get wallclock time.
 *
 * @return
 *    Seconds elapsed since RTCDRV was initialized.
 ******************************************************************************/
uint32_t RTCDRV_GetWallClock( void )
{
  uint64_t tmp;
  uint32_t ticks, wallClock, wallClockStartPoint;

  INT_Disable();
  ticks               = RTC_COUNTERGET();
  wallClock           = wallClockTime;
  wallClockStartPoint = wallClockInitTime;
  INT_Enable();

  tmp = ticks - wallClockStartPoint;
  return wallClock + (uint32_t)TICKS_TO_SEC( tmp );
}
/***************************************************************************//**
 * @brief
 *    Set wallclock time.
 *
 * @param[in] secs Value to set (seconds).
 *
 * @return
 *    @ref ECODE_EMDRV_RTCDRV_OK
 ******************************************************************************/
Ecode_t RTCDRV_SetWallClock( uint32_t secs )
{
  wallClockTimeBase = secs - TICKS_TO_SEC( RTCDRV_GetWallClockTicks32() );
  return ECODE_EMDRV_RTCDRV_OK;
}
/***************************************************************************//**
 * @brief
 *    Get wallclock time.
 *
 * @return
 *    Seconds elapsed since RTCDRV was initialized.
 ******************************************************************************/
uint32_t RTCDRV_GetWallClock( void )
{
  return wallClockTimeBase
         + (uint32_t)TICKS_TO_SEC( RTCDRV_GetWallClockTicks32() );
}
Beispiel #4
0
void RTCC_IRQHandler(void)
#endif
{
  uint32_t flags, timeElapsed, cnt, timeToNextTimerCompletion;

  INT_Disable();

  // CNT will normally be COMP0+1 at this point,
  // unless IRQ latency exceeded one tick period.

  flags = RTC_INTGET();

  if ( flags & RTC_COMP_INT ) {

    // Stop timer system by disabling the compare IRQ.
    // Update all timers with the time elapsed, call callbacks if needed,
    // then find the timer with the shortest timeout (if any at all) and
    // reenable the compare IRQ if needed.

    inTimerIRQ = true;

    cnt = RTC_COUNTERGET();

    // This loop is repeated if CNT is incremented while processing.
    do {

      RTC_INTDISABLE( RTC_COMP_INT );

      timeElapsed = TIMEDIFF( cnt, lastStart );

      // Update all timers with elapsed time.
      checkAllTimers( timeElapsed );

      // Execute timer callbacks.
      executeTimerCallbacks();

      // Restart RTC according to next timeout.
      rescheduleRtc( cnt );

      cnt = RTC_COUNTERGET();
      timeElapsed = TIMEDIFF( cnt, lastStart );
      timeToNextTimerCompletion = TIMEDIFF( RTC_COMPAREGET(), lastStart );
      /* If the counter has passed the COMP(ARE) register value since we
         checked the timers, then we should recheck the timers and reschedule
         again. */
    }
    while ( rtcRunning && (timeElapsed > timeToNextTimerCompletion));
    inTimerIRQ = false;
  }

#if defined( EMDRV_RTCDRV_WALLCLOCK_CONFIG )
  if ( flags & RTC_OF_INT ) {
    uint64_t ticks;

    RTC_INTCLEAR( RTC_OF_INT );

    ticks             = MAX_RTC_TICK_CNT - wallClockInitTime;
    wallClockInitTime = 0;
    wallClockTime    += TICKS_TO_SEC( ticks );
  }
#endif

  INT_Enable();
}