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

4.104.114.84.9
Last change on this file since ee4f57d was ee4f57d, checked in by Ralf Corsepius <ralf.corsepius@…>, on Mar 23, 2004 at 9:59:52 AM

2004-03-23 Ralf Corsepius <ralf_corsepius@…>

  • libchip/ide/ata.c, libchip/ide/ata_internal.h, libchip/ide/ide_controller.c, libchip/ide/ide_ctrl_cfg.h, libchip/ide/ide_ctrl_io.h, libchip/network/cs8900.c, libchip/network/dec21140.c, libchip/network/elnk.c, libchip/network/if_fxp.c, libchip/network/open_eth.c, libchip/network/open_eth.h, libchip/network/sonic.c, libchip/network/sonic.h, libchip/rtc/icm7170.c, libchip/rtc/icm7170.h, libchip/rtc/icm7170_reg.c, libchip/rtc/icm7170_reg2.c, libchip/rtc/icm7170_reg4.c, libchip/rtc/icm7170_reg8.c, libchip/rtc/m48t08.c, libchip/rtc/m48t08.h, libchip/rtc/m48t08_reg.c, libchip/rtc/m48t08_reg2.c, libchip/rtc/m48t08_reg4.c, libchip/rtc/m48t08_reg8.c, libchip/rtc/rtc.h, libchip/serial/mc68681.c, libchip/serial/mc68681.h, libchip/serial/mc68681_reg.c, libchip/serial/mc68681_reg2.c, libchip/serial/mc68681_reg4.c, libchip/serial/mc68681_reg8.c, libchip/serial/ns16550.c, libchip/serial/ns16550_p.h, libchip/serial/serial.h, libchip/serial/z85c30.c, libchip/serial/z85c30.h, libchip/serial/z85c30_p.h, libchip/serial/z85c30_reg.c, libchip/shmdr/addlq.c, libchip/shmdr/cnvpkt.c, libchip/shmdr/dump.c, libchip/shmdr/fatal.c, libchip/shmdr/getlq.c, libchip/shmdr/init.c, libchip/shmdr/initlq.c, libchip/shmdr/intr.c, libchip/shmdr/poll.c, libchip/shmdr/send.c, libchip/shmdr/shm_driver.h: Convert to using c99 fixed-size types.
  • 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};
175
Note: See TracBrowser for help on using the repository browser.