LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
rtc.c
Go to the documentation of this file.
1
/*------------------------------------------------------------------------/
2
/RTC control module
3
/-------------------------------------------------------------------------/
4
/
5
/ Copyright (C) 2011, ChaN, all right reserved.
6
/
7
/ * This software is a free software and there is NO WARRANTY.
8
/ * No restriction on use. You can use, modify and redistribute it for
9
/ personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
10
/ * Redistributions of source code must retain the above copyright notice.
11
/
12
/-------------------------------------------------------------------------*/
13
14
#include "chip.h"
15
#include "board.h"
16
#include "
rtc.h
"
17
18
19
int
rtc_initialize
(
void
)
20
{
21
static
int
init;
22
IP_RTC_TIME_T
rtcTime;
23
24
if
(init)
/* Already initialized */
25
return
1;
26
27
/* RTC Block section ------------------------------------------------------ */
28
Chip_RTC_Init
(
LPC_RTC
);
29
30
/* Set current time for RTC */
31
/* Current time is 8:00:00PM, 2013-01-31 */
32
rtcTime.
time
[
RTC_TIMETYPE_SECOND
] = 0;
33
rtcTime.
time
[
RTC_TIMETYPE_MINUTE
] = 0;
34
rtcTime.
time
[
RTC_TIMETYPE_HOUR
] = 20;
35
rtcTime.
time
[
RTC_TIMETYPE_DAYOFMONTH
] = 31;
36
rtcTime.
time
[
RTC_TIMETYPE_MONTH
] = 1;
37
rtcTime.
time
[
RTC_TIMETYPE_YEAR
] = 2013;
38
Chip_RTC_SetFullAlarmTime
(
LPC_RTC
, &rtcTime);
39
40
/* Enable rtc (starts increase the tick counter and second counter register) */
41
Chip_RTC_Enable
(
LPC_RTC
,
ENABLE
);
42
init = 1;
43
44
return
1;
45
}
46
47
int
rtc_gettime
(
RTC
*rtc)
48
{
49
IP_RTC_TIME_T
rtcTime;
50
51
Chip_RTC_GetFullTime
(
LPC_RTC
, &rtcTime);
52
53
rtc->
sec
= rtcTime.
time
[
RTC_TIMETYPE_SECOND
];
54
rtc->
min
= rtcTime.
time
[
RTC_TIMETYPE_MINUTE
];
55
rtc->
hour
= rtcTime.
time
[
RTC_TIMETYPE_HOUR
];
56
rtc->
wday
= rtcTime.
time
[
RTC_TIMETYPE_DAYOFWEEK
];
57
rtc->
mday
= rtcTime.
time
[
RTC_TIMETYPE_DAYOFMONTH
];
58
rtc->
month
= rtcTime.
time
[
RTC_TIMETYPE_MONTH
];
59
rtc->
year
= rtcTime.
time
[
RTC_TIMETYPE_YEAR
];
60
return
1;
61
}
62
63
int
rtc_settime
(
const
RTC
*rtc)
64
{
65
IP_RTC_TIME_T
rtcTime;
66
67
rtcTime.
time
[
RTC_TIMETYPE_SECOND
] = rtc->
sec
;
68
rtcTime.
time
[
RTC_TIMETYPE_MINUTE
] = rtc->
min
;
69
rtcTime.
time
[
RTC_TIMETYPE_HOUR
] = rtc->
hour
;
70
rtcTime.
time
[
RTC_TIMETYPE_DAYOFMONTH
] = rtc->
wday
;
71
rtcTime.
time
[
RTC_TIMETYPE_DAYOFMONTH
] = rtc->
mday
;
72
rtcTime.
time
[
RTC_TIMETYPE_MONTH
] = rtc->
month
;
73
rtcTime.
time
[
RTC_TIMETYPE_YEAR
] = rtc->
year
;
74
75
Chip_RTC_GetFullTime
(
LPC_RTC
, &rtcTime);
76
77
return
1;
78
}
79
87
DWORD
get_fattime
()
88
{
89
RTC
rtc;
90
91
/* Get local time */
92
rtc_gettime
(&rtc);
93
94
/* Pack date and time into a DWORD variable */
95
return
((
DWORD
) (rtc.
year
- 1980) << 25)
96
| ((
DWORD
) rtc.
month
<< 21)
97
| ((
DWORD
) rtc.
mday
<< 16)
98
| ((
DWORD
) rtc.
hour
<< 11)
99
| ((
DWORD
) rtc.
min
<< 5)
100
| ((
DWORD
) rtc.
sec
>> 1);
101
}
software
filesystems
fatfslpc
rtc.c
Generated on Fri May 10 2013 10:42:08 for LPCOpen Platform by
1.8.2