1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef __BTC_TASK_H__
16 #define __BTC_TASK_H__
17 
18 #include <stdint.h>
19 #include "bt_common.h"
20 #include "osi/thread.h"
21 
22 #if CONFIG_BT_BLUEDROID_ENABLED
23 #include "common/bt_target.h"
24 #endif
25 
26 typedef struct btc_msg {
27     uint8_t sig;    //event signal
28     uint8_t aid;    //application id
29     uint8_t pid;    //profile id
30     uint8_t act;    //profile action, defined in seprerate header files
31     void   *arg;    //param for btc function or function param
32 } btc_msg_t;
33 
34 typedef struct btc_adv_packet {
35     uint8_t addr[6];
36     uint8_t addr_type;
37 } btc_adv_packet_t;
38 
39 typedef enum {
40     BTC_SIG_API_CALL = 0,   // APP TO STACK
41     BTC_SIG_API_CB,         // STACK TO APP
42     BTC_SIG_NUM,
43 } btc_sig_t; //btc message type
44 
45 typedef enum {
46     BTC_PID_MAIN_INIT = 0,
47     BTC_PID_DEV,
48     BTC_PID_GATTS,
49 #if (GATTC_INCLUDED == TRUE)
50     BTC_PID_GATTC,
51 #endif  ///GATTC_INCLUDED == TRUE
52     BTC_PID_GATT_COMMON,
53     BTC_PID_GAP_BLE,
54     BTC_PID_BLE_HID,
55     BTC_PID_SPPLIKE,
56 #if (BLUFI_INCLUDED == TRUE)
57     BTC_PID_BLUFI,
58 #endif  ///BLUFI_INCLUDED == TRUE
59     BTC_PID_DM_SEC,
60     BTC_PID_ALARM,
61 #if (CLASSIC_BT_INCLUDED == TRUE)
62     BTC_PID_GAP_BT,
63     BTC_PID_PRF_QUE,
64     BTC_PID_A2DP,
65     BTC_PID_AVRC_CT,
66     BTC_PID_AVRC_TG,
67     BTC_PID_SPP,
68 #if (BTC_HF_INCLUDED == TRUE)
69     BTC_PID_HF,
70 #endif /* BTC_HF_INCLUDED */
71 #if (BTC_HF_CLIENT_INCLUDED == TRUE)
72     BTC_PID_HF_CLIENT,
73 #endif /* BTC_HF_CLIENT_INCLUDED */
74 #endif  /* CLASSIC_BT_INCLUDED */
75 #if CONFIG_BLE_MESH
76     BTC_PID_PROV,
77     BTC_PID_MODEL,
78     BTC_PID_HEALTH_CLIENT,
79     BTC_PID_HEALTH_SERVER,
80     BTC_PID_CONFIG_CLIENT,
81     BTC_PID_CONFIG_SERVER,
82     BTC_PID_GENERIC_CLIENT,
83     BTC_PID_LIGHTING_CLIENT,
84     BTC_PID_SENSOR_CLIENT,
85     BTC_PID_TIME_SCENE_CLIENT,
86     BTC_PID_GENERIC_SERVER,
87     BTC_PID_LIGHTING_SERVER,
88     BTC_PID_SENSOR_SERVER,
89     BTC_PID_TIME_SCENE_SERVER,
90     BTC_PID_BLE_MESH_BLE_COEX,
91 #endif /* CONFIG_BLE_MESH */
92     BTC_PID_NUM,
93 } btc_pid_t; //btc profile id
94 
95 typedef struct {
96     void (* btc_call)(btc_msg_t *msg);
97     void (* btc_cb)(btc_msg_t *msg);
98 } btc_func_t;
99 
100 typedef void (* btc_arg_deep_copy_t)(btc_msg_t *msg, void *dst, void *src);
101 
102 /**
103  * transfer an message to another module in the different task.
104  * @param  msg       message
105  * @param  arg       paramter
106  * @param  arg_len   length of paramter
107  * @param  copy_func deep copy function
108  * @return           BT_STATUS_SUCCESS: success
109  *                   others: fail
110  */
111 bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func);
112 
113 /**
114  * transfer an message to another module in tha same task.
115  * @param  msg       message
116  * @param  arg       paramter
117  * @return           BT_STATUS_SUCCESS: success
118  *                   others: fail
119  */
120 bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg);
121 
122 bt_status_t btc_init(void);
123 void btc_deinit(void);
124 bool btc_check_queue_is_congest(void);
125 int get_btc_work_queue_size(void);
126 
127 #endif /* __BTC_TASK_H__ */
128