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