diff --git a/components/bt/bluedroid/btc/core/btc_alarm.c b/components/bt/bluedroid/btc/core/btc_alarm.c new file mode 100644 index 000000000..15587d674 --- /dev/null +++ b/components/bt/bluedroid/btc/core/btc_alarm.c @@ -0,0 +1,27 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// 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 "btc_task.h" +#include "btc_alarm.h" + +void btc_alarm_handler(btc_msg_t *msg) +{ + btc_alarm_args_t *arg = (btc_alarm_args_t *)msg->arg; + + LOG_DEBUG("%s act %d\n", __FUNCTION__, msg->act); + + if (arg->cb) { + arg->cb(arg->cb_data); + } +} diff --git a/components/bt/bluedroid/btc/core/btc_task.c b/components/bt/bluedroid/btc/core/btc_task.c index d576fdd76..e267f0936 100644 --- a/components/bt/bluedroid/btc/core/btc_task.c +++ b/components/bt/bluedroid/btc/core/btc_task.c @@ -26,6 +26,7 @@ #include "btc_gap_ble.h" #include "btc_blufi_prf.h" #include "btc_dm.h" +#include "btc_alarm.h" #include "bta_gatt_api.h" #if CONFIG_CLASSIC_BT_ENABLED #include "btc_gap_bt.h" @@ -48,6 +49,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { [BTC_PID_SPPLIKE] = {NULL, NULL}, [BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler }, [BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler }, + [BTC_PID_ALARM] = {btc_alarm_handler, NULL }, #if CONFIG_CLASSIC_BT_ENABLED [BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, NULL }, [BTC_PID_PRF_QUE] = {btc_profile_queue_handler, NULL }, diff --git a/components/bt/bluedroid/btc/include/btc_alarm.h b/components/bt/bluedroid/btc/include/btc_alarm.h new file mode 100644 index 000000000..ca9640a3f --- /dev/null +++ b/components/bt/bluedroid/btc/include/btc_alarm.h @@ -0,0 +1,30 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// 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. + + +#ifndef __BTC_ALARM_H__ +#define __BTC_ALARM_H__ + +#include +#include "alarm.h" + +/* btc_alarm_args_t */ +typedef struct { + osi_alarm_callback_t cb; + void *cb_data; +} btc_alarm_args_t; + +void btc_alarm_handler(btc_msg_t *msg); + +#endif /* __BTC_ALARM_H__ */ diff --git a/components/bt/bluedroid/btc/include/btc_task.h b/components/bt/bluedroid/btc/include/btc_task.h index bb8996974..9cb1fa610 100644 --- a/components/bt/bluedroid/btc/include/btc_task.h +++ b/components/bt/bluedroid/btc/include/btc_task.h @@ -44,6 +44,7 @@ typedef enum { BTC_PID_SPPLIKE, BTC_PID_BLUFI, BTC_PID_DM_SEC, + BTC_PID_ALARM, #if CONFIG_CLASSIC_BT_ENABLED BTC_PID_GAP_BT, BTC_PID_PRF_QUE, diff --git a/components/bt/bluedroid/osi/alarm.c b/components/bt/bluedroid/osi/alarm.c index 3d36be727..4ac903cc4 100644 --- a/components/bt/bluedroid/osi/alarm.c +++ b/components/bt/bluedroid/osi/alarm.c @@ -27,6 +27,8 @@ #include "freertos/FreeRTOSConfig.h" #include "freertos/xtensa_api.h" #include "rom/ets_sys.h" +#include "btc_task.h" +#include "btc_alarm.h" #define RTC_TIMER_TICKS_TO_MS(ticks) (((ticks/625)<<1) + (ticks-(ticks/625)*625)/312) @@ -122,17 +124,21 @@ static struct alarm_t *alarm_cbs_lookfor_available(void) static void alarm_cb_handler(TimerHandle_t xTimer) { struct alarm_t *alarm; - if (!xTimer) { LOG_ERROR("TimerName: NULL\n"); return; } - + alarm = pvTimerGetTimerID(xTimer); LOG_DEBUG("TimerID %p, Name %s\n", alarm, pcTimerGetTimerName(xTimer)); - if (alarm->cb) { - alarm->cb(alarm->cb_data); - } + + btc_msg_t msg; + btc_alarm_args_t arg; + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_ALARM; + arg.cb = alarm->cb; + arg.cb_data = alarm->cb_data; + btc_transfer_context(&msg, &arg, sizeof(btc_alarm_args_t), NULL); } osi_alarm_t *osi_alarm_new(char *alarm_name, osi_alarm_callback_t callback, void *data, period_ms_t timer_expire)