4 * http://www.dave-tech.it
5 * http://www.wawnet.biz
6 * mailto:info@wawnet.biz
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/hardware.h>
30 /* we always count down the max. */
31 #define TIMER_LOAD_VAL 0xffff
33 /* macro to read the 16 bit timer */
34 #define READ_TIMER (TCNTO1 & 0xffff)
37 #error CONFIG_USE_IRQ NOT supported
40 static ulong timestamp;
48 TCNTB1 = TIMER_LOAD_VAL;
54 lastdec = TCNTB1 = TIMER_LOAD_VAL;
60 * timer without interrupts
62 ulong get_timer (ulong base)
64 return get_timer_masked () - base;
67 void __udelay (unsigned long usec)
77 while (get_timer_masked () < tmo)
81 void reset_timer_masked (void)
88 ulong get_timer_masked (void)
90 ulong now = READ_TIMER;
94 timestamp += lastdec - now;
96 /* we have an overflow ... */
97 timestamp += lastdec + TIMER_LOAD_VAL - now;
104 void udelay_masked (unsigned long usec)
112 tmo *= CONFIG_SYS_HZ;
115 tmo = usec * CONFIG_SYS_HZ;
119 endtime = get_timer(0) + tmo;
122 ulong now = get_timer_masked ();
123 diff = endtime - now;