7. How to use Timer Interrupts in 1SJ LoRa Device?

To understand how the timer interrupt works in our 1SJ device, let us first look at lora_app.c
Navigate to the function LoRaWAN_Init in line 222 and take a look at the timer functions seen below.

In the function LoRaWAN_Init, we can see many timer functions defined. Let us take a look at the timer function inside the yellow box as an example.
Generally, the 1SJ timer interrupts are executed in 4 steps:
| |
1. |
The timer object is first defined as "TxTimer" seen in line 181 in lora_app.c |
| |
|
 |
| |
2. |
Next, the timer interrupt is created using UTIL_TIMER_Create as seen in line 277. |
| |
3. |
Next, the timer interval is set using UTIL_TIMER_SetPeriod as seen in line 278.
(Units is in milliseconds) |
| |
4. |
Lastly, the timer is started with UTIL_TIMER_Start as seen in line 279. |
| |
|
 |
Definition of UTIL Functions:
To look at the details and parameters of each UTIL function, we can directly look it up inside Keil.
For example, for UTIL_TIMER_Create, we can highlight the function, right click and click Go To Definition as seen below.

As seen below, the function takes into account 5 parameters:
| |
1. |
Timer Object |
|
2. |
Tentative Timer Interval (The actual timer interval is set using UTIL_TIMER_SetPeriod) |
|
3. |
Timer Mode (Either "ONE_SHOT" or "PERIODIC") |
|
4. |
Call back function for this timer interrupt |
|
5. |
NULL parameter |
|
|

|
Let us now take a look at the callback function that was used for this UTIL function. The callback function as seen in the 4th parameter of the UTIL_TIMER_Create function is known as OnTxTimerEvent.

We will once again highlight the function, right click and Go To Definition.

As seen in the OnTxTimerEvent function defined below, it calls the task sequencer which will be elaborated in the next section.
