source: rtems/c/src/libchip/rtc/m48t08.c @ a1f514f

4.104.114.84.95
Last change on this file since a1f514f was a1f514f, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 28, 1998 at 11:03:40 PM

First cut implementation of real-time clock support in libchip. This
version compiles cleanly but there is not a BSP with a configuration
table to utilize it.

  • 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 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 MK48T08_CONTROL_WRITE  0x80
36#define MK48T08_CONTROL_READ   0x40
37#define MK48T08_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_Port_Tbl[ minor ].ulCtrlPort1;
69  getReg = RTC_Port_Tbl[ minor ].getRegister;
70  setReg = RTC_Port_Tbl[ 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 | MK48T08_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  /*
102   *  Put the RTC back into normal mode.
103   */
104
105  (*setReg)( m48t08, M48T08_CONTROL, controlReg );
106
107  return 0;
108}
109
110/*
111 *  m48t08_set_time
112 */
113
114int m48t08_set_time(
115  int                minor,
116  rtems_time_of_day *time
117)
118{
119  unsigned32     m48t08;
120  getRegister_f  getReg;
121  setRegister_f  setReg;
122  unsigned8      controlReg;
123
124  m48t08 = RTC_Port_Tbl[ minor ].ulCtrlPort1;
125  getReg = RTC_Port_Tbl[ minor ].getRegister;
126  setReg = RTC_Port_Tbl[ minor ].setRegister;
127
128  /*
129   *  Put the RTC into read mode
130   */
131
132  controlReg = (*getReg)( m48t08, M48T08_CONTROL );
133  (*setReg)( m48t08, M48T08_CONTROL, controlReg | MK48T08_CONTROL_WRITE );
134 
135  if ( time->year >= 2088 )
136    rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
137
138  (*setReg)( m48t08, M48T08_YEAR,    To_BCD(time->year % 100) );
139  (*setReg)( m48t08, M48T08_MONTH,   To_BCD(time->month) );
140  (*setReg)( m48t08, M48T08_DATE,    To_BCD(time->day) );
141  (*setReg)( m48t08, M48T08_HOUR,    To_BCD(time->hour) );
142  (*setReg)( m48t08, M48T08_MINUTE,  To_BCD(time->minute) );
143  (*setReg)( m48t08, M48T08_SECOND,  To_BCD(time->second) );
144 
145  /*
146   *  Put the RTC back into normal mode.
147   */
148
149  (*setReg)( m48t08, M48T08_CONTROL, controlReg );
150
151  return 0;
152}
Note: See TracBrowser for help on using the repository browser.