forked from JohnsonShen/NuBrick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer1IRQ.c
66 lines (55 loc) · 2.37 KB
/
timer1IRQ.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*=============================================================*
* _ _ ___ _ _ *
* | \| | _ _ | _ ) _ _ (_) __ | |__ *
* | .` | | +| | | _ \ | '_| | | / _| | / / *
* |_|\_| \_,_| |___/ _|_|_ _|_|_ \__|_ |_\_\ *
*_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| *
*"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' *
* *
* NuBrick IoT applications firmware *
* *
* Written by MB40 for Nuvoton Technology. *
* tlshen@nuvoton.com/tzulan611126@gmail.com *
* HCHEISH@nuvoton.com *
*=============================================================*
*/
#include "timer1IRQ.h"
volatile uint32_t TMR1INTCount; // 1s timer counter
// *************************************************************************
// Timer1 initialize setting
// Sleep every 1s and wake up
// *************************************************************************
void Timer1Init()
{
/* Enable peripheral clock */
CLK_EnableModuleClock(TMR1_MODULE);
/* Peripheral clock source */
CLK_SetModuleClock(TMR1_MODULE, CLK_CLKSEL1_TMR1SEL_LIRC, 0);
/* Enable Timer0 NVIC */
NVIC_EnableIRQ(TMR1_IRQn);
/* Open Timer0 time-out frequency to 1 Hz in periodic mode */
TIMER_Open(TIMER1, TIMER_PERIODIC_MODE, 1);
/* Enable Timer0 time-out interrupt and wake-up function */
TIMER_EnableInt(TIMER1);
TIMER_EnableWakeup(TIMER1);
/* Start Timer0 counting */
TIMER_Start(TIMER1);
}
/*---------------------------------------------------------------------------------------------------------*/
/* TMR1 IRQ handler */
/*---------------------------------------------------------------------------------------------------------*/
void TMR1_IRQHandler(void)
{
if(TIMER_GetIntFlag(TIMER1) == 1)
{
/* Clear Timer0 time-out interrupt flag */
TIMER_ClearIntFlag(TIMER1);
TMR1INTCount++;
}
if(TIMER_GetWakeupFlag(TIMER1) == 1)
{
/* Clear Timer0 wake-up flag */
TIMER_ClearWakeupFlag(TIMER1);
printf("I'm awake by TMR.\n");
}
}