/******************************************************************************* ** ** Function GKI_start_timer ** ** Description An application can call this function to start one of ** it's four general purpose timers. Any of the four timers ** can be 1-shot or continuous. If a timer is already running, ** it will be reset to the new parameters. ** ** Parameters tnum - (input) timer number to be started (TIMER_0, ** TIMER_1, TIMER_2, or TIMER_3) ** ticks - (input) the number of system ticks til the ** timer expires. ** is_continuous - (input) TRUE if timer restarts automatically, ** else FALSE if it is a 'one-shot'. ** ** Returns void ** *******************************************************************************/ void GKI_start_timer (UINT8 tnum, INT32 ticks, BOOLEAN is_continuous) { INT32 reload; INT32 orig_ticks; UINT8 task_id = GKI_get_taskid(); BOOLEAN bad_timer = FALSE; if (ticks <= 0) ticks = 1; orig_ticks = ticks; /* save the ticks in case adjustment is necessary */ /* If continuous timer, set reload, else set it to 0 */ if (is_continuous) reload = ticks; else reload = 0; GKI_disable(); if(gki_timers_is_timer_running() == FALSE) { #if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0)) /* if inactivity delay timer is not running, start system tick */ if(gki_cb.com.OSTicksTilStop == 0) { #endif if(gki_cb.com.p_tick_cb) { /* start system tick */ gki_cb.com.system_tick_running = TRUE; (gki_cb.com.p_tick_cb) (TRUE); } #if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0)) } else { /* clear inactivity delay timer */ gki_cb.com.OSTicksTilStop = 0; } #endif } /* Add the time since the last task timer update. ** Note that this works when no timers are active since ** both OSNumOrigTicks and OSTicksTilExp are 0. */ if (GKI_MAX_INT32 - (gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp) > ticks) { ticks += gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp; } else ticks = GKI_MAX_INT32; switch (tnum) { #if (GKI_NUM_TIMERS > 0) case TIMER_0: gki_cb.com.OSTaskTmr0R[task_id] = reload; gki_cb.com.OSTaskTmr0 [task_id] = ticks; break; #endif #if (GKI_NUM_TIMERS > 1) case TIMER_1: gki_cb.com.OSTaskTmr1R[task_id] = reload; gki_cb.com.OSTaskTmr1 [task_id] = ticks; break; #endif #if (GKI_NUM_TIMERS > 2) case TIMER_2: gki_cb.com.OSTaskTmr2R[task_id] = reload; gki_cb.com.OSTaskTmr2 [task_id] = ticks; break; #endif #if (GKI_NUM_TIMERS > 3) case TIMER_3: gki_cb.com.OSTaskTmr3R[task_id] = reload; gki_cb.com.OSTaskTmr3 [task_id] = ticks; break; #endif default: bad_timer = TRUE; /* Timer number is bad, so do not use */ } /* Update the expiration timeout if a legitimate timer */ if (!bad_timer) { /* Only update the timeout value if it is less than any other newly started timers */ gki_adjust_timer_count (orig_ticks); } GKI_enable(); }
/******************************************************************************* ** ** Function GKI_start_timer ** ** Description An application can call this function to start one of ** it's four general purpose timers. Any of the four timers ** can be 1-shot or continuous. If a timer is already running, ** it will be reset to the new parameters. ** ** Parameters tnum - (input) timer number to be started (TIMER_0, ** TIMER_1, TIMER_2, or TIMER_3) ** ticks - (input) the number of system ticks til the ** timer expires. ** is_continuous - (input) TRUE if timer restarts automatically, ** else FALSE if it is a 'one-shot'. ** ** Returns void ** *******************************************************************************/ void GKI_start_timer (UINT8 tnum, INT32 ticks, BOOLEAN is_continuous) { INT32 reload; INT32 orig_ticks; UINT8 task_id = GKI_get_taskid(); BOOLEAN bad_timer = FALSE; if (ticks <= 0) ticks = 1; orig_ticks = ticks; /* save the ticks in case adjustment is necessary */ /* If continuous timer, set reload, else set it to 0 */ if (is_continuous) reload = ticks; else reload = 0; GKI_disable(); /* Add the time since the last task timer update. ** Note that this works when no timers are active since ** both OSNumOrigTicks and OSTicksTilExp are 0. */ if (INT32_MAX - (gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp) > ticks) { ticks += gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp; } else ticks = INT32_MAX; switch (tnum) { #if (GKI_NUM_TIMERS > 0) case TIMER_0: gki_cb.com.OSTaskTmr0R[task_id] = reload; gki_cb.com.OSTaskTmr0 [task_id] = ticks; break; #endif #if (GKI_NUM_TIMERS > 1) case TIMER_1: gki_cb.com.OSTaskTmr1R[task_id] = reload; gki_cb.com.OSTaskTmr1 [task_id] = ticks; break; #endif #if (GKI_NUM_TIMERS > 2) case TIMER_2: gki_cb.com.OSTaskTmr2R[task_id] = reload; gki_cb.com.OSTaskTmr2 [task_id] = ticks; break; #endif #if (GKI_NUM_TIMERS > 3) case TIMER_3: gki_cb.com.OSTaskTmr3R[task_id] = reload; gki_cb.com.OSTaskTmr3 [task_id] = ticks; break; #endif default: bad_timer = TRUE; /* Timer number is bad, so do not use */ } /* Update the expiration timeout if a legitimate timer */ if (!bad_timer) { /* Only update the timeout value if it is less than any other newly started timers */ gki_adjust_timer_count (orig_ticks); } GKI_enable(); }