comparison target-utils/pirexplore/rtc.c @ 72:92c1ed6b4b67

pirexplore: RTC read implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 26 Jul 2013 20:32:43 +0000
parents
children c54c6ad1c66f
comparison
equal deleted inserted replaced
71:0c1480317c18 72:92c1ed6b4b67
1 #include "types.h"
2 #include "rtc.h"
3
4 static void
5 read_time(tm)
6 struct rtctime *tm;
7 {
8 tm->year = RTC_REGS.rtc_cur.year;
9 tm->month = RTC_REGS.rtc_cur.month;
10 tm->day_of_month = RTC_REGS.rtc_cur.day_of_month;
11 tm->day_of_week = RTC_REGS.rtc_cur.day_of_week;
12 tm->hours = RTC_REGS.rtc_cur.hours;
13 tm->minutes = RTC_REGS.rtc_cur.minutes;
14 tm->seconds = RTC_REGS.rtc_cur.seconds;
15 }
16
17 void
18 cmd_rtc()
19 {
20 u8 ctrl;
21 struct rtctime time1, time2;
22 int c;
23
24 ctrl = RTC_REGS.rtc_ctrl_reg;
25 printf("RTC_CTRL_REG = %02X ", ctrl);
26 switch (ctrl) {
27 case 0x00:
28 printf("(frozen)\n");
29 break;
30 case 0x01:
31 printf("(running)\n");
32 break;
33 default:
34 printf("(unexpected)\n");
35 return;
36 }
37 printf("Reading RTC time");
38 for (;;) {
39 c = serial_in_poll();
40 if (c >= 0) {
41 printf("<INTERRUPT>\n");
42 return;
43 }
44 read_time(&time1);
45 read_time(&time2);
46 if (!bcmp(&time1.minutes, &time2.minutes, 6))
47 break;
48 }
49 printf("\nDATE %02X-%02X-%02X DOW %02X TIME %02X:%02X:%02X\n",
50 time2.year, time2.month, time2.day_of_month, time2.day_of_week,
51 time2.hours, time2.minutes, time2.seconds);
52 }