source: rtems/c/src/libchip/rtc/icm7170.c @ 74172b7d

5
Last change on this file since 74172b7d was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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