4 * http://www.dave-tech.it
5 * http://www.wawnet.biz
6 * mailto:info@wawnet.biz
8 * SPDX-License-Identifier: GPL-2.0+
12 #include <asm/hardware.h>
14 /* we always count down the max. */
15 #define TIMER_LOAD_VAL 0xffff
17 /* macro to read the 16 bit timer */
18 #define READ_TIMER (TCNTO1 & 0xffff)
21 #error CONFIG_USE_IRQ NOT supported
24 static ulong timestamp;
32 TCNTB1 = TIMER_LOAD_VAL;
38 lastdec = TCNTB1 = TIMER_LOAD_VAL;
44 * timer without interrupts
46 ulong get_timer (ulong base)
48 return get_timer_masked () - base;
51 void __udelay (unsigned long usec)
61 while (get_timer_masked () < tmo)
65 ulong get_timer_masked (void)
67 ulong now = READ_TIMER;
71 timestamp += lastdec - now;
73 /* we have an overflow ... */
74 timestamp += lastdec + TIMER_LOAD_VAL - now;
81 void udelay_masked (unsigned long usec)
92 tmo = usec * CONFIG_SYS_HZ;
96 endtime = get_timer(0) + tmo;
99 ulong now = get_timer_masked ();
100 diff = endtime - now;