-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer_funcs.c
51 lines (37 loc) · 1.24 KB
/
timer_funcs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* timer_funcs.c
*
* Created on: 29/12/2023
* Author: carlos
*/
#include "timer_funcs.h"
// Queue handle
QueueHandle_t xTimerQueue;
// Counter variable
uint32_t counter = 0;
// Initialize Timer0A
void Timer0A_Init(void) {
// Enable of periferic of timer 0
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
// Configures timer 0 to operate in periodic more, and enables the timer itself
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerEnable(TIMER0_BASE, TIMER_A);
// Defines the recharge of timer 0 to 10 seconds
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet());
// Registers the interrupt handler of timer 0
TimerIntRegister(TIMER0_BASE, TIMER_A, timer_count_time);
// Enable of itnerrupt of timer 0
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Interrupt global enable
IntMasterEnable();
}
//Function that adds a second to the counter and passes it on to a queue
void timer_count_time(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet());
counter++;
xQueueOverwriteFromISR(xTimerQueue, &counter, NULL);
BaseType_t xHigherPriorityTaskWoken = pdTRUE;
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}