OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [powerpc/] [score603e/] [tod/] [tod_g1.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 * Real Time Clock (SGS-Thomson M48T08/M48T18) for RTEMS
3
 *
4
 *  This part is only found on the first generation board.
5
 *
6
 *  Based on MVME162 TOD Driver by:
7
 *    COPYRIGHT (C) 1997
8
 *    by Katsutoshi Shibuya - BU Denken Co.,Ltd. - Sapporo - JAPAN
9
 *    ALL RIGHTS RESERVED
10
 *
11
 *  The license and distribution terms for this file may be
12
 *  found in the file LICENSE in this distribution or at
13
 *  http://www.OARcorp.com/rtems/license.html.
14
 *
15
 *  $Id: tod_g1.c,v 1.2 2001-09-27 12:01:04 chris Exp $
16
 */
17
 
18
#include <rtems.h>
19
#include <tod.h>
20
#include <bsp.h>
21
 
22
/*
23
 *  These routines are M48T08 and M48T18 dependent and should be in
24
 *  a separate support library.
25
 */
26
 
27
static int M48T08_GetField(
28
  volatile unsigned char *mk48t08,
29
  int                     n,
30
  unsigned char           mask
31
)
32
{
33
  unsigned char x;
34
 
35
  x = mk48t08[n] & mask;
36
  return ((x >> 4) * 10) + (x & 0x0f);
37
}
38
 
39
static void M48T08_SetField(
40
  volatile unsigned char *mk48t08,
41
  int                     n,
42
  unsigned char           d
43
)
44
{
45
  mk48t08[n] = ((d / 10) << 4) + (d % 10);
46
}
47
 
48
static void M48T08_GetTOD(
49
  volatile unsigned char *mk48t08,
50
  rtems_time_of_day      *rtc_tod
51
)
52
{
53
  int year;
54
 
55
  mk48t08[0] |= 0x40;     /* Stop read register */
56
 
57
  year = M48T08_GetField( mk48t08, 7, 0xff );
58
  if ( year >= 88 )
59
    year += 1900;
60
  else
61
    year += 2000;
62
 
63
  rtc_tod->year   = year;
64
  rtc_tod->month  = M48T08_GetField( mk48t08, 6, 0x1f );
65
  rtc_tod->day    = M48T08_GetField( mk48t08, 5, 0x3f );
66
  rtc_tod->hour   = M48T08_GetField( mk48t08, 3, 0x3f );
67
  rtc_tod->minute = M48T08_GetField( mk48t08, 2, 0x7f );
68
  rtc_tod->second = M48T08_GetField( mk48t08, 1, 0x7f );
69
  rtc_tod->ticks  = 0;
70
  mk48t08[0] &= 0x3f;     /* Release read register */
71
}
72
 
73
static void M48T08_SetTOD(
74
  volatile unsigned char *mk48t08,
75
  rtems_time_of_day      *rtc_tod
76
)
77
{
78
  int year;
79
 
80
  year = rtc_tod->year;
81
 
82
  if ( year >= 2088 )        /* plan ahead :) */
83
    rtems_fatal_error_occurred( 0xBAD0BAD0 );
84
 
85
  if ( year >= 2000 )
86
    year -= 2000;
87
  else
88
    year -= 1900;
89
 
90
  mk48t08[0] |= 0x80;     /* Stop write register */
91
  M48T08_SetField( mk48t08, 7, year );
92
  M48T08_SetField( mk48t08, 6, rtc_tod->month );
93
  M48T08_SetField( mk48t08, 5, rtc_tod->day );
94
  M48T08_SetField( mk48t08, 4, 1 );      /* I don't know which day of week is */
95
  M48T08_SetField( mk48t08, 3, rtc_tod->hour );
96
  M48T08_SetField( mk48t08, 2, rtc_tod->minute );
97
  M48T08_SetField( mk48t08, 1, rtc_tod->second );
98
  mk48t08[0] &= 0x3f;     /* Write these parameters */
99
}
100
 
101
/*
102
 *  This code is dependent on the Vista 603e's use of the M48T18 RTC/NVRAM
103
 *  and should remain in this file.
104
 */
105
 
106
void setRealTimeToRTEMS()
107
{
108
  rtems_time_of_day rtc_tod;
109
 
110
  M48T08_GetTOD( SCORE603E_RTC_ADDRESS, &rtc_tod );
111
  rtems_clock_set( &rtc_tod );
112
}
113
 
114
void setRealTimeFromRTEMS()
115
{
116
  rtems_time_of_day rtems_tod;
117
 
118
  rtems_clock_get( RTEMS_CLOCK_GET_TOD, &rtems_tod );
119
  M48T08_SetTOD( SCORE603E_RTC_ADDRESS, &rtems_tod );
120
}
121
 
122
int checkRealTime()
123
{
124
  rtems_time_of_day rtems_tod;
125
  rtems_time_of_day rtc_tod;
126
 
127
  M48T08_GetTOD( SCORE603E_RTC_ADDRESS, &rtc_tod );
128
  rtems_clock_get( RTEMS_CLOCK_GET_TOD, &rtems_tod );
129
 
130
  if( rtems_tod.year == rtc_tod.year &&
131
      rtems_tod.month == rtc_tod.month &&
132
      rtems_tod.day == rtc_tod.day ) {
133
     return ((rtems_tod.hour   - rtc_tod.hour) * 3600) +
134
            ((rtems_tod.minute - rtc_tod.minute) * 60) +
135
             (rtems_tod.second - rtc_tod.second);
136
  }
137
  return 9999;
138
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.