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.h"
29 #include "gpio.h"
30 #include "timer.h"
31 #include "radio.h"
32
33 #if defined( REGION_AS923 )
34
35 #define RF_FREQUENCY 923000000 // Hz
36
37 #elif defined( REGION_AU915 )
38
39 #define RF_FREQUENCY 915000000 // Hz
40
41 #elif defined( REGION_CN779 )
42
43 #define RF_FREQUENCY 779000000 // Hz
44
45 #elif defined( REGION_EU868 )
46
47 #define RF_FREQUENCY 868000000 // Hz
48
49 #elif defined( REGION_KR920 )
50
51 #define RF_FREQUENCY 920000000 // Hz
52
53 #elif defined( REGION_IN865 )
54
55 #define RF_FREQUENCY 865000000 // Hz
56
57 #elif defined( REGION_US915 )
58
59 #define RF_FREQUENCY 915000000 // Hz
60
61 #elif defined( REGION_RU864 )
62
63 #define RF_FREQUENCY 864000000 // Hz
64
65 #else
66 #error "Please define a frequency band in the compiler options."
67 #endif
68
69 #if defined( USE_MODEM_LORA )
70
71 #define LORA_BANDWIDTH 0 // [0: 125 kHz,
72 // 1: 250 kHz,
73 // 2: 500 kHz,
74 // 3: Reserved]
75 #define LORA_SPREADING_FACTOR 10 // [SF7..SF12]
76 #define LORA_CODINGRATE 1 // [1: 4/5,
77 // 2: 4/6,
78 // 3: 4/7,
79 // 4: 4/8]
80 #define LORA_SYMBOL_TIMEOUT 5 // Symbols
81 #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
82 #define LORA_FIX_LENGTH_PAYLOAD_ON false
83 #define LORA_IQ_INVERSION_ON false
84
85 #elif defined( USE_MODEM_FSK )
86
87 #define FSK_DATARATE 50000 // bps
88 #define FSK_BANDWIDTH 50000 // Hz
89 #define FSK_AFC_BANDWIDTH 83333 // Hz
90 #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx
91 #define FSK_FIX_LENGTH_PAYLOAD_ON false
92
93 #else
94 #error "Please define a modem in the compiler options."
95 #endif
96
97 /*!
98 * Radio events function pointer
99 */
100 static RadioEvents_t RadioEvents;
101
102 /*!
103 * LED GPIO pins objects
104 */
105 extern Gpio_t Led4;
106
107 /*!
108 * \brief Function to be executed on Radio Rx Done event
109 */
110 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
111
112 /*!
113 * Main application entry point.
114 */
main(void)115 int main( void )
116 {
117 // Target board initialization
118 BoardInitMcu( );
119 BoardInitPeriph( );
120
121 // Radio initialization
122 RadioEvents.RxDone = OnRxDone;
123
124 Radio.Init( &RadioEvents );
125
126 Radio.SetChannel( RF_FREQUENCY );
127
128 #if defined( USE_MODEM_LORA )
129
130 Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
131 LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
132 LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
133 0, true, 0, 0, LORA_IQ_INVERSION_ON, true );
134
135 Radio.SetMaxPayloadLength( MODEM_LORA, 255 );
136
137 #elif defined( USE_MODEM_FSK )
138
139 Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
140 0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
141 0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, true,
142 0, 0, false, true );
143
144 Radio.SetMaxPayloadLength( MODEM_FSK, 255 );
145
146 #else
147 #error "Please define a frequency band in the compiler options."
148 #endif
149
150 Radio.Rx( 0 ); // Continuous Rx
151
152 while( 1 )
153 {
154 BoardLowPowerHandler( );
155 }
156 }
157
OnRxDone(uint8_t * payload,uint16_t size,int16_t rssi,int8_t snr)158 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
159 {
160 static uint8_t ledState = 1;
161 // Toggle LED 4
162 ledState ^= 1;
163 GpioWrite( &Led4, ledState );
164 }
165