source: rtems/c/src/libchip/rtc/icm7170.c @ fb339a8

4.104.114.84.95
Last change on this file since fb339a8 was 1177cda, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 29, 1998 at 12:02:11 AM

New files for Harris Semiconductor ICM7170.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  This file interfaces with the real-time clock found in
3 *  a Harris ICM7170
4 *
5 *  Year 2K Notes:
6 *
7 *  This chip only uses a two digit field to store the year.  This
8 *  code uses the RTEMS Epoch as a pivot year.  This lets us map the
9 *  two digit year field as follows:
10 *
11 *    + two digit years 0-87 are mapped to 2000-2087.
12 *    + two digit years 88-99 are mapped to 1988-1999.
13 *
14 *  This is less than the time span supported by RTEMS.
15 *
16 *  COPYRIGHT (c) 1989-1998.
17 *  On-Line Applications Research Corporation (OAR).
18 *  Copyright assigned to U.S. Government, 1994.
19 *
20 *  The license and distribution terms for this file may be
21 *  found in the file LICENSE in this distribution or at
22 *  http://www.OARcorp.com/rtems/license.html.
23 *
24 *  $Id$
25 */
26
27#include <rtems.h>
28#include <libchip/rtc.h>
29#include <libchip/icm7170.h>
30
31/*
32 *  Control register bits
33 */
34
35/* XXX */
36
37/*
38 *  icm7170_initialize
39 */
40
41void icm7170_initialize(
42  int minor
43)
44{
45  unsigned32     icm7170;
46  setRegister_f  setReg;           
47  unsigned32     clock;
48
49  icm7170 = RTC_Table[ minor ].ulCtrlPort1;
50  setReg = RTC_Table[ minor ].setRegister;
51
52  /*
53   *  Initialize the RTC with the proper clock frequency
54   */
55
56  clock = (unsigned32) RTC_Table[ minor ].pDeviceParams;
57  (*setReg)( icm7170, ICM7170_CONTROL, 0x0c | clock );
58}
59
60/*
61 *  icm7170_get_time
62 */
63
64int icm7170_get_time(
65  int                minor,
66  rtems_time_of_day *time
67)
68{
69  unsigned32     icm7170;
70  getRegister_f  getReg;
71  setRegister_f  setReg;
72  unsigned32     year;
73
74  icm7170 = RTC_Table[ minor ].ulCtrlPort1;
75  getReg = RTC_Table[ minor ].getRegister;
76  setReg = RTC_Table[ minor ].setRegister;
77
78  /*
79   *  Put the RTC into read mode
80   */
81
82  (void) (*getReg)( icm7170, ICM7170_COUNTER_HUNDREDTHS );
83
84  /*
85   *  Now get the time
86   */
87
88
89  year = (*getReg)( icm7170, ICM7170_YEAR );
90  if ( year < 88 )
91    year += 2000;
92  else
93    year += 1900;
94
95  time->year   = year;
96  time->month  = (*getReg)( icm7170, ICM7170_MONTH );
97  time->day    = (*getReg)( icm7170, ICM7170_DATE );
98  time->hour   = (*getReg)( icm7170, ICM7170_HOUR );
99  time->minute = (*getReg)( icm7170, ICM7170_MINUTE );
100  time->second = (*getReg)( icm7170, ICM7170_SECOND );
101 
102  time->ticks  = 0;
103
104  /*
105   *  Put the RTC back into normal mode.
106   */
107
108  (void) (*getReg)( icm7170, ICM7170_COUNTER_HUNDREDTHS );
109
110  return 0;
111}
112
113/*
114 *  icm7170_set_time
115 */
116
117int icm7170_set_time(
118  int                minor,
119  rtems_time_of_day *time
120)
121{
122  unsigned32     icm7170;
123  getRegister_f  getReg;
124  setRegister_f  setReg;
125  unsigned32     year;
126  unsigned32     clock;
127
128  icm7170 = RTC_Table[ minor ].ulCtrlPort1;
129  getReg = RTC_Table[ minor ].getRegister;
130  setReg = RTC_Table[ minor ].setRegister;
131  clock = (unsigned32) RTC_Table[ minor ].pDeviceParams;
132
133  year = time->year;
134
135  if ( year >= 2088 )
136    rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
137
138  if ( year >= 2000 )
139    year -= 2000;
140  else
141    year -= 1900;
142
143  (*setReg)( icm7170, ICM7170_CONTROL, 0x04 | clock );
144
145  (*setReg)( icm7170, ICM7170_YEAR,    year );
146  (*setReg)( icm7170, ICM7170_MONTH,   time->month );
147  (*setReg)( icm7170, ICM7170_DATE,    time->day );
148  (*setReg)( icm7170, ICM7170_HOUR,    time->hour );
149  (*setReg)( icm7170, ICM7170_MINUTE,  time->minute );
150  (*setReg)( icm7170, ICM7170_SECOND,  time->second );
151 
152  /*
153   *  This is not really right.
154   */
155
156  (*setReg)( icm7170, ICM7170_DAY_OF_WEEK,  1 );
157
158  /*
159   *  Put the RTC back into normal mode.
160   */
161
162  (*setReg)( icm7170, ICM7170_CONTROL, 0x0c | clock );
163
164  return 0;
165}
166
167/*
168 *  Driver function table
169 */
170
171rtc_fns icm7170_fns = {
172  icm7170_initialize,
173  icm7170_get_time,
174  icm7170_set_time
175};
176
Note: See TracBrowser for help on using the repository browser.