2 * U-boot - interrupts.c Interrupt related routines
4 * Copyright (c) 2005 blackfin.uclinux.org
6 * This file is based on interrupts.c
7 * Copyright 1996 Roman Zippel
8 * Copyright 1999 D. Jeff Dionne <jeff@uclinux.org>
9 * Copyright 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
10 * Copyright 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
11 * Copyright 2003 Metrowerks/Motorola
12 * Copyright 2003 Bas Vermeulen <bas@buyways.nl>,
13 * BuyWays B.V. (www.buyways.nl)
15 * (C) Copyright 2000-2004
16 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
18 * See file CREDITS for list of people who contributed to this
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License as
23 * published by the Free Software Foundation; either version 2 of
24 * the License, or (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
38 #include <asm/machdep.h>
40 #include <asm/cpu/defBF533.h>
43 static ulong timestamp;
44 static ulong last_time;
47 int irq_flags; /* needed by asm-blackfin/system.h */
49 /* Functions just to satisfy the linker */
52 * This function is derived from PowerPC code (read timebase as long long).
53 * On BF533 it just returns the timer value.
55 unsigned long long get_ticks(void)
61 * This function is derived from PowerPC code (timebase clock frequency).
62 * On BF533 it returns the number of timer ticks per second.
64 ulong get_tbclk (void)
72 void enable_interrupts(void)
74 restore_flags(int_flag);
77 int disable_interrupts(void)
79 save_and_cli(int_flag);
83 int interrupt_init(void)
88 void udelay(unsigned long usec)
90 unsigned long delay, start, stop;
92 cclk = (CONFIG_CCLK_HZ);
96 * how many clock ticks to delay?
97 * - request(in useconds) * clock_ticks(Hz) / useconds/second
100 delay = (usec * (cclk/244)) >> 12 ;
103 delay = (1000 * (cclk/244)) >> 12 ;
107 asm volatile (" %0 = CYCLES;": "=g"(start));
109 asm volatile (" %0 = CYCLES; ": "=g"(stop));
110 } while (stop - start < delay);
116 void timer_init(void)
120 *pTCOUNT = MAX_TIM_LOAD;
121 *pTPERIOD = MAX_TIM_LOAD;
129 /* Any network command or flash
130 * command is started get_timer shall
131 * be called before TCOUNT gets reset,
132 * to implement the accurate timeouts.
134 * How ever milliconds doesn't return
135 * the number that has been elapsed from
138 * As get_timer is used in the u-boot
139 * only for timeouts this should be
142 ulong get_timer(ulong base)
146 /* Number of clocks elapsed */
147 ulong clocks = (MAX_TIM_LOAD - (*pTCOUNT));
149 /* Find if the TCOUNT is reset
150 timestamp gives the number of times
152 if(clocks < last_time)
156 /* Get the number of milliseconds */
157 milisec = clocks/(CONFIG_CCLK_HZ / 1000);
159 /* Find the number of millisonds
160 that got elapsed before this TCOUNT
162 milisec += timestamp * (MAX_TIM_LOAD/(CONFIG_CCLK_HZ / 1000));
164 return (milisec - base);