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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [m68knommu/] [kernel/] [time.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1625 jcastillo
/*
2
 *  linux/arch/m68knommu/kernel/time.c
3
 *
4
 *  Copyright (C) 1998  D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
5
 *                      Kenneth Albanowski <kjahds@kjahds.com>,
6
 *                      The Silver Hammer Group, Ltd.
7
 *
8
 *  Copied/hacked from:
9
 *
10
 *  linux/arch/m68k/kernel/time.c
11
 *
12
 *  Copyright (C) 1991, 1992, 1995  Linus Torvalds
13
 *
14
 * This file contains the m68k-specific time handling details.
15
 * Most of the stuff is located in the machine specific files.
16
 */
17
 
18
#include <linux/config.h>
19
#include <linux/errno.h>
20
#include <linux/sched.h>
21
#include <linux/kernel.h>
22
#include <linux/param.h>
23
#include <linux/string.h>
24
#include <linux/mm.h>
25
 
26
#include <asm/machdep.h>
27
#include <asm/segment.h>
28
#include <asm/io.h>
29
 
30
#include <linux/timex.h>
31
 
32
 
33
static inline int set_rtc_mmss(unsigned long nowtime)
34
{
35
  if (mach_set_clock_mmss)
36
    return mach_set_clock_mmss (nowtime);
37
  return -1;
38
}
39
 
40
/*
41
 * timer_interrupt() needs to keep up the real-time clock,
42
 * as well as call the "do_timer()" routine every clocktick
43
 */
44
void timer_interrupt(int irq, void *dummy, struct pt_regs * regs)
45
{
46
        /* last time the cmos clock got updated */
47
        static long last_rtc_update=0;
48
 
49
        /* may need to kick the hardware timer */
50
        if (mach_tick)
51
          mach_tick();
52
 
53
        do_timer(regs);
54
 
55
        /*
56
         * If we have an externally synchronized Linux clock, then update
57
         * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
58
         * called as close as possible to 500 ms before the new second starts.
59
         */
60
        if (time_state != TIME_BAD && xtime.tv_sec > last_rtc_update + 660 &&
61
            xtime.tv_usec > 500000 - (tick >> 1) &&
62
            xtime.tv_usec < 500000 + (tick >> 1)) {
63
          if (set_rtc_mmss(xtime.tv_sec) == 0)
64
            last_rtc_update = xtime.tv_sec;
65
          else
66
            last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
67
        }
68
 
69
}
70
 
71
/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
72
 * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
73
 * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
74
 *
75
 * [For the Julian calendar (which was used in Russia before 1917,
76
 * Britain & colonies before 1752, anywhere else before 1582,
77
 * and is still in use by some communities) leave out the
78
 * -year/100+year/400 terms, and add 10.]
79
 *
80
 * This algorithm was first published by Gauss (I think).
81
 *
82
 * WARNING: this function will overflow on 2106-02-07 06:28:16 on
83
 * machines were long is 32-bit! (However, as time_t is signed, we
84
 * will already get problems at other places on 2038-01-19 03:14:08)
85
 */
86
static inline unsigned long mktime(unsigned int year, unsigned int mon,
87
        unsigned int day, unsigned int hour,
88
        unsigned int min, unsigned int sec)
89
{
90
        if (0 >= (int) (mon -= 2)) {     /* 1..12 -> 11,12,1..10 */
91
                mon += 12;      /* Puts Feb last since it has leap day */
92
                year -= 1;
93
        }
94
        return (((
95
            (unsigned long)(year/4 - year/100 + year/400 + 367*mon/12 + day) +
96
              year*365 - 719499
97
            )*24 + hour /* now have hours */
98
           )*60 + min /* now have minutes */
99
          )*60 + sec; /* finally seconds */
100
}
101
 
102
void time_init(void)
103
{
104
        unsigned int year, mon, day, hour, min, sec;
105
 
106
        extern void arch_gettod(int *year, int *mon, int *day, int *hour,
107
                                int *min, int *sec);
108
 
109
        arch_gettod (&year, &mon, &day, &hour, &min, &sec);
110
 
111
        if ((year += 1900) < 1970)
112
                year += 100;
113
        xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
114
        xtime.tv_usec = 0;
115
 
116
        if (mach_sched_init)
117
                mach_sched_init(timer_interrupt);
118
}
119
 
120
/*
121
 * This version of gettimeofday has near microsecond resolution.
122
 */
123
void do_gettimeofday(struct timeval *tv)
124
{
125
        unsigned long flags;
126
 
127
        save_flags(flags);
128
        cli();
129
        *tv = xtime;
130
        if (mach_gettimeoffset) {
131
          tv->tv_usec += mach_gettimeoffset();
132
          if (tv->tv_usec >= 1000000) {
133
            tv->tv_usec -= 1000000;
134
            tv->tv_sec++;
135
          }
136
        }
137
        restore_flags(flags);
138
}
139
 
140
void do_settimeofday(struct timeval *tv)
141
{
142
        cli();
143
        /* This is revolting. We need to set the xtime.tv_usec
144
         * correctly. However, the value in this location is
145
         * is value at the last tick.
146
         * Discover what correction gettimeofday
147
         * would have done, and then undo it!
148
         */
149
        if (mach_gettimeoffset)
150
          tv->tv_usec -= mach_gettimeoffset();
151
 
152
        if (tv->tv_usec < 0) {
153
                tv->tv_usec += 1000000;
154
                tv->tv_sec--;
155
        }
156
 
157
        xtime = *tv;
158
        time_state = TIME_BAD;
159
        time_maxerror = MAXPHASE;
160
        time_esterror = MAXPHASE;
161
        sti();
162
}
163
 

powered by: WebSVN 2.1.0

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