/* * Starts a oneshot timer with a timeout in seconds. */ void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) { osi_alarm_t *alarm = NULL; assert(p_tle != NULL); // Get the alarm for the timer list entry. osi_mutex_lock(&btu_oneshot_alarm_lock, OSI_MUTEX_MAX_TIMEOUT); if (!hash_map_has_key(btu_oneshot_alarm_hash_map, p_tle)) { alarm = osi_alarm_new("btu_oneshot", btu_oneshot_alarm_cb, (void *)p_tle, 0); hash_map_set(btu_oneshot_alarm_hash_map, p_tle, alarm); } osi_mutex_unlock(&btu_oneshot_alarm_lock); alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle); if (alarm == NULL) { LOG_ERROR("%s Unable to create alarm", __func__); return; } osi_alarm_cancel(alarm); p_tle->event = type; p_tle->in_use = TRUE; // NOTE: This value is in seconds but stored in a ticks field. p_tle->ticks = timeout_sec; osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000)); }
void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks) { osi_alarm_t *alarm = NULL; assert(p_tle != NULL); // Get the alarm for the timer list entry. osi_mutex_lock(&btu_l2cap_alarm_lock, OSI_MUTEX_MAX_TIMEOUT); if (!hash_map_has_key(btu_l2cap_alarm_hash_map, p_tle)) { alarm = osi_alarm_new("btu_l2cap", btu_l2cap_alarm_cb, (void *)p_tle, 0); hash_map_set(btu_l2cap_alarm_hash_map, p_tle, (void *)alarm); } osi_mutex_unlock(&btu_l2cap_alarm_lock); alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle); if (alarm == NULL) { LOG_ERROR("%s Unable to create alarm", __func__); return; } osi_alarm_cancel(alarm); p_tle->event = type; p_tle->ticks = timeout_ticks; p_tle->in_use = TRUE; // The quick timer ticks are 100ms long. osi_alarm_set(alarm, (period_ms_t)(timeout_ticks * 100)); }
static int hci_layer_init_env(void) { command_waiting_response_t *cmd_wait_q; // The host is only allowed to send at most one command initially, // as per the Bluetooth spec, Volume 2, Part E, 4.4 (Command Flow Control) // This value can change when you get a command complete or command status event. hci_host_env.command_credits = 1; hci_host_env.command_queue = fixed_queue_new(SIZE_MAX); if (hci_host_env.command_queue) { fixed_queue_register_dequeue(hci_host_env.command_queue, event_command_ready); } else { LOG_ERROR("%s unable to create pending command queue.", __func__); return -1; } hci_host_env.packet_queue = fixed_queue_new(SIZE_MAX); if (hci_host_env.packet_queue) { fixed_queue_register_dequeue(hci_host_env.packet_queue, event_packet_ready); } else { LOG_ERROR("%s unable to create pending packet queue.", __func__); return -1; } // Init Commands waiting response list and timer cmd_wait_q = &hci_host_env.cmd_waiting_q; cmd_wait_q->timer_is_set = false; cmd_wait_q->commands_pending_response = list_new(NULL); if (!cmd_wait_q->commands_pending_response) { LOG_ERROR("%s unable to create list for commands pending response.", __func__); return -1; } pthread_mutex_init(&cmd_wait_q->commands_pending_response_lock, NULL); cmd_wait_q->command_response_timer = osi_alarm_new("cmd_rsp_to", command_timed_out, cmd_wait_q, COMMAND_PENDING_TIMEOUT); if (!cmd_wait_q->command_response_timer) { LOG_ERROR("%s unable to create command response timer.", __func__); return -1; } return 0; }