summaryrefslogtreecommitdiffstats
path: root/c/src/libchip
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-07-29 00:02:11 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-07-29 00:02:11 +0000
commit1177cda0d33e326e6fa7d049c6138c1d5e83d87b (patch)
tree8e381b43dae455d5697629b526a9b622c103a1ea /c/src/libchip
parentNew files. (diff)
downloadrtems-1177cda0d33e326e6fa7d049c6138c1d5e83d87b.tar.bz2
New files for Harris Semiconductor ICM7170.
Diffstat (limited to 'c/src/libchip')
-rw-r--r--c/src/libchip/rtc/icm7170.c176
-rw-r--r--c/src/libchip/rtc/icm7170.h52
2 files changed, 228 insertions, 0 deletions
diff --git a/c/src/libchip/rtc/icm7170.c b/c/src/libchip/rtc/icm7170.c
new file mode 100644
index 0000000000..f3cf513d2e
--- /dev/null
+++ b/c/src/libchip/rtc/icm7170.c
@@ -0,0 +1,176 @@
+/*
+ * This file interfaces with the real-time clock found in
+ * a Harris ICM7170
+ *
+ * Year 2K Notes:
+ *
+ * This chip only uses a two digit field to store the year. This
+ * code uses the RTEMS Epoch as a pivot year. This lets us map the
+ * two digit year field as follows:
+ *
+ * + two digit years 0-87 are mapped to 2000-2087.
+ * + two digit years 88-99 are mapped to 1988-1999.
+ *
+ * This is less than the time span supported by RTEMS.
+ *
+ * COPYRIGHT (c) 1989-1998.
+ * On-Line Applications Research Corporation (OAR).
+ * Copyright assigned to U.S. Government, 1994.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
+#include <rtems.h>
+#include <libchip/rtc.h>
+#include <libchip/icm7170.h>
+
+/*
+ * Control register bits
+ */
+
+/* XXX */
+
+/*
+ * icm7170_initialize
+ */
+
+void icm7170_initialize(
+ int minor
+)
+{
+ unsigned32 icm7170;
+ setRegister_f setReg;
+ unsigned32 clock;
+
+ icm7170 = RTC_Table[ minor ].ulCtrlPort1;
+ setReg = RTC_Table[ minor ].setRegister;
+
+ /*
+ * Initialize the RTC with the proper clock frequency
+ */
+
+ clock = (unsigned32) RTC_Table[ minor ].pDeviceParams;
+ (*setReg)( icm7170, ICM7170_CONTROL, 0x0c | clock );
+}
+
+/*
+ * icm7170_get_time
+ */
+
+int icm7170_get_time(
+ int minor,
+ rtems_time_of_day *time
+)
+{
+ unsigned32 icm7170;
+ getRegister_f getReg;
+ setRegister_f setReg;
+ unsigned32 year;
+
+ icm7170 = RTC_Table[ minor ].ulCtrlPort1;
+ getReg = RTC_Table[ minor ].getRegister;
+ setReg = RTC_Table[ minor ].setRegister;
+
+ /*
+ * Put the RTC into read mode
+ */
+
+ (void) (*getReg)( icm7170, ICM7170_COUNTER_HUNDREDTHS );
+
+ /*
+ * Now get the time
+ */
+
+
+ year = (*getReg)( icm7170, ICM7170_YEAR );
+ if ( year < 88 )
+ year += 2000;
+ else
+ year += 1900;
+
+ time->year = year;
+ time->month = (*getReg)( icm7170, ICM7170_MONTH );
+ time->day = (*getReg)( icm7170, ICM7170_DATE );
+ time->hour = (*getReg)( icm7170, ICM7170_HOUR );
+ time->minute = (*getReg)( icm7170, ICM7170_MINUTE );
+ time->second = (*getReg)( icm7170, ICM7170_SECOND );
+
+ time->ticks = 0;
+
+ /*
+ * Put the RTC back into normal mode.
+ */
+
+ (void) (*getReg)( icm7170, ICM7170_COUNTER_HUNDREDTHS );
+
+ return 0;
+}
+
+/*
+ * icm7170_set_time
+ */
+
+int icm7170_set_time(
+ int minor,
+ rtems_time_of_day *time
+)
+{
+ unsigned32 icm7170;
+ getRegister_f getReg;
+ setRegister_f setReg;
+ unsigned32 year;
+ unsigned32 clock;
+
+ icm7170 = RTC_Table[ minor ].ulCtrlPort1;
+ getReg = RTC_Table[ minor ].getRegister;
+ setReg = RTC_Table[ minor ].setRegister;
+ clock = (unsigned32) RTC_Table[ minor ].pDeviceParams;
+
+ year = time->year;
+
+ if ( year >= 2088 )
+ rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
+
+ if ( year >= 2000 )
+ year -= 2000;
+ else
+ year -= 1900;
+
+ (*setReg)( icm7170, ICM7170_CONTROL, 0x04 | clock );
+
+ (*setReg)( icm7170, ICM7170_YEAR, year );
+ (*setReg)( icm7170, ICM7170_MONTH, time->month );
+ (*setReg)( icm7170, ICM7170_DATE, time->day );
+ (*setReg)( icm7170, ICM7170_HOUR, time->hour );
+ (*setReg)( icm7170, ICM7170_MINUTE, time->minute );
+ (*setReg)( icm7170, ICM7170_SECOND, time->second );
+
+ /*
+ * This is not really right.
+ */
+
+ (*setReg)( icm7170, ICM7170_DAY_OF_WEEK, 1 );
+
+ /*
+ * Put the RTC back into normal mode.
+ */
+
+ (*setReg)( icm7170, ICM7170_CONTROL, 0x0c | clock );
+
+ return 0;
+}
+
+/*
+ * Driver function table
+ */
+
+rtc_fns icm7170_fns = {
+ icm7170_initialize,
+ icm7170_get_time,
+ icm7170_set_time
+};
+
diff --git a/c/src/libchip/rtc/icm7170.h b/c/src/libchip/rtc/icm7170.h
new file mode 100644
index 0000000000..0e488b988c
--- /dev/null
+++ b/c/src/libchip/rtc/icm7170.h
@@ -0,0 +1,52 @@
+/*
+ * This file contains the definitions for the following real-time clocks:
+ *
+ * + Harris Semiconduction ICM7170
+ *
+ * COPYRIGHT (c) 1989-1998.
+ * On-Line Applications Research Corporation (OAR).
+ * Copyright assigned to U.S. Government, 1994.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
+#ifndef __LIBCHIP_ICM7170_h
+#define __LIBCHIP_ICM7170_h
+
+/*
+ * Register indices
+ */
+
+#define ICM7170_CONTROL 0x11
+
+
+#define ICM7170_COUNTER_HUNDREDTHS 0x00
+#define ICM7170_HOUR 0x01
+#define ICM7170_MINUTE 0x02
+#define ICM7170_SECOND 0x03
+#define ICM7170_MONTH 0x04
+#define ICM7170_DATE 0x05
+#define ICM7170_YEAR 0x06
+#define ICM7170_DAY_OF_WEEK 0x07
+
+/*
+ * Configuration information in the parameters field
+ */
+
+#define ICM7170_AT_32_KHZ 0x00
+#define ICM7170_AT_1_MHZ 0x01
+#define ICM7170_AT_2_MHZ 0x02
+#define ICM7170_AT_4_MHZ 0x03
+
+/*
+ * Driver function table
+ */
+
+extern rtc_fns icm7170_fns;
+
+#endif
+/* end of include file */