[5aeed17] | 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 | * |
---|
[0e27119] | 17 | * The license and distribution terms for this file may be |
---|
| 18 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 19 | * http://www.rtems.org/license/LICENSE. |
---|
[5aeed17] | 20 | */ |
---|
| 21 | |
---|
| 22 | #include <libchip/rtc.h> |
---|
| 23 | |
---|
| 24 | #include <bsp/lpc24xx.h> |
---|
[7ae2775] | 25 | #include <bsp/io.h> |
---|
[5aeed17] | 26 | |
---|
| 27 | #define LPC24XX_RTC_NUMBER 1 |
---|
| 28 | |
---|
[c468f18b] | 29 | static void lpc24xx_rtc_initialize(int minor) |
---|
[5aeed17] | 30 | { |
---|
[7ae2775] | 31 | /* Enable module power */ |
---|
[c468f18b] | 32 | lpc24xx_module_enable(LPC24XX_MODULE_RTC, LPC24XX_MODULE_PCLK_DEFAULT); |
---|
[7ae2775] | 33 | |
---|
[5aeed17] | 34 | /* Enable the RTC and use external clock */ |
---|
| 35 | RTC_CCR = RTC_CCR_CLKEN | RTC_CCR_CLKSRC; |
---|
| 36 | |
---|
| 37 | /* Disable interrupts */ |
---|
| 38 | RTC_CIIR = 0; |
---|
| 39 | RTC_CISS = 0; |
---|
| 40 | RTC_AMR = 0xff; |
---|
| 41 | |
---|
| 42 | /* Clear interrupts */ |
---|
| 43 | RTC_ILR = RTC_ILR_RTCCIF | RTC_ILR_RTCALF | RTC_ILR_RTSSF; |
---|
| 44 | } |
---|
| 45 | |
---|
[c468f18b] | 46 | static int lpc24xx_rtc_get_time(int minor, rtems_time_of_day *tod) |
---|
[5aeed17] | 47 | { |
---|
| 48 | tod->ticks = 0; |
---|
| 49 | tod->second = RTC_SEC; |
---|
| 50 | tod->minute = RTC_MIN; |
---|
| 51 | tod->hour = RTC_HOUR; |
---|
| 52 | tod->day = RTC_DOM; |
---|
| 53 | tod->month = RTC_MONTH; |
---|
| 54 | tod->year = RTC_YEAR; |
---|
| 55 | |
---|
| 56 | return 0; |
---|
| 57 | } |
---|
| 58 | |
---|
[c468f18b] | 59 | static int lpc24xx_rtc_set_time(int minor, const rtems_time_of_day *tod) |
---|
[5aeed17] | 60 | { |
---|
| 61 | RTC_SEC = tod->second; |
---|
| 62 | RTC_MIN = tod->minute; |
---|
| 63 | RTC_HOUR = tod->hour; |
---|
| 64 | RTC_DOM = tod->day; |
---|
| 65 | RTC_MONTH = tod->month; |
---|
| 66 | RTC_YEAR = tod->year; |
---|
| 67 | |
---|
| 68 | return 0; |
---|
| 69 | } |
---|
| 70 | |
---|
[c468f18b] | 71 | static bool lpc24xx_rtc_probe(int minor) |
---|
[5aeed17] | 72 | { |
---|
| 73 | return true; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | const rtc_fns lpc24xx_rtc_ops = { |
---|
| 77 | .deviceInitialize = lpc24xx_rtc_initialize, |
---|
| 78 | .deviceGetTime = lpc24xx_rtc_get_time, |
---|
| 79 | .deviceSetTime = lpc24xx_rtc_set_time |
---|
| 80 | }; |
---|
| 81 | |
---|
[82dcbc8] | 82 | size_t RTC_Count = LPC24XX_RTC_NUMBER; |
---|
[5aeed17] | 83 | |
---|
| 84 | rtems_device_minor_number RTC_Minor = 0; |
---|
| 85 | |
---|
| 86 | rtc_tbl RTC_Table [LPC24XX_RTC_NUMBER] = { |
---|
| 87 | { |
---|
| 88 | .sDeviceName = "/dev/rtc", |
---|
| 89 | .deviceType = RTC_CUSTOM, |
---|
| 90 | .pDeviceFns = &lpc24xx_rtc_ops, |
---|
| 91 | .deviceProbe = lpc24xx_rtc_probe, |
---|
| 92 | .pDeviceParams = NULL, |
---|
| 93 | .ulCtrlPort1 = 0, |
---|
| 94 | .ulDataPort = 0, |
---|
| 95 | .getRegister = NULL, |
---|
| 96 | .setRegister = NULL |
---|
| 97 | } |
---|
| 98 | }; |
---|