/***************************************************************************** * FUNCTION * EvmStartTimer * DESCRIPTION * Start an Event Manager timer. * PARAMETERS * timer [IN] * ticks [IN] * stopHardware [IN] * RETURNS * void *****************************************************************************/ void EvmStartTimer(EvmTimer *timer, TimeT ticks, BOOL stopHardware) { /* Assert(timer->func != 0); */ if (stopHardware) { OS_StopHardware(); } /* Configure the timer's internals */ timer->startTime = OS_GetSystemTime(); timer->time = ticks; /* If the timer is already on the list, don't add it again. */ if (!IsNodeOnList(&BTC(timerList), &timer->node)) { InsertHeadList(&BTC(timerList), &timer->node); } /* Reset the time amount for the OS timer */ ResetOsTimer(timer->startTime); if (stopHardware) { OS_ResumeHardware(); } }
/*--------------------------------------------------------------------------- * USBTRAN_SendData() * Send a packet to the BT host via an USB interface. * This function is called from HCI_Process, part of the EVM_Process or * stack thread. * * Requires: * * Parameters: * hciPacket - ptr to HciPacket * Returns: * BT_STATUS_PENDING * BT_STATUS_FAILED */ void USBTRAN_SendData(HciPacket *hciPacket) { OS_StopHardware(); InsertTailList(&USTRAN(txQueue), (ListEntry *)&hciPacket->node); if (! USTRAN(txPacket)) { /* A packet is not being transmitted so send one now. */ usbTransmitData(); } OS_ResumeHardware(); }
/***************************************************************************** * 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"); }