comparison target-utils/pirexplore/rtc.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
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 }
53
54 void
55 cmd_rtccomp()
56 {
57 printf("%04X\n", (RTC_REGS.rtc_comp_msb_reg << 8) |
58 RTC_REGS.rtc_comp_lsb_reg);
59 }