1e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/****************************************************************************** 2e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * 3e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * Copyright (C) 1999-2012 Broadcom Corporation 4e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * 5e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 6e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * you may not use this file except in compliance with the License. 7e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * You may obtain a copy of the License at: 8e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * 9e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 10e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * 11e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 12e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 13e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * See the License for the specific language governing permissions and 15e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * limitations under the License. 16e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * 17e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ******************************************************************************/ 18e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#include "gki_int.h" 19e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 20e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#ifndef BT_ERROR_TRACE_0 21e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#define BT_ERROR_TRACE_0(l,m) 22e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 23e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 24e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/* Make sure that this has been defined in target.h */ 25e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#ifndef GKI_NUM_TIMERS 26e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#error NO TIMERS: Must define at least 1 timer in the system! 27e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 28e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 29e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 30e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#define GKI_NO_NEW_TMRS_STARTED (0x7fffffffL) /* Largest signed positive timer count */ 31e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#define GKI_UNUSED_LIST_ENTRY (0x80000000L) /* Marks an unused timer list entry (initial value) */ 32e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#define GKI_MAX_INT32 (0x7fffffffL) 33e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 34e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 35e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 36e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function gki_timers_init 37e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 38e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This internal function is called once at startup to initialize 39e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** all the timer structures. 40e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 41e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 42e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 43e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 44e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid gki_timers_init(void) 45e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 46e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT8 tt; 47e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 48e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilExp = 0; /* Remaining time (of OSTimeCurTimeout) before next timer expires */ 49e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSNumOrigTicks = 0; 50e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0)) 51e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilStop = 0; /* clear inactivity delay timer */ 52e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 53e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 54e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project for (tt = 0; tt < GKI_MAX_TASKS; tt++) 55e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 56e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSWaitTmr [tt] = 0; 57e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 58e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 0) 59e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr0 [tt] = 0; 60e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr0R [tt] = 0; 61e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 62e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 63e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 1) 64e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr1 [tt] = 0; 65e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr1R [tt] = 0; 66e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 67e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 68e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 2) 69e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr2 [tt] = 0; 70e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr2R [tt] = 0; 71e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 72e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 73e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 3) 74e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr3 [tt] = 0; 75e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr3R [tt] = 0; 76e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 77e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 78e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 79e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project for (tt = 0; tt < GKI_MAX_TIMER_QUEUES; tt++) 80e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 81e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.timer_queues[tt] = NULL; 82e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 83e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 84e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.p_tick_cb = NULL; 85e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.system_tick_running = FALSE; 86e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 87e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 88e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 89e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 90e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 91e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 92e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function gki_timers_is_timer_running 93e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 94e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This internal function is called to test if any gki timer are running 95e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 96e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 97e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns TRUE if at least one time is running in the system, FALSE else. 98e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 99e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 100e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source ProjectBOOLEAN gki_timers_is_timer_running(void) 101e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 102e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT8 tt; 103e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project for (tt = 0; tt < GKI_MAX_TASKS; tt++) 104e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 105e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 106e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 0) 107e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if(gki_cb.com.OSTaskTmr0 [tt]) 108e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 109e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return TRUE; 110e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 111e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 112e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 113e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 1) 114e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if(gki_cb.com.OSTaskTmr1 [tt] ) 115e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 116e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return TRUE; 117e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 118e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 119e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 120e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 2) 121e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if(gki_cb.com.OSTaskTmr2 [tt] ) 122e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 123e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return TRUE; 124e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 125e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 126e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 127e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 3) 128e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if(gki_cb.com.OSTaskTmr3 [tt] ) 129e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 130e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return TRUE; 131e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 132e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 133e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 134e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 135e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return FALSE; 136e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 137e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 138e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 139e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 140e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 141e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_get_tick_count 142e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 143e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function returns the current system ticks 144e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 145e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns The current number of system ticks 146e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 147e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 148e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source ProjectUINT32 GKI_get_tick_count(void) 149e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 150e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return gki_cb.com.OSTicks; 151e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 152e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 153e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 154e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 155e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 156e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_ready_to_sleep 157e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 158e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function returns the number of system ticks until the 159e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** next timer will expire. It is typically called by a power 160e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** savings manager to find out how long it can have the system 161e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** sleep before it needs to service the next entry. 162e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 163e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters: None 164e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 165e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns Number of ticks til the next timer expires 166e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Note: the value is a signed value. This value should be 167e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** compared to x > 0, to avoid misinterpreting negative tick 168e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** values. 169e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 170e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 171e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source ProjectINT32 GKI_ready_to_sleep (void) 172e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 173e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return (gki_cb.com.OSTicksTilExp); 174e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 175e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 176e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 177e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 178e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 179e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_start_timer 180e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 181e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description An application can call this function to start one of 182e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** it's four general purpose timers. Any of the four timers 183e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** can be 1-shot or continuous. If a timer is already running, 184e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** it will be reset to the new parameters. 185e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 186e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters tnum - (input) timer number to be started (TIMER_0, 187e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** TIMER_1, TIMER_2, or TIMER_3) 188e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** ticks - (input) the number of system ticks til the 189e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** timer expires. 190e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** is_continuous - (input) TRUE if timer restarts automatically, 191e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** else FALSE if it is a 'one-shot'. 192e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 193e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 194e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 195e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 196e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid GKI_start_timer (UINT8 tnum, INT32 ticks, BOOLEAN is_continuous) 197e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 198e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project INT32 reload; 199e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project INT32 orig_ticks; 200e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT8 task_id = GKI_get_taskid(); 201e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project BOOLEAN bad_timer = FALSE; 202e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 203e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (ticks <= 0) 204e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ticks = 1; 205e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 206e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project orig_ticks = ticks; /* save the ticks in case adjustment is necessary */ 207e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 208e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 209e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If continuous timer, set reload, else set it to 0 */ 210e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (is_continuous) 211e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project reload = ticks; 212e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 213e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project reload = 0; 214e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 215e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_disable(); 216e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 217e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if(gki_timers_is_timer_running() == FALSE) 218e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 219e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0)) 220e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* if inactivity delay timer is not running, start system tick */ 221e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if(gki_cb.com.OSTicksTilStop == 0) 222e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 223e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 224e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if(gki_cb.com.p_tick_cb) 225e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 226e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* start system tick */ 227e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.system_tick_running = TRUE; 228e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project (gki_cb.com.p_tick_cb) (TRUE); 229e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 230e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0)) 231e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 232e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 233e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 234e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* clear inactivity delay timer */ 235e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilStop = 0; 236e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 237e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 238e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 239e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Add the time since the last task timer update. 240e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ** Note that this works when no timers are active since 241e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ** both OSNumOrigTicks and OSTicksTilExp are 0. 242e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project */ 243e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (GKI_MAX_INT32 - (gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp) > ticks) 244e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 245e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ticks += gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp; 246e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 247e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 248e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ticks = GKI_MAX_INT32; 249e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 250e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project switch (tnum) 251e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 252e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 0) 253e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project case TIMER_0: 254e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr0R[task_id] = reload; 255e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr0 [task_id] = ticks; 256e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 257e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 258e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 259e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 1) 260e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project case TIMER_1: 261e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr1R[task_id] = reload; 262e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr1 [task_id] = ticks; 263e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 264e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 265e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 266e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 2) 267e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project case TIMER_2: 268e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr2R[task_id] = reload; 269e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr2 [task_id] = ticks; 270e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 271e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 272e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 273e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 3) 274e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project case TIMER_3: 275e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr3R[task_id] = reload; 276e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr3 [task_id] = ticks; 277e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 278e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 279e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project default: 280e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project bad_timer = TRUE; /* Timer number is bad, so do not use */ 281e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 282e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 283e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Update the expiration timeout if a legitimate timer */ 284e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (!bad_timer) 285e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 286e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Only update the timeout value if it is less than any other newly started timers */ 287e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_adjust_timer_count (orig_ticks); 288e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 289e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 290e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_enable(); 291e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 292e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 293e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 294e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 295e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 296e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_stop_timer 297e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 298e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description An application can call this function to stop one of 299e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** it's four general purpose timers. There is no harm in 300e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** stopping a timer that is already stopped. 301e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 302e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters tnum - (input) timer number to be started (TIMER_0, 303e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** TIMER_1, TIMER_2, or TIMER_3) 304e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 305e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 306e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 307e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid GKI_stop_timer (UINT8 tnum) 308e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 309e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT8 task_id = GKI_get_taskid(); 310e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 311e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_disable(); 312e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 313e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project switch (tnum) 314e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 315e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 0) 316e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project case TIMER_0: 317e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr0R[task_id] = 0; 318e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr0 [task_id] = 0; 319e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 320e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 321e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 322e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 1) 323e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project case TIMER_1: 324e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr1R[task_id] = 0; 325e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr1 [task_id] = 0; 326e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 327e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 328e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 329e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 2) 330e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project case TIMER_2: 331e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr2R[task_id] = 0; 332e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr2 [task_id] = 0; 333e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 334e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 335e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 336e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 3) 337e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project case TIMER_3: 338e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr3R[task_id] = 0; 339e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr3 [task_id] = 0; 340e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 341e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 342e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 343e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 344e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_timers_is_timer_running() == FALSE) 345e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 346e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.p_tick_cb) 347e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 348e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0)) 349e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* if inactivity delay timer is not running */ 350e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if ((gki_cb.com.system_tick_running)&&(gki_cb.com.OSTicksTilStop == 0)) 351e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 352e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* set inactivity delay timer */ 353e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* when timer expires, system tick will be stopped */ 354e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilStop = GKI_DELAY_STOP_SYS_TICK; 355e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 356e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#else 357e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.system_tick_running = FALSE; 358e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.p_tick_cb(FALSE); /* stop system tick */ 359e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 360e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 361e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 362e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 363e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_enable(); 364e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 365e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 366e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 367e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 368e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 369e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 370e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 371e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_timer_update 372e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 373e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by an OS to drive the GKI's timers. 374e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** It is typically called at every system tick to 375e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** update the timers for all tasks, and check for timeouts. 376e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 377e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Note: It has been designed to also allow for variable tick updates 378e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** so that systems with strict power savings requirements can 379e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** have the update occur at variable intervals. 380e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 381e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters: ticks_since_last_update - (input) This is the number of TICKS that have 382e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** occurred since the last time GKI_timer_update was called. 383e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 384e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 385e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 386e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 387e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid GKI_timer_update (INT32 ticks_since_last_update) 388e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 389e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT8 task_id; 390e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project long next_expiration; /* Holds the next soonest expiration time after this update */ 391e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 392e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Increment the number of ticks used for time stamps */ 393e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicks += ticks_since_last_update; 394e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 395e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If any timers are running in any tasks, decrement the remaining time til 396e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * the timer updates need to take place (next expiration occurs) 397e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project */ 398e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilExp -= ticks_since_last_update; 399e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 400e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Don't allow timer interrupt nesting */ 401e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.timer_nesting) 402e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 403e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 404e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.timer_nesting = 1; 405e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 406e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_DELAY_STOP_SYS_TICK) && (GKI_DELAY_STOP_SYS_TICK > 0)) 407e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* if inactivity delay timer is set and expired */ 408e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTicksTilStop) 409e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 410e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if( gki_cb.com.OSTicksTilStop <= (UINT32)ticks_since_last_update ) 411e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 412e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if(gki_cb.com.p_tick_cb) 413e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 414e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.system_tick_running = FALSE; 415e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project (gki_cb.com.p_tick_cb) (FALSE); /* stop system tick */ 416e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 417e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilStop = 0; /* clear inactivity delay timer */ 418e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.timer_nesting = 0; 419e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 420e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 421e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 422e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilStop -= ticks_since_last_update; 423e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 424e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 425e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 426e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* No need to update the ticks if no timeout has occurred */ 427e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTicksTilExp > 0) 428e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 429e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.timer_nesting = 0; 430e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 431e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 432e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 433e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_disable(); 434e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 435e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project next_expiration = GKI_NO_NEW_TMRS_STARTED; 436e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 437e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If here then gki_cb.com.OSTicksTilExp <= 0. If negative, then increase gki_cb.com.OSNumOrigTicks 438e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project to account for the difference so timer updates below are decremented by the full number 439e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project of ticks. gki_cb.com.OSNumOrigTicks is reset at the bottom of this function so changing this 440e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project value only affects the timer updates below 441e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project */ 442e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSNumOrigTicks -= gki_cb.com.OSTicksTilExp; 443e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 444e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Check for OS Task Timers */ 445e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project for (task_id = 0; task_id < GKI_MAX_TASKS; task_id++) 446e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 4475c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen if (gki_cb.com.OSRdyTbl[task_id] == TASK_DEAD) 4485c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen { 4495c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen // task is shutdown do not try to service timers 4505c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen continue; 4515c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen } 4525c65c3a0f42e174e47fecd4e569606003217ff4eMartijn Coenen 453e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSWaitTmr[task_id] > 0) /* If timer is running */ 454e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 455e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSWaitTmr[task_id] -= gki_cb.com.OSNumOrigTicks; 456e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSWaitTmr[task_id] <= 0) 457e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 458e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Timer Expired */ 459e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSRdyTbl[task_id] = TASK_READY; 460e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 461e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 462e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 463e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 0) 464e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If any timer is running, decrement */ 465e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr0[task_id] > 0) 466e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 467e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr0[task_id] -= gki_cb.com.OSNumOrigTicks; 468e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 469e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr0[task_id] <= 0) 470e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 471e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Set Timer 0 Expired event mask and reload timer */ 472e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_TIMER_UPDATES_FROM_ISR) && GKI_TIMER_UPDATES_FROM_ISR == TRUE) 473e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_isend_event (task_id, TIMER_0_EVT_MASK); 474e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#else 475e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_send_event (task_id, TIMER_0_EVT_MASK); 476e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 477e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr0[task_id] = gki_cb.com.OSTaskTmr0R[task_id]; 478e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 479e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 480e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 481e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Check to see if this timer is the next one to expire */ 482e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr0[task_id] > 0 && gki_cb.com.OSTaskTmr0[task_id] < next_expiration) 483e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project next_expiration = gki_cb.com.OSTaskTmr0[task_id]; 484e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 485e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 486e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 1) 487e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If any timer is running, decrement */ 488e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr1[task_id] > 0) 489e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 490e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr1[task_id] -= gki_cb.com.OSNumOrigTicks; 491e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 492e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr1[task_id] <= 0) 493e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 494e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Set Timer 1 Expired event mask and reload timer */ 495e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_TIMER_UPDATES_FROM_ISR) && GKI_TIMER_UPDATES_FROM_ISR == TRUE) 496e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_isend_event (task_id, TIMER_1_EVT_MASK); 497e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#else 498e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_send_event (task_id, TIMER_1_EVT_MASK); 499e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 500e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr1[task_id] = gki_cb.com.OSTaskTmr1R[task_id]; 501e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 502e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 503e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 504e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Check to see if this timer is the next one to expire */ 505e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr1[task_id] > 0 && gki_cb.com.OSTaskTmr1[task_id] < next_expiration) 506e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project next_expiration = gki_cb.com.OSTaskTmr1[task_id]; 507e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 508e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 509e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 2) 510e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If any timer is running, decrement */ 511e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr2[task_id] > 0) 512e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 513e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr2[task_id] -= gki_cb.com.OSNumOrigTicks; 514e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 515e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr2[task_id] <= 0) 516e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 517e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Set Timer 2 Expired event mask and reload timer */ 518e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_TIMER_UPDATES_FROM_ISR) && GKI_TIMER_UPDATES_FROM_ISR == TRUE) 519e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_isend_event (task_id, TIMER_2_EVT_MASK); 520e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#else 521e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_send_event (task_id, TIMER_2_EVT_MASK); 522e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 523e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr2[task_id] = gki_cb.com.OSTaskTmr2R[task_id]; 524e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 525e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 526e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 527e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Check to see if this timer is the next one to expire */ 528e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr2[task_id] > 0 && gki_cb.com.OSTaskTmr2[task_id] < next_expiration) 529e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project next_expiration = gki_cb.com.OSTaskTmr2[task_id]; 530e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 531e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 532e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (GKI_NUM_TIMERS > 3) 533e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If any timer is running, decrement */ 534e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr3[task_id] > 0) 535e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 536e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr3[task_id] -= gki_cb.com.OSNumOrigTicks; 537e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 538e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr3[task_id] <= 0) 539e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 540e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Set Timer 3 Expired event mask and reload timer */ 541e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#if (defined(GKI_TIMER_UPDATES_FROM_ISR) && GKI_TIMER_UPDATES_FROM_ISR == TRUE) 542e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_isend_event (task_id, TIMER_3_EVT_MASK); 543e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#else 544e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_send_event (task_id, TIMER_3_EVT_MASK); 545e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 546e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTaskTmr3[task_id] = gki_cb.com.OSTaskTmr3R[task_id]; 547e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 548e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 549e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 550e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Check to see if this timer is the next one to expire */ 551e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSTaskTmr3[task_id] > 0 && gki_cb.com.OSTaskTmr3[task_id] < next_expiration) 552e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project next_expiration = gki_cb.com.OSTaskTmr3[task_id]; 553e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project#endif 554e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 555e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 556e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 557e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Set the next timer experation value if there is one to start */ 558e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (next_expiration < GKI_NO_NEW_TMRS_STARTED) 559e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 560e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilExp = gki_cb.com.OSNumOrigTicks = next_expiration; 561e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 562e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 563e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 564e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilExp = gki_cb.com.OSNumOrigTicks = 0; 565e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 566e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 567e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.timer_nesting = 0; 568e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 569e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_enable(); 570e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 571e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 572e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 573e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 574e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 575e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 576e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 577e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_timer_queue_empty 578e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 579e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by applications to see whether the timer 580e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** queue is empty 581e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 582e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters 583e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 584e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns BOOLEAN 585e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 586e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 587e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source ProjectBOOLEAN GKI_timer_queue_empty (void) 588e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 589e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT8 tt; 590e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 591e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project for (tt = 0; tt < GKI_MAX_TIMER_QUEUES; tt++) 592e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 593e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.timer_queues[tt]) 594e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return FALSE; 595e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 596e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 597e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return TRUE; 598e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 599e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 600e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 601e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 602e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_timer_queue_register_callback 603e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 604e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by applications to register system tick 605e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** start/stop callback for time queues 606e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 607e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 608e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters p_callback - (input) pointer to the system tick callback 609e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 610e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns BOOLEAN 611e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 612e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 613e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid GKI_timer_queue_register_callback (SYSTEM_TICK_CBACK *p_callback) 614e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 615e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.p_tick_cb = p_callback; 616e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 617e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 618e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 619e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 620e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 621e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 622e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_init_timer_list 623e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 624e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by applications when they 625e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** want to initialize a timer list. 626e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 627e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters p_timer_listq - (input) pointer to the timer list queue object 628e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 629e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 630e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 631e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 632e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid GKI_init_timer_list (TIMER_LIST_Q *p_timer_listq) 633e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 634e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_first = NULL; 635e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_last = NULL; 636e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->last_ticks = 0; 637e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 638e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 639e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 640e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 641e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 642e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 643e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_init_timer_list_entry 644e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 645e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by the applications when they 646e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** want to initialize a timer list entry. This must be 647e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** done prior to first use of the entry. 648e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 649e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters p_tle - (input) pointer to a timer list queue entry 650e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 651e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 652e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 653e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 654e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid GKI_init_timer_list_entry (TIMER_LIST_ENT *p_tle) 655e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 656e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_next = NULL; 657e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_prev = NULL; 658e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->ticks = GKI_UNUSED_LIST_ENTRY; 659e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->in_use = FALSE; 660e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 661e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 662e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 663e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 664e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 665e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_update_timer_list 666e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 667e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by the applications when they 668e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** want to update a timer list. This should be at every 669e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** timer list unit tick, e.g. once per sec, once per minute etc. 670e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 671e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters p_timer_listq - (input) pointer to the timer list queue object 672e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** num_units_since_last_update - (input) number of units since the last update 673e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** (allows for variable unit update) 674e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 675e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** NOTE: The following timer list update routines should not be used for exact time 676e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** critical purposes. The timer tasks should be used when exact timing is needed. 677e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 678e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns the number of timers that have expired 679e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 680e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 681e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source ProjectUINT16 GKI_update_timer_list (TIMER_LIST_Q *p_timer_listq, INT32 num_units_since_last_update) 682e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 683e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project TIMER_LIST_ENT *p_tle; 684e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT16 num_time_out = 0; 685e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project INT32 rem_ticks; 686e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project INT32 temp_ticks; 687e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 688e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle = p_timer_listq->p_first; 689e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 690e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* First, get the guys who have previously timed out */ 691e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Note that the tick value of the timers should always be '0' */ 692e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project while ((p_tle) && (p_tle->ticks <= 0)) 693e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 694e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project num_time_out++; 695e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle = p_tle->p_next; 696e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 697e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 698e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Timer entriy tick values are relative to the preceeding entry */ 699e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project rem_ticks = num_units_since_last_update; 700e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 701e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Now, adjust remaining timer entries */ 702e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project while ((p_tle != NULL) && (rem_ticks > 0)) 703e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 704e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project temp_ticks = p_tle->ticks; 705e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->ticks -= rem_ticks; 706e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 707e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* See if this timer has just timed out */ 708e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle->ticks <= 0) 709e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 710e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* We set the number of ticks to '0' so that the legacy code 711e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * that assumes a '0' or nonzero value will still work as coded. */ 712e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->ticks = 0; 713e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 714e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project num_time_out++; 715e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 716e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 717e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project rem_ticks -= temp_ticks; /* Decrement the remaining ticks to process */ 718e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle = p_tle->p_next; 719e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 720e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 721e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->last_ticks > 0) 722e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 723e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->last_ticks -= num_units_since_last_update; 724e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 725e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If the last timer has expired set last_ticks to 0 so that other list update 726e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project * functions will calculate correctly 727e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project */ 728e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->last_ticks < 0) 729e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->last_ticks = 0; 730e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 731e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 732e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return (num_time_out); 733e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 734e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 735e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 736e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 737e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_get_remaining_ticks 738e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 739e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by an application to get remaining 740e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** ticks to expire 741e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 742e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters p_timer_listq - (input) pointer to the timer list queue object 743e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** p_target_tle - (input) pointer to a timer list queue entry 744e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 745e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns 0 if timer is not used or timer is not in the list 746e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** remaining ticks if success 747e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 748e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 749e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source ProjectUINT32 GKI_get_remaining_ticks (TIMER_LIST_Q *p_timer_listq, TIMER_LIST_ENT *p_target_tle) 750e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 751e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project TIMER_LIST_ENT *p_tle; 752e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT32 rem_ticks = 0; 753e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 754e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_target_tle->in_use) 755e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 756e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle = p_timer_listq->p_first; 757e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 758e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* adding up all of ticks in previous entries */ 759e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project while ((p_tle)&&(p_tle != p_target_tle)) 760e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 761e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project rem_ticks += p_tle->ticks; 762e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle = p_tle->p_next; 763e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 764e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 765e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* if found target entry */ 766e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle == p_target_tle) 767e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 768e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project rem_ticks += p_tle->ticks; 769e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 770e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 771e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 772e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project BT_ERROR_TRACE_0(TRACE_LAYER_GKI, "GKI_get_remaining_ticks: No timer entry in the list"); 773e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return(0); 774e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 775e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 776e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 777e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 778e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project BT_ERROR_TRACE_0(TRACE_LAYER_GKI, "GKI_get_remaining_ticks: timer entry is not active"); 779e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 780e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 781e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return (rem_ticks); 782e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 783e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 784e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 785e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 786e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_add_to_timer_list 787e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 788e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by an application to add a timer 789e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** entry to a timer list. 790e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 791e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Note: A timer value of '0' will effectively insert an already 792e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** expired event. Negative tick values will be ignored. 793e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 794e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters p_timer_listq - (input) pointer to the timer list queue object 795e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** p_tle - (input) pointer to a timer list queue entry 796e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 797e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 798e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 799e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 800e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid GKI_add_to_timer_list (TIMER_LIST_Q *p_timer_listq, TIMER_LIST_ENT *p_tle) 801e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 802e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT32 nr_ticks_total; 803e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT8 tt; 804e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project TIMER_LIST_ENT *p_temp; 805e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle == NULL || p_timer_listq == NULL) { 806e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project GKI_TRACE_3("%s: invalid argument %x, %x****************************<<", __func__, p_timer_listq, p_tle); 807e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 808e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 809e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 810e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 811e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Only process valid tick values */ 812e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle->ticks >= 0) 813e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 814e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If this entry is the last in the list */ 815e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle->ticks >= p_timer_listq->last_ticks) 816e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 817e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* If this entry is the only entry in the list */ 818e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->p_first == NULL) 819e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_first = p_tle; 820e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 821e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 822e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Insert the entry onto the end of the list */ 823e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->p_last != NULL) 824e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_last->p_next = p_tle; 825e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 826e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_prev = p_timer_listq->p_last; 827e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 828e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 829e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_next = NULL; 830e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_last = p_tle; 831e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project nr_ticks_total = p_tle->ticks; 832e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->ticks -= p_timer_listq->last_ticks; 833e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 834e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->last_ticks = nr_ticks_total; 835e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 836e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else /* This entry needs to be inserted before the last entry */ 837e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 838e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Find the entry that the new one needs to be inserted in front of */ 839e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_temp = p_timer_listq->p_first; 840e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project while (p_tle->ticks > p_temp->ticks) 841e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 842e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Update the tick value if looking at an unexpired entry */ 843e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_temp->ticks > 0) 844e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->ticks -= p_temp->ticks; 845e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 846e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_temp = p_temp->p_next; 847e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 848e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 849e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* The new entry is the first in the list */ 850e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_temp == p_timer_listq->p_first) 851e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 852e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_next = p_timer_listq->p_first; 853e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_first->p_prev = p_tle; 854e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_first = p_tle; 855e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 856e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 857e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 858e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_temp->p_prev->p_next = p_tle; 859e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_prev = p_temp->p_prev; 860e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_temp->p_prev = p_tle; 861e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_next = p_temp; 862e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 863e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_temp->ticks -= p_tle->ticks; 864e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 865e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 866e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->in_use = TRUE; 867e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 868e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* if we already add this timer queue to the array */ 869e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project for (tt = 0; tt < GKI_MAX_TIMER_QUEUES; tt++) 870e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 871e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.timer_queues[tt] == p_timer_listq) 872e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 873e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 874e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* add this timer queue to the array */ 875e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project for (tt = 0; tt < GKI_MAX_TIMER_QUEUES; tt++) 876e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 877e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.timer_queues[tt] == NULL) 878e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 879e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 880e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (tt < GKI_MAX_TIMER_QUEUES) 881e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 882e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.timer_queues[tt] = p_timer_listq; 883e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 884e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 885e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 886e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 887e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 888e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 889e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 890e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 891e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 892e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function GKI_remove_from_timer_list 893e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 894e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called by an application to remove a timer 895e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** entry from a timer list. 896e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 897e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters p_timer_listq - (input) pointer to the timer list queue object 898e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** p_tle - (input) pointer to a timer list queue entry 899e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 900e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 901e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 902e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 903e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid GKI_remove_from_timer_list (TIMER_LIST_Q *p_timer_listq, TIMER_LIST_ENT *p_tle) 904e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 905e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project UINT8 tt; 906e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 907e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Verify that the entry is valid */ 908e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle == NULL || p_tle->in_use == FALSE || p_timer_listq->p_first == NULL) 909e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 910e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 911e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 912e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 913e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Add the ticks remaining in this timer (if any) to the next guy in the list. 914e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project ** Note: Expired timers have a tick value of '0'. 915e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project */ 916e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle->p_next != NULL) 917e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 918e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_next->ticks += p_tle->ticks; 919e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 920e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 921e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 922e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->last_ticks -= p_tle->ticks; 923e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 924e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 925e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Unlink timer from the list. 926e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project */ 927e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->p_first == p_tle) 928e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 929e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_first = p_tle->p_next; 930e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 931e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->p_first != NULL) 932e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_first->p_prev = NULL; 933e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 934e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->p_last == p_tle) 935e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_last = NULL; 936e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 937e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 938e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 939e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->p_last == p_tle) 940e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 941e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_last = p_tle->p_prev; 942e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 943e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->p_last != NULL) 944e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_timer_listq->p_last->p_next = NULL; 945e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 946e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 947e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 948e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle->p_next != NULL && p_tle->p_next->p_prev == p_tle) 949e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_next->p_prev = p_tle->p_prev; 950e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 951e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 952e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Error case - chain messed up ?? */ 953e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 954e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 955e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 956e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_tle->p_prev != NULL && p_tle->p_prev->p_next == p_tle) 957e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_prev->p_next = p_tle->p_next; 958e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project else 959e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 960e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* Error case - chain messed up ?? */ 961e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 962e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 963e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 964e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 965e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 966e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->p_next = p_tle->p_prev = NULL; 967e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->ticks = GKI_UNUSED_LIST_ENTRY; 968e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project p_tle->in_use = FALSE; 969e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 970e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* if timer queue is empty */ 971e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (p_timer_listq->p_first == NULL && p_timer_listq->p_last == NULL) 972e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 973e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project for (tt = 0; tt < GKI_MAX_TIMER_QUEUES; tt++) 974e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 975e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.timer_queues[tt] == p_timer_listq) 976e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 977e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.timer_queues[tt] = NULL; 978e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project break; 979e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 980e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 981e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 982e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 983e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 984e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 985e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 986e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 987e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project/******************************************************************************* 988e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 989e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Function gki_adjust_timer_count 990e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 991e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Description This function is called whenever a new timer or GKI_wait occurs 992e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** to adjust (if necessary) the current time til the first expiration. 993e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** This only needs to make an adjustment if the new timer (in ticks) is 994e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** less than the number of ticks remaining on the current timer. 995e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 996e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Parameters: ticks - (input) number of system ticks of the new timer entry 997e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 998e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** NOTE: This routine MUST be called while interrupts are disabled to 999e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** avoid updates while adjusting the timer variables. 1000e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 1001e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** Returns void 1002e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project** 1003e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project*******************************************************************************/ 1004e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Projectvoid gki_adjust_timer_count (INT32 ticks) 1005e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project{ 1006e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (ticks > 0) 1007e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 1008e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project /* See if the new timer expires before the current first expiration */ 1009e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project if (gki_cb.com.OSNumOrigTicks == 0 || (ticks < gki_cb.com.OSTicksTilExp && gki_cb.com.OSTicksTilExp > 0)) 1010e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project { 1011e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSNumOrigTicks = (gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp) + ticks; 1012e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project gki_cb.com.OSTicksTilExp = ticks; 1013e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 1014e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project } 1015e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project 1016e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project return; 1017e9df6ba5a8fcccf306a80b1670b423be8fe7746The Android Open Source Project} 1018