File indexing completed on 2025-05-11 08:22:48
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 #include <libchip/chip.h>
0029 #include <libchip/rtc.h>
0030
0031 #include <bsp.h>
0032
0033 #define ARBITRARY_DAY_OF_WEEK 1
0034
0035 void atsam_rtc_get_time(rtems_time_of_day *tod)
0036 {
0037 Rtc *rtc = RTC;
0038 uint8_t hour;
0039 uint8_t minute;
0040 uint8_t second;
0041 uint16_t year;
0042 uint8_t month;
0043 uint8_t day;
0044 uint8_t week;
0045
0046 RTC_GetDate(rtc, &year, &month, &day, &week);
0047 RTC_GetTime(rtc, &hour, &minute, &second);
0048
0049 tod->ticks = 0;
0050 tod->second = second;
0051 tod->minute = minute;
0052 tod->hour = hour;
0053 tod->day = day;
0054 tod->month = month;
0055 tod->year = year;
0056 }
0057
0058 static void atsam_rtc_device_initialize(int minor)
0059 {
0060 Rtc *rtc = RTC;
0061
0062 RTC_DisableIt(rtc, 0x1F);
0063 }
0064
0065 static int atsam_rtc_device_get_time(int minor, rtems_time_of_day *tod)
0066 {
0067 atsam_rtc_get_time(tod);
0068
0069 return 0;
0070 }
0071
0072 static int atsam_rtc_device_set_time(int minor, const rtems_time_of_day *tod)
0073 {
0074 Rtc *rtc = RTC;
0075 uint8_t hour;
0076 uint8_t minute;
0077 uint8_t second;
0078 uint16_t year;
0079 uint8_t month;
0080 uint8_t day;
0081 uint8_t week;
0082
0083 second = (uint8_t) tod->second;
0084 minute = (uint8_t) tod->minute;
0085 hour = (uint8_t) tod->hour;
0086 day = (uint8_t) tod->day;
0087 month = (uint8_t) tod->month;
0088 week = ARBITRARY_DAY_OF_WEEK;
0089 year = (uint16_t) tod->year;
0090
0091 RTC_SetDate(rtc, year, month, day, week);
0092 RTC_SetTime(rtc, hour, minute, second);
0093
0094 return 0;
0095 }
0096
0097 static bool atsam_rtc_device_probe(int minor)
0098 {
0099 return true;
0100 }
0101
0102 const rtc_fns atsam_rtc_device_ops = {
0103 .deviceInitialize = atsam_rtc_device_initialize,
0104 .deviceGetTime = atsam_rtc_device_get_time,
0105 .deviceSetTime = atsam_rtc_device_set_time
0106 };
0107
0108 rtc_tbl RTC_Table[] = {
0109 {
0110 .sDeviceName = "/dev/rtc",
0111 .deviceType = RTC_CUSTOM,
0112 .pDeviceFns = &atsam_rtc_device_ops,
0113 .deviceProbe = atsam_rtc_device_probe
0114 }
0115 };
0116
0117 size_t RTC_Count = RTEMS_ARRAY_SIZE(RTC_Table);