ble_lcp.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file ble_lcp.h
5 *
6 * @brief LCP SDK API
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 *****************************************************************************************
36 */
37
38 /**
39 * @addtogroup BLE
40 * @{
41 * @brief Definitions and prototypes for the BLE SDK interface.
42 */
43
44 /**
45 * @addtogroup BLE_LCP Light Communication Protocol (LCP)
46 * @{
47 * @brief Definitions and prototypes for the LCP interface.
48 */
49
50 #ifndef _BLE_LCP_H_
51 #define _BLE_LCP_H_
52
53
54 /**@addtogroup BLE_LCP_TYPEDEFS Typedefs
55 * @{ */
56 /**@brief RX handler callback function. */
57 typedef uint16_t (*rx_handler_cb_t) (uint8_t header, uint8_t length, uint8_t *p_payload);
58 /** @} */
59
60 /**@addtogroup BLE_LCP_ENUMERATIONS Enumerations
61 * @{ */
62 /**@brief Protocol Mode. */
63 enum PROTOCOL_MODE
64 {
65 BLE_ADV, /**< BLE ADV mode. */
66 BLE_SCAN, /**< BLE SCAN mode. */
67 LCP_TX, /**< LCP TX mode. */
68 LCP_RX, /**< LCP RX mode. */
69 };
70 /** @} */
71
72 /**@addtogroup BLE_LCP_STRUCTURES Structures
73 * @{ */
74 /**@brief LCP Parameter. */
75 typedef struct
76 {
77 uint8_t mode; /**< Set protocol mode, see @ref PROTOCOL_MODE. */
78 int8_t txpwr_dbm; /**< The value of the tx power(range: -20-7), uint: dBm. */
79 uint8_t ch_idx; /**< The value of the channel index(range: 0-39). */
80 uint32_t freq; /**< The value of the frequency(range: 2360-2520), uint: MHz. */
81 uint32_t access_address; /**< The value of the access address. */
82 uint32_t crc_init; /**< The initial value of the crc. */
83 rx_handler_cb_t rx_handler_cb; /**< The callback function of rx. */
84 } gdx_lcp_config_t;
85 /** @} */
86
87 /** @addtogroup BLE_LCP_FUNCTIONS Functions
88 * @{ */
89 /**
90 ****************************************************************************************
91 * @brief Initialize LCP.
92 *
93 * @param[in] gdx_lcp_config: Configure the parameter of LCP, @ref gdx_lcp_config_t.
94 *
95 * @retval ::SDK_SUCCESS: The LCP parameter is successfully configured.
96 * @retval ::SDK_ERR_POINTER_NULL: Invalid pointer supplied.
97 * @retval ::SDK_ERR_INVALID_PARAM: Invalid parameter supplied.
98 ****************************************************************************************
99 */
100 uint16_t gdx_lcp_init(gdx_lcp_config_t *gdx_lcp_config);
101
102 /**
103 ****************************************************************************************
104 * @brief Deinitialize LCP.
105 *
106 * @retval ::SDK_SUCCESS: The LCP is successfully Deinitialized.
107 ****************************************************************************************
108 */
109 uint16_t gdx_lcp_deinit(void);
110
111 /**
112 ****************************************************************************************
113 * @brief Set the tx power of LCP.
114 *
115 * @param[in] txpwr_dbm: The value of the tx power, Range: -20dbm to 7dbm.
116 *
117 * @retval ::SDK_SUCCESS: Operation is Success.
118 * @retval ::SDK_ERR_INVALID_PARAM: Invalid parameter supplied.
119 ****************************************************************************************
120 */
121 uint16_t gdx_lcp_tx_power_set(int8_t txpwr_dbm);
122
123 /**
124 ****************************************************************************************
125 * @brief Get the tx power of LCP.
126 *
127 * @param[in] txpwr_dbm: The value of the tx power, Range: -20dbm to 7dbm.
128 *
129 * @retval ::SDK_SUCCESS: Operation is Success.
130 * @retval ::SDK_ERR_POINTER_NULL: Invalid pointer supplied.
131 ****************************************************************************************
132 */
133 uint16_t gdx_lcp_tx_power_get(int8_t *txpwr_dbm);
134
135 /**
136 ****************************************************************************************
137 * @brief Set the channel of LCP.
138 *
139 * @param[in] freq: The value of the frequency, Range: 2360MHz to 2520MHz.
140 * @param[in] ch_idx: The value of the channel index, Range: 0 to 39.
141 *
142 * @retval ::SDK_SUCCESS: Operation is Success.
143 * @retval ::SDK_ERR_INVALID_PARAM: Invalid parameter supplied.
144 ****************************************************************************************
145 */
146 uint16_t gdx_lcp_channel_set(uint32_t freq, uint8_t ch_idx);
147
148 /**
149 ****************************************************************************************
150 * @brief Get the channel of LCP.
151 *
152 * @param[in] freq: The value of the frequency, Range: 2360MHz to 2520MHz.
153 * @param[in] ch_idx: The value of the channel index, Range: 0 to 39.
154 *
155 * @retval ::SDK_SUCCESS: Operation is Success.
156 * @retval ::SDK_ERR_POINTER_NULL: Invalid pointer supplied.
157 ****************************************************************************************
158 */
159 uint16_t gdx_lcp_channel_get(uint32_t *freq, uint8_t *ch_idx);
160
161 /**
162 ****************************************************************************************
163 * @brief Set the rate of LCP.
164 *
165 * @param[in] rate: The phy rate of LCP communication. Should be called before gdx_lcp_init
166 *
167 * @retval :void.
168 ****************************************************************************************
169 */
170 void gdx_lcp_rate_set(bool rate);
171
172 /**
173 ****************************************************************************************
174 * @brief Get the rate of LCP.
175 *
176 *
177 * @retval ::0: 1Mbps.
178 * @retval ::1: 2Mbps.
179 ****************************************************************************************
180 */
181 bool gdx_lcp_rate_get(void);
182
183 /**
184 ****************************************************************************************
185 * @brief Get the rssi of LCP.
186 *
187 *
188 * @retval ::Rssi of current channel. Should be called after gdx_lcp_rx_start
189 ****************************************************************************************
190 */
191 int8_t gdx_lcp_rssi_get(void);
192
193 /**
194 ****************************************************************************************
195 * @brief Transmmit a packet.
196 *
197 * @param[in] header: The header of the packet.
198 * @param[in] length: The length of the packet payload.
199 * @param[in] p_payload: The pointer of the packet payload.
200 *
201 * @retval ::SDK_SUCCESS: Operation is Success.
202 * @retval ::SDK_ERR_INVALID_PARAM: Invalid parameter supplied.
203 ****************************************************************************************
204 */
205 uint16_t gdx_lcp_data_tx(uint8_t header, uint8_t length, uint8_t *p_payload);
206
207 /**
208 ****************************************************************************************
209 * @brief Start receiving packets
210 *
211 * @retval ::SDK_SUCCESS: Operation is Success.
212 ****************************************************************************************
213 */
214 uint16_t gdx_lcp_rx_start(void);
215
216 /**
217 ****************************************************************************************
218 * @brief Stop receiving packets
219 *
220 * @retval ::SDK_SUCCESS: Operation is Success.
221 ****************************************************************************************
222 */
223 uint16_t gdx_lcp_rx_stop(void);
224
225 /**
226 ****************************************************************************************
227 * @brief Set lcp access address
228 *
229 * @retval ::SDK_SUCCESS: Operation is Success.
230 ****************************************************************************************
231 */
232 uint16_t gdx_lcp_access_address_set(uint32_t access_address);
233 /** @} */
234
235 #endif
236
237 /** @} */
238 /** @} */
LCP_TX
@ LCP_TX
LCP TX mode.
Definition: ble_lcp.h:67
gdx_lcp_init
uint16_t gdx_lcp_init(gdx_lcp_config_t *gdx_lcp_config)
Initialize LCP.
PROTOCOL_MODE
PROTOCOL_MODE
Protocol Mode.
Definition: ble_lcp.h:64
gdx_lcp_config_t::access_address
uint32_t access_address
The value of the access address.
Definition: ble_lcp.h:81
gdx_lcp_rssi_get
int8_t gdx_lcp_rssi_get(void)
Get the rssi of LCP.
gdx_lcp_config_t
LCP Parameter.
Definition: ble_lcp.h:76
gdx_lcp_tx_power_set
uint16_t gdx_lcp_tx_power_set(int8_t txpwr_dbm)
Set the tx power of LCP.
gdx_lcp_rate_set
void gdx_lcp_rate_set(bool rate)
Set the rate of LCP.
gdx_lcp_rx_stop
uint16_t gdx_lcp_rx_stop(void)
Stop receiving packets.
gdx_lcp_rate_get
bool gdx_lcp_rate_get(void)
Get the rate of LCP.
gdx_lcp_config_t::freq
uint32_t freq
The value of the frequency(range: 2360-2520), uint: MHz.
Definition: ble_lcp.h:80
gdx_lcp_data_tx
uint16_t gdx_lcp_data_tx(uint8_t header, uint8_t length, uint8_t *p_payload)
Transmmit a packet.
gdx_lcp_config_t::mode
uint8_t mode
Set protocol mode, see PROTOCOL_MODE.
Definition: ble_lcp.h:77
rx_handler_cb_t
uint16_t(* rx_handler_cb_t)(uint8_t header, uint8_t length, uint8_t *p_payload)
RX handler callback function.
Definition: ble_lcp.h:57
gdx_lcp_tx_power_get
uint16_t gdx_lcp_tx_power_get(int8_t *txpwr_dbm)
Get the tx power of LCP.
gdx_lcp_rx_start
uint16_t gdx_lcp_rx_start(void)
Start receiving packets.
gdx_lcp_channel_set
uint16_t gdx_lcp_channel_set(uint32_t freq, uint8_t ch_idx)
Set the channel of LCP.
LCP_RX
@ LCP_RX
LCP RX mode.
Definition: ble_lcp.h:68
gdx_lcp_config_t::crc_init
uint32_t crc_init
The initial value of the crc.
Definition: ble_lcp.h:82
gdx_lcp_access_address_set
uint16_t gdx_lcp_access_address_set(uint32_t access_address)
Set lcp access address.
gdx_lcp_config_t::rx_handler_cb
rx_handler_cb_t rx_handler_cb
The callback function of rx.
Definition: ble_lcp.h:83
BLE_ADV
@ BLE_ADV
BLE ADV mode.
Definition: ble_lcp.h:65
gdx_lcp_config_t::ch_idx
uint8_t ch_idx
The value of the channel index(range: 0-39).
Definition: ble_lcp.h:79
gdx_lcp_config_t::txpwr_dbm
int8_t txpwr_dbm
The value of the tx power(range: -20-7), uint: dBm.
Definition: ble_lcp.h:78
gdx_lcp_deinit
uint16_t gdx_lcp_deinit(void)
Deinitialize LCP.
BLE_SCAN
@ BLE_SCAN
BLE SCAN mode.
Definition: ble_lcp.h:66
gdx_lcp_channel_get
uint16_t gdx_lcp_channel_get(uint32_t *freq, uint8_t *ch_idx)
Get the channel of LCP.