]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cpu/lh7a40x/interrupts.c
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Alex Zuepke <azu@sysgo.de>
11 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
13 * See file CREDITS for list of people who contributed to this
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
36 static ulong timer_load_val
= 0;
38 /* macro to read the 16 bit timer */
39 static inline ulong
READ_TIMER(void)
41 lh7a40x_timers_t
* timers
= LH7A40X_TIMERS_PTR
;
42 lh7a40x_timer_t
* timer
= &timers
->timer1
;
44 return (timer
->value
& 0x0000ffff);
47 static ulong timestamp
;
50 int interrupt_init (void)
52 lh7a40x_timers_t
* timers
= LH7A40X_TIMERS_PTR
;
53 lh7a40x_timer_t
* timer
= &timers
->timer1
;
55 /* a periodic timer using the 508kHz source */
56 timer
->control
= (TIMER_PER
| TIMER_CLK508K
);
58 if (timer_load_val
== 0) {
60 * 10ms period with 508.469kHz clock = 5084
62 timer_load_val
= CONFIG_SYS_HZ
/100;
65 /* load value for 10 ms timeout */
66 lastdec
= timer
->load
= timer_load_val
;
68 /* auto load, start timer */
69 timer
->control
= timer
->control
| TIMER_EN
;
76 * timer without interrupts
79 void reset_timer (void)
81 reset_timer_masked ();
84 ulong
get_timer (ulong base
)
86 return (get_timer_masked() - base
);
89 void set_timer (ulong t
)
94 void udelay (unsigned long usec
)
101 tmo
*= CONFIG_SYS_HZ
;
106 tmo
= usec
* CONFIG_SYS_HZ
;
113 /* check for rollover during this delay */
115 if ((tmp
+ tmo
) < tmp
)
116 reset_timer_masked(); /* timer would roll over */
120 while (get_timer_masked () < tmo
);
123 void reset_timer_masked (void)
126 lastdec
= READ_TIMER();
130 ulong
get_timer_masked (void)
132 ulong now
= READ_TIMER();
134 if (lastdec
>= now
) {
136 timestamp
+= (lastdec
- now
);
138 /* we have an overflow ... */
139 timestamp
+= ((lastdec
+ timer_load_val
) - now
);
146 void udelay_masked (unsigned long usec
)
155 tmo
*= CONFIG_SYS_HZ
;
159 tmo
= usec
* CONFIG_SYS_HZ
;
166 endtime
= get_timer_masked () + tmo
;
169 ulong now
= get_timer_masked ();
170 diff
= endtime
- now
;
175 * This function is derived from PowerPC code (read timebase as long long).
176 * On ARM it just returns the timer value.
178 unsigned long long get_ticks(void)
184 * This function is derived from PowerPC code (timebase clock frequency).
185 * On ARM it returns the number of timer ticks per second.
187 ulong
get_tbclk (void)
191 tbclk
= timer_load_val
* 100;