Ejemplo n.º 1
0
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
    uint64_t timestamp_ticks;
    uint64_t current_ticks = RTC_CounterGet();
    timestamp_t current_time = ((uint64_t)(current_ticks * 1000000) / (LOW_ENERGY_CLOCK_FREQUENCY / RTC_CLOCKDIV_INT));


    /* calculate offset value */
    timestamp_t offset = timestamp - current_time;
    if(offset > 0xEFFFFFFF) offset = 100;

    /* map offset to RTC value */
    // ticks = offset * RTC frequency div 1000000
    timestamp_ticks = ((uint64_t)offset * (LOW_ENERGY_CLOCK_FREQUENCY / RTC_CLOCKDIV_INT)) / 1000000;
    timestamp_ticks += current_ticks;

    /* RTC has 24 bit resolution */
    timestamp_ticks &= 0xFFFFFF;

    /* check for RTC limitation */
    if((timestamp_ticks - RTC_CounterGet()) >= 0x800000) timestamp_ticks = RTC_CounterGet() + 2;

    /* Set callback */
    RTC_FreezeEnable(true);
    RTC_CompareSet(0, (uint32_t)timestamp_ticks);
    RTC_IntEnable(RTC_IF_COMP0);
    RTC_FreezeEnable(false);
}
Ejemplo n.º 2
0
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
    RTC_IntDisable(RTC_IF_COMP0);
    RTC_IntClear(RTC_IF_COMP0);
    RTC_FreezeEnable(true);
    RTC_CompareSet(0, (uint32_t) (timestamp & RTC_MAX_VALUE));
    RTC_FreezeEnable(false);
    RTC_IntEnable(RTC_IF_COMP0);
}
Ejemplo n.º 3
0
void lp_ticker_free()
{
    /* Disable the RTC if it was inited and is no longer in use by anyone. */
    if (rtc_inited) {
        NVIC_DisableIRQ(RTC_IRQn);
        RTC_Reset();
        CMU_ClockEnable(cmuClock_RTC, false);
        rtc_inited = false;
    }
    RTC_FreezeEnable(false);
}