1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* Real Time Clock (MK48T08) for RTEMS on MVME162
*
* Author:
* COPYRIGHT (C) 1997
* by Katsutoshi Shibuya - BU Denken Co.,Ltd. - Sapporo - JAPAN
* ALL RIGHTS RESERVED
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.OARcorp.com/rtems/license.html.
*
* This material is a part of the MVME162 Board Support Package
* for the RTEMS executive. Its licensing policies are those of the
* RTEMS above.
*
* $Id$
*/
#include <rtems.h>
#include <tod.h>
#define tod ((volatile unsigned char *)0xfffc1ff8)
static int getTod(int n, unsigned char mask)
{
unsigned char x;
x = tod[n]&mask;
return (x>>4)*10+(x&0x0f);
}
static void setTod(int n, unsigned char d)
{
tod[n] = ((d/10)<<4)+(d%10);
}
void setRealTimeToRTEMS()
{
rtems_time_of_day t;
tod[0] |= 0x40; /* Stop read register */
t.year = 1900+getTod(7,0xff);
t.month = getTod(6,0x1f);
t.day = getTod(5,0x3f);
t.hour = getTod(3,0x3f);
t.minute = getTod(2,0x7f);
t.second = getTod(1,0x7f);
t.ticks = 0;
tod[0] &= 0x3f; /* Release read register */
rtems_clock_set(&t);
}
void setRealTimeFromRTEMS()
{
rtems_time_of_day t;
rtems_clock_get(RTEMS_CLOCK_GET_TOD,&t);
t.year -= 1900;
tod[0] |= 0x80; /* Stop write register */
setTod(7,t.year);
setTod(6,t.month);
setTod(5,t.day);
setTod(4,1); /* I don't know which day of week is */
setTod(3,t.hour);
setTod(2,t.minute);
setTod(1,t.second);
tod[0] &= 0x3f; /* Write these parameters */
}
int checkRealTime()
{
rtems_time_of_day t;
int d;
tod[0] |= 0x40; /* Stop read register */
rtems_clock_get(RTEMS_CLOCK_GET_TOD,&t);
if((t.year != 1900+getTod(7,0xff))
|| (t.month != getTod(6,0x1f))
|| (t.day != getTod(5,0x3f)))
d = 9999;
else
d = (t.hour-getTod(3,0x3f))*3600
+ (t.minute-getTod(3,0x7f))*60
+ (t.second - getTod(1,0x7f));
tod[1] &= 0x3f;
return d;
}
|