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     BTC_PID_HD,
69     BTC_PID_HH,
70 #if (BTC_HF_INCLUDED == TRUE)
71     BTC_PID_HF,
72 #endif /* BTC_HF_INCLUDED */
73 #if (BTC_HF_CLIENT_INCLUDED == TRUE)
74     BTC_PID_HF_CLIENT,
75 #endif /* BTC_HF_CLIENT_INCLUDED */
76 #endif  /* CLASSIC_BT_INCLUDED */
77 #if CONFIG_BLE_MESH
78     BTC_PID_PROV,
79     BTC_PID_MODEL,
80     BTC_PID_HEALTH_CLIENT,
81     BTC_PID_HEALTH_SERVER,
82     BTC_PID_CONFIG_CLIENT,
83     BTC_PID_CONFIG_SERVER,
84     BTC_PID_GENERIC_CLIENT,
85     BTC_PID_LIGHTING_CLIENT,
86     BTC_PID_SENSOR_CLIENT,
87     BTC_PID_TIME_SCENE_CLIENT,
88     BTC_PID_GENERIC_SERVER,
89     BTC_PID_LIGHTING_SERVER,
90     BTC_PID_SENSOR_SERVER,
91     BTC_PID_TIME_SCENE_SERVER,
92     BTC_PID_BLE_MESH_BLE_COEX,
93 #endif /* CONFIG_BLE_MESH */
94     BTC_PID_NUM,
95 } btc_pid_t; //btc profile id
96 
97 typedef struct {
98     void (* btc_call)(btc_msg_t *msg);
99     void (* btc_cb)(btc_msg_t *msg);
100 } btc_func_t;
101 
102 typedef void (* btc_arg_deep_copy_t)(btc_msg_t *msg, void *dst, void *src);
103 
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107 
108 /**
109  * transfer an message to another module in the different task.
110  * @param  msg       message
111  * @param  arg       paramter
112  * @param  arg_len   length of paramter
113  * @param  copy_func deep copy function
114  * @return           BT_STATUS_SUCCESS: success
115  *                   others: fail
116  */
117 bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func);
118 
119 /**
120  * transfer an message to another module in tha same task.
121  * @param  msg       message
122  * @param  arg       paramter
123  * @return           BT_STATUS_SUCCESS: success
124  *                   others: fail
125  */
126 bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg);
127 
128 bt_status_t btc_init(void);
129 void btc_deinit(void);
130 bool btc_check_queue_is_congest(void);
131 int get_btc_work_queue_size(void);
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /* __BTC_TASK_H__ */
138