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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [mvme162/] [tod/] [tod.c] - Blame information for rev 173

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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