From cd7896c5c4bffa5a6f9a414177ea0038d6172964 Mon Sep 17 00:00:00 2001 From: Dmitry Grinberg Date: Wed, 21 May 2014 16:27:50 -0700 Subject: [PATCH] add wakelock control callback Change-Id: Iffa8f33767a037fceb4757cdff07f25f30acf453 --- btif/src/bluetooth.c | 3 +++ gki/ulinux/gki_ulinux.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c index 44644de2d..f6c2f4856 100755 --- a/btif/src/bluetooth.c +++ b/btif/src/bluetooth.c @@ -68,6 +68,8 @@ bt_callbacks_t *bt_hal_cbacks = NULL; ** Externs ************************************************************************************/ +extern bt_wakelock_callback config_wakelock_callback; + /* list all extended interfaces here */ /* handsfree profile */ @@ -119,6 +121,7 @@ static int init(bt_callbacks_t* callbacks ) /* store reference to user callbacks */ bt_hal_cbacks = callbacks; + config_wakelock_callback = callbacks->bt_wakelock_cb; /* add checks for individual callbacks ? */ diff --git a/gki/ulinux/gki_ulinux.c b/gki/ulinux/gki_ulinux.c index d03eb05d1..a66a32f9d 100755 --- a/gki/ulinux/gki_ulinux.c +++ b/gki/ulinux/gki_ulinux.c @@ -29,6 +29,7 @@ #include #include #include +#include #include /* must be 1st header defined */ #include @@ -74,8 +75,6 @@ #define UNLOCK(m) pthread_mutex_unlock(&m) #define INIT(m) pthread_mutex_init(&m, NULL) -#define WAKE_LOCK_ID "brcm_btld" -#define PARTIAL_WAKE_LOCK 1 #if GKI_DYNAMIC_MEMORY == FALSE tGKI_CB gki_cb; @@ -113,6 +112,7 @@ typedef struct int g_GkiTimerWakeLockOn = 0; gki_pthread_info_t gki_pthread_info[GKI_MAX_TASKS]; +bt_wakelock_callback config_wakelock_callback = NULL; /***************************************************************************** ** Static functions @@ -122,13 +122,33 @@ gki_pthread_info_t gki_pthread_info[GKI_MAX_TASKS]; ** Externs ******************************************************************************/ -extern int acquire_wake_lock(int lock, const char* id); -extern int release_wake_lock(const char* id); + /***************************************************************************** ** Functions ******************************************************************************/ +/* send a given byte into the wakelock pipe */ +static void wakelock_op_gki(unsigned char op) +{ + if (!config_wakelock_callback) + GKI_ERROR_LOG("Cannot perform wakelock operation with no callback\n"); + else + config_wakelock_callback(op); +} + +/* release a wakelock by sending a zero down the pipe */ +static void release_wake_lock_gki(void) +{ + wakelock_op_gki(0); +} + +/* acquire a wakelock by sending a one down the pipe */ +static void acquire_wake_lock_gki(void) +{ + wakelock_op_gki(1); +} + /***************************************************************************** ** @@ -527,8 +547,8 @@ void GKI_shutdown(void) #endif if (g_GkiTimerWakeLockOn) { - GKI_TRACE("GKI_shutdown : release_wake_lock(brcm_btld)"); - release_wake_lock(WAKE_LOCK_ID); + GKI_TRACE("GKI_shutdown : release_wake_lock_gki()"); + release_wake_lock_gki(); g_GkiTimerWakeLockOn = 0; } } @@ -569,14 +589,14 @@ void gki_system_tick_start_stop_cback(BOOLEAN start) GKI_TIMER_TRACE(">>> STOP GKI_timer_update(), wake_lock_count:%d", --wake_lock_count); - release_wake_lock(WAKE_LOCK_ID); + release_wake_lock_gki(); g_GkiTimerWakeLockOn = 0; } } else { /* restart GKI_timer_update() loop */ - acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); + acquire_wake_lock_gki(); g_GkiTimerWakeLockOn = 1; *p_run_cond = GKI_TIMER_TICK_RUN_COND; -- 2.11.0