-
Notifications
You must be signed in to change notification settings - Fork 0
/
SxRadio.h
343 lines (315 loc) · 13.2 KB
/
SxRadio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
/ _____) _ | |
( (____ _____ ____ _| |_ _____ ____| |__
\____ \| ___ | (_ _) ___ |/ ___) _ \
_____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
(C)2013 Semtech
Description: Generic radio driver definition
License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis and Gregory Cristian
*/
#ifndef __SXRADIO_H__
#define __SXRADIO_H__
#include <stdint.h>
#include "SxRadioEvents.h"
/*!
* \brief Radio driver definition
*/
class SxRadio
{
public:
/*!
* Radio driver supported modems
*/
typedef enum
{
MODEM_FSK = 0,
MODEM_LORA,
}RadioModems_t;
/*!
* Radio driver internal state machine states definition
*/
typedef enum
{
RF_IDLE = 0,
RF_RX_RUNNING,
RF_TX_RUNNING,
RF_CAD,
RF_LBT
}RadioState_t;
SxRadio(uint32_t WakeupTime) : WakeupTime(WakeupTime), freq_offset(0), State(RF_IDLE), Modem(MODEM_LORA) { }
virtual ~SxRadio() {};
/*!
* \brief Initializes the radio
*
* \param [IN] events Structure containing the driver callback functions
*/
virtual void Init( SxRadioEvents *events ) = 0;
/*!
* \brief Prepares the radio for destruction
*/
virtual void Terminate( void ) = 0;
/*!
* Return current radio status
*
* \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
*/
virtual RadioState_t Status( void ) { return State; }
/*!
* \brief Configures the radio with the given modem
*
* \param [IN] modem Modem to be used [0: FSK, 1: LoRa]
*/
virtual void SetModem( RadioModems_t modem ) = 0;
virtual RadioModems_t GetModem( void ) { return Modem; }
/*!
* \brief Sets the channel frequency
*
* \param [IN] freq Channel RF frequency
*/
virtual void SetChannel( uint32_t freq ) = 0;
/*!
* \brief Sets the channels configuration
*
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
* \param [IN] freq Channel RF frequency
* \param [IN] rssiThresh RSSI threshold
* \param [IN] rssiVal pointer to variable to hold RSSI value if desired - ignored if NULL
*
* \retval isFree [true: Channel is free, false: Channel is not free]
*/
virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t timeout = 5000, int16_t *rssiVal = NULL ) = 0;
/*!
* \brief Generates a 32 bits random value based on the RSSI readings
*
* \remark This function sets the radio in LoRa modem mode and disables
* all interrupts.
* After calling this function either Radio.SetRxConfig or
* Radio.SetTxConfig functions must be called.
*
* \retval randomValue 32 bits random value
*/
virtual uint32_t Random( void ) = 0;
/*!
* \brief Sets the reception parameters
*
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
* \param [IN] bandwidth Sets the bandwidth
* FSK : >= 2600 and <= 250000 Hz
* LoRa: [0: 125 kHz, 1: 250 kHz,
* 2: 500 kHz, 3: Reserved]
* \param [IN] datarate Sets the Datarate
* FSK : 600..300000 bits/s
* LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
* 10: 1024, 11: 2048, 12: 4096 chips]
* \param [IN] coderate Sets the coding rate (LoRa only)
* FSK : N/A ( set to 0 )
* LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
* \param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only)
* FSK : >= 2600 and <= 250000 Hz
* LoRa: N/A ( set to 0 )
* \param [IN] preambleLen Sets the Preamble length
* FSK : Number of bytes
* LoRa: Length in symbols (the hardware adds 4 more symbols)
* \param [IN] symbTimeout Sets the RxSingle timeout value (LoRa only)
* FSK : N/A ( set to 0 )
* LoRa: timeout in symbols
* \param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
* \param [IN] payloadLen Sets payload length when fixed length is used
* \param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON]
* \param [IN] FreqHopOn Enables disables the intra-packet frequency hopping
* FSK : N/A ( set to 0 )
* LoRa: [0: OFF, 1: ON]
* \param [IN] HopPeriod Number of symbols bewteen each hop
* FSK : N/A ( set to 0 )
* LoRa: Number of symbols
* \param [IN] iqInverted Inverts IQ signals (LoRa only)
* FSK : N/A ( set to 0 )
* LoRa: [0: not inverted, 1: inverted]
* \param [IN] rxContinuous Sets the reception in continuous mode
* [false: single mode, true: continuous mode]
* \param [IN] fskPad Duration in ms to increase FSK rx window
* FSK: time in ms to increase FSK rx window duration
* LoRa: N/A
*/
virtual void SetRxConfig( RadioModems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidthAfc, uint16_t preambleLen,
uint16_t symbTimeout, bool fixLen,
uint8_t payloadLen,
bool crcOn, bool FreqHopOn, uint8_t HopPeriod,
bool iqInverted, bool rxContinuous , uint32_t fskPad = 0) = 0;
/*!
* \brief Sets the transmission parameters
*
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
* \param [IN] power Sets the output power [dBm]
* \param [IN] fdev Sets the frequency deviation (FSK only)
* FSK : [Hz]
* LoRa: 0
* \param [IN] bandwidth Sets the bandwidth (LoRa only)
* FSK : 0
* LoRa: [0: 125 kHz, 1: 250 kHz,
* 2: 500 kHz, 3: Reserved]
* \param [IN] datarate Sets the Datarate
* FSK : 600..300000 bits/s
* LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
* 10: 1024, 11: 2048, 12: 4096 chips]
* \param [IN] coderate Sets the coding rate (LoRa only)
* FSK : N/A ( set to 0 )
* LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
* \param [IN] preambleLen Sets the preamble length
* FSK : Number of bytes
* LoRa: Length in symbols (the hardware adds 4 more symbols)
* \param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
* \param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON]
* \param [IN] FreqHopOn Enables disables the intra-packet frequency hopping
* FSK : N/A ( set to 0 )
* LoRa: [0: OFF, 1: ON]
* \param [IN] HopPeriod Number of symbols bewteen each hop
* FSK : N/A ( set to 0 )
* LoRa: Number of symbols
* \param [IN] iqInverted Inverts IQ signals (LoRa only)
* FSK : N/A ( set to 0 )
* LoRa: [0: not inverted, 1: inverted]
* \param [IN] timeout Transmission timeout [us]
*/
virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preambleLen,
bool fixLen, bool crcOn, bool FreqHopOn,
uint8_t HopPeriod, bool iqInverted, uint32_t timeout ) = 0;
virtual void SetTxPower(int8_t power) = 0;
virtual void SetTxContinuousWave( uint32_t freq, int8_t power, uint16_t time ) = 0;
virtual void SetTxContinuousWave( uint32_t freq, int8_t pa, int8_t hp, int8_t tx, uint16_t time ) = 0;
/*!
* \brief Checks if the given RF frequency is supported by the hardware
*
* \param [IN] frequency RF frequency to be checked
* \retval isSupported [true: supported, false: unsupported]
*/
virtual bool CheckRfFrequency( uint32_t frequency ) { return true; }
/*!
* \brief Computes the packet time on air for the given payload
*
* \Remark Can only be called once SetRxConfig or SetTxConfig have been called
*
* \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
* \param [IN] pktLen Packet payload length
*
* \retval airTime Computed airTime for the given packet payload length
*/
virtual double TimeOnAir( RadioModems_t modem, uint8_t pktLen ) = 0;
/*!
* \brief Sends the buffer of size. Prepares the packet to be sent and sets
* the radio in transmission
*
* \param [IN]: buffer Buffer pointer
* \param [IN]: size Buffer size
*/
virtual void Send( const uint8_t *buffer, uint8_t size ) = 0;
/*!
* \brief Sets the radio in sleep mode
*/
virtual void Sleep( bool warm_start = false ) = 0;
/*!
* \brief Wakeup the radio from sleep mode
*/
virtual void Wakeup( bool warm_start = false ) = 0;
/*!
* \brief Sets the radio in standby mode
*/
virtual void Standby(bool use_rc = false ) = 0;
/*!
* \brief Sets the radio in reception mode for the given time
* \param [IN] timeout Reception timeout [us]
* [0: continuous, others timeout]
*/
virtual void Rx( uint32_t timeout ) = 0;
/*!
* \brief Start a Channel Activity Detection
*/
virtual void StartCad( void ) = 0;
/*!
* \brief Reads the current RSSI value
*
* \retval rssiValue Current RSSI value in [dBm]
*/
virtual int16_t Rssi( RadioModems_t modem ) = 0;
/*!
* \brief Writes the radio register at the specified address
*
* \param [IN]: addr Register address
* \param [IN]: data New register value
*/
#if !defined(TARGET_XDOT_MAX32670)
virtual void Write( uint8_t addr, uint8_t data ) = 0;
/*!
* \brief Reads the radio register at the specified address
*
* \param [IN]: addr Register address
* \retval data Register value
*/
virtual uint8_t Read ( uint8_t addr ) = 0;
/*!
* \brief Writes multiple radio registers starting at address
*
* \param [IN] addr First Radio register address
* \param [IN] buffer Buffer containing the new register's values
* \param [IN] size Number of registers to be written
*/
virtual void WriteBuffer( uint8_t addr, const uint8_t *buffer, uint8_t size ) = 0;
/*!
* \brief Reads multiple radio registers starting at address
*
* \param [IN] addr First Radio register address
* \param [OUT] buffer Buffer where to copy the registers data
* \param [IN] size Number of registers to be read
*/
virtual void ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
#else
virtual void SetSyncWord( int mode ) = 0;
#endif
virtual void SignalMacEvent(void) {};
virtual void SignalLinkEvent(void) {};
virtual void SignalRxTimeout(void) {};
virtual void ResetRadio(void) {};
virtual uint32_t GetTimeOnAir(void) = 0;
void GrabMutex(void) { mutex.lock(); }
void ReleaseMutex(void) { mutex.unlock(); }
int32_t GetFrequencyOffset() { return freq_offset; }
void SetFrequencyOffset(int32_t offset) { freq_offset = offset; }
const uint32_t WakeupTime;
#if defined(TARGET_XDOT_MAX32670)
virtual uint8_t GetVddMin(void) = 0;
virtual void SetVddMin(uint8_t vdd) = 0;
#if defined(MTS_RADIO_CTRL_COMMANDS)
virtual void SetLNA(uint8_t rxBoosted) = 0;
virtual uint8_t GetLNA(void) = 0;
virtual void SetPaDutyCycle(uint8_t paDutyCycle) = 0;
virtual uint8_t GetPaDutyCycle(void) = 0;
virtual void SetHpMax(uint8_t hpMax) = 0;
virtual uint8_t GetHpMax(void) = 0;
virtual void SetXTATrim(uint8_t xtaTrim) = 0;
virtual uint8_t GetXTATrim(void) = 0;
virtual void SetXTBTrim(uint8_t xtbTrim) = 0;
virtual uint8_t GetXTBTrim(void) = 0;
virtual void setSWState(uint8_t value) = 0;
virtual uint8_t getSWState(void) = 0;
virtual void SetRampTime(uint8_t rampTime) = 0;
virtual uint8_t GetRampTime(void) = 0;
virtual void SetTxInfPreamble(uint8_t enable, int8_t power, uint32_t frequency, uint32_t bandwidth, uint8_t spreadingFactor) = 0;
virtual uint8_t GetTxInfPreamble(void) = 0;
#endif //__MTS_RADIO_CTRL_COMMANDS__
#endif //__TARGET_XDOT_MAX32670__
protected:
int32_t freq_offset;
RadioState_t State;
RadioModems_t Modem;
/*!
* Access protection
*/
Mutex mutex;
};
#endif // __SXRADIO_H__