1 /*!
2 * \file main.c
3 *
4 * \brief Tx Continuous Wave implementation
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 #include "board.h"
24 #include "gpio.h"
25 #include "timer.h"
26 #include "radio.h"
27
28 #if defined( REGION_AS923 )
29
30 #define RF_FREQUENCY 923000000 // Hz
31 #define TX_OUTPUT_POWER 14 // 14 dBm
32
33 #elif defined( REGION_AU915 )
34
35 #define RF_FREQUENCY 915000000 // Hz
36 #define TX_OUTPUT_POWER 14 // 14 dBm
37
38 #elif defined( REGION_CN470 )
39
40 #define RF_FREQUENCY 470000000 // Hz
41 #define TX_OUTPUT_POWER 20 // 20 dBm
42
43 #elif defined( REGION_CN779 )
44
45 #define RF_FREQUENCY 779000000 // Hz
46 #define TX_OUTPUT_POWER 14 // 14 dBm
47
48 #elif defined( REGION_EU433 )
49
50 #define RF_FREQUENCY 433000000 // Hz
51 #define TX_OUTPUT_POWER 20 // 20 dBm
52
53 #elif defined( REGION_EU868 )
54
55 #define RF_FREQUENCY 868000000 // Hz
56 #define TX_OUTPUT_POWER 14 // 14 dBm
57
58 #elif defined( REGION_KR920 )
59
60 #define RF_FREQUENCY 920000000 // Hz
61 #define TX_OUTPUT_POWER 14 // 14 dBm
62
63 #elif defined( REGION_IN865 )
64
65 #define RF_FREQUENCY 865000000 // Hz
66 #define TX_OUTPUT_POWER 14 // 14 dBm
67
68 #elif defined( REGION_US915 )
69
70 #define RF_FREQUENCY 915000000 // Hz
71 #define TX_OUTPUT_POWER 14 // 14 dBm
72
73 #elif defined( REGION_RU864 )
74
75 #define RF_FREQUENCY 864000000 // Hz
76 #define TX_OUTPUT_POWER 14 // 14 dBm
77
78 #else
79
80 #error "Please define a frequency band in the compiler options."
81
82 #endif
83 #define TX_TIMEOUT 10 // seconds (MAX value)
84
85 static TimerEvent_t Led1Timer;
86 volatile bool Led1TimerEvent = false;
87
88 static TimerEvent_t Led2Timer;
89 volatile bool Led2TimerEvent = false;
90
91 /*!
92 * Radio events function pointer
93 */
94 static RadioEvents_t RadioEvents;
95
96 /*!
97 * LED GPIO pins objects
98 */
99 extern Gpio_t Led1;
100 extern Gpio_t Led2;
101
102 /*!
103 * \brief Function executed on Led 1 Timeout event
104 */
OnLed1TimerEvent(void * context)105 void OnLed1TimerEvent( void* context )
106 {
107 Led1TimerEvent = true;
108 }
109
110 /*!
111 * \brief Function executed on Led 2 Timeout event
112 */
OnLed2TimerEvent(void * context)113 void OnLed2TimerEvent( void* context )
114 {
115 Led2TimerEvent = true;
116 }
117
118 /*!
119 * \brief Function executed on Radio Tx Timeout event
120 */
OnRadioTxTimeout(void)121 void OnRadioTxTimeout( void )
122 {
123 // Restarts continuous wave transmission when timeout expires
124 Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT );
125 }
126
127 /**
128 * Main application entry point.
129 */
main(void)130 int main( void )
131 {
132 // Target board initialization
133 BoardInitMcu( );
134 BoardInitPeriph( );
135
136 TimerInit( &Led1Timer, OnLed1TimerEvent );
137 TimerSetValue( &Led1Timer, 90 );
138
139 TimerInit( &Led2Timer, OnLed2TimerEvent );
140 TimerSetValue( &Led2Timer, 90 );
141
142 // Switch LED 1 ON
143 GpioWrite( &Led1, 0 );
144 TimerStart( &Led1Timer );
145
146 // Radio initialization
147 RadioEvents.TxTimeout = OnRadioTxTimeout;
148 Radio.Init( &RadioEvents );
149
150 Radio.SetTxContinuousWave( RF_FREQUENCY, TX_OUTPUT_POWER, TX_TIMEOUT );
151
152 // Blink LEDs just to show some activity
153 while( 1 )
154 {
155 // Process Radio IRQ
156 if( Radio.IrqProcess != NULL )
157 {
158 Radio.IrqProcess( );
159 }
160 if( Led1TimerEvent == true )
161 {
162 Led1TimerEvent = false;
163
164 // Switch LED 1 OFF
165 GpioWrite( &Led1, 1 );
166 // Switch LED 2 ON
167 GpioWrite( &Led2, 0 );
168 TimerStart( &Led2Timer );
169 }
170
171 if( Led2TimerEvent == true )
172 {
173 Led2TimerEvent = false;
174
175 // Switch LED 2 OFF
176 GpioWrite( &Led2, 1 );
177 // Switch LED 1 ON
178 GpioWrite( &Led1, 0 );
179 TimerStart( &Led1Timer );
180 }
181 }
182 }
183