1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup lpc24xx |
---|
5 | * |
---|
6 | * @brief RTC configuration. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2008 |
---|
11 | * Embedded Brains GmbH |
---|
12 | * Obere Lagerstr. 30 |
---|
13 | * D-82178 Puchheim |
---|
14 | * Germany |
---|
15 | * rtems@embedded-brains.de |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be found in the file |
---|
18 | * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <libchip/rtc.h> |
---|
22 | |
---|
23 | #include <bsp/lpc24xx.h> |
---|
24 | |
---|
25 | #define LPC24XX_RTC_NUMBER 1 |
---|
26 | |
---|
27 | static void lpc24xx_rtc_initialize( int minor) |
---|
28 | { |
---|
29 | /* Enable the RTC and use external clock */ |
---|
30 | RTC_CCR = RTC_CCR_CLKEN | RTC_CCR_CLKSRC; |
---|
31 | |
---|
32 | /* Disable interrupts */ |
---|
33 | RTC_CIIR = 0; |
---|
34 | RTC_CISS = 0; |
---|
35 | RTC_AMR = 0xff; |
---|
36 | |
---|
37 | /* Clear interrupts */ |
---|
38 | RTC_ILR = RTC_ILR_RTCCIF | RTC_ILR_RTCALF | RTC_ILR_RTSSF; |
---|
39 | } |
---|
40 | |
---|
41 | static int lpc24xx_rtc_get_time( int minor, rtems_time_of_day *tod) |
---|
42 | { |
---|
43 | tod->ticks = 0; |
---|
44 | tod->second = RTC_SEC; |
---|
45 | tod->minute = RTC_MIN; |
---|
46 | tod->hour = RTC_HOUR; |
---|
47 | tod->day = RTC_DOM; |
---|
48 | tod->month = RTC_MONTH; |
---|
49 | tod->year = RTC_YEAR; |
---|
50 | |
---|
51 | return 0; |
---|
52 | } |
---|
53 | |
---|
54 | static int lpc24xx_rtc_set_time( int minor, const rtems_time_of_day *tod) |
---|
55 | { |
---|
56 | RTC_SEC = tod->second; |
---|
57 | RTC_MIN = tod->minute; |
---|
58 | RTC_HOUR = tod->hour; |
---|
59 | RTC_DOM = tod->day; |
---|
60 | RTC_MONTH = tod->month; |
---|
61 | RTC_YEAR = tod->year; |
---|
62 | |
---|
63 | return 0; |
---|
64 | } |
---|
65 | |
---|
66 | static bool lpc24xx_rtc_probe( int minor) |
---|
67 | { |
---|
68 | return true; |
---|
69 | } |
---|
70 | |
---|
71 | const rtc_fns lpc24xx_rtc_ops = { |
---|
72 | .deviceInitialize = lpc24xx_rtc_initialize, |
---|
73 | .deviceGetTime = lpc24xx_rtc_get_time, |
---|
74 | .deviceSetTime = lpc24xx_rtc_set_time |
---|
75 | }; |
---|
76 | |
---|
77 | unsigned long RTC_Count = LPC24XX_RTC_NUMBER; |
---|
78 | |
---|
79 | rtems_device_minor_number RTC_Minor = 0; |
---|
80 | |
---|
81 | rtc_tbl RTC_Table [LPC24XX_RTC_NUMBER] = { |
---|
82 | { |
---|
83 | .sDeviceName = "/dev/rtc", |
---|
84 | .deviceType = RTC_CUSTOM, |
---|
85 | .pDeviceFns = &lpc24xx_rtc_ops, |
---|
86 | .deviceProbe = lpc24xx_rtc_probe, |
---|
87 | .pDeviceParams = NULL, |
---|
88 | .ulCtrlPort1 = 0, |
---|
89 | .ulDataPort = 0, |
---|
90 | .getRegister = NULL, |
---|
91 | .setRegister = NULL |
---|
92 | } |
---|
93 | }; |
---|