-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTC.c
63 lines (49 loc) · 1.15 KB
/
RTC.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
/*
* Desc:
* Author: Prangon Das ([email protected])
*/
#include "MKL46Z4.h"
#include "RTC.h"
uint32_t seconds = 0;
uint32_t alarm = 0;
void init_RTC_IRQ(uint8_t interrupt) {
SIM->SCGC6 |= SIM_SCGC6_RTC_MASK;
interrupt ? (NVIC->IP[RTC_IPR_REGISTER] |= NVIC_IPR_RTC_ALARM_MASK) : (NVIC->IP[RTC_IPR_REGISTER] |=
NVIC_IPR_RTC_SEC_MASK);
interrupt ? (NVIC->ICPR[0] |= NVIC_ICPR_RTC_ALARM_MASK) : (NVIC->ICPR[0] |=
NVIC_ICPR_RTC_SEC_MASK);
interrupt ? (NVIC->ISER[0] |= NVIC_ISER_RTC_ALARM_MASK) : (NVIC->ISER[0] |=
NVIC_ISER_RTC_SEC_MASK);
interrupt ? (RTC->IER = RTC_IER_TAIE_MASK) : (RTC->IER |= RTC_IER_TSIE_O_MASK);
RTC->CR = RTC_CR_CLK_OSC_WK;
}
void RTC_alarmSet(uint32_t time){
RTC->TAR = time;
}
void RTC_start(){
RTC->TSR |= RTC->TSR;
RTC->SR |= RTC_SR_TCE_MASK;
}
uint32_t RTC_getAlarm(){
return alarm;
}
uint32_t RTC_getSeconds(){
return seconds;
}
void RTC_reset(){
RTC->CR |= RTC_CR_SWR_MASK;
RTC->CR &= ~RTC_CR_SWR_MASK;
seconds = 0;
alarm = 0;
}
void RTC_IRQHandler(){
__asm("CPSID I");
alarm++;
RTC->TAR |= RTC->TAR;
__asm("CPSIE I");
}
void RTC_Seconds_IRQHandler(){
__asm("CPSID I");
seconds++;
__asm("CPSIE I");
}