1 /*
2  * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __BTC_TASK_H__
8 #define __BTC_TASK_H__
9 
10 #include <stdint.h>
11 #include "bt_common.h"
12 #include "osi/thread.h"
13 
14 #if CONFIG_BT_BLUEDROID_ENABLED
15 #include "common/bt_target.h"
16 #endif
17 
18 typedef struct btc_msg {
19     uint8_t sig;    //event signal
20     uint8_t aid;    //application id
21     uint8_t pid;    //profile id
22     uint8_t act;    //profile action, defined in seprerate header files
23     UINT8   arg[0]; //param for btc function or function param
24 } btc_msg_t;
25 
26 typedef struct btc_adv_packet {
27     uint8_t addr[6];
28     uint8_t addr_type;
29 } btc_adv_packet_t;
30 
31 typedef enum {
32     BTC_SIG_API_CALL = 0,   // APP TO STACK
33     BTC_SIG_API_CB,         // STACK TO APP
34     BTC_SIG_NUM,
35 } btc_sig_t; //btc message type
36 
37 typedef enum {
38     BTC_PID_MAIN_INIT = 0,
39     BTC_PID_DEV,
40     BTC_PID_GATTS,
41 #if (GATTC_INCLUDED == TRUE)
42     BTC_PID_GATTC,
43 #endif  ///GATTC_INCLUDED == TRUE
44     BTC_PID_GATT_COMMON,
45     BTC_PID_GAP_BLE,
46     BTC_PID_BLE_HID,
47     BTC_PID_SPPLIKE,
48 #if (BLUFI_INCLUDED == TRUE)
49     BTC_PID_BLUFI,
50 #endif  ///BLUFI_INCLUDED == TRUE
51     BTC_PID_DM_SEC,
52     BTC_PID_ALARM,
53 #if (CLASSIC_BT_INCLUDED == TRUE)
54     BTC_PID_GAP_BT,
55     BTC_PID_PRF_QUE,
56     BTC_PID_A2DP,
57     BTC_PID_AVRC_CT,
58     BTC_PID_AVRC_TG,
59     BTC_PID_SPP,
60     BTC_PID_HD,
61     BTC_PID_HH,
62     BTC_PID_L2CAP,
63     BTC_PID_SDP,
64 #if (BTC_HF_INCLUDED == TRUE)
65     BTC_PID_HF,
66 #endif /* BTC_HF_INCLUDED */
67 #if (BTC_HF_CLIENT_INCLUDED == TRUE)
68     BTC_PID_HF_CLIENT,
69 #endif /* BTC_HF_CLIENT_INCLUDED */
70 #endif  /* CLASSIC_BT_INCLUDED */
71 #if CONFIG_BLE_MESH
72     BTC_PID_PROV,
73     BTC_PID_MODEL,
74     BTC_PID_HEALTH_CLIENT,
75     BTC_PID_HEALTH_SERVER,
76     BTC_PID_CONFIG_CLIENT,
77     BTC_PID_CONFIG_SERVER,
78     BTC_PID_GENERIC_CLIENT,
79     BTC_PID_LIGHTING_CLIENT,
80     BTC_PID_SENSOR_CLIENT,
81     BTC_PID_TIME_SCENE_CLIENT,
82     BTC_PID_GENERIC_SERVER,
83     BTC_PID_LIGHTING_SERVER,
84     BTC_PID_SENSOR_SERVER,
85     BTC_PID_TIME_SCENE_SERVER,
86     BTC_PID_BLE_MESH_BLE_COEX,
87 #endif /* CONFIG_BLE_MESH */
88     BTC_PID_NUM,
89 } btc_pid_t; //btc profile id
90 
91 typedef struct {
92     void (* btc_call)(btc_msg_t *msg);
93     void (* btc_cb)(btc_msg_t *msg);
94 } btc_func_t;
95 
96 typedef void (* btc_arg_deep_copy_t)(btc_msg_t *msg, void *dst, void *src);
97 typedef void (* btc_arg_deep_free_t)(btc_msg_t *msg);
98 
99 #ifdef __cplusplus
100 extern "C" {
101 #endif
102 
103 /**
104  * transfer an message to another module in the different task.
105  * @param  msg       message
106  * @param  arg       paramter
107  * @param  arg_len   length of paramter
108  * @param  copy_func deep copy function
109  * @param  free_func deep free function
110  * @return           BT_STATUS_SUCCESS: success
111  *                   others: fail
112  */
113 bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func,
114                                     btc_arg_deep_free_t free_func);
115 
116 /**
117  * transfer an message to another module in tha same task.
118  * @param  msg       message
119  * @return           BT_STATUS_SUCCESS: success
120  *                   others: fail
121  */
122 bt_status_t btc_inter_profile_call(btc_msg_t *msg);
123 
124 bt_status_t btc_init(void);
125 void btc_deinit(void);
126 bool btc_check_queue_is_congest(void);
127 int get_btc_work_queue_size(void);
128 
129 /**
130  * get the BTC thread handle
131  * @return           NULL: fail
132  *                   others: pointer of osi_thread structure of BTC
133  */
134 osi_thread_t *btc_get_current_thread(void);
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* __BTC_TASK_H__ */
141