source: rtems/c/src/lib/libchip/rtc/m48t08.c @ cb5e6f68

4.104.114.84.95
Last change on this file since cb5e6f68 was cb5e6f68, checked in by Joel Sherrill <joel.sherrill@…>, on 07/29/98 at 00:03:07

Renamed control register constants.

Set time->ticks to 0.

Added function table.

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