File indexing completed on 2025-05-11 08:23:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include <libchip/rtc.h>
0036
0037 #include <bsp/lpc24xx.h>
0038 #include <bsp/io.h>
0039
0040 #define LPC24XX_RTC_NUMBER 1
0041
0042 static void lpc24xx_rtc_initialize(int minor)
0043 {
0044
0045 lpc24xx_module_enable(LPC24XX_MODULE_RTC, LPC24XX_MODULE_PCLK_DEFAULT);
0046
0047
0048 RTC_CCR = RTC_CCR_CLKEN | RTC_CCR_CLKSRC;
0049
0050
0051 RTC_CIIR = 0;
0052 RTC_CISS = 0;
0053 RTC_AMR = 0xff;
0054
0055
0056 RTC_ILR = RTC_ILR_RTCCIF | RTC_ILR_RTCALF | RTC_ILR_RTSSF;
0057 }
0058
0059 static int lpc24xx_rtc_get_time(int minor, rtems_time_of_day *tod)
0060 {
0061 tod->ticks = 0;
0062 tod->second = RTC_SEC;
0063 tod->minute = RTC_MIN;
0064 tod->hour = RTC_HOUR;
0065 tod->day = RTC_DOM;
0066 tod->month = RTC_MONTH;
0067 tod->year = RTC_YEAR;
0068
0069 return 0;
0070 }
0071
0072 static int lpc24xx_rtc_set_time(int minor, const rtems_time_of_day *tod)
0073 {
0074 RTC_SEC = tod->second;
0075 RTC_MIN = tod->minute;
0076 RTC_HOUR = tod->hour;
0077 RTC_DOM = tod->day;
0078 RTC_MONTH = tod->month;
0079 RTC_YEAR = tod->year;
0080
0081 return 0;
0082 }
0083
0084 static bool lpc24xx_rtc_probe(int minor)
0085 {
0086 return true;
0087 }
0088
0089 const rtc_fns lpc24xx_rtc_ops = {
0090 .deviceInitialize = lpc24xx_rtc_initialize,
0091 .deviceGetTime = lpc24xx_rtc_get_time,
0092 .deviceSetTime = lpc24xx_rtc_set_time
0093 };
0094
0095 size_t RTC_Count = LPC24XX_RTC_NUMBER;
0096
0097 rtc_tbl RTC_Table [LPC24XX_RTC_NUMBER] = {
0098 {
0099 .sDeviceName = "/dev/rtc",
0100 .deviceType = RTC_CUSTOM,
0101 .pDeviceFns = &lpc24xx_rtc_ops,
0102 .deviceProbe = lpc24xx_rtc_probe,
0103 .pDeviceParams = NULL,
0104 .ulCtrlPort1 = 0,
0105 .ulDataPort = 0,
0106 .getRegister = NULL,
0107 .setRegister = NULL
0108 }
0109 };