/***************************************************************************** * FUNCTION * ResetOsTimer * DESCRIPTION * Resets the actual OS timer based on the shortest remaining * timer. * PARAMETERS * curTime [IN] * RETURNS * void *****************************************************************************/ static void ResetOsTimer(TimeT curTime) { EvmTimer *timer; ListEntry *node; TimeT timeElapsed; TimeT minWait = (TimeT) (-1); /* Look for timers scheduled in the future */ if (!IsListEmpty(&BTC(timerList))) { node = GetHeadList(&BTC(timerList)); while (node != &BTC(timerList)) { timer = (EvmTimer*) node; node = node->Flink; timeElapsed = curTime - timer->startTime; /* If the timer must elapse sooner than minWait, adjust minWait */ if (timeElapsed < timer->time) { minWait = min(minWait, timer->time - timeElapsed); } else { OS_Report("[TIMER] Timer(%x) timeout (%u, %u) when reset OS timer. Just Fire timer", timer, timeElapsed, timer->time); TimerFired(); return; } } } /* Are any timers in the future? */ if (minWait < (TimeT) (-1)) { OS_StartTimer(minWait, TimerFired); } else { OS_CancelTimer(); } }
FmpChannel *FmpFindChannelByLink(BtRemoteDevice *remote_dev) { FmpChannel *channel; channel = (FmpChannel *)GetHeadList(&FMP(dev_list)); while ((ListEntry *)channel != &FMP(dev_list)) { if ((channel->link == remote_dev) || ((channel->cmgr_handler.bdc != 0) && (channel->cmgr_handler.bdc->link == remote_dev)) ) { return channel; } /* try the next node in the device list */ channel = (FmpChannel *)GetNextNode(&channel->node); } return NULL; }
/***************************************************************************** * FUNCTION * EvmCancelTimer * DESCRIPTION * Cancel an Event Manager timer. * PARAMETERS * timer [IN] * stopHardware [IN] * RETURNS * void *****************************************************************************/ void EvmCancelTimer(EvmTimer *timer, BOOL stopHardware) { EvmTimer *curTimer; ListEntry *node; if (stopHardware) { OS_StopHardware(); } /* Look for the timer in our active timer list and remove it. */ if (!IsListEmpty(&BTC(timerList))) { node = GetHeadList(&BTC(timerList)); while (node != &BTC(timerList)) { curTimer = (EvmTimer*) node; node = node->Flink; if (curTimer == timer) { RemoveEntryList(&curTimer->node); /* Recalculates the correct OS timer period */ ResetOsTimer(OS_GetSystemTime()); break; } } } /* * If the timer was not found in our active list, simply assume it was * already cancelled. */ if (stopHardware) { OS_ResumeHardware(); } }
/***************************************************************************** * FUNCTION * CheckTimers * DESCRIPTION * Look for expired timers and call their notify functions * PARAMETERS * void * RETURNS * void *****************************************************************************/ static void CheckTimers(void) { EvmTimer *timer; ListEntry *node; TimeT curTime; TimeT timeElapsed; U8 timerFired; //bt_prompt_trace(MOD_BT, "[BT] +CheckTimers"); OS_StopHardware(); timerFired = FALSE; /* See if we have any expired timers */ if (!IsListEmpty(&BTC(timerList))) { curTime = OS_GetSystemTime(); /* Look through all active timers */ node = GetHeadList(&BTC(timerList)); while (node != &BTC(timerList)) { timer = (EvmTimer*) node; node = node->Flink; /* Calculate elapsed time */ if(curTime >= timer->startTime){ timeElapsed = curTime - timer->startTime; }else{ bt_prompt_trace(MOD_BT, "[TIMER] timer overrun : curTime=%u, timer->startTime=%u", curTime, timer->startTime); timeElapsed = curTime + (0xFFFFFFFF - timer->startTime); } //bt_prompt_trace(MOD_BT, "[BT] timeElapsed=%d, wait time=%d",timeElapsed, timer->time); /* If its time is complete, remove the timer and fire it. */ if (timeElapsed >= timer->time) { RemoveEntryList(&timer->node); OS_ResumeHardware(); //bt_prompt_trace(MOD_BT, "[BT] timer->func(timer) : 0x%x", (U32)timer->func); timer->func(timer); //bt_prompt_trace(MOD_BT, "[BT] timer->func(timer) success"); timerFired = TRUE; OS_StopHardware(); /* * Start looking back at the beginning of the list * This is necessary because the contents of the list * might have been modified during timer->func. */ node = GetHeadList(&BTC(timerList)); curTime = OS_GetSystemTime(); } } /* * If any timer fired, we need to reset the OS timer and * re-schedule the stack task. */ if (timerFired) { OS_NotifyEvm(); ResetOsTimer(curTime); } } OS_ResumeHardware(); //bt_prompt_trace(MOD_BT, "[BT] -CheckTimers"); }