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