Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:48

0001 /*
0002  * Real Time Clock (MK48T08) for RTEMS on MVME162
0003  *
0004  *  Author:
0005  *    COPYRIGHT (C) 1997
0006  *    by Katsutoshi Shibuya - BU Denken Co.,Ltd. - Sapporo - JAPAN
0007  *    ALL RIGHTS RESERVED
0008  *
0009  *  The license and distribution terms for this file may be
0010  *  found in the file LICENSE in this distribution or at
0011  *  http://www.rtems.org/license/LICENSE.
0012  *
0013  *  This material is a part of the MVME162 Board Support Package
0014  *  for the RTEMS executive. Its licensing policies are those of the
0015  *  RTEMS above.
0016  */
0017 
0018 #include <rtems.h>
0019 #include <rtems/tod.h>
0020 
0021 #define tod ((volatile unsigned char *)0xfffc1ff8)
0022 
0023 static int  getTod(int n, unsigned char mask)
0024 {
0025     unsigned char   x;
0026 
0027     x = tod[n]&mask;
0028     return (x>>4)*10+(x&0x0f);
0029 }
0030 
0031 static void setTod(int n, unsigned char d)
0032 {
0033     tod[n] = ((d/10)<<4)+(d%10);
0034 }
0035 
0036 void    setRealTimeToRTEMS(void)
0037 {
0038     rtems_time_of_day   t;
0039 
0040     tod[0] |= 0x40; /* Stop read register */
0041     t.year = 1900+getTod(7,0xff);
0042     t.month = getTod(6,0x1f);
0043     t.day = getTod(5,0x3f);
0044     t.hour = getTod(3,0x3f);
0045     t.minute = getTod(2,0x7f);
0046     t.second = getTod(1,0x7f);
0047     t.ticks = 0;
0048     tod[0] &= 0x3f; /* Release read register */
0049 
0050     rtems_clock_set(&t);
0051 }
0052 
0053 void    setRealTimeFromRTEMS()
0054 {
0055     rtems_time_of_day   t;
0056 
0057     rtems_clock_get_tod(&t);
0058     t.year -= 1900;
0059 
0060     tod[0] |= 0x80; /* Stop write register */
0061     setTod(7,t.year);
0062     setTod(6,t.month);
0063     setTod(5,t.day);
0064     setTod(4,1);    /* I don't know which day of week is */
0065     setTod(3,t.hour);
0066     setTod(2,t.minute);
0067     setTod(1,t.second);
0068     tod[0] &= 0x3f; /* Write these parameters */
0069 }
0070 
0071 int checkRealTime()
0072 {
0073     rtems_time_of_day   t;
0074     int     d;
0075 
0076     tod[0] |= 0x40; /* Stop read register */
0077     rtems_clock_get_tod(&t);
0078     if((t.year != 1900+getTod(7,0xff))
0079        || (t.month != getTod(6,0x1f))
0080        || (t.day != getTod(5,0x3f)))
0081     d = 9999;
0082     else
0083     d = (t.hour-getTod(3,0x3f))*3600
0084         + (t.minute-getTod(3,0x7f))*60
0085         + (t.second - getTod(1,0x7f));
0086     tod[1] &= 0x3f;
0087     return d;
0088 }