source: rtems/c/src/libchip/rtc/m48t08.c @ 08311cc3

4.104.114.84.9
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 17, 1999 at 5:51:34 PM

Updated copyright notice.

  • 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 Mostek M48T08 or M48T18 or compatibles.
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.OARcorp.com/rtems/license.html.
22 *
23 *  $Id$
24 */
25
26#include <rtems.h>
27#include <libchip/rtc.h>
28#include <libchip/m48t08.h>
29
30/*
31 *  Control register bits
32 */
33
34#define M48T08_CONTROL_WRITE  0x80
35#define M48T08_CONTROL_READ   0x40
36#define M48T08_CONTROL_SIGN   0x20
37
38/*
39 *  m48t08_initialize
40 */
41
42void m48t08_initialize(
43  int minor
44)
45{
46}
47
48/*
49 *  m48t08_get_time
50 */
51
52#define From_BCD( _x ) ((((_x) >> 4) * 10) + ((_x) & 0x0F))
53#define To_BCD( _x )   ((((_x) / 10) << 4) + ((_x) % 10))
54
55int m48t08_get_time(
56  int                minor,
57  rtems_time_of_day *time
58)
59{
60  unsigned32     m48t08;
61  getRegister_f  getReg;
62  setRegister_f  setReg;
63  unsigned8      controlReg;
64  unsigned32     value1;
65  unsigned32     value2;
66
67  m48t08 = RTC_Table[ minor ].ulCtrlPort1;
68  getReg = RTC_Table[ minor ].getRegister;
69  setReg = RTC_Table[ minor ].setRegister;
70
71  /*
72   *  Put the RTC into read mode
73   */
74
75  controlReg = (*getReg)( m48t08, M48T08_CONTROL );
76  (*setReg)( m48t08, M48T08_CONTROL, controlReg | M48T08_CONTROL_READ );
77 
78  value1 = (*getReg)( m48t08, M48T08_YEAR );
79  value2 = From_BCD( value1 );
80  if ( value2 < 88 )
81    time->year = 2000 + value2;
82  else
83    time->year = 1900 + value2;
84
85  value1 = (*getReg)( m48t08, M48T08_MONTH );
86  time->month = From_BCD( value1 );
87
88  value1 = (*getReg)( m48t08, M48T08_DATE );
89  time->day = From_BCD( value1 );
90
91  value1 = (*getReg)( m48t08, M48T08_HOUR );
92  time->hour = From_BCD( value1 );
93
94  value1 = (*getReg)( m48t08, M48T08_MINUTE );
95  time->minute = From_BCD( value1 );
96
97  value1 = (*getReg)( m48t08, M48T08_SECOND );
98  time->second = From_BCD( value1 );
99 
100  time->ticks  = 0;
101
102  /*
103   *  Put the RTC back into normal mode.
104   */
105
106  (*setReg)( m48t08, M48T08_CONTROL, controlReg );
107
108  return 0;
109}
110
111/*
112 *  m48t08_set_time
113 */
114
115int m48t08_set_time(
116  int                minor,
117  rtems_time_of_day *time
118)
119{
120  unsigned32     m48t08;
121  getRegister_f  getReg;
122  setRegister_f  setReg;
123  unsigned8      controlReg;
124
125  m48t08 = RTC_Table[ minor ].ulCtrlPort1;
126  getReg = RTC_Table[ minor ].getRegister;
127  setReg = RTC_Table[ minor ].setRegister;
128
129  /*
130   *  Put the RTC into read mode
131   */
132
133  controlReg = (*getReg)( m48t08, M48T08_CONTROL );
134  (*setReg)( m48t08, M48T08_CONTROL, controlReg | M48T08_CONTROL_WRITE );
135 
136  if ( time->year >= 2088 )
137    rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
138
139  (*setReg)( m48t08, M48T08_YEAR,    To_BCD(time->year % 100) );
140  (*setReg)( m48t08, M48T08_MONTH,   To_BCD(time->month) );
141  (*setReg)( m48t08, M48T08_DATE,    To_BCD(time->day) );
142  (*setReg)( m48t08, M48T08_HOUR,    To_BCD(time->hour) );
143  (*setReg)( m48t08, M48T08_MINUTE,  To_BCD(time->minute) );
144  (*setReg)( m48t08, M48T08_SECOND,  To_BCD(time->second) );
145 
146  /*
147   *  Put the RTC back into normal mode.
148   */
149
150  (*setReg)( m48t08, M48T08_CONTROL, controlReg );
151
152  return 0;
153}
154
155/*
156 *  Driver function table
157 */
158
159rtc_fns m48t08_fns = {
160  m48t08_initialize,
161  m48t08_get_time,
162  m48t08_set_time
163};
164
Note: See TracBrowser for help on using the repository browser.