• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
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 _BT_HCI_H_
16 #define _BT_HCI_H_
17 
18 #include <stdint.h>
19 #include <stdbool.h>
20 
21 typedef enum {
22     BT_HCI_CH_0 = 0,
23     BT_HCI_CH_NUM
24 } BT_HCI_CH_T;
25 
26 typedef enum {
27     BT_HCI_PKT_TYPE_HCI_UART = 0,
28     BT_HCI_PKT_TYPE_NUM
29 } BT_HCI_PKT_TYPE_T;
30 
31 /*
32  * @param data ptr
33  * @param data length
34  * @return length of processed rx data
35  */
36 typedef uint32_t (*BT_HCI_RX_IRQ_HANDLER)(const uint8_t *data, uint32_t len);
37 
38 /*
39  * @param data ptr
40  * @param data length
41  */
42 typedef void (*BT_HCI_TX_IRQ_HANDLER)(const uint8_t *data, uint32_t len);
43 
44 typedef void (*BT_WAKEUP_IND_IRQ_HANDLER)(void);
45 
46 typedef void (*AON_POWER_ON_CPUS_REQ_IRQ_HANDLER)(void);
47 
48 /*
49  * Open bt hci
50  * @param hci channel
51  * @param packet type
52  * @param rx irq handler
53  * @param tx irq handler
54  * @param rx blocking mode, if set to true, host can only cache and process a packet , host should always call bt_hci_rx_done after rx_handler
55  *  if set to false, host can cache several packets, host should copy data to somewhere else in rx_handler , host should never call bt_hci_rx_done
56  * @return 0 on success
57  */
58 int bt_hci_open(BT_HCI_CH_T ch, BT_HCI_PKT_TYPE_T type, BT_HCI_RX_IRQ_HANDLER rx_handler, BT_HCI_TX_IRQ_HANDLER tx_handler, bool rx_blocking);
59 
60 /*
61  * Host start receiving data
62  * @param hci channel
63  * @return 0 on success
64  */
65 int bt_hci_rx_start(BT_HCI_CH_T ch);
66 
67 /*
68  * Host stop receiving data
69  * @param hci channel
70  * @return 0 on success
71  */
72 int bt_hci_rx_stop(BT_HCI_CH_T ch);
73 
74 /*
75  * Host complete a reception
76  * @param hci channel
77  */
78 void bt_hci_rx_done(BT_HCI_CH_T ch);
79 
80 /*
81  * Check whether host could send data to controller
82  * Be careful, do NOT send data even it return true when hci flow control forbid host to send data to controller
83  * @param hci channel
84  * @return true if host could send data to controller, return false if not, this would happen when controller could not
85  *  handle reception in time and cause host sending jam
86  */
87 bool bt_hci_tx_available(BT_HCI_CH_T ch);
88 
89 /*
90  * Host send data to controller
91  * @param hci channel
92  * @param packet type
93  * @param data ptr
94  * @param data length
95  * @return 0 on success
96  */
97 int bt_hci_tx(BT_HCI_CH_T ch, BT_HCI_PKT_TYPE_T type, const uint8_t *data, uint32_t len);
98 
99 /*
100  * Close bt hci
101  * @param hci channel
102  * @param packet type
103  * @return 0 on success
104  */
105 int bt_hci_close(BT_HCI_CH_T ch, BT_HCI_PKT_TYPE_T type);
106 
107 /*
108  * Host send wakeup request to controller, and disable controller to enter deep sleep again until host send next sleep enable
109  */
110 void host_wakeup_request(void);
111 
112 /*
113  * Host send wakeup request to controller, and controller's sleep enable is not changed, must be called before bt_hci_open
114  */
115 void host_wakeup_request2(void);
116 
117 /*
118  * Register the bt wakeup indication handler, the handler should be registered before bt_hci_open
119  * Host received controller's wakeup indication, corresponding to host_wakeup_request
120  * @param handler
121  *
122  */
123 void bt_wakeup_ind_irq_handler_register(BT_WAKEUP_IND_IRQ_HANDLER handler);
124 
125 /*
126  * Register the bt wakeup indication2 handler, the handler should be registered before bt_hci_open
127  * Host received controller's wakeup indication, corresponding to host_wakeup_request2
128  * @param handler
129  *
130  */
131 void bt_wakeup_ind2_irq_handler_register(BT_WAKEUP_IND_IRQ_HANDLER handler);
132 
133 /*
134  * Initialize interface between host and aon module
135  */
136 void ipc_cpup_aon_init(void);
137 
138 /*
139  * Host request controller to quit aon mode and enter normal mode
140  */
141 void cpup_power_on_cpus_req_send(void);
142 
143 /*
144  * Register the handler when host receives the requeset that controller want to exit aon mode and enter normal mode
145  * the handler should be registered before ipc_cpup_aon_init
146  * @param handler
147  *
148  */
149 void aon_power_on_cpus_req_irq_handler_register(AON_POWER_ON_CPUS_REQ_IRQ_HANDLER handler);
150 
151 #endif
152