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