提交 | 用户 | age
|
6a6261
|
1 |
/*!
|
Q |
2 |
* \file radio.h
|
|
3 |
*
|
|
4 |
* \brief Radio driver API definition
|
|
5 |
*
|
|
6 |
* \copyright Revised BSD License, see section \ref LICENSE.
|
|
7 |
*
|
|
8 |
* \code
|
|
9 |
* ______ _
|
|
10 |
* / _____) _ | |
|
|
11 |
* ( (____ _____ ____ _| |_ _____ ____| |__
|
|
12 |
* \____ \| ___ | (_ _) ___ |/ ___) _ \
|
|
13 |
* _____) ) ____| | | || |_| ____( (___| | | |
|
|
14 |
* (______/|_____)_|_|_| \__)_____)\____)_| |_|
|
|
15 |
* (C)2013-2017 Semtech
|
|
16 |
*
|
|
17 |
* \endcode
|
|
18 |
*
|
|
19 |
* \author Miguel Luis ( Semtech )
|
|
20 |
*
|
|
21 |
* \author Gregory Cristian ( Semtech )
|
|
22 |
*/
|
|
23 |
#ifndef __RADIO_H__
|
|
24 |
#define __RADIO_H__
|
|
25 |
|
|
26 |
#include<stdint.h>
|
|
27 |
#include<stdbool.h>
|
|
28 |
|
|
29 |
//#define USE_MODEM_LORA
|
|
30 |
|
|
31 |
/*!
|
|
32 |
* Radio driver supported modems
|
|
33 |
*/
|
|
34 |
typedef enum
|
|
35 |
{
|
|
36 |
MODEM_FSK = 0,
|
|
37 |
MODEM_LORA,
|
|
38 |
}RadioModems_t;
|
|
39 |
|
|
40 |
/*!
|
|
41 |
* Radio driver internal state machine states definition
|
|
42 |
*/
|
|
43 |
typedef enum
|
|
44 |
{
|
|
45 |
RF_IDLE = 0, //!< The radio is idle
|
|
46 |
RF_RX_RUNNING, //!< The radio is in reception state
|
|
47 |
RF_TX_RUNNING, //!< The radio is in transmission state
|
|
48 |
RF_CAD, //!< The radio is doing channel activity detection
|
|
49 |
}RadioState_t;
|
|
50 |
|
|
51 |
/*!
|
|
52 |
* \brief Radio driver callback functions
|
|
53 |
*/
|
|
54 |
typedef struct
|
|
55 |
{
|
|
56 |
/*!
|
|
57 |
* \brief Tx Done callback prototype.
|
|
58 |
*/
|
|
59 |
void ( *TxDone )( void );
|
|
60 |
/*!
|
|
61 |
* \brief Tx Timeout callback prototype.
|
|
62 |
*/
|
|
63 |
void ( *TxTimeout )( void );
|
|
64 |
/*!
|
|
65 |
* \brief Rx Done callback prototype.
|
|
66 |
*
|
|
67 |
* \param [IN] payload Received buffer pointer
|
|
68 |
* \param [IN] size Received buffer size
|
|
69 |
* \param [IN] rssi RSSI value computed while receiving the frame [dBm]
|
|
70 |
* \param [IN] snr Raw SNR value given by the radio hardware
|
|
71 |
* FSK : N/A ( set to 0 )
|
|
72 |
* LoRa: SNR value in dB
|
|
73 |
*/
|
|
74 |
void ( *RxDone )( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
|
|
75 |
/*!
|
|
76 |
* \brief Rx Timeout callback prototype.
|
|
77 |
*/
|
|
78 |
void ( *RxTimeout )( void );
|
|
79 |
/*!
|
|
80 |
* \brief Rx Error callback prototype.
|
|
81 |
*/
|
|
82 |
void ( *RxError )( void );
|
|
83 |
/*!
|
|
84 |
* \brief FHSS Change Channel callback prototype.
|
|
85 |
*
|
|
86 |
* \param [IN] currentChannel Index number of the current channel
|
|
87 |
*/
|
|
88 |
void ( *FhssChangeChannel )( uint8_t currentChannel );
|
|
89 |
|
|
90 |
/*!
|
|
91 |
* \brief CAD Done callback prototype.
|
|
92 |
*
|
|
93 |
* \param [IN] channelDetected Channel Activity detected during the CAD
|
|
94 |
*/
|
|
95 |
void ( *CadDone ) ( bool channelActivityDetected );
|
|
96 |
}RadioEvents_t;
|
|
97 |
|
|
98 |
/*!
|
|
99 |
* \brief Radio driver definition
|
|
100 |
*/
|
|
101 |
struct Radio_s
|
|
102 |
{
|
|
103 |
/*!
|
|
104 |
* \brief Initializes the radio
|
|
105 |
*
|
|
106 |
* \param [IN] events Structure containing the driver callback functions
|
|
107 |
*/
|
|
108 |
void ( *Init )( RadioEvents_t *events );
|
|
109 |
/*!
|
|
110 |
* Return current radio status
|
|
111 |
*
|
|
112 |
* \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
|
|
113 |
*/
|
|
114 |
RadioState_t ( *GetStatus )( void );
|
|
115 |
/*!
|
|
116 |
* \brief Configures the radio with the given modem
|
|
117 |
*
|
|
118 |
* \param [IN] modem Modem to be used [0: FSK, 1: LoRa]
|
|
119 |
*/
|
|
120 |
void ( *SetModem )( RadioModems_t modem );
|
|
121 |
/*!
|
|
122 |
* \brief Sets the channel frequency
|
|
123 |
*
|
|
124 |
* \param [IN] freq Channel RF frequency
|
|
125 |
*/
|
|
126 |
void ( *SetChannel )( uint32_t freq );
|
|
127 |
/*!
|
|
128 |
* \brief Checks if the channel is free for the given time
|
|
129 |
*
|
|
130 |
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
|
|
131 |
* \param [IN] freq Channel RF frequency
|
|
132 |
* \param [IN] rssiThresh RSSI threshold
|
|
133 |
* \param [IN] maxCarrierSenseTime Max time while the RSSI is measured
|
|
134 |
*
|
|
135 |
* \retval isFree [true: Channel is free, false: Channel is not free]
|
|
136 |
*/
|
|
137 |
bool ( *IsChannelFree )( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t maxCarrierSenseTime );
|
|
138 |
/*!
|
|
139 |
* \brief Generates a 32 bits random value based on the RSSI readings
|
|
140 |
*
|
|
141 |
* \remark This function sets the radio in LoRa modem mode and disables
|
|
142 |
* all interrupts.
|
|
143 |
* After calling this function either Radio.SetRxConfig or
|
|
144 |
* Radio.SetTxConfig functions must be called.
|
|
145 |
*
|
|
146 |
* \retval randomValue 32 bits random value
|
|
147 |
*/
|
|
148 |
uint32_t ( *Random )( void );
|
|
149 |
/*!
|
|
150 |
* \brief Sets the reception parameters
|
|
151 |
*
|
|
152 |
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
|
|
153 |
* \param [IN] bandwidth Sets the bandwidth
|
|
154 |
* FSK : >= 2600 and <= 250000 Hz
|
|
155 |
* LoRa: [0: 125 kHz, 1: 250 kHz,
|
|
156 |
* 2: 500 kHz, 3: Reserved]
|
|
157 |
* \param [IN] datarate Sets the Datarate
|
|
158 |
* FSK : 600..300000 bits/s
|
|
159 |
* LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
|
|
160 |
* 10: 1024, 11: 2048, 12: 4096 chips]
|
|
161 |
* \param [IN] coderate Sets the coding rate (LoRa only)
|
|
162 |
* FSK : N/A ( set to 0 )
|
|
163 |
* LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
|
|
164 |
* \param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only)
|
|
165 |
* FSK : >= 2600 and <= 250000 Hz
|
|
166 |
* LoRa: N/A ( set to 0 )
|
|
167 |
* \param [IN] preambleLen Sets the Preamble length
|
|
168 |
* FSK : Number of bytes
|
|
169 |
* LoRa: Length in symbols (the hardware adds 4 more symbols)
|
|
170 |
* \param [IN] symbTimeout Sets the RxSingle timeout value
|
|
171 |
* FSK : timeout in number of bytes
|
|
172 |
* LoRa: timeout in symbols
|
|
173 |
* \param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
|
|
174 |
* \param [IN] payloadLen Sets payload length when fixed length is used
|
|
175 |
* \param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON]
|
|
176 |
* \param [IN] freqHopOn Enables disables the intra-packet frequency hopping
|
|
177 |
* FSK : N/A ( set to 0 )
|
|
178 |
* LoRa: [0: OFF, 1: ON]
|
|
179 |
* \param [IN] hopPeriod Number of symbols between each hop
|
|
180 |
* FSK : N/A ( set to 0 )
|
|
181 |
* LoRa: Number of symbols
|
|
182 |
* \param [IN] iqInverted Inverts IQ signals (LoRa only)
|
|
183 |
* FSK : N/A ( set to 0 )
|
|
184 |
* LoRa: [0: not inverted, 1: inverted]
|
|
185 |
* \param [IN] rxContinuous Sets the reception in continuous mode
|
|
186 |
* [false: single mode, true: continuous mode]
|
|
187 |
*/
|
|
188 |
void ( *SetRxConfig )( RadioModems_t modem, uint32_t bandwidth,
|
|
189 |
uint32_t datarate, uint8_t coderate,
|
|
190 |
uint32_t bandwidthAfc, uint16_t preambleLen,
|
|
191 |
uint16_t symbTimeout, bool fixLen,
|
|
192 |
uint8_t payloadLen,
|
|
193 |
bool crcOn, bool freqHopOn, uint8_t hopPeriod,
|
|
194 |
bool iqInverted, bool rxContinuous );
|
|
195 |
/*!
|
|
196 |
* \brief Sets the transmission parameters
|
|
197 |
*
|
|
198 |
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
|
|
199 |
* \param [IN] power Sets the output power [dBm]
|
|
200 |
* \param [IN] fdev Sets the frequency deviation (FSK only)
|
|
201 |
* FSK : [Hz]
|
|
202 |
* LoRa: 0
|
|
203 |
* \param [IN] bandwidth Sets the bandwidth (LoRa only)
|
|
204 |
* FSK : 0
|
|
205 |
* LoRa: [0: 125 kHz, 1: 250 kHz,
|
|
206 |
* 2: 500 kHz, 3: Reserved]
|
|
207 |
* \param [IN] datarate Sets the Datarate
|
|
208 |
* FSK : 600..300000 bits/s
|
|
209 |
* LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
|
|
210 |
* 10: 1024, 11: 2048, 12: 4096 chips]
|
|
211 |
* \param [IN] coderate Sets the coding rate (LoRa only)
|
|
212 |
* FSK : N/A ( set to 0 )
|
|
213 |
* LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
|
|
214 |
* \param [IN] preambleLen Sets the preamble length
|
|
215 |
* FSK : Number of bytes
|
|
216 |
* LoRa: Length in symbols (the hardware adds 4 more symbols)
|
|
217 |
* \param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
|
|
218 |
* \param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON]
|
|
219 |
* \param [IN] freqHopOn Enables disables the intra-packet frequency hopping
|
|
220 |
* FSK : N/A ( set to 0 )
|
|
221 |
* LoRa: [0: OFF, 1: ON]
|
|
222 |
* \param [IN] hopPeriod Number of symbols between each hop
|
|
223 |
* FSK : N/A ( set to 0 )
|
|
224 |
* LoRa: Number of symbols
|
|
225 |
* \param [IN] iqInverted Inverts IQ signals (LoRa only)
|
|
226 |
* FSK : N/A ( set to 0 )
|
|
227 |
* LoRa: [0: not inverted, 1: inverted]
|
|
228 |
* \param [IN] timeout Transmission timeout [ms]
|
|
229 |
*/
|
|
230 |
void ( *SetTxConfig )( RadioModems_t modem, int8_t power, uint32_t fdev,
|
|
231 |
uint32_t bandwidth, uint32_t datarate,
|
|
232 |
uint8_t coderate, uint16_t preambleLen,
|
|
233 |
bool fixLen, bool crcOn, bool freqHopOn,
|
|
234 |
uint8_t hopPeriod, bool iqInverted, uint32_t timeout );
|
|
235 |
/*!
|
|
236 |
* \brief Checks if the given RF frequency is supported by the hardware
|
|
237 |
*
|
|
238 |
* \param [IN] frequency RF frequency to be checked
|
|
239 |
* \retval isSupported [true: supported, false: unsupported]
|
|
240 |
*/
|
|
241 |
bool ( *CheckRfFrequency )( uint32_t frequency );
|
|
242 |
/*!
|
|
243 |
* \brief Computes the packet time on air in ms for the given payload
|
|
244 |
*
|
|
245 |
* \Remark Can only be called once SetRxConfig or SetTxConfig have been called
|
|
246 |
*
|
|
247 |
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
|
|
248 |
* \param [IN] pktLen Packet payload length
|
|
249 |
*
|
|
250 |
* \retval airTime Computed airTime (ms) for the given packet payload length
|
|
251 |
*/
|
|
252 |
uint32_t ( *TimeOnAir )( RadioModems_t modem, uint8_t pktLen );
|
|
253 |
/*!
|
|
254 |
* \brief Sends the buffer of size. Prepares the packet to be sent and sets
|
|
255 |
* the radio in transmission
|
|
256 |
*
|
|
257 |
* \param [IN]: buffer Buffer pointer
|
|
258 |
* \param [IN]: size Buffer size
|
|
259 |
*/
|
|
260 |
void ( *Send )( uint8_t *buffer, uint8_t size );
|
|
261 |
/*!
|
|
262 |
* \brief Sets the radio in sleep mode
|
|
263 |
*/
|
|
264 |
void ( *Sleep )( void );
|
|
265 |
/*!
|
|
266 |
* \brief Sets the radio in standby mode
|
|
267 |
*/
|
|
268 |
void ( *Standby )( void );
|
|
269 |
/*!
|
|
270 |
* \brief Sets the radio in reception mode for the given time
|
|
271 |
* \param [IN] timeout Reception timeout [ms]
|
|
272 |
* [0: continuous, others timeout]
|
|
273 |
*/
|
|
274 |
void ( *Rx )( uint32_t timeout );
|
|
275 |
/*!
|
|
276 |
* \brief Start a Channel Activity Detection
|
|
277 |
*/
|
|
278 |
void ( *StartCad )( void );
|
|
279 |
/*!
|
|
280 |
* \brief Sets the radio in continuous wave transmission mode
|
|
281 |
*
|
|
282 |
* \param [IN]: freq Channel RF frequency
|
|
283 |
* \param [IN]: power Sets the output power [dBm]
|
|
284 |
* \param [IN]: time Transmission mode timeout [s]
|
|
285 |
*/
|
|
286 |
void ( *SetTxContinuousWave )( uint32_t freq, int8_t power, uint16_t time );
|
|
287 |
/*!
|
|
288 |
* \brief Reads the current RSSI value
|
|
289 |
*
|
|
290 |
* \retval rssiValue Current RSSI value in [dBm]
|
|
291 |
*/
|
|
292 |
int16_t ( *Rssi )( RadioModems_t modem );
|
|
293 |
/*!
|
|
294 |
* \brief Writes the radio register at the specified address
|
|
295 |
*
|
|
296 |
* \param [IN]: addr Register address
|
|
297 |
* \param [IN]: data New register value
|
|
298 |
*/
|
|
299 |
void ( *Write )( uint16_t addr, uint8_t data );
|
|
300 |
/*!
|
|
301 |
* \brief Reads the radio register at the specified address
|
|
302 |
*
|
|
303 |
* \param [IN]: addr Register address
|
|
304 |
* \retval data Register value
|
|
305 |
*/
|
|
306 |
uint8_t ( *Read )( uint16_t addr );
|
|
307 |
/*!
|
|
308 |
* \brief Writes multiple radio registers starting at address
|
|
309 |
*
|
|
310 |
* \param [IN] addr First Radio register address
|
|
311 |
* \param [IN] buffer Buffer containing the new register's values
|
|
312 |
* \param [IN] size Number of registers to be written
|
|
313 |
*/
|
|
314 |
void ( *WriteBuffer )( uint16_t addr, uint8_t *buffer, uint8_t size );
|
|
315 |
/*!
|
|
316 |
* \brief Reads multiple radio registers starting at address
|
|
317 |
*
|
|
318 |
* \param [IN] addr First Radio register address
|
|
319 |
* \param [OUT] buffer Buffer where to copy the registers data
|
|
320 |
* \param [IN] size Number of registers to be read
|
|
321 |
*/
|
|
322 |
void ( *ReadBuffer )( uint16_t addr, uint8_t *buffer, uint8_t size );
|
|
323 |
/*!
|
|
324 |
* \brief Sets the maximum payload length.
|
|
325 |
*
|
|
326 |
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
|
|
327 |
* \param [IN] max Maximum payload length in bytes
|
|
328 |
*/
|
|
329 |
void ( *SetMaxPayloadLength )( RadioModems_t modem, uint8_t max );
|
|
330 |
/*!
|
|
331 |
* \brief Sets the network to public or private. Updates the sync byte.
|
|
332 |
*
|
|
333 |
* \remark Applies to LoRa modem only
|
|
334 |
*
|
|
335 |
* \param [IN] enable if true, it enables a public network
|
|
336 |
*/
|
|
337 |
void ( *SetPublicNetwork )( bool enable );
|
|
338 |
/*!
|
|
339 |
* \brief Gets the time required for the board plus radio to get out of sleep.[ms]
|
|
340 |
*
|
|
341 |
* \retval time Radio plus board wakeup time in ms.
|
|
342 |
*/
|
|
343 |
uint32_t ( *GetWakeupTime )( void );
|
|
344 |
/*!
|
|
345 |
* \brief Process radio irq
|
|
346 |
*/
|
|
347 |
void ( *IrqProcess )( void );
|
|
348 |
/*
|
|
349 |
* The next functions are available only on SX126x radios.
|
|
350 |
*/
|
|
351 |
/*!
|
|
352 |
* \brief Sets the radio in reception mode with Max LNA gain for the given time
|
|
353 |
*
|
|
354 |
* \remark Available on SX126x radios only.
|
|
355 |
*
|
|
356 |
* \param [IN] timeout Reception timeout [ms]
|
|
357 |
* [0: continuous, others timeout]
|
|
358 |
*/
|
|
359 |
void ( *RxBoosted )( uint32_t timeout );
|
|
360 |
/*!
|
|
361 |
* \brief Sets the Rx duty cycle management parameters
|
|
362 |
*
|
|
363 |
* \remark Available on SX126x radios only.
|
|
364 |
*
|
|
365 |
* \param [in] rxTime Structure describing reception timeout value
|
|
366 |
* \param [in] sleepTime Structure describing sleep timeout value
|
|
367 |
*/
|
|
368 |
void ( *SetRxDutyCycle ) ( uint32_t rxTime, uint32_t sleepTime );
|
|
369 |
};
|
|
370 |
|
|
371 |
/*!
|
|
372 |
* \brief Radio driver
|
|
373 |
*
|
|
374 |
* \remark This variable is defined and initialized in the specific radio
|
|
375 |
* board implementation
|
|
376 |
*/
|
|
377 |
extern const struct Radio_s Radio;
|
|
378 |
|
|
379 |
#endif // __RADIO_H__
|