]> granicus.if.org Git - esp-idf/commitdiff
component/bt: transfer bluedroid timer events to be handled by BTC task
authorwangmengyang <wangmengyang@espressif.com>
Fri, 14 Apr 2017 10:49:30 +0000 (18:49 +0800)
committerwangmengyang <wangmengyang@espressif.com>
Fri, 14 Apr 2017 10:49:30 +0000 (18:49 +0800)
components/bt/bluedroid/btc/core/btc_alarm.c [new file with mode: 0644]
components/bt/bluedroid/btc/core/btc_task.c
components/bt/bluedroid/btc/include/btc_alarm.h [new file with mode: 0644]
components/bt/bluedroid/btc/include/btc_task.h
components/bt/bluedroid/osi/alarm.c

diff --git a/components/bt/bluedroid/btc/core/btc_alarm.c b/components/bt/bluedroid/btc/core/btc_alarm.c
new file mode 100644 (file)
index 0000000..15587d6
--- /dev/null
@@ -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);
+    }
+}
index d576fdd7622c7a09dc91daae21088607a9c8c31c..e267f093623b884bd8016b814c4d83f9d6255851 100644 (file)
@@ -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 (file)
index 0000000..ca9640a
--- /dev/null
@@ -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 <stdint.h>
+#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__ */
index bb8996974681c0f2e119011aec69a926cfc023ca..9cb1fa610776cae3445580855723820a86f58813 100644 (file)
@@ -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,
index 3d36be7270ecfc729a6d3376a400c74cd4c96fac..4ac903cc4e8d3d8390f73ee25a40655d97c7244e 100644 (file)
@@ -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)