2 * U-boot - interrupts.c Interrupt related routines
4 * Copyright (c) 2005-2008 Analog Devices Inc.
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 * Licensed under the GPL-2 or later.
23 #include <asm/blackfin.h>
26 static ulong timestamp
;
27 static ulong last_time
;
30 int irq_flags
; /* needed by asm-blackfin/system.h */
32 /* Functions just to satisfy the linker */
35 * This function is derived from PowerPC code (read timebase as long long).
36 * On Blackfin it just returns the timer value.
38 unsigned long long get_ticks(void)
44 * This function is derived from PowerPC code (timebase clock frequency).
45 * On Blackfin it returns the number of timer ticks per second.
55 void enable_interrupts(void)
57 local_irq_restore(int_flag
);
60 int disable_interrupts(void)
62 local_irq_save(int_flag
);
66 void udelay(unsigned long usec
)
68 unsigned long delay
, start
, stop
;
70 cclk
= (CONFIG_CCLK_HZ
);
74 * how many clock ticks to delay?
75 * - request(in useconds) * clock_ticks(Hz) / useconds/second
78 delay
= (usec
* (cclk
/ 244)) >> 12;
81 delay
= (1000 * (cclk
/ 244)) >> 12;
85 asm volatile (" %0 = CYCLES;" : "=r" (start
));
87 asm volatile (" %0 = CYCLES; " : "=r" (stop
));
88 } while (stop
- start
< delay
);
94 #define MAX_TIM_LOAD 0xFFFFFFFF
99 *pTCOUNT
= MAX_TIM_LOAD
;
100 *pTPERIOD
= MAX_TIM_LOAD
;
111 * Any network command or flash
112 * command is started get_timer shall
113 * be called before TCOUNT gets reset,
114 * to implement the accurate timeouts.
116 * How ever milliconds doesn't return
117 * the number that has been elapsed from
120 * As get_timer is used in the u-boot
121 * only for timeouts this should be
124 ulong
get_timer(ulong base
)
128 /* Number of clocks elapsed */
129 ulong clocks
= (MAX_TIM_LOAD
- (*pTCOUNT
));
132 * Find if the TCOUNT is reset
133 * timestamp gives the number of times
136 if (clocks
< last_time
)
140 /* Get the number of milliseconds */
141 milisec
= clocks
/ (CONFIG_CCLK_HZ
/ 1000);
144 * Find the number of millisonds that
145 * got elapsed before this TCOUNT cycle
147 milisec
+= timestamp
* (MAX_TIM_LOAD
/ (CONFIG_CCLK_HZ
/ 1000));
149 return (milisec
- base
);
152 void reset_timer(void)