1 /*!
2 * \file main.c
3 *
4 * \brief Radio sensitivity test
5 *
6 * \remark When LED1 stops blinking LoRa packets aren't received any more and
7 * the sensitivity level has been reached.
8 * By reading the RF generator output power we can estimate the board
9 * sensitivity
10 *
11 * \copyright Revised BSD License, see section \ref LICENSE.
12 *
13 * \code
14 * ______ _
15 * / _____) _ | |
16 * ( (____ _____ ____ _| |_ _____ ____| |__
17 * \____ \| ___ | (_ _) ___ |/ ___) _ \
18 * _____) ) ____| | | || |_| ____( (___| | | |
19 * (______/|_____)_|_|_| \__)_____)\____)_| |_|
20 * (C)2013-2017 Semtech
21 *
22 * \endcode
23 *
24 * \author Miguel Luis ( Semtech )
25 *
26 * \author Gregory Cristian ( Semtech )
27 */
28 #include "board-config.h"
29 #include "board.h"
30 #include "gpio.h"
31 #include "timer.h"
32 #include "radio.h"
33
34 #if defined( REGION_AS923 )
35
36 #define RF_FREQUENCY 923000000 // Hz
37
38 #elif defined( REGION_AU915 )
39
40 #define RF_FREQUENCY 915000000 // Hz
41
42 #elif defined( REGION_CN779 )
43
44 #define RF_FREQUENCY 779000000 // Hz
45
46 #elif defined( REGION_EU868 )
47
48 #define RF_FREQUENCY 868000000 // Hz
49
50 #elif defined( REGION_KR920 )
51
52 #define RF_FREQUENCY 920000000 // Hz
53
54 #elif defined( REGION_IN865 )
55
56 #define RF_FREQUENCY 865000000 // Hz
57
58 #elif defined( REGION_US915 )
59
60 #define RF_FREQUENCY 915000000 // Hz
61
62 #elif defined( REGION_RU864 )
63
64 #define RF_FREQUENCY 864000000 // Hz
65
66 #else
67 #error "Please define a frequency band in the compiler options."
68 #endif
69
70 #if defined( USE_MODEM_LORA )
71
72 #define LORA_BANDWIDTH 0 // [0: 125 kHz,
73 // 1: 250 kHz,
74 // 2: 500 kHz,
75 // 3: Reserved]
76 #define LORA_SPREADING_FACTOR 10 // [SF7..SF12]
77 #define LORA_CODINGRATE 1 // [1: 4/5,
78 // 2: 4/6,
79 // 3: 4/7,
80 // 4: 4/8]
81 #define LORA_SYMBOL_TIMEOUT 5 // Symbols
82 #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
83 #define LORA_FIX_LENGTH_PAYLOAD_ON false
84 #define LORA_IQ_INVERSION_ON false
85
86 #elif defined( USE_MODEM_FSK )
87
88 #define FSK_DATARATE 50000 // bps
89 #define FSK_BANDWIDTH 50000 // Hz
90 #define FSK_AFC_BANDWIDTH 83333 // Hz
91 #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx
92 #define FSK_FIX_LENGTH_PAYLOAD_ON false
93
94 #else
95 #error "Please define a modem in the compiler options."
96 #endif
97
98 /*!
99 * Radio events function pointer
100 */
101 static RadioEvents_t RadioEvents;
102
103 /*!
104 * LED GPIO pins objects
105 */
106 extern Gpio_t Led1;
107
108 /*!
109 * \brief Function to be executed on Radio Rx Done event
110 */
111 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
112
113 /*!
114 * Main application entry point.
115 */
main(void)116 int main( void )
117 {
118 // Target board initialization
119 BoardInitMcu( );
120 BoardInitPeriph( );
121
122 // Radio initialization
123 RadioEvents.RxDone = OnRxDone;
124
125 Radio.Init( &RadioEvents );
126
127 Radio.SetChannel( RF_FREQUENCY );
128
129 #if defined( USE_MODEM_LORA )
130
131 Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
132 LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
133 LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
134 0, true, 0, 0, LORA_IQ_INVERSION_ON, true );
135
136 Radio.SetMaxPayloadLength( MODEM_LORA, 255 );
137
138 #elif defined( USE_MODEM_FSK )
139
140 Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
141 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
142 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true,
143 0, 0, false, true );
144
145 Radio.SetMaxPayloadLength( MODEM_FSK, 255 );
146
147 #else
148 #error "Please define a frequency band in the compiler options."
149 #endif
150
151 Radio.Rx( 0 ); // Continuous Rx
152
153 while( 1 )
154 {
155 BoardLowPowerHandler( );
156 }
157 }
158
OnRxDone(uint8_t * payload,uint16_t size,int16_t rssi,int8_t snr)159 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
160 {
161 static uint8_t ledState = 1;
162 // Toggle LED 1
163 ledState ^= 1;
164 GpioWrite( &Led1, ledState );
165 }
166