/
alarm.c
128 lines (123 loc) · 3.06 KB
/
alarm.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <time.h>
#include "rtc.h"
/*
* Returns 1 if t1>t2, -1 if t1<t2, 0 if t1==t2
*/
int compare_time(tm *t1, tm *t2)
{
int retval = 0;
// printf("Compare time\n");
if(t1->tm_mon < t2->tm_mon){
retval = -1;
goto end;
}
else if(t1->tm_mon > t2->tm_mon){
retval = 1;
goto end;
}
else {
//continue on checking members
// printf("mon ==\n");
if (t1->tm_mday < t2->tm_mday) {
retval = -1;
goto end;
}
else if (t1->tm_mday > t2->tm_mday) {
retval = 1;
goto end;
}
else {
//continue on checking members
// printf("mday ==\n");
if (t1->tm_hour < t2->tm_hour) {
retval = -1;
goto end;
}
else if (t1->tm_hour > t2->tm_hour) {
retval = 1;
goto end;
}
else {
//continue on checking members
// printf("hour ==\n");
if (t1->tm_min < t2->tm_min) {
retval = -1;
goto end;
}
else if (t1->tm_min > t2->tm_min) {
retval = 1;
goto end;
}
else {
// printf("min ==\n");
//continue on checking members
if (t1->tm_sec < t2->tm_sec) {
retval = -1;
goto end;
}
else if (t1->tm_sec > t2->tm_sec) {
retval = 1;
goto end;
}
else {
//They're equal;
retval = 0;
goto end;
}
}
}
}
}
end:
return retval;
}
int compare_time_minhour(tm *t1, tm *t2)
{
int retval = 0;
// printf("Compare time\n");
if (t1->tm_hour < t2->tm_hour) {
retval = -1;
goto end;
}
else if (t1->tm_hour > t2->tm_hour) {
retval = 1;
goto end;
}
else {
//continue on checking members
// printf("hour ==\n");
if (t1->tm_min < t2->tm_min) {
retval = -1;
goto end;
}
else if (t1->tm_min > t2->tm_min) {
retval = 1;
goto end;
}
else {
retval = 0;
goto end;
}
}
end:
return retval;
}
tm get_alarm(int alarmid){
tm time;
int* flags;
X12RtcGetAlarm(alarmid, &time, &flags);
return time;
}
/*
* \param aflgs Each bit enables a specific comparision.
* - Bit 0: Seconds
* - Bit 1: Minutes
* - Bit 2: Hours
* - Bit 3: Day of month
* - Bit 4: Month
* - Bit 7: Day of week (Sunday is zero)
*/
void set_alarm(int alarmid, tm time){
int flags = 0b00000110; // minutes, hours
X12RtcSetAlarm(alarmid, &time, flags);
}