1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSBSPsARMLPC176X |
---|
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 |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * http://www.rtems.org/license/LICENSE. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <libchip/rtc.h> |
---|
23 | #include <bsp/io.h> |
---|
24 | |
---|
25 | #define LPC176X_RTC_NUMBER 1U |
---|
26 | |
---|
27 | void bsp_rtc_initialize( void ); |
---|
28 | int bsp_rtc_get_time( rtems_time_of_day *tod ); |
---|
29 | int bsp_rtc_set_time( const rtems_time_of_day *tod ); |
---|
30 | bool bsp_rtc_probe( void ); |
---|
31 | |
---|
32 | /** |
---|
33 | * @brief Initialize the rtc device. |
---|
34 | */ |
---|
35 | void bsp_rtc_initialize( void ) |
---|
36 | { |
---|
37 | /* Enable module power */ |
---|
38 | lpc176x_module_enable( LPC176X_MODULE_RTC, LPC176X_MODULE_PCLK_DEFAULT ); |
---|
39 | |
---|
40 | /* Enable the RTC and use external clock */ |
---|
41 | RTC_CCR = RTC_CCR_CLKEN | RTC_CCR_CLKSRC; |
---|
42 | |
---|
43 | /* Disable interrupts */ |
---|
44 | RTC_CIIR = 0U; |
---|
45 | RTC_CISS = 0U; |
---|
46 | RTC_AMR = 0xFFU; |
---|
47 | |
---|
48 | /* Clear interrupts */ |
---|
49 | RTC_ILR = RTC_ILR_RTCCIF | RTC_ILR_RTCALF | RTC_ILR_RTSSF; |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * @brief Gets the information according to the current time. |
---|
54 | * |
---|
55 | * @param tod Value to be modified. |
---|
56 | * @return 0 |
---|
57 | */ |
---|
58 | int bsp_rtc_get_time( rtems_time_of_day *tod ) |
---|
59 | { |
---|
60 | tod->ticks = 0; |
---|
61 | tod->second = RTC_SEC; |
---|
62 | tod->minute = RTC_MIN; |
---|
63 | tod->hour = RTC_HOUR; |
---|
64 | tod->day = RTC_DOM; |
---|
65 | tod->month = RTC_MONTH; |
---|
66 | tod->year = RTC_YEAR; |
---|
67 | |
---|
68 | return 0; |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * @brief Sets the information according to the current time. |
---|
73 | * |
---|
74 | * @param tod Value to get the new information. |
---|
75 | * @return 0 |
---|
76 | */ |
---|
77 | int bsp_rtc_set_time( const rtems_time_of_day *tod ) |
---|
78 | { |
---|
79 | RTC_SEC = tod->second; |
---|
80 | RTC_MIN = tod->minute; |
---|
81 | RTC_HOUR = tod->hour; |
---|
82 | RTC_DOM = tod->day; |
---|
83 | RTC_MONTH = tod->month; |
---|
84 | RTC_YEAR = tod->year; |
---|
85 | |
---|
86 | return 0; |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * @brief Used to probe. At the moment is not used. |
---|
91 | * |
---|
92 | * @return true. |
---|
93 | */ |
---|
94 | bool bsp_rtc_probe( void ) |
---|
95 | { |
---|
96 | return true; |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief Represents the real time clock options. |
---|
101 | */ |
---|
102 | const rtc_fns lpc176x_rtc_ops = { |
---|
103 | .deviceInitialize = (void *) bsp_rtc_initialize, |
---|
104 | .deviceGetTime = (void *) bsp_rtc_get_time, |
---|
105 | .deviceSetTime = (void *) bsp_rtc_set_time |
---|
106 | }; |
---|
107 | |
---|
108 | size_t RTC_Count = LPC176X_RTC_NUMBER; |
---|
109 | |
---|
110 | /** |
---|
111 | * @brief Table to describes the rtc device. |
---|
112 | */ |
---|
113 | rtc_tbl RTC_Table[ LPC176X_RTC_NUMBER ] = { |
---|
114 | { |
---|
115 | .sDeviceName = "/dev/rtc", |
---|
116 | .deviceType = RTC_CUSTOM, |
---|
117 | .pDeviceFns = &lpc176x_rtc_ops, |
---|
118 | .deviceProbe = (void *) bsp_rtc_probe, |
---|
119 | .pDeviceParams = NULL, |
---|
120 | .ulCtrlPort1 = 0, |
---|
121 | .ulDataPort = 0, |
---|
122 | .getRegister = NULL, |
---|
123 | .setRegister = NULL |
---|
124 | } |
---|
125 | }; |
---|