-
Notifications
You must be signed in to change notification settings - Fork 1
/
SX128x.hpp
1861 lines (1643 loc) · 57.8 KB
/
SX128x.hpp
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of SX128x Portable driver.
Copyright (C) 2020 ReimuNotMoe
This program is based on sx1280-driver from Semtech S.A.,
see LICENSE-SEMTECH.txt for details.
Original maintainer of sx1280-driver: Miguel Luis, Gregory Cristian
and Matthieu Verdy
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#include <thread>
#include <mutex>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cinttypes>
/*!
* \brief Represents the SX128x and its features
*
* It implements the commands the SX128x can understands
*/
class SX128x {
public:
enum {
/*!
* \brief Enables/disables driver debug features
*/
SX1280_DEBUG = 0,
/*!
* \brief Compensation delay for SetAutoTx method in microseconds
*/
AUTO_TX_OFFSET = 33,
/*!
* \brief The address of the register holding the firmware version MSB
*/
REG_LR_FIRMWARE_VERSION_MSB = 0x0153,
/*!
* \brief The address of the register holding the first byte defining the CRC seed
*
* \remark Only used for packet types GFSK and Flrc
*/
REG_LR_CRCSEEDBASEADDR = 0x09C8,
/*!
* \brief The address of the register holding the first byte defining the CRC polynomial
*
* \remark Only used for packet types GFSK and Flrc
*/
REG_LR_CRCPOLYBASEADDR = 0x09C6,
/*!
* \brief The address of the register holding the first byte defining the whitening seed
*
* \remark Only used for packet types GFSK, FLRC and BLE
*/
REG_LR_WHITSEEDBASEADDR = 0x09C5,
/*!
* \brief The address of the register holding the ranging id check length
*
* \remark Only used for packet type Ranging
*/
REG_LR_RANGINGIDCHECKLENGTH = 0x0931,
/*!
* \brief The address of the register holding the device ranging id
*
* \remark Only used for packet type Ranging
*/
REG_LR_DEVICERANGINGADDR = 0x0916,
/*!
* \brief The address of the register holding the device ranging id
*
* \remark Only used for packet type Ranging
*/
REG_LR_REQUESTRANGINGADDR = 0x0912,
/*!
* \brief The address of the register holding ranging results configuration
* and the corresponding mask
*
* \remark Only used for packet type Ranging
*/
REG_LR_RANGINGRESULTCONFIG = 0x0924,
MASK_RANGINGMUXSEL = 0xCF,
/*!
* \brief The address of the register holding the first byte of ranging results
* Only used for packet type Ranging
*/
REG_LR_RANGINGRESULTBASEADDR = 0x0961,
/*!
* \brief The address of the register allowing to read ranging results
*
* \remark Only used for packet type Ranging
*/
REG_LR_RANGINGRESULTSFREEZE = 0x097F,
/*!
* \brief The address of the register holding the first byte of ranging calibration
*
* \remark Only used for packet type Ranging
*/
REG_LR_RANGINGRERXTXDELAYCAL = 0x092C,
/*!
*\brief The address of the register holding the ranging filter window size
*
* \remark Only used for packet type Ranging
*/
REG_LR_RANGINGFILTERWINDOWSIZE = 0x091E,
/*!
*\brief The address of the register to reset for clearing ranging filter
*
* \remark Only used for packet type Ranging
*/
REG_LR_RANGINGRESULTCLEARREG = 0x0923,
REG_RANGING_RSSI = 0x0964,
/*!
* \brief The default number of samples considered in built-in ranging filter
*/
DEFAULT_RANGING_FILTER_SIZE = 127,
/*!
* \brief The address of the register holding LORA packet parameters
*/
REG_LR_PACKETPARAMS = 0x903,
/*!
* \brief The address of the register holding payload length
*
* \remark Do NOT try to read it directly. Use GetRxBuffer( ) instead.
*/
REG_LR_PAYLOADLENGTH = 0x901,
/*!
* \brief The addresses of the registers holding SyncWords values
*
* \remark The addresses depends on the Packet Type in use, and not all
* SyncWords are available for every Packet Type
*/
REG_LR_SYNCWORDBASEADDRESS1 = 0x09CE,
REG_LR_SYNCWORDBASEADDRESS2 = 0x09D3,
REG_LR_SYNCWORDBASEADDRESS3 = 0x09D8,
/*!
* \brief The MSB address and mask used to read the estimated frequency
* error
*/
REG_LR_ESTIMATED_FREQUENCY_ERROR_MSB = 0x0954,
REG_LR_ESTIMATED_FREQUENCY_ERROR_MASK = 0x0FFFFF,
/*!
* \brief Defines how many bit errors are tolerated in sync word detection
*/
REG_LR_SYNCWORDTOLERANCE = 0x09CD,
/*!
* \brief Register and mask for GFSK and BLE preamble length forcing
*/
REG_LR_PREAMBLELENGTH = 0x09C1,
MASK_FORCE_PREAMBLELENGTH = 0x8F,
/*!
* \brief Register for MSB Access Address (BLE)
*/
REG_LR_BLE_ACCESS_ADDRESS = 0x09CF,
BLE_ADVERTIZER_ACCESS_ADDRESS = 0x8E89BED6,
/*!
* \brief Select high sensitivity versus power consumption
*/
REG_LNA_REGIME = 0x0891,
MASK_LNA_REGIME = 0xC0,
/*
* \brief Register and mask controling the enabling of manual gain control
*/
REG_ENABLE_MANUAL_GAIN_CONTROL = 0x089F,
MASK_MANUAL_GAIN_CONTROL = 0x80,
/*!
* \brief Register and mask controling the demodulation detection
*/
REG_DEMOD_DETECTION = 0x0895,
MASK_DEMOD_DETECTION = 0xFE,
/*!
* Register and mask to set the manual gain parameter
*/
REG_MANUAL_GAIN_VALUE = 0x089E,
MASK_MANUAL_GAIN_VALUE = 0xF0,
/*!
* \brief Provides the frequency of the chip running on the radio and the frequency step
*
* \remark These defines are used for computing the frequency divider to set the RF frequency
*/
XTAL_FREQ = 52000000
};
double FREQ_STEP = (double) XTAL_FREQ / pow(2.0, 18.0);
public:
/*!
* \brief Represents the states of the radio
*/
typedef enum {
RF_IDLE = 0x00, //!< The radio is idle
RF_RX_RUNNING, //!< The radio is in reception state
RF_TX_RUNNING, //!< The radio is in transmission state
RF_CAD, //!< The radio is doing channel activity detection
} RadioStates_t;
/*!
* \brief Represents the operating mode the radio is actually running
*/
typedef enum {
MODE_SLEEP = 0x00, //! The radio is in sleep mode
MODE_CALIBRATION, //! The radio is in calibration mode
MODE_STDBY_RC, //! The radio is in standby mode with RC oscillator
MODE_STDBY_XOSC, //! The radio is in standby mode with XOSC oscillator
MODE_FS, //! The radio is in frequency synthesis mode
MODE_RX, //! The radio is in receive mode
MODE_TX, //! The radio is in transmit mode
MODE_CAD //! The radio is in channel activity detection mode
} RadioOperatingModes_t;
/*!
* \brief Declares the oscillator in use while in standby mode
*
* Using the STDBY_RC standby mode allow to reduce the energy consumption
* STDBY_XOSC should be used for time critical applications
*/
typedef enum {
STDBY_RC = 0x00,
STDBY_XOSC = 0x01,
} RadioStandbyModes_t;
/*!
* \brief Declares the power regulation used to power the device
*
* This command allows the user to specify if DC-DC or LDO is used for power regulation.
* Using only LDO implies that the Rx or Tx current is doubled
*/
typedef enum {
USE_LDO = 0x00, //! Use LDO (default value)
USE_DCDC = 0x01, //! Use DCDC
} RadioRegulatorModes_t;
/*!
* \brief Represents the possible packet type (i.e. modem) used
*/
typedef enum {
PACKET_TYPE_GFSK = 0x00,
PACKET_TYPE_LORA,
PACKET_TYPE_RANGING,
PACKET_TYPE_FLRC,
PACKET_TYPE_BLE,
PACKET_TYPE_NONE = 0x0F,
} RadioPacketTypes_t;
/*!
* \brief Represents the ramping time for power amplifier
*/
typedef enum {
RADIO_RAMP_02_US = 0x00,
RADIO_RAMP_04_US = 0x20,
RADIO_RAMP_06_US = 0x40,
RADIO_RAMP_08_US = 0x60,
RADIO_RAMP_10_US = 0x80,
RADIO_RAMP_12_US = 0xA0,
RADIO_RAMP_16_US = 0xC0,
RADIO_RAMP_20_US = 0xE0,
} RadioRampTimes_t;
/*!
* \brief Represents the number of symbols to be used for channel activity detection operation
*/
typedef enum {
LORA_CAD_01_SYMBOL = 0x00,
LORA_CAD_02_SYMBOLS = 0x20,
LORA_CAD_04_SYMBOLS = 0x40,
LORA_CAD_08_SYMBOLS = 0x60,
LORA_CAD_16_SYMBOLS = 0x80,
} RadioLoRaCadSymbols_t;
/*!
* \brief Represents the possible combinations of bitrate and bandwidth for
* GFSK and BLE packet types
*
* The bitrate is expressed in Mb/s and the bandwidth in MHz
*/
typedef enum {
GFSK_BLE_BR_2_000_BW_2_4 = 0x04,
GFSK_BLE_BR_1_600_BW_2_4 = 0x28,
GFSK_BLE_BR_1_000_BW_2_4 = 0x4C,
GFSK_BLE_BR_1_000_BW_1_2 = 0x45,
GFSK_BLE_BR_0_800_BW_2_4 = 0x70,
GFSK_BLE_BR_0_800_BW_1_2 = 0x69,
GFSK_BLE_BR_0_500_BW_1_2 = 0x8D,
GFSK_BLE_BR_0_500_BW_0_6 = 0x86,
GFSK_BLE_BR_0_400_BW_1_2 = 0xB1,
GFSK_BLE_BR_0_400_BW_0_6 = 0xAA,
GFSK_BLE_BR_0_250_BW_0_6 = 0xCE,
GFSK_BLE_BR_0_250_BW_0_3 = 0xC7,
GFSK_BLE_BR_0_125_BW_0_3 = 0xEF,
} RadioGfskBleBitrates_t;
/*!
* \brief Represents the modulation index used in GFSK and BLE packet
* types
*/
typedef enum {
GFSK_BLE_MOD_IND_0_35 = 0,
GFSK_BLE_MOD_IND_0_50 = 1,
GFSK_BLE_MOD_IND_0_75 = 2,
GFSK_BLE_MOD_IND_1_00 = 3,
GFSK_BLE_MOD_IND_1_25 = 4,
GFSK_BLE_MOD_IND_1_50 = 5,
GFSK_BLE_MOD_IND_1_75 = 6,
GFSK_BLE_MOD_IND_2_00 = 7,
GFSK_BLE_MOD_IND_2_25 = 8,
GFSK_BLE_MOD_IND_2_50 = 9,
GFSK_BLE_MOD_IND_2_75 = 10,
GFSK_BLE_MOD_IND_3_00 = 11,
GFSK_BLE_MOD_IND_3_25 = 12,
GFSK_BLE_MOD_IND_3_50 = 13,
GFSK_BLE_MOD_IND_3_75 = 14,
GFSK_BLE_MOD_IND_4_00 = 15,
} RadioGfskBleModIndexes_t;
/*!
* \brief Represents the possible combination of bitrate and bandwidth for FLRC
* packet type
*
* The bitrate is in Mb/s and the bitrate in MHz
*/
typedef enum {
FLRC_BR_1_300_BW_1_2 = 0x45,
FLRC_BR_1_040_BW_1_2 = 0x69,
FLRC_BR_0_650_BW_0_6 = 0x86,
FLRC_BR_0_520_BW_0_6 = 0xAA,
FLRC_BR_0_325_BW_0_3 = 0xC7,
FLRC_BR_0_260_BW_0_3 = 0xEB,
} RadioFlrcBitrates_t;
/*!
* \brief Represents the possible values for coding rate parameter in FLRC
* packet type
*/
typedef enum {
FLRC_CR_1_2 = 0x00,
FLRC_CR_3_4 = 0x02,
FLRC_CR_1_0 = 0x04,
} RadioFlrcCodingRates_t;
/*!
* \brief Represents the modulation shaping parameter for GFSK, FLRC and BLE
* packet types
*/
typedef enum {
RADIO_MOD_SHAPING_BT_OFF = 0x00, //! No filtering
RADIO_MOD_SHAPING_BT_1_0 = 0x10,
RADIO_MOD_SHAPING_BT_0_5 = 0x20,
} RadioModShapings_t;
/*!
* \brief Represents the possible spreading factor values in LORA packet types
*/
typedef enum {
LORA_SF5 = 0x50,
LORA_SF6 = 0x60,
LORA_SF7 = 0x70,
LORA_SF8 = 0x80,
LORA_SF9 = 0x90,
LORA_SF10 = 0xA0,
LORA_SF11 = 0xB0,
LORA_SF12 = 0xC0,
} RadioLoRaSpreadingFactors_t;
/*!
* \brief Represents the bandwidth values for LORA packet type
*/
typedef enum {
LORA_BW_0200 = 0x34,
LORA_BW_0400 = 0x26,
LORA_BW_0800 = 0x18,
LORA_BW_1600 = 0x0A,
} RadioLoRaBandwidths_t;
/*!
* \brief Represents the coding rate values for LORA packet type
*/
typedef enum {
LORA_CR_4_5 = 0x01,
LORA_CR_4_6 = 0x02,
LORA_CR_4_7 = 0x03,
LORA_CR_4_8 = 0x04,
LORA_CR_LI_4_5 = 0x05,
LORA_CR_LI_4_6 = 0x06,
LORA_CR_LI_4_7 = 0x07,
} RadioLoRaCodingRates_t;
/*!
* \brief Represents the preamble length values for GFSK and FLRC packet
* types
*/
typedef enum {
PREAMBLE_LENGTH_04_BITS = 0x00, //!< Preamble length: 04 bits
PREAMBLE_LENGTH_08_BITS = 0x10, //!< Preamble length: 08 bits
PREAMBLE_LENGTH_12_BITS = 0x20, //!< Preamble length: 12 bits
PREAMBLE_LENGTH_16_BITS = 0x30, //!< Preamble length: 16 bits
PREAMBLE_LENGTH_20_BITS = 0x40, //!< Preamble length: 20 bits
PREAMBLE_LENGTH_24_BITS = 0x50, //!< Preamble length: 24 bits
PREAMBLE_LENGTH_28_BITS = 0x60, //!< Preamble length: 28 bits
PREAMBLE_LENGTH_32_BITS = 0x70, //!< Preamble length: 32 bits
} RadioPreambleLengths_t;
/*!
* \brief Represents the SyncWord length for FLRC packet type
*/
typedef enum {
FLRC_NO_SYNCWORD = 0x00,
FLRC_SYNCWORD_LENGTH_4_BYTE = 0x04,
} RadioFlrcSyncWordLengths_t;
/*!
* \brief The length of sync words for GFSK packet type
*/
typedef enum {
GFSK_SYNCWORD_LENGTH_1_BYTE = 0x00, //!< Sync word length: 1 byte
GFSK_SYNCWORD_LENGTH_2_BYTE = 0x02, //!< Sync word length: 2 bytes
GFSK_SYNCWORD_LENGTH_3_BYTE = 0x04, //!< Sync word length: 3 bytes
GFSK_SYNCWORD_LENGTH_4_BYTE = 0x06, //!< Sync word length: 4 bytes
GFSK_SYNCWORD_LENGTH_5_BYTE = 0x08, //!< Sync word length: 5 bytes
} RadioSyncWordLengths_t;
/*!
* \brief Represents the possible combinations of SyncWord correlators
* activated for GFSK and FLRC packet types
*/
typedef enum {
RADIO_RX_MATCH_SYNCWORD_OFF = 0x00, //!< No correlator turned on, i.e. do not search for SyncWord
RADIO_RX_MATCH_SYNCWORD_1 = 0x10,
RADIO_RX_MATCH_SYNCWORD_2 = 0x20,
RADIO_RX_MATCH_SYNCWORD_1_2 = 0x30,
RADIO_RX_MATCH_SYNCWORD_3 = 0x40,
RADIO_RX_MATCH_SYNCWORD_1_3 = 0x50,
RADIO_RX_MATCH_SYNCWORD_2_3 = 0x60,
RADIO_RX_MATCH_SYNCWORD_1_2_3 = 0x70,
} RadioSyncWordRxMatchs_t;
/*!
* \brief Radio packet length mode for GFSK and FLRC packet types
*/
typedef enum {
RADIO_PACKET_FIXED_LENGTH = 0x00, //!< The packet is known on both sides, no header included in the packet
RADIO_PACKET_VARIABLE_LENGTH = 0x20, //!< The packet is on variable size, header included
} RadioPacketLengthModes_t;
/*!
* \brief Represents the CRC length for GFSK and FLRC packet types
*
* \warning Not all configurations are available for both GFSK and FLRC
* packet type. Refer to the datasheet for possible configuration.
*/
typedef enum {
RADIO_CRC_OFF = 0x00, //!< No CRC in use
RADIO_CRC_1_BYTES = 0x10,
RADIO_CRC_2_BYTES = 0x20,
RADIO_CRC_3_BYTES = 0x30,
} RadioCrcTypes_t;
/*!
* \brief Radio whitening mode activated or deactivated for GFSK, FLRC and
* BLE packet types
*/
typedef enum {
RADIO_WHITENING_ON = 0x00,
RADIO_WHITENING_OFF = 0x08,
} RadioWhiteningModes_t;
/*!
* \brief Holds the packet length mode of a LORA packet type
*/
typedef enum {
LORA_PACKET_VARIABLE_LENGTH = 0x00, //!< The packet is on variable size, header included
LORA_PACKET_FIXED_LENGTH = 0x80, //!< The packet is known on both sides, no header included in the packet
LORA_PACKET_EXPLICIT = LORA_PACKET_VARIABLE_LENGTH,
LORA_PACKET_IMPLICIT = LORA_PACKET_FIXED_LENGTH,
} RadioLoRaPacketLengthsModes_t;
/*!
* \brief Represents the CRC mode for LORA packet type
*/
typedef enum {
LORA_CRC_ON = 0x20, //!< CRC activated
LORA_CRC_OFF = 0x00, //!< CRC not used
} RadioLoRaCrcModes_t;
/*!
* \brief Represents the IQ mode for LORA packet type
*/
typedef enum {
LORA_IQ_NORMAL = 0x40,
LORA_IQ_INVERTED = 0x00,
} RadioLoRaIQModes_t;
/*!
* \brief Represents the length of the ID to check in ranging operation
*/
typedef enum {
RANGING_IDCHECK_LENGTH_08_BITS = 0x00,
RANGING_IDCHECK_LENGTH_16_BITS,
RANGING_IDCHECK_LENGTH_24_BITS,
RANGING_IDCHECK_LENGTH_32_BITS,
} RadioRangingIdCheckLengths_t;
/*!
* \brief Represents the result type to be used in ranging operation
*/
typedef enum {
RANGING_RESULT_RAW = 0x00,
RANGING_RESULT_AVERAGED = 0x01,
RANGING_RESULT_DEBIASED = 0x02,
RANGING_RESULT_FILTERED = 0x03,
} RadioRangingResultTypes_t;
/*!
* \brief Represents the connection state for BLE packet type
*/
typedef enum {
BLE_PAYLOAD_LENGTH_MAX_31_BYTES = 0x00,
BLE_PAYLOAD_LENGTH_MAX_37_BYTES = 0x20,
BLE_TX_TEST_MODE = 0x40,
BLE_PAYLOAD_LENGTH_MAX_255_BYTES = 0x80,
} RadioBleConnectionStates_t;
/*!
* \brief Represents the CRC field length for BLE packet type
*/
typedef enum {
BLE_CRC_OFF = 0x00,
BLE_CRC_3B = 0x10,
} RadioBleCrcTypes_t;
/*!
* \brief Represents the specific packets to use in BLE packet type
*/
typedef enum {
BLE_PRBS_9 = 0x00, //!< Pseudo Random Binary Sequence based on 9th degree polynomial
BLE_PRBS_15 = 0x0C, //!< Pseudo Random Binary Sequence based on 15th degree polynomial
BLE_EYELONG_1_0 = 0x04, //!< Repeated '11110000' sequence
BLE_EYELONG_0_1 = 0x18, //!< Repeated '00001111' sequence
BLE_EYESHORT_1_0 = 0x08, //!< Repeated '10101010' sequence
BLE_EYESHORT_0_1 = 0x1C, //!< Repeated '01010101' sequence
BLE_ALL_1 = 0x10, //!< Repeated '11111111' sequence
BLE_ALL_0 = 0x14, //!< Repeated '00000000' sequence
} RadioBleTestPayloads_t;
/*!
* \brief Represents the interruption masks available for the radio
*
* \remark Note that not all these interruptions are available for all packet types
*/
typedef enum {
IRQ_RADIO_NONE = 0x0000,
IRQ_TX_DONE = 0x0001,
IRQ_RX_DONE = 0x0002,
IRQ_SYNCWORD_VALID = 0x0004,
IRQ_SYNCWORD_ERROR = 0x0008,
IRQ_HEADER_VALID = 0x0010,
IRQ_HEADER_ERROR = 0x0020,
IRQ_CRC_ERROR = 0x0040,
IRQ_RANGING_SLAVE_RESPONSE_DONE = 0x0080,
IRQ_RANGING_SLAVE_REQUEST_DISCARDED = 0x0100,
IRQ_RANGING_MASTER_RESULT_VALID = 0x0200,
IRQ_RANGING_MASTER_TIMEOUT = 0x0400,
IRQ_RANGING_SLAVE_REQUEST_VALID = 0x0800,
IRQ_CAD_DONE = 0x1000,
IRQ_CAD_DETECTED = 0x2000,
IRQ_RX_TX_TIMEOUT = 0x4000,
IRQ_PREAMBLE_DETECTED = 0x8000,
IRQ_RADIO_ALL = 0xFFFF,
} RadioIrqMasks_t;
/*!
* \brief Represents the digital input/output of the radio
*/
typedef enum {
RADIO_DIO1 = 0x02,
RADIO_DIO2 = 0x04,
RADIO_DIO3 = 0x08,
} RadioDios_t;
/*!
* \brief Represents the tick size available for Rx/Tx timeout operations
*/
typedef enum {
RADIO_TICK_SIZE_0015_US = 0x00,
RADIO_TICK_SIZE_0062_US = 0x01,
RADIO_TICK_SIZE_1000_US = 0x02,
RADIO_TICK_SIZE_4000_US = 0x03,
} RadioTickSizes_t;
/*!
* \brief Represents the role of the radio during ranging operations
*/
typedef enum {
RADIO_RANGING_ROLE_SLAVE = 0x00,
RADIO_RANGING_ROLE_MASTER = 0x01,
} RadioRangingRoles_t;
/*!
* \brief Represents the possible Mask settings for sensitivity selection
*/
typedef enum {
LNA_LOW_POWER_MODE,
LNA_HIGH_SENSITIVITY_MODE,
} RadioLnaSettings_t;
/*!
* \brief Represents an amount of time measurable by the radio clock
*
* @code
* Time = PeriodBase * PeriodBaseCount
* Example:
* PeriodBase = RADIO_TICK_SIZE_4000_US( 4 ms )
* PeriodBaseCount = 1000
* Time = 4e-3 * 1000 = 4 seconds
* @endcode
*/
typedef struct TickTime_s {
RadioTickSizes_t PeriodBase; //!< The base time of ticktime
/*!
* \brief The number of periodBase for ticktime
* Special values are:
* - 0x0000 for single mode
* - 0xFFFF for continuous mode
*/
uint16_t PeriodBaseCount;
} TickTime_t;
/*!
* \brief The type describing the modulation parameters for every packet types
*/
typedef struct {
RadioPacketTypes_t PacketType; //!< Packet to which the modulation parameters are referring to.
struct {
/*!
* \brief Holds the GFSK modulation parameters
*
* In GFSK modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token.
*/
struct {
RadioGfskBleBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for BLE and GFSK modulations
RadioGfskBleModIndexes_t ModulationIndex; //!< The coding rate for BLE and GFSK modulations
RadioModShapings_t ModulationShaping; //!< The modulation shaping for BLE and GFSK modulations
} Gfsk;
/*!
* \brief Holds the LORA modulation parameters
*
* LORA modulation is defined by Spreading Factor (SF), Bandwidth and Coding Rate
*/
struct {
RadioLoRaSpreadingFactors_t SpreadingFactor; //!< Spreading Factor for the LORA modulation
RadioLoRaBandwidths_t Bandwidth; //!< Bandwidth for the LORA modulation
RadioLoRaCodingRates_t CodingRate; //!< Coding rate for the LORA modulation
} LoRa;
/*!
* \brief Holds the FLRC modulation parameters
*
* In FLRC modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token.
*/
struct {
RadioFlrcBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for FLRC modulation
RadioFlrcCodingRates_t CodingRate; //!< The coding rate for FLRC modulation
RadioModShapings_t ModulationShaping; //!< The modulation shaping for FLRC modulation
} Flrc;
/*!
* \brief Holds the BLE modulation parameters
*
* In BLE modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token.
*/
struct {
RadioGfskBleBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for BLE and GFSK modulations
RadioGfskBleModIndexes_t ModulationIndex; //!< The coding rate for BLE and GFSK modulations
RadioModShapings_t ModulationShaping; //!< The modulation shaping for BLE and GFSK modulations
} Ble;
} Params; //!< Holds the modulation parameters structure
} ModulationParams_t;
/*!
* \brief The type describing the packet parameters for every packet types
*/
typedef struct {
RadioPacketTypes_t PacketType; //!< Packet to which the packet parameters are referring to.
struct {
/*!
* \brief Holds the GFSK packet parameters
*/
struct {
RadioPreambleLengths_t PreambleLength; //!< The preamble length for GFSK packet type
RadioSyncWordLengths_t SyncWordLength; //!< The synchronization word length for GFSK packet type
RadioSyncWordRxMatchs_t SyncWordMatch; //!< The synchronization correlator to use to check synchronization word
RadioPacketLengthModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the GFSK packet. If the header is implicit, it will not be transmitted
uint8_t PayloadLength; //!< Size of the payload in the GFSK packet
RadioCrcTypes_t CrcLength; //!< Size of the CRC block in the GFSK packet
RadioWhiteningModes_t Whitening; //!< Usage of whitening on payload and CRC blocks plus header block if header type is variable
} Gfsk;
/*!
* \brief Holds the LORA packet parameters
*/
struct {
uint8_t PreambleLength; //!< The preamble length is the number of LORA symbols in the preamble. To set it, use the following formula @code Number of symbols = PreambleLength[3:0] * ( 2^PreambleLength[7:4] ) @endcode
RadioLoRaPacketLengthsModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the LORA packet. If the header is implicit, it will not be transmitted
uint8_t PayloadLength; //!< Size of the payload in the LORA packet
RadioLoRaCrcModes_t Crc; //!< Size of CRC block in LORA packet
RadioLoRaIQModes_t InvertIQ; //!< Allows to swap IQ for LORA packet
} LoRa;
/*!
* \brief Holds the FLRC packet parameters
*/
struct {
RadioPreambleLengths_t PreambleLength; //!< The preamble length for FLRC packet type
RadioFlrcSyncWordLengths_t SyncWordLength; //!< The synchronization word length for FLRC packet type
RadioSyncWordRxMatchs_t SyncWordMatch; //!< The synchronization correlator to use to check synchronization word
RadioPacketLengthModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the FLRC packet. If the header is implicit, it will not be transmitted.
uint8_t PayloadLength; //!< Size of the payload in the FLRC packet
RadioCrcTypes_t CrcLength; //!< Size of the CRC block in the FLRC packet
RadioWhiteningModes_t Whitening; //!< Usage of whitening on payload and CRC blocks plus header block if header type is variable
} Flrc;
/*!
* \brief Holds the BLE packet parameters
*/
struct {
RadioBleConnectionStates_t ConnectionState; //!< The BLE state
RadioBleCrcTypes_t CrcLength; //!< Size of the CRC block in the BLE packet
RadioBleTestPayloads_t BleTestPayload; //!< Special BLE payload for test purpose
RadioWhiteningModes_t Whitening; //!< Usage of whitening on PDU and CRC blocks of BLE packet
} Ble;
} Params; //!< Holds the packet parameters structure
} PacketParams_t;
/*!
* \brief Represents the packet status for every packet type
*/
typedef struct {
RadioPacketTypes_t packetType; //!< Packet to which the packet status are referring to.
union {
struct {
int8_t RssiSync; //!< The RSSI measured on last packet
struct {
bool SyncError: 1; //!< SyncWord error on last packet
bool LengthError: 1; //!< Length error on last packet
bool CrcError: 1; //!< CRC error on last packet
bool AbortError: 1; //!< Abort error on last packet
bool HeaderReceived: 1; //!< Header received on last packet
bool PacketReceived: 1; //!< Packet received
bool PacketControlerBusy: 1; //!< Packet controller busy
} ErrorStatus; //!< The error status Byte
struct {
bool RxNoAck
: 1; //!< No acknowledgment received for Rx with variable length packets
bool PacketSent
: 1; //!< Packet sent, only relevant in Tx mode
} TxRxStatus; //!< The Tx/Rx status Byte
uint8_t SyncAddrStatus
: 3; //!< The id of the correlator who found the packet
} Gfsk;
struct {
int8_t RssiPkt; //!< The RSSI of the last packet
int8_t SnrPkt; //!< The SNR of the last packet
} LoRa;
struct {
int8_t RssiSync; //!< The RSSI of the last packet
struct {
bool SyncError: 1; //!< SyncWord error on last packet
bool LengthError: 1; //!< Length error on last packet
bool CrcError: 1; //!< CRC error on last packet
bool AbortError: 1; //!< Abort error on last packet
bool HeaderReceived: 1; //!< Header received on last packet
bool PacketReceived: 1; //!< Packet received
bool PacketControlerBusy: 1; //!< Packet controller busy
} ErrorStatus; //!< The error status Byte
struct {
uint8_t RxPid: 2; //!< PID of the Rx
bool RxNoAck
: 1; //!< No acknowledgment received for Rx with variable length packets
bool RxPidErr: 1; //!< Received PID error
bool PacketSent
: 1; //!< Packet sent, only relevant in Tx mode
} TxRxStatus; //!< The Tx/Rx status Byte
uint8_t SyncAddrStatus
: 3; //!< The id of the correlator who found the packet
} Flrc;
struct {
int8_t RssiSync; //!< The RSSI of the last packet
struct {
bool SyncError: 1; //!< SyncWord error on last packet
bool LengthError: 1; //!< Length error on last packet
bool CrcError: 1; //!< CRC error on last packet
bool AbortError: 1; //!< Abort error on last packet
bool HeaderReceived: 1; //!< Header received on last packet
bool PacketReceived: 1; //!< Packet received
bool PacketControlerBusy: 1; //!< Packet controller busy
} ErrorStatus; //!< The error status Byte
struct {
bool PacketSent
: 1; //!< Packet sent, only relevant in Tx mode
} TxRxStatus; //!< The Tx/Rx status Byte
uint8_t SyncAddrStatus
: 3; //!< The id of the correlator who found the packet
} Ble;
};
} PacketStatus_t;
/*!
* \brief Represents the Rx internal counters values when GFSK or LORA packet type is used
*/
typedef struct {
RadioPacketTypes_t packetType; //!< Packet to which the packet status are referring to.
union {
struct {
uint16_t PacketReceived; //!< Number of received packets
uint16_t CrcError; //!< Number of CRC errors
uint16_t LengthError; //!< Number of length errors
uint16_t SyncwordError; //!< Number of sync-word errors
} Gfsk;
struct {
uint16_t PacketReceived; //!< Number of received packets
uint16_t CrcError; //!< Number of CRC errors
uint16_t HeaderValid; //!< Number of valid headers
} LoRa;
};
} RxCounter_t;
/*!
* \brief Represents a calibration configuration
*/
typedef struct {
uint8_t RC64KEnable: 1; //!< Calibrate RC64K clock
uint8_t RC13MEnable: 1; //!< Calibrate RC13M clock
uint8_t PLLEnable: 1; //!< Calibrate PLL
uint8_t ADCPulseEnable: 1; //!< Calibrate ADC Pulse
uint8_t ADCBulkNEnable: 1; //!< Calibrate ADC bulkN
uint8_t ADCBulkPEnable: 1; //!< Calibrate ADC bulkP
} CalibrationParams_t;
/*!
* \brief Represents a sleep mode configuration
*/
typedef struct {
uint8_t WakeUpRTC
: 1; //!< Get out of sleep mode if wakeup signal received from RTC
uint8_t InstructionRamRetention: 1; //!< InstructionRam is conserved during sleep
uint8_t DataBufferRetention: 1; //!< Data buffer is conserved during sleep
uint8_t DataRamRetention: 1; //!< Data ram is conserved during sleep
} SleepParams_t;
/*!
* \brief Structure describing the radio status
*/
typedef union {
/*!
* \brief Structure of the radio status
*/
struct {
uint8_t CpuBusy: 1; //!< Flag for CPU radio busy
uint8_t DmaBusy: 1; //!< Flag for DMA busy
uint8_t CmdStatus: 3; //!< Command status
uint8_t ChipMode: 3; //!< Chip mode
} Fields;
/*!
* \brief Serialized radio status
*/
uint8_t Value;
} RadioStatus_t;
/*!
* \brief Structure describing the ranging codes for callback functions
*/
typedef enum {
IRQ_RANGING_SLAVE_ERROR_CODE = 0x00,
IRQ_RANGING_SLAVE_VALID_CODE,
IRQ_RANGING_MASTER_ERROR_CODE,
IRQ_RANGING_MASTER_VALID_CODE,
} IrqRangingCode_t;
/*!
* \brief Structure describing the error codes for callback functions
*/
typedef enum {
IRQ_HEADER_ERROR_CODE = 0x00,
IRQ_SYNCWORD_ERROR_CODE,
IRQ_CRC_ERROR_CODE,
IRQ_RANGING_ON_LORA_ERROR_CODE,
} IrqErrorCode_t;
/*!
* \brief Structure describing the validity codes for callback function rxValid
*/
typedef enum {
IRQ_HEADER_VALID_CODE = 0x00,
IRQ_SYNCWORD_VALID_CODE,
} IrqValidCode_t;
/*!
* \brief Represents all possible opcode understood by the radio
*/
typedef enum RadioCommands_u {
RADIO_GET_STATUS = 0xC0,
RADIO_WRITE_REGISTER = 0x18,
RADIO_READ_REGISTER = 0x19,
RADIO_WRITE_BUFFER = 0x1A,
RADIO_READ_BUFFER = 0x1B,
RADIO_SET_SLEEP = 0x84,
RADIO_SET_STANDBY = 0x80,
RADIO_SET_FS = 0xC1,
RADIO_SET_TX = 0x83,
RADIO_SET_RX = 0x82,
RADIO_SET_RXDUTYCYCLE = 0x94,
RADIO_SET_CAD = 0xC5,
RADIO_SET_TXCONTINUOUSWAVE = 0xD1,
RADIO_SET_TXCONTINUOUSPREAMBLE = 0xD2,
RADIO_SET_PACKETTYPE = 0x8A,
RADIO_GET_PACKETTYPE = 0x03,
RADIO_SET_RFFREQUENCY = 0x86,
RADIO_SET_TXPARAMS = 0x8E,
RADIO_SET_CADPARAMS = 0x88,
RADIO_SET_BUFFERBASEADDRESS = 0x8F,
RADIO_SET_MODULATIONPARAMS = 0x8B,
RADIO_SET_PACKETPARAMS = 0x8C,
RADIO_GET_RXBUFFERSTATUS = 0x17,
RADIO_GET_PACKETSTATUS = 0x1D,
RADIO_GET_RSSIINST = 0x1F,
RADIO_SET_DIOIRQPARAMS = 0x8D,
RADIO_GET_IRQSTATUS = 0x15,
RADIO_CLR_IRQSTATUS = 0x97,
RADIO_CALIBRATE = 0x89,
RADIO_SET_REGULATORMODE = 0x96,
RADIO_SET_SAVECONTEXT = 0xD5,
RADIO_SET_AUTOTX = 0x98,
RADIO_SET_AUTOFS = 0x9E,
RADIO_SET_LONGPREAMBLE = 0x9B,
RADIO_SET_UARTSPEED = 0x9D,
RADIO_SET_RANGING_ROLE = 0xA3,
} RadioCommands_t;
/*!
* \brief Radio registers definition
*
*/
typedef struct
{
uint16_t Addr; //!< The address of the register
uint8_t Value; //!< The value of the register
} RadioRegisters_t;
/*!
* \brief Radio hardware registers initialization definition
*/
// #define RADIO_INIT_REGISTERS_VALUE { }
/*!