Platform/ECM3532/DSP/framework/src/timer.c
//start periodic/one short timer.
start periodic/one short timer.
start periodic / one short timer .
void startTimer(tTimerHandle timerHandle, uint16_t msVal,uint8_t periodic)
{
    timer *t;
    uint16_t timeInTick;
    TIME temp_time_now;
    if (msVal > MAX_TIMER_MS_COUNT) {
        DBG_TIMER("Issue:timer set value exceeds MAX_TIMER_MS_COUNT:\n\r");
        return;
    }
    if ((timerHandle >= MAX_TIMERS) || (0 == timers[timerHandle].timerCb)) {
        DBG_TIMER("Issue in starting timer\n\r");
        return;
    }
    timeInTick =  (1000 / 32) * msVal;
    timeInTick += timeInTick + (uint32_t)(msVal >> 1);
    disable_spi_interrupt();
    t = &timers[timerHandle];
    t->time = timeInTick;
    t->periodic = periodic;
    t->periodTime = timeInTick;
    temp_time_now = get_time_now();
    if (!timer_next) {
        time_now = temp_time_now;
        time_timer_set = time_now;
        start_physical_timer((timer_next = t)->time);
    } else if ((t->time + time_now) < (timer_next->time + time_timer_set)) {
        time_now = temp_time_now;
        timers_update(time_now - time_timer_set);
        time_timer_set = time_now;
        start_physical_timer((timer_next = t)->time);
    } else {
        t->time += (temp_time_now- time_timer_set);
    }
    t->inUse = TRUE;
    enable_spi_interrupt();
    return;
}
void startTimer ( tTimerHandle timerHandle , uint16_t msVal , uint8_t periodic ) { timer * t ; uint16_t timeInTick ; TIME temp_time_now ; if ( msVal > MAX_TIMER_MS_COUNT ) { DBG_TIMER ( " \n \r " ) ; return ; } if ( ( timerHandle >= MAX_TIMERS ) || ( 0 == timers [ timerHandle ] . timerCb ) ) { DBG_TIMER ( " \n \r " ) ; return ; } timeInTick = ( 1000 / 32 ) * msVal ; timeInTick += timeInTick + ( uint32_t ) ( msVal >> 1 ) ; disable_spi_interrupt ( ) ; t = & timers [ timerHandle ] ; t -> time = timeInTick ; t -> periodic = periodic ; t -> periodTime = timeInTick ; temp_time_now = get_time_now ( ) ; if ( ! timer_next ) { time_now = temp_time_now ; time_timer_set = time_now ; start_physical_timer ( ( timer_next = t ) -> time ) ; } else if ( ( t -> time + time_now ) < ( timer_next -> time + time_timer_set ) ) { time_now = temp_time_now ; timers_update ( time_now - time_timer_set ) ; time_timer_set = time_now ; start_physical_timer ( ( timer_next = t ) -> time ) ; } else { t -> time += ( temp_time_now - time_timer_set ) ; } t -> inUse = TRUE ; enable_spi_interrupt ( ) ; return ; }
start periodic/one short timer.
start periodic / one short timer .
//To avoid saturation, multipication by (1000/16) is achieved in two stages. // Store periodic timer details //DBG_TIMER("time=%d:\n\r", (uint16_t)t->time); //DBG_TIMER("timeNow=%d:\n\r", (uint16_t)temp_time_now); /* no timers set at all, so this is shortest */ /* new timer is shorter than current one, so */ /* new timer is longer, than current one */