FreeCalypso > hg > freecalypso-sw
changeset 72:92c1ed6b4b67
pirexplore: RTC read implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 26 Jul 2013 20:32:43 +0000 |
parents | 0c1480317c18 |
children | c54c6ad1c66f |
files | target-utils/include/rtc.h target-utils/pirexplore/Makefile target-utils/pirexplore/cmdtab.c target-utils/pirexplore/rtc.c |
diffstat | 4 files changed, 89 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/include/rtc.h Fri Jul 26 20:32:43 2013 +0000 @@ -0,0 +1,34 @@ +/* Calypso RTC registers */ + +#ifndef __CALYPSO_RTC_H +#define __CALYPSO_RTC_H + +#include "types.h" + +#define RTC_REGS_BASE 0xFFFE1800 + +struct rtctime { + u8 seconds; + u8 minutes; + u8 hours; + u8 day_of_month; + u8 month; + u8 year; + u8 day_of_week; + u8 pad; +}; + +struct rtcregs { + struct rtctime rtc_cur; + struct rtctime rtc_alarm; + u8 rtc_ctrl_reg; + u8 rtc_status_reg; + u8 rtc_int_reg; + u8 rtc_comp_lsb_reg; + u8 rtc_comp_msb_reg; + u8 rtc_res_prog_reg; +}; + +#define RTC_REGS (*(volatile struct rtcregs *) RTC_REGS_BASE) + +#endif /* include guard */
--- a/target-utils/pirexplore/Makefile Fri Jul 26 18:11:41 2013 +0000 +++ b/target-utils/pirexplore/Makefile Fri Jul 26 20:32:43 2013 +0000 @@ -5,7 +5,7 @@ OBJCOPY=arm-elf-objcopy PROG= pirexplore -OBJS= crt0.o cmdtab.o main.o mygetchar.o +OBJS= crt0.o cmdtab.o main.o mygetchar.o rtc.o LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a LDS= ../env/iram.lds
--- a/target-utils/pirexplore/cmdtab.c Fri Jul 26 18:11:41 2013 +0000 +++ b/target-utils/pirexplore/cmdtab.c Fri Jul 26 20:32:43 2013 +0000 @@ -6,6 +6,7 @@ extern void cmd_r8(); extern void cmd_r16(); extern void cmd_r32(); +extern void cmd_rtc(); extern void cmd_w8(); extern void cmd_w16(); extern void cmd_w32(); @@ -17,6 +18,7 @@ {"r8", cmd_r8}, {"r16", cmd_r16}, {"r32", cmd_r32}, + {"rtc", cmd_rtc}, {"w8", cmd_w8}, {"w16", cmd_w16}, {"w32", cmd_w32},
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/pirexplore/rtc.c Fri Jul 26 20:32:43 2013 +0000 @@ -0,0 +1,52 @@ +#include "types.h" +#include "rtc.h" + +static void +read_time(tm) + struct rtctime *tm; +{ + tm->year = RTC_REGS.rtc_cur.year; + tm->month = RTC_REGS.rtc_cur.month; + tm->day_of_month = RTC_REGS.rtc_cur.day_of_month; + tm->day_of_week = RTC_REGS.rtc_cur.day_of_week; + tm->hours = RTC_REGS.rtc_cur.hours; + tm->minutes = RTC_REGS.rtc_cur.minutes; + tm->seconds = RTC_REGS.rtc_cur.seconds; +} + +void +cmd_rtc() +{ + u8 ctrl; + struct rtctime time1, time2; + int c; + + ctrl = RTC_REGS.rtc_ctrl_reg; + printf("RTC_CTRL_REG = %02X ", ctrl); + switch (ctrl) { + case 0x00: + printf("(frozen)\n"); + break; + case 0x01: + printf("(running)\n"); + break; + default: + printf("(unexpected)\n"); + return; + } + printf("Reading RTC time"); + for (;;) { + c = serial_in_poll(); + if (c >= 0) { + printf("<INTERRUPT>\n"); + return; + } + read_time(&time1); + read_time(&time2); + if (!bcmp(&time1.minutes, &time2.minutes, 6)) + break; + } + printf("\nDATE %02X-%02X-%02X DOW %02X TIME %02X:%02X:%02X\n", + time2.year, time2.month, time2.day_of_month, time2.day_of_week, + time2.hours, time2.minutes, time2.seconds); +}