Hardware Reference
In-Depth Information
70 memset(&rtc,0,sizeof rtc);
71 memset(&t1,0,sizeof t1);
72
73 rc = i2c_rd_rtc(&rtc);
74 if ( rc < 0 ) {
75 perror("Reading DS1307 RTC clock.");
76 exit(1);
77 } else if ( rc != 2 ) {
78 fprintf(stderr,"Read error: got %d of 2 msgs.\n",rc);
79 exit(1);
80 } else
81 rc = 0;
82
83 /
84
Check the date returned by the RTC:
85
/
86 memset(&t1,0,sizeof t1);
87 t1.tm_year = (rtc.year_10s
10 + rtc.year_1s) + 2000 − 1900;
88 t1.tm_mon = rtc.month_10s
10 + rtc.month_1s − 1;
89 t1.tm_mday = rtc.day_10s
10 + rtc.day_1s;
90 t1.tm_hour = rtc.hour_10s
10 + rtc.hour_1s;
91 t1.tm_min = rtc.mins_10s
10 + rtc.mins_1s;
92 t1.tm_sec = rtc.secs_10s
10 + rtc.secs_1s;
93 t1.tm_isdst = −1; /
Determine if daylight savings
/
94
95 t0 = t1;
96 if ( mktime(&t1) == 1L /
/
97 || t1.tm_year != t0.tm_year || t1.tm_mon != t0.tm_mon
98 || t1.tm_mday != t0.tm_mday || t1.tm_hour != t0.tm_hour
99 || t1.tm_min != t0.tm_min || t1.tm_sec != t0.tm_sec ) {
100 strftime(dtbuf,sizeof dtbuf,date_format,&t0);
101 fprintf(stderr,"Read RTC date is not valid: %s\n",dtbuf);
102 exit(2);
103 }
104
105 if ( t1.tm_wday != rtc.wkday−1 ) {
106 fprintf(stderr,
107 "Warning:RTC weekday is incorrect %d but should be %d\n",
108 rtc.wkday,t1.tm_wday);
109 }
110
111 #if 0 /
t1 is modified
/
112 printf("%d%d−%d%d−%d%d%d%d:%d%d:%d%d(wkday %d)\n",
113 rtc.year_10s,rtc.year_1s ,
114 rtc.month_10s,rtc.month_1s ,
115 rtc.day_10s, rtc.day_1s ,
116 rtc.hour_10s,rtc.hour_1s ,
Change to a 1 for debugging
Search WWH ::




Custom Search