source: rtems/c/src/lib/libbsp/powerpc/score603e/tod/tod.c @ d59e9b9

4.104.115
Last change on this file since d59e9b9 was d59e9b9, checked in by Joel Sherrill <joel.sherrill@…>, on 10/01/08 at 16:09:23

2008-10-01 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, preinstall.am, PCI_bus/PCI.c, PCI_bus/PCI.h, PCI_bus/universe.c, console/85c30.c, console/85c30.h, console/consolebsp.h, console/tbl85c30.c, include/gen2.h, startup/Hwr_init.c, startup/bspstart.c, startup/genpvec.c, startup/setvec.c, startup/vmeintr.c, timer/timer.c, tod/tod.c, vme/VMEConfig.h: Some clean up.
  • include/coverhd.h: Removed.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  Real Time Clock (Harris ICM7170) for RTEMS
3 *
4 *  This part is found on the second generation of this board.
5 *
6 *  COPYRIGHT (c) 1989-2008.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#include <rtems.h>
17#include <tod.h>
18#include <bsp.h>
19
20/*
21 * These values are programed into a register and must not be changed.
22 */
23
24#define ICM1770_CRYSTAL_FREQ_32K      0x00
25#define ICM1770_CRYSTAL_FREQ_1M       0x01
26#define ICM1770_CRYSTAL_FREQ_2M       0x02
27#define ICM1770_CRYSTAL_FREQ_4M       0x03
28
29void ICM7170_GetTOD(
30  volatile unsigned char *imc1770_regs,
31  uint8_t                icm1770_freq,
32  rtems_time_of_day      *rtc_tod
33);
34void ICM7170_SetTOD(
35  volatile unsigned char *imc1770_regs,
36  uint8_t                icm1770_freq,
37  rtems_time_of_day      *rtc_tod
38);
39
40/*
41 *  This code is dependent on the Vista 603e's use of the ICM7170 RTC/NVRAM
42 *  and should remain in this file.
43 */
44
45void setRealTimeToRTEMS()
46{
47  rtems_time_of_day rtc_tod;
48
49  ICM7170_GetTOD( BSP_RTC_ADDRESS, BSP_RTC_FREQUENCY, &rtc_tod );
50  rtems_clock_set( &rtc_tod );
51}
52
53void setRealTimeFromRTEMS()
54{
55  rtems_time_of_day rtems_tod;
56
57  rtems_clock_get( RTEMS_CLOCK_GET_TOD, &rtems_tod );
58  ICM7170_SetTOD( BSP_RTC_ADDRESS, BSP_RTC_FREQUENCY, &rtems_tod );
59}
60
61int checkRealTime()
62{
63  rtems_time_of_day rtems_tod;
64  rtems_time_of_day rtc_tod;
65
66  ICM7170_GetTOD( BSP_RTC_ADDRESS, BSP_RTC_FREQUENCY, &rtc_tod );
67  rtems_clock_get( RTEMS_CLOCK_GET_TOD, &rtems_tod );
68
69  if( rtems_tod.year == rtc_tod.year &&
70      rtems_tod.month == rtc_tod.month &&
71      rtems_tod.day == rtc_tod.day ) {
72     return ((rtems_tod.hour   - rtc_tod.hour) * 3600) +
73            ((rtems_tod.minute - rtc_tod.minute) * 60) +
74             (rtems_tod.second - rtc_tod.second);
75  }
76  return 9999;
77}
78
79/*
80 *  These routines are ICM7170 should be in
81 *  a separate support library.
82 * XXX Make static
83 */
84static int ICM7170_GetField(
85  volatile unsigned char *imc1770_regs,
86  int                     reg
87)
88{
89  unsigned char x;
90
91  x = imc1770_regs[reg*4];
92
93  return x;
94}
95
96static void ICM7170_SetField(
97  volatile unsigned char *imc1770_regs,
98  int                     reg,
99  unsigned char             d
100)
101{
102  imc1770_regs[reg*4] = d;
103}
104
105void ICM7170_GetTOD(
106  volatile unsigned char *imc1770_regs,
107  uint8_t                icm1770_freq,
108  rtems_time_of_day      *rtc_tod
109)
110{
111  int year;
112  int usec;
113  static bool init = true;
114
115  /* Initialize the clock at once prior to reading */
116  if (init ) {
117    ICM7170_SetField( imc1770_regs,  0x11, (0x0c | icm1770_freq) );
118    init = false;
119  }
120
121  /* Latch times */
122  /* rtc_tod->ticks  = */
123
124  usec = ICM7170_GetField( imc1770_regs, 0x00 );
125
126  year = ICM7170_GetField( imc1770_regs, 0x06 );
127  if ( year >= 88 )
128    year += 1900;
129  else
130    year += 2000;
131
132  rtc_tod->year   = year;
133  rtc_tod->month  = ICM7170_GetField( imc1770_regs, 0x04 );
134  rtc_tod->day    = ICM7170_GetField( imc1770_regs, 0x05 );
135  rtc_tod->hour   = ICM7170_GetField( imc1770_regs, 0x01 );
136  rtc_tod->minute = ICM7170_GetField( imc1770_regs, 0x02 );
137  rtc_tod->second = ICM7170_GetField( imc1770_regs, 0x03 );
138  rtc_tod->ticks  = ICM7170_GetField( imc1770_regs, 0x00 );
139}
140
141void ICM7170_SetTOD(
142  volatile unsigned char *imc1770_regs,
143  uint8_t                icm1770_freq,
144  rtems_time_of_day      *rtc_tod
145)
146{
147  int year;
148
149  year = rtc_tod->year;
150  if ( year >= 2088 )        /* plan ahead :) */
151    rtems_fatal_error_occurred( 0xBAD0BAD0 );
152
153  if ( year >= 2000 )
154    year -= 2000;
155  else
156    year -= 1900;
157
158  ICM7170_SetField( imc1770_regs, 0x11, (0x04 |icm1770_freq ) );
159
160  ICM7170_SetField( imc1770_regs, 0x06, year );
161  ICM7170_SetField( imc1770_regs, 0x04, rtc_tod->month );
162  ICM7170_SetField( imc1770_regs, 0x05, rtc_tod->day );
163  ICM7170_SetField( imc1770_regs, 0x01, rtc_tod->hour );
164  ICM7170_SetField( imc1770_regs, 0x02, rtc_tod->minute );
165  ICM7170_SetField( imc1770_regs, 0x03, rtc_tod->second );
166
167  /*
168   * I don't know which day of week is
169   *
170   */
171  ICM7170_SetField( imc1770_regs, 0x07, 1 );
172
173  ICM7170_SetField( imc1770_regs,  0x11, (0x0c | icm1770_freq) );
174}
Note: See TracBrowser for help on using the repository browser.