diff options
-rw-r--r-- | bta/sys/bta_sys.h | 5 | ||||
-rw-r--r-- | btif/include/btif_media.h | 1 | ||||
-rw-r--r-- | btif/src/btif_media_task.c | 189 | ||||
-rw-r--r-- | gki/Android.mk | 1 | ||||
-rw-r--r-- | gki/common/gki.h | 14 | ||||
-rw-r--r-- | gki/common/gki_common.h | 14 | ||||
-rw-r--r-- | gki/common/gki_time.c | 394 | ||||
-rw-r--r-- | gki/ulinux/gki_ulinux.c | 35 | ||||
-rw-r--r-- | include/gki_target.h | 55 | ||||
-rw-r--r-- | main/Android.mk | 3 | ||||
-rw-r--r-- | stack/btm/btm_inq.c | 2 | ||||
-rw-r--r-- | stack/btm/btm_sec.c | 6 | ||||
-rw-r--r-- | stack/btu/btu_task.c | 17 | ||||
-rw-r--r-- | stack/include/btu.h | 7 | ||||
-rw-r--r-- | stack/l2cap/l2c_fcr.c | 1 | ||||
-rw-r--r-- | stack/rfcomm/rfc_l2cap_if.c | 2 |
16 files changed, 58 insertions, 688 deletions
diff --git a/bta/sys/bta_sys.h b/bta/sys/bta_sys.h index c669f5b9f..2204b550b 100644 --- a/bta/sys/bta_sys.h +++ b/bta/sys/bta_sys.h @@ -170,11 +170,6 @@ typedef struct #define BTA_MBOX TASK_MBOX_2 #endif -/* GKI timer id used for protocol timer for BTA. */ -#ifndef BTA_TIMER -#define BTA_TIMER TIMER_1 -#endif - /***************************************************************************** ** Global data *****************************************************************************/ diff --git a/btif/include/btif_media.h b/btif/include/btif_media.h index 5e2f823dc..96971bfa4 100644 --- a/btif/include/btif_media.h +++ b/btif/include/btif_media.h @@ -272,7 +272,6 @@ void btif_a2dp_set_tx_flush(BOOLEAN enable); void btif_a2dp_set_rx_flush(BOOLEAN enable); void btif_media_check_iop_exceptions(UINT8 *peer_bda); void btif_reset_decoder(UINT8 *p_av); -BOOLEAN btif_media_task_start_decoding_req(void); int btif_a2dp_get_track_frequency(UINT8 frequency); int btif_a2dp_get_track_channel_count(UINT8 channeltype); diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c index b7965b457..04bd63c16 100644 --- a/btif/src/btif_media_task.c +++ b/btif/src/btif_media_task.c @@ -26,6 +26,7 @@ ** ******************************************************************************/ +#include <assert.h> #include <string.h> #include <stdio.h> #include <sys/types.h> @@ -56,6 +57,9 @@ #include "btif_av_co.h" #include "btif_media.h" +#include "osi/include/alarm.h" +#include "osi/include/thread.h" + #if (BTA_AV_INCLUDED == TRUE) #include "sbc_encoder.h" #endif @@ -81,7 +85,6 @@ OI_CODEC_SBC_DECODER_CONTEXT context; OI_UINT32 contextData[CODEC_DATA_WORDS(2, SBC_CODEC_FAST_FILTER_BUFFERS)]; OI_INT16 pcmData[15*SBC_MAX_SAMPLES_PER_FRAME*SBC_MAX_CHANNELS]; #endif -#include "thread.h" /***************************************************************************** ** Constants @@ -97,21 +100,13 @@ OI_INT16 pcmData[15*SBC_MAX_SAMPLES_PER_FRAME*SBC_MAX_CHANNELS]; /* BTIF media task gki event definition */ #define BTIF_MEDIA_TASK_CMD TASK_MBOX_0_EVT_MASK -#define BTIF_MEDIA_TASK_DATA TASK_MBOX_1_EVT_MASK #define BTIF_MEDIA_TASK_KILL EVENT_MASK(GKI_SHUTDOWN_EVT) -#define BTIF_MEDIA_AA_TASK_TIMER_ID TIMER_0 -#define BTIF_MEDIA_AV_TASK_TIMER_ID TIMER_1 -#define BTIF_MEDIA_AVK_TASK_TIMER_ID TIMER_2 - #define BTIF_MEDIA_AA_TASK_TIMER TIMER_0_EVT_MASK -#define BTIF_MEDIA_AV_TASK_TIMER TIMER_1_EVT_MASK #define BTIF_MEDIA_AVK_TASK_TIMER TIMER_2_EVT_MASK - #define BTIF_MEDIA_TASK_CMD_MBOX TASK_MBOX_0 /* cmd mailbox */ -#define BTIF_MEDIA_TASK_DATA_MBOX TASK_MBOX_1 /* data mailbox */ /* BTIF media cmd event definition : BTIF_MEDIA_TASK_CMD */ enum @@ -129,8 +124,6 @@ enum BTIF_MEDIA_AUDIO_FEEDING_INIT, BTIF_MEDIA_AUDIO_RECEIVING_INIT, BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE, - BTIF_MEDIA_AUDIO_SINK_START_DECODING, - BTIF_MEDIA_AUDIO_SINK_STOP_DECODING, BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK }; @@ -275,6 +268,8 @@ typedef struct UINT32 sample_rate; UINT8 channel_count; + alarm_t *media_alarm; + alarm_t *decode_alarm; #endif } tBTIF_MEDIA_CB; @@ -295,8 +290,7 @@ static tBTIF_MEDIA_CB btif_media_cb; static int media_task_running = MEDIA_TASK_STATE_OFF; static UINT64 last_frame_us = 0; -fixed_queue_t *btif_media_cmd_msg_queue; -fixed_queue_t *btif_media_data_msg_queue; +static fixed_queue_t *btif_media_cmd_msg_queue; /***************************************************************************** ** Local functions @@ -322,14 +316,12 @@ extern OI_STATUS OI_CODEC_SBC_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context static void btif_media_flush_q(BUFFER_Q *p_q); static void btif_media_task_aa_handle_stop_decoding(void ); static void btif_media_task_aa_rx_flush(void); -static BOOLEAN btif_media_task_stop_decoding_req(void); /***************************************************************************** ** Externs *****************************************************************************/ static void btif_media_task_handle_cmd(BT_HDR *p_msg); -static void btif_media_task_handle_media(BT_HDR*p_msg); /* Handle incoming media packets A2DP SINK streaming*/ #if (BTA_AV_SINK_INCLUDED == TRUE) static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg); @@ -349,9 +341,8 @@ static void btif_media_aa_prep_2_send(UINT8 nb_frame); static void btif_media_task_aa_handle_decoder_reset(BT_HDR *p_msg); static void btif_media_task_aa_handle_clear_track(void); #endif -static void btif_media_task_aa_handle_start_decoding(void ); +static void btif_media_task_aa_handle_start_decoding(void); #endif -BOOLEAN btif_media_task_start_decoding_req(void); BOOLEAN btif_media_task_clear_track(void); static const char *BT_MEDIA_WORKQUEUE_NAME = "bt_media_workqueue"; @@ -395,8 +386,6 @@ const char* dump_media_event(UINT16 event) CASE_RETURN_STR(BTIF_MEDIA_AUDIO_FEEDING_INIT) CASE_RETURN_STR(BTIF_MEDIA_AUDIO_RECEIVING_INIT) CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_CFG_UPDATE) - CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_START_DECODING) - CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_STOP_DECODING) CASE_RETURN_STR(BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK) default: @@ -774,7 +763,6 @@ int btif_a2dp_start_media_task(void) APPL_TRACE_EVENT("## A2DP START MEDIA THREAD ##"); btif_media_cmd_msg_queue = fixed_queue_new(SIZE_MAX); - btif_media_data_msg_queue = fixed_queue_new(SIZE_MAX); /* start a2dp media task */ bt_media_workqueue_thread = thread_new(BT_MEDIA_WORKQUEUE_NAME); @@ -810,13 +798,11 @@ void btif_a2dp_stop_media_task(void) { APPL_TRACE_EVENT("## A2DP STOP MEDIA THREAD ##"); fixed_queue_free(btif_media_cmd_msg_queue, NULL); - fixed_queue_free(btif_media_data_msg_queue, NULL); thread_free(bt_media_workqueue_thread); bt_media_workqueue_thread = NULL; btif_media_cmd_msg_queue = NULL; - btif_media_data_msg_queue = NULL; } /***************************************************************************** @@ -903,7 +889,7 @@ void btif_a2dp_on_idle(void) { btif_media_cb.rx_flush = TRUE; btif_media_task_aa_rx_flush_req(); - btif_media_task_stop_decoding_req(); + btif_media_task_aa_handle_stop_decoding(); btif_media_task_clear_track(); APPL_TRACE_DEBUG("Stopped BT track"); } @@ -953,63 +939,6 @@ BOOLEAN btif_media_task_clear_track(void) GKI_send_event(BT_MEDIA_TASK, (UINT16)EVENT_MASK(BTIF_MEDIA_TASK_CMD_MBOX)); return TRUE; } -/******************************************************************************* - ** - ** Function btif_media_task_stop_decoding_req - ** - ** Description - ** - ** Returns TRUE is success - ** - *******************************************************************************/ -BOOLEAN btif_media_task_stop_decoding_req(void) -{ - BT_HDR *p_buf; - - if (!btif_media_cb.is_rx_timer) - return TRUE; /* if timer is not running no need to send message */ - - if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) - { - return FALSE; - } - - p_buf->event = BTIF_MEDIA_AUDIO_SINK_STOP_DECODING; - - fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf); - // Signal the target thread work is ready. - GKI_send_event(BT_MEDIA_TASK, (UINT16)EVENT_MASK(BTIF_MEDIA_TASK_CMD_MBOX)); - return TRUE; -} - -/******************************************************************************* - ** - ** Function btif_media_task_start_decoding_req - ** - ** Description - ** - ** Returns TRUE is success - ** - *******************************************************************************/ -BOOLEAN btif_media_task_start_decoding_req(void) -{ - BT_HDR *p_buf; - - if(btif_media_cb.is_rx_timer) - return FALSE; /* if timer is already running no need to send message */ - - if (NULL == (p_buf = GKI_getbuf(sizeof(BT_HDR)))) - { - return FALSE; - } - - p_buf->event = BTIF_MEDIA_AUDIO_SINK_START_DECODING; - - fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf); - // Signal the target thread work is ready. - GKI_send_event(BT_MEDIA_TASK, (UINT16)EVENT_MASK(BTIF_MEDIA_TASK_CMD_MBOX)); - return TRUE; -} /***************************************************************************** ** @@ -1132,7 +1061,7 @@ void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av) { btif_media_cb.rx_flush = TRUE; btif_media_task_aa_rx_flush_req(); - btif_media_task_stop_decoding_req(); + btif_media_task_aa_handle_stop_decoding(); UIPC_Close(UIPC_CH_ID_AV_AUDIO); btif_media_cb.data_channel_open = FALSE; return; @@ -1178,7 +1107,7 @@ void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av) { btif_media_cb.rx_flush = TRUE; btif_media_task_aa_rx_flush_req(); - btif_media_task_stop_decoding_req(); + btif_media_task_aa_handle_stop_decoding(); return; } @@ -1397,11 +1326,6 @@ void btif_media_thread(UNUSED_ATTR void *context) btif_media_task_handle_cmd(p_msg); } - /* Process all messages in the queue */ - while ((p_msg = (BT_HDR *)fixed_queue_try_dequeue(btif_media_data_msg_queue)) != NULL) { - btif_media_task_handle_media(p_msg); - } - if (event & BTIF_MEDIA_AA_TASK_TIMER) { /* advance audio timer expiration */ @@ -1525,17 +1449,11 @@ static void btif_media_task_handle_cmd(BT_HDR *p_msg) btif_media_task_aa_handle_decoder_reset(p_msg); #endif break; - case BTIF_MEDIA_AUDIO_SINK_START_DECODING: - btif_media_task_aa_handle_start_decoding(); - break; case BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK: #if (BTA_AV_SINK_INCLUDED == TRUE) btif_media_task_aa_handle_clear_track(); #endif break; - case BTIF_MEDIA_AUDIO_SINK_STOP_DECODING: - btif_media_task_aa_handle_stop_decoding(); - break; case BTIF_MEDIA_FLUSH_AA_RX: btif_media_task_aa_rx_flush(); break; @@ -1601,20 +1519,6 @@ static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg) } #endif -/******************************************************************************* - ** - ** Function btif_media_task_handle_media - ** - ** Description - ** - ** Returns void - ** - *******************************************************************************/ -static void btif_media_task_handle_media(BT_HDR*p_msg) -{ - APPL_TRACE_DEBUG(" btif_media_task_handle_media "); - GKI_freebuf(p_msg); -} #if (BTA_AV_INCLUDED == TRUE) /******************************************************************************* ** @@ -2190,36 +2094,27 @@ void btif_a2dp_set_peer_sep(UINT8 sep) { btif_media_cb.peer_sep = sep; } -/******************************************************************************* - ** - ** Function btif_media_task_aa_handle_stop_decoding - ** - ** Description - ** - ** Returns void - ** - *******************************************************************************/ -static void btif_media_task_aa_handle_stop_decoding(void ) -{ - btif_media_cb.is_rx_timer = FALSE; - GKI_stop_timer(BTIF_MEDIA_AVK_TASK_TIMER_ID); +static void btif_decode_alarm_cb(UNUSED_ATTR void *context) { + GKI_send_event(BT_MEDIA_TASK, BTIF_MEDIA_AVK_TASK_TIMER); + alarm_set(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK, btif_decode_alarm_cb, NULL); } -/******************************************************************************* - ** - ** Function btif_media_task_aa_handle_start_decoding - ** - ** Description - ** - ** Returns void - ** - *******************************************************************************/ -static void btif_media_task_aa_handle_start_decoding(void ) -{ - if(btif_media_cb.is_rx_timer == TRUE) - return; - btif_media_cb.is_rx_timer = TRUE; - GKI_start_timer(BTIF_MEDIA_AVK_TASK_TIMER_ID, GKI_MS_TO_TICKS(BTIF_SINK_MEDIA_TIME_TICK), TRUE); +static void btif_media_task_aa_handle_stop_decoding(void) { + alarm_cancel(btif_media_cb.decode_alarm); + btif_media_cb.decode_alarm = NULL; +} + +static void btif_media_task_aa_handle_start_decoding(void) { + if (btif_media_cb.decode_alarm) + return; + + btif_media_cb.decode_alarm = alarm_new(); + if (!btif_media_cb.decode_alarm) { + LOG_ERROR("%s unable to allocate decode alarm.", __func__); + return; + } + + alarm_set(btif_media_cb.decode_alarm, BTIF_SINK_MEDIA_TIME_TICK, btif_decode_alarm_cb, NULL); } #if (BTA_AV_SINK_INCLUDED == TRUE) @@ -2397,6 +2292,12 @@ static void btif_media_task_feeding_state_reset(void) (int)btif_media_cb.media_feeding_state.pcm.bytes_per_tick); } } + +static void btif_media_task_alarm_cb(UNUSED_ATTR void *context) { + GKI_send_event(BT_MEDIA_TASK, BTIF_MEDIA_AA_TASK_TIMER); + alarm_set(btif_media_cb.media_alarm, BTIF_MEDIA_TIME_TICK, btif_media_task_alarm_cb, NULL); +} + /******************************************************************************* ** ** Function btif_media_task_aa_start_tx @@ -2420,10 +2321,17 @@ static void btif_media_task_aa_start_tx(void) /* Reset the media feeding state */ btif_media_task_feeding_state_reset(); - APPL_TRACE_EVENT("starting timer %d ticks (%d)", - GKI_MS_TO_TICKS(BTIF_MEDIA_TIME_TICK), TICKS_PER_SEC); + APPL_TRACE_EVENT("starting timer %dms", BTIF_MEDIA_TIME_TICK); + + assert(btif_media_cb.media_alarm == NULL); + + btif_media_cb.media_alarm = alarm_new(); + if (!btif_media_cb.media_alarm) { + LOG_ERROR("%s unable to allocate media alarm.", __func__); + return; + } - GKI_start_timer(BTIF_MEDIA_AA_TASK_TIMER_ID, GKI_MS_TO_TICKS(BTIF_MEDIA_TIME_TICK), TRUE); + alarm_set(btif_media_cb.media_alarm, BTIF_MEDIA_TIME_TICK, btif_media_task_alarm_cb, NULL); } /******************************************************************************* @@ -2440,7 +2348,8 @@ static void btif_media_task_aa_stop_tx(void) APPL_TRACE_DEBUG("btif_media_task_aa_stop_tx is timer: %d", btif_media_cb.is_tx_timer); /* Stop the timer first */ - GKI_stop_timer(BTIF_MEDIA_AA_TASK_TIMER_ID); + alarm_free(btif_media_cb.media_alarm); + btif_media_cb.media_alarm = NULL; btif_media_cb.is_tx_timer = FALSE; UIPC_Close(UIPC_CH_ID_AV_AUDIO); @@ -2545,7 +2454,7 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt) if(GKI_queue_length(&btif_media_cb.RxSbcQ) == MAX_A2DP_DELAYED_START_FRAME_COUNT) { BTIF_TRACE_DEBUG(" Initiate Decoding "); - btif_media_task_start_decoding_req(); + btif_media_task_aa_handle_start_decoding(); } } else diff --git a/gki/Android.mk b/gki/Android.mk index 9c2cfd064..3268540dd 100644 --- a/gki/Android.mk +++ b/gki/Android.mk @@ -23,7 +23,6 @@ endif LOCAL_PRELINK_MODULE := false LOCAL_SRC_FILES := \ ./common/gki_buffer.c \ - ./common/gki_time.c \ ./ulinux/gki_ulinux.c LOCAL_MODULE := libbt-brcm_gki diff --git a/gki/common/gki.h b/gki/common/gki.h index 7e719c113..092cd121e 100644 --- a/gki/common/gki.h +++ b/gki/common/gki.h @@ -55,16 +55,8 @@ static const char GKI_MODULE[] = "gki_module"; #define TASK_MBOX_2_EVT_MASK 0x0004 #define TASK_MBOX_3_EVT_MASK 0x0008 - -#define TIMER_0 0 -#define TIMER_1 1 -#define TIMER_2 2 -#define TIMER_3 3 - #define TIMER_0_EVT_MASK 0x0010 -#define TIMER_1_EVT_MASK 0x0020 #define TIMER_2_EVT_MASK 0x0040 -#define TIMER_3_EVT_MASK 0x0080 #define APPL_EVT_0 8 #define APPL_EVT_1 9 @@ -167,12 +159,6 @@ UINT16 GKI_get_pool_bufsize (UINT8); /* Timer management */ void GKI_delay(UINT32); -UINT32 GKI_get_tick_count(void); -INT32 GKI_ready_to_sleep (void); -void GKI_start_timer(UINT8, INT32, BOOLEAN); -void GKI_stop_timer (UINT8); -void GKI_timer_update(INT32); -UINT32 GKI_get_remaining_ticks (TIMER_LIST_Q *, TIMER_LIST_ENT *); UINT16 GKI_wait(UINT16, UINT32); extern INT32 GKI_timer_ticks_getinitial(const TIMER_LIST_ENT *tle); diff --git a/gki/common/gki_common.h b/gki/common/gki_common.h index 90ea68649..233d061e7 100644 --- a/gki/common/gki_common.h +++ b/gki/common/gki_common.h @@ -77,19 +77,6 @@ typedef struct UINT16 OSWaitEvt[GKI_MAX_TASKS]; /* events that have to be processed by the task */ UINT16 OSWaitForEvt[GKI_MAX_TASKS]; /* events the task is waiting for*/ - UINT32 OSTicks; /* system ticks from start */ - - /* Timer related variables - */ - INT32 OSTicksTilExp; /* Number of ticks till next timer expires */ - INT32 OSNumOrigTicks; /* Number of ticks between last timer expiration to the next one */ - - INT32 OSWaitTmr [GKI_MAX_TASKS]; /* ticks the task has to wait, for specific events */ - - /* Only take up space timers used in the system (GKI_NUM_TIMERS defined in target.h) */ - INT32 OSTaskTmr[GKI_MAX_TASKS][GKI_NUM_TIMERS]; - INT32 OSTaskTmrR[GKI_MAX_TASKS][GKI_NUM_TIMERS]; - /* Define the buffer pool management variables */ FREE_QUEUE_T freeq[GKI_NUM_TOTAL_BUF_POOLS]; @@ -112,6 +99,5 @@ typedef struct */ BOOLEAN gki_chk_buf_damage(void *); void gki_buffer_init (void); -void gki_timers_init(void); void gki_adjust_timer_count (INT32); void gki_dealloc_free_queue(void); diff --git a/gki/common/gki_time.c b/gki/common/gki_time.c deleted file mode 100644 index c95e28f7c..000000000 --- a/gki/common/gki_time.c +++ /dev/null @@ -1,394 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 1999-2012 Broadcom Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -#include <assert.h> -#include "gki_int.h" -#include "osi/include/log.h" - -#define GKI_NO_NEW_TMRS_STARTED (0x7fffffffL) /* Largest signed positive timer count */ - -// Used for controlling alarms from AlarmService. -extern void alarm_service_reschedule(void); - -/******************************************************************************* -** -** Function gki_timers_init -** -** Description This internal function is called once at startup to initialize -** all the timer structures. -** -** Returns void -** -*******************************************************************************/ -void gki_timers_init(void) -{ - UINT8 tt; - - gki_cb.com.OSTicksTilExp = 0; /* Remaining time (of OSTimeCurTimeout) before next timer expires */ - gki_cb.com.OSNumOrigTicks = 0; - - for (tt = 0; tt < GKI_MAX_TASKS; tt++) - { - gki_cb.com.OSWaitTmr [tt] = 0; - - for (int i = 0; i < GKI_NUM_TIMERS; ++i) { - gki_cb.com.OSTaskTmr[tt][i] = 0; - gki_cb.com.OSTaskTmrR[tt][i] = 0; - } - } - - return; -} - -/******************************************************************************* -** -** Function gki_timers_is_timer_running -** -** Description This internal function is called to test if any gki timer are running -** -** -** Returns TRUE if at least one time is running in the system, FALSE else. -** -*******************************************************************************/ -BOOLEAN gki_timers_is_timer_running(void) { - for (int i = 0; i < GKI_MAX_TASKS; ++i) - for (int j = 0; j < GKI_NUM_TIMERS; ++j) - if (gki_cb.com.OSTaskTmr[i][j]) - return true; - return false; -} - -/******************************************************************************* -** -** Function GKI_get_tick_count -** -** Description This function returns the current system ticks -** -** Returns The current number of system ticks -** -*******************************************************************************/ -UINT32 GKI_get_tick_count(void) -{ - return gki_cb.com.OSTicks; -} - - -/******************************************************************************* -** -** Function GKI_ready_to_sleep -** -** Description This function returns the number of system ticks until the -** next timer will expire. It is typically called by a power -** savings manager to find out how long it can have the system -** sleep before it needs to service the next entry. -** -** Parameters: None -** -** Returns Number of ticks til the next timer expires -** Note: the value is a signed value. This value should be -** compared to x > 0, to avoid misinterpreting negative tick -** values. -** -*******************************************************************************/ -INT32 GKI_ready_to_sleep (void) -{ - return (gki_cb.com.OSTicksTilExp); -} - - -/******************************************************************************* -** -** Function GKI_start_timer -** -** Description An application can call this function to start one of -** it's four general purpose timers. Any of the four timers -** can be 1-shot or continuous. If a timer is already running, -** it will be reset to the new parameters. -** -** Parameters tnum - (input) timer number to be started (TIMER_0, -** TIMER_1, TIMER_2, or TIMER_3) -** ticks - (input) the number of system ticks til the -** timer expires. -** is_continuous - (input) TRUE if timer restarts automatically, -** else FALSE if it is a 'one-shot'. -** -** Returns void -** -*******************************************************************************/ -void GKI_start_timer (UINT8 tnum, INT32 ticks, BOOLEAN is_continuous) -{ - INT32 reload; - INT32 orig_ticks; - UINT8 task_id = GKI_get_taskid(); - - if (ticks <= 0) - ticks = 1; - - orig_ticks = ticks; /* save the ticks in case adjustment is necessary */ - - - /* If continuous timer, set reload, else set it to 0 */ - if (is_continuous) - reload = ticks; - else - reload = 0; - - GKI_disable(); - - /* Add the time since the last task timer update. - ** Note that this works when no timers are active since - ** both OSNumOrigTicks and OSTicksTilExp are 0. - */ - if (INT32_MAX - (gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp) > ticks) - { - ticks += gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp; - } - else - ticks = INT32_MAX; - - assert(tnum < GKI_NUM_TIMERS); - - gki_cb.com.OSTaskTmr[task_id][tnum] = ticks; - gki_cb.com.OSTaskTmrR[task_id][tnum] = reload; - - gki_adjust_timer_count (orig_ticks); - GKI_enable(); -} - -/******************************************************************************* -** -** Function GKI_stop_timer -** -** Description An application can call this function to stop one of -** it's four general purpose timers. There is no harm in -** stopping a timer that is already stopped. -** -** Parameters tnum - (input) timer number to be started (TIMER_0, -** TIMER_1, TIMER_2, or TIMER_3) -** Returns void -** -*******************************************************************************/ -void GKI_stop_timer(UINT8 tnum) { - assert(tnum < GKI_NUM_TIMERS); - - UINT8 task_id = GKI_get_taskid(); - - gki_cb.com.OSTaskTmr[task_id][tnum] = 0; - gki_cb.com.OSTaskTmrR[task_id][tnum] = 0; -} - - -/******************************************************************************* -** -** Function GKI_timer_update -** -** Description This function is called by an OS to drive the GKI's timers. -** It is typically called at every system tick to -** update the timers for all tasks, and check for timeouts. -** -** Note: It has been designed to also allow for variable tick updates -** so that systems with strict power savings requirements can -** have the update occur at variable intervals. -** -** Parameters: ticks_since_last_update - (input) This is the number of TICKS that have -** occurred since the last time GKI_timer_update was called. -** -** Returns void -** -*******************************************************************************/ -void GKI_timer_update (INT32 ticks_since_last_update) -{ - UINT8 task_id; - long next_expiration; /* Holds the next soonest expiration time after this update */ - - /* Increment the number of ticks used for time stamps */ - gki_cb.com.OSTicks += ticks_since_last_update; - - /* If any timers are running in any tasks, decrement the remaining time til - * the timer updates need to take place (next expiration occurs) - */ - gki_cb.com.OSTicksTilExp -= ticks_since_last_update; - - /* Don't allow timer interrupt nesting */ - if (gki_cb.com.timer_nesting) - return; - - gki_cb.com.timer_nesting = 1; - - /* No need to update the ticks if no timeout has occurred */ - if (gki_cb.com.OSTicksTilExp > 0) - { - // When using alarms from AlarmService we should - // always have work to be done here. - LOG_ERROR("%s no work to be done when expected work", __func__); - gki_cb.com.timer_nesting = 0; - return; - } - - next_expiration = GKI_NO_NEW_TMRS_STARTED; - - /* If here then gki_cb.com.OSTicksTilExp <= 0. If negative, then increase gki_cb.com.OSNumOrigTicks - to account for the difference so timer updates below are decremented by the full number - of ticks. gki_cb.com.OSNumOrigTicks is reset at the bottom of this function so changing this - value only affects the timer updates below - */ - gki_cb.com.OSNumOrigTicks -= gki_cb.com.OSTicksTilExp; - - /* Protect this section because if a GKI_timer_stop happens between: - * - gki_cb.com.OSTaskTmr0[task_id] -= gki_cb.com.OSNumOrigTicks; - * - gki_cb.com.OSTaskTmr0[task_id] = gki_cb.com.OSTaskTmr0R[task_id]; - * then the timer may appear stopped while it is about to be reloaded. - */ - GKI_disable(); - - /* Check for OS Task Timers */ - for (task_id = 0; task_id < GKI_MAX_TASKS; task_id++) - { - if (gki_cb.com.OSWaitTmr[task_id] > 0) /* If timer is running */ - { - gki_cb.com.OSWaitTmr[task_id] -= gki_cb.com.OSNumOrigTicks; - if (gki_cb.com.OSWaitTmr[task_id] <= 0) - { - /* Timer Expired */ - gki_cb.com.task_state[task_id] = TASK_READY; - } - } - - for (int i = 0; i < GKI_NUM_TIMERS; ++i) { - /* If any timer is running, decrement */ - if (gki_cb.com.OSTaskTmr[task_id][i] > 0) - { - gki_cb.com.OSTaskTmr[task_id][i] -= gki_cb.com.OSNumOrigTicks; - - if (gki_cb.com.OSTaskTmr[task_id][i] <= 0) - { - /* Reload timer and set timer expired event mask */ - gki_cb.com.OSTaskTmr[task_id][i] = gki_cb.com.OSTaskTmrR[task_id][i]; - - // (1 << (i+4)) evaluates to the same value as TIMER_x_EVT_MASK. - GKI_send_event(task_id, (1 << (i+4))); - } - } - - /* Check to see if this timer is the next one to expire */ - if (gki_cb.com.OSTaskTmr[task_id][i] > 0 && gki_cb.com.OSTaskTmr[task_id][i] < next_expiration) - next_expiration = gki_cb.com.OSTaskTmr[task_id][i]; - } - } - /* Set the next timer experation value if there is one to start */ - if (next_expiration < GKI_NO_NEW_TMRS_STARTED) - { - gki_cb.com.OSTicksTilExp = gki_cb.com.OSNumOrigTicks = next_expiration; - } - else - { - gki_cb.com.OSTicksTilExp = gki_cb.com.OSNumOrigTicks = 0; - } - - // Set alarm service for next alarm. - alarm_service_reschedule(); - - GKI_enable(); - - gki_cb.com.timer_nesting = 0; - - return; -} - -/* Returns the initial number of ticks for this timer entry. */ -INT32 GKI_timer_ticks_getinitial(const TIMER_LIST_ENT *tle) { - assert(tle != NULL); - return tle->ticks_initial; -} - -/******************************************************************************* -** -** Function GKI_get_remaining_ticks -** -** Description This function is called by an application to get remaining -** ticks to expire -** -** Parameters p_timer_listq - (input) pointer to the timer list queue object -** p_target_tle - (input) pointer to a timer list queue entry -** -** Returns 0 if timer is not used or timer is not in the list -** remaining ticks if success -** -*******************************************************************************/ -UINT32 GKI_get_remaining_ticks (TIMER_LIST_Q *p_timer_listq, TIMER_LIST_ENT *p_target_tle) -{ - TIMER_LIST_ENT *p_tle; - UINT32 rem_ticks = 0; - - if (p_target_tle->in_use) - { - p_tle = p_timer_listq->p_first; - - /* adding up all of ticks in previous entries */ - while ((p_tle)&&(p_tle != p_target_tle)) - { - rem_ticks += p_tle->ticks; - p_tle = p_tle->p_next; - } - - /* if found target entry */ - if (p_tle == p_target_tle) - { - rem_ticks += p_tle->ticks; - } - else - { - return(0); - } - } - - return (rem_ticks); -} - -/******************************************************************************* -** -** Function gki_adjust_timer_count -** -** Description This function is called whenever a new timer or GKI_wait occurs -** to adjust (if necessary) the current time til the first expiration. -** This only needs to make an adjustment if the new timer (in ticks) is -** less than the number of ticks remaining on the current timer. -** -** Parameters: ticks - (input) number of system ticks of the new timer entry -** -** NOTE: This routine MUST be called while interrupts are disabled to -** avoid updates while adjusting the timer variables. -** -** Returns void -** -*******************************************************************************/ -void gki_adjust_timer_count (INT32 ticks) -{ - if (ticks > 0) - { - /* See if the new timer expires before the current first expiration */ - if (gki_cb.com.OSNumOrigTicks == 0 || (ticks < gki_cb.com.OSTicksTilExp && gki_cb.com.OSTicksTilExp > 0)) - { - gki_cb.com.OSNumOrigTicks = (gki_cb.com.OSNumOrigTicks - gki_cb.com.OSTicksTilExp) + ticks; - gki_cb.com.OSTicksTilExp = ticks; - alarm_service_reschedule(); - } - } - - return; -} diff --git a/gki/ulinux/gki_ulinux.c b/gki/ulinux/gki_ulinux.c index aedc0a7d1..74ddd59a4 100644 --- a/gki/ulinux/gki_ulinux.c +++ b/gki/ulinux/gki_ulinux.c @@ -69,28 +69,6 @@ typedef struct static gki_pthread_info_t gki_pthread_info[GKI_MAX_TASKS]; -// Only a single alarm is used to wake bluedroid. -// NOTE: Must be manipulated with the GKI_disable() lock held. -static alarm_t *alarm_timer; -static int32_t alarm_ticks; - -static void bt_alarm_cb(UNUSED_ATTR void *data) { - GKI_timer_update(alarm_ticks); -} - -// Schedules the next timer with the alarm timer module. -// NOTE: Must be called with GKI_disable() lock held. -void alarm_service_reschedule() { - alarm_ticks = GKI_ready_to_sleep(); - - assert(alarm_ticks >= 0); - - if (alarm_ticks > 0) - alarm_set(alarm_timer, GKI_TICKS_TO_MS(alarm_ticks), bt_alarm_cb, NULL); - else - LOG_VERBOSE("%s no more alarms.", __func__); -} - static future_t *init(void) { pthread_mutexattr_t attr; @@ -99,16 +77,10 @@ static future_t *init(void) memset (&gki_cb, 0, sizeof (gki_cb)); gki_buffer_init(); - gki_timers_init(); - alarm_timer = alarm_new(); - - gki_cb.com.OSTicks = (UINT32) times(0); pthread_mutexattr_init(&attr); -#ifndef __CYGWIN__ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); -#endif p_os = &gki_cb.os; pthread_mutex_init(&p_os->GKI_mutex, &attr); return NULL; @@ -126,14 +98,13 @@ static future_t *init(void) *******************************************************************************/ UINT32 GKI_get_os_tick_count(void) { - return gki_cb.com.OSTicks; + struct timespec timespec; + clock_gettime(CLOCK_BOOTTIME, ×pec); + return (timespec.tv_sec * 1000) + (timespec.tv_nsec / 1000000); } static future_t *clean_up(void) { - alarm_free(alarm_timer); - alarm_timer = NULL; - gki_dealloc_free_queue(); /* Destroy mutex and condition variable objects */ diff --git a/include/gki_target.h b/include/gki_target.h index 860b0ea46..be0eae030 100644 --- a/include/gki_target.h +++ b/include/gki_target.h @@ -46,61 +46,6 @@ /****************************************************************************** ** -** Timer configuration -** -******************************************************************************/ - -/* The number of GKI timers in the software system. */ -#ifndef GKI_NUM_TIMERS -#define GKI_NUM_TIMERS 4 -#endif - -/* A conversion value for translating ticks to calculate GKI timer. */ -#ifndef TICKS_PER_SEC -#define TICKS_PER_SEC 100 -#endif - -/************************************************************************ -** Utility macros converting ticks to time with user define OS ticks per sec -**/ -#ifndef GKI_MS_TO_TICKS -#define GKI_MS_TO_TICKS(x) ((x) / (1000 / TICKS_PER_SEC)) -#endif - -#ifndef GKI_SECS_TO_TICKS -#define GKI_SECS_TO_TICKS(x) ((x) * (TICKS_PER_SEC)) -#endif - -#ifndef GKI_TICKS_TO_MS -#define GKI_TICKS_TO_MS(x) ((x) * 1000 / TICKS_PER_SEC) -#endif - -#ifndef GKI_TICKS_TO_SECS -#define GKI_TICKS_TO_SECS(x) ((x) / TICKS_PER_SEC) -#endif - - - -/* TICK per second from OS (OS dependent change this macro accordingly to various OS) */ -#ifndef OS_TICKS_PER_SEC -#define OS_TICKS_PER_SEC 1000 -#endif - -/************************************************************************ -** Utility macros converting ticks to time with user define OS ticks per sec -**/ - -#ifndef GKI_OS_TICKS_TO_MS -#define GKI_OS_TICKS_TO_MS(x) ((x) * 1000 / OS_TICKS_PER_SEC) -#endif - - -#ifndef GKI_OS_TICKS_TO_SECS -#define GKI_OS_TICKS_TO_SECS(x) ((x) / OS_TICKS_PER_SEC)) -#endif - -/****************************************************************************** -** ** Buffer configuration ** ******************************************************************************/ diff --git a/main/Android.mk b/main/Android.mk index 70058ca34..ffb2fefaa 100644 --- a/main/Android.mk +++ b/main/Android.mk @@ -127,13 +127,12 @@ LOCAL_SHARED_LIBRARIES := \ libpower \ LOCAL_STATIC_LIBRARIES := \ - libbt-brcm_gki \ libbt-brcm_bta \ + libbt-brcm_gki \ libbt-brcm_stack \ libbtdevice \ libbt-hci \ libbt-utils \ - libbt-qcom_sbc_decoder \ libbtcore \ libosi \ libtinyxml2 \ diff --git a/stack/btm/btm_inq.c b/stack/btm/btm_inq.c index 629423273..7d544d8e5 100644 --- a/stack/btm/btm_inq.c +++ b/stack/btm/btm_inq.c @@ -1988,7 +1988,7 @@ void btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode) p_cur->dev_class[2] = dc[2]; p_cur->clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID; - p_i->time_of_resp = GKI_get_tick_count (); + p_i->time_of_resp = GKI_get_os_tick_count(); if (p_i->inq_count != p_inq->inq_counter) p_inq->inq_cmpl_info.num_resp++; /* A new response was found */ diff --git a/stack/btm/btm_sec.c b/stack/btm/btm_sec.c index 83d1679e9..029eb39b2 100644 --- a/stack/btm/btm_sec.c +++ b/stack/btm/btm_sec.c @@ -44,7 +44,7 @@ #include "gatt_int.h" #endif -#define BTM_SEC_MAX_COLLISION_DELAY (GKI_SECS_TO_TICKS(5)) +#define BTM_SEC_MAX_COLLISION_DELAY (5000) #ifdef APPL_AUTH_WRITE_EXCEPTION BOOLEAN (APPL_AUTH_WRITE_EXCEPTION)(BD_ADDR bd_addr); @@ -3562,9 +3562,9 @@ static void btm_sec_auth_collision (UINT16 handle) tBTM_SEC_DEV_REC *p_dev_rec; if (!btm_cb.collision_start_time) - btm_cb.collision_start_time = GKI_get_tick_count (); + btm_cb.collision_start_time = GKI_get_os_tick_count(); - if ((GKI_get_tick_count () - btm_cb.collision_start_time) < btm_cb.max_collision_delay) + if ((GKI_get_os_tick_count() - btm_cb.collision_start_time) < btm_cb.max_collision_delay) { if (handle == BTM_SEC_INVALID_HANDLE) { diff --git a/stack/btu/btu_task.c b/stack/btu/btu_task.c index 99d73b970..6cef4fb7c 100644 --- a/stack/btu/btu_task.c +++ b/stack/btu/btu_task.c @@ -447,7 +447,6 @@ void btu_general_alarm_cb(void *data) { TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; fixed_queue_enqueue(btu_general_alarm_queue, p_tle); - GKI_send_event(BTU_TASK, TIMER_0_EVT_MASK); } void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) { @@ -476,20 +475,6 @@ void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) { /******************************************************************************* ** -** Function btu_remaining_time -** -** Description Return amount of time to expire -** -** Returns time in second -** -*******************************************************************************/ -UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle) -{ - return(GKI_get_remaining_ticks (&btu_cb.timer_queue, p_tle)); -} - -/******************************************************************************* -** ** Function btu_stop_timer ** ** Description Stop a timer. @@ -542,7 +527,6 @@ static void btu_l2cap_alarm_cb(void *data) { TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; fixed_queue_enqueue(btu_l2cap_alarm_queue, p_tle); - GKI_send_event(BTU_TASK, TIMER_2_EVT_MASK); } void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks) { @@ -602,7 +586,6 @@ void btu_oneshot_alarm_cb(void *data) { btu_stop_timer_oneshot(p_tle); fixed_queue_enqueue(btu_oneshot_alarm_queue, p_tle); - GKI_send_event(BTU_TASK, TIMER_3_EVT_MASK); } /* diff --git a/stack/include/btu.h b/stack/include/btu.h index 5449c1a78..2da0035d7 100644 --- a/stack/include/btu.h +++ b/stack/include/btu.h @@ -224,10 +224,6 @@ typedef struct tBTU_TIMER_REG timer_reg[BTU_MAX_REG_TIMER]; tBTU_EVENT_REG event_reg[BTU_MAX_REG_EVENT]; - TIMER_LIST_Q quick_timer_queue; /* Timer queue for transport level (100/10 msec)*/ - TIMER_LIST_Q timer_queue; /* Timer queue for normal BTU task (1 second) */ - TIMER_LIST_Q timer_queue_oneshot; /* Timer queue for oneshot BTU tasks */ - BOOLEAN reset_complete; /* TRUE after first ack from device received */ UINT8 trace_level; /* Trace level for HCI layer */ } tBTU_CB; @@ -253,16 +249,13 @@ extern void btu_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout) extern void btu_stop_timer (TIMER_LIST_ENT *p_tle); extern void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); extern void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle); -extern UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle); -extern UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle); extern void btu_uipc_rx_cback(BT_HDR *p_msg); /* ** Quick Timer */ #if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0) -#define QUICK_TIMER_TICKS (GKI_SECS_TO_TICKS (1)/QUICK_TIMER_TICKS_PER_SEC) extern void btu_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); extern void btu_stop_quick_timer (TIMER_LIST_ENT *p_tle); extern void btu_process_quick_timer_evt (void); diff --git a/stack/l2cap/l2c_fcr.c b/stack/l2cap/l2c_fcr.c index 1dbcbeb54..ec9a4ef88 100644 --- a/stack/l2cap/l2c_fcr.c +++ b/stack/l2cap/l2c_fcr.c @@ -243,7 +243,6 @@ void l2c_fcr_cleanup (tL2C_CCB *p_ccb) UINT16 i; UINT32 throughput_avg, ack_delay_avg, ack_q_count_avg; - dur = GKI_OS_TICKS_TO_MS(dur); BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, "--- L2CAP ERTM Stats for CID: 0x%04x Duration: %08ums", p_ccb->local_cid, dur); BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, diff --git a/stack/rfcomm/rfc_l2cap_if.c b/stack/rfcomm/rfc_l2cap_if.c index 9c11d060a..3207a0345 100644 --- a/stack/rfcomm/rfc_l2cap_if.c +++ b/stack/rfcomm/rfc_l2cap_if.c @@ -105,7 +105,7 @@ void RFCOMM_ConnectInd (BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id) RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectInd start timer for collision, initiator's LCID(0x%x), acceptor's LCID(0x%x)", p_mcb->lcid, p_mcb->pending_lcid); - rfc_timer_start(p_mcb, (UINT16)(GKI_get_tick_count()%10 + 2)); + rfc_timer_start(p_mcb, (UINT16)(GKI_get_os_tick_count()%10 + 2)); return; } else |