source: rtems/c/src/libchip/rtc/icm7170.c @ 73b5bd5d

4.104.114.84.9
Last change on this file since 73b5bd5d was 73b5bd5d, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 15, 2004 at 1:33:58 PM

Remove stray white spaces.

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