/*******************************************************************************
**
** Function         ptim_start_timer
**
** Description      Start a protocol timer for the specified amount
**                  of time in seconds.
**
** Returns          void
**
*******************************************************************************/
void ptim_start_timer(tPTIM_CB *p_cb, TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout)
{
    /* if timer list is currently empty, start periodic GKI timer */
    if (p_cb->timer_queue.p_first == NULL)
    {
        p_cb->last_gki_ticks = GKI_get_tick_count();
        GKI_start_timer(p_cb->timer_id, GKI_MS_TO_TICKS(p_cb->period), TRUE);
    }

    GKI_remove_from_timer_list(&p_cb->timer_queue, p_tle);

    p_tle->event = type;
    p_tle->ticks = timeout;
    p_tle->ticks_initial = timeout;

    GKI_add_to_timer_list(&p_cb->timer_queue, p_tle);
}
Exemplo n.º 2
0
/*******************************************************************************
**
** Function         nfa_sys_ptim_start_timer
**
** Description      Start a protocol timer for the specified amount
**                  of time in seconds.
**
** Returns          void
**
*******************************************************************************/
void nfa_sys_ptim_start_timer (tPTIM_CB *p_cb, TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout)
{
    NFA_TRACE_DEBUG1 ("nfa_sys_ptim_start_timer %08x", p_tle);

    /* if timer list is currently empty, start periodic GKI timer */
    if (p_cb->timer_queue.p_first == NULL)
    {
        NFA_TRACE_DEBUG0 ("ptim timer start");
        p_cb->last_gki_ticks = GKI_get_tick_count ();
        GKI_start_timer (p_cb->timer_id, GKI_MS_TO_TICKS (p_cb->period), TRUE);
    }

    GKI_remove_from_timer_list (&p_cb->timer_queue, p_tle);

    p_tle->event = type;
    p_tle->ticks = timeout;

    GKI_add_to_timer_list (&p_cb->timer_queue, p_tle);
}
/** Callback from Java thread after alarm from AlarmService fires. */
static void bt_alarm_cb(void *data)
{
    GKI_disable();

    alarm_service.timer_last_expired_us = GKI_now_us();

    UINT32 ticks_taken = 0;
    UINT32 ticks_scheduled = alarm_service.ticks_scheduled;

    if (alarm_service.timer_last_expired_us > alarm_service.timer_started_us)
    {
        ticks_taken = GKI_MS_TO_TICKS((alarm_service.timer_last_expired_us
                                       - alarm_service.timer_started_us) / 1000);
    } else {
        // this could happen on some platform
        ALOGE("%s now_us %lld less than %lld", __func__, alarm_service.timer_last_expired_us,
              alarm_service.timer_started_us);
    }
    GKI_enable();

    GKI_timer_update(ticks_taken > ticks_scheduled
                   ? ticks_taken : ticks_scheduled);
}