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.
24 #include <asm/blackfin.h>
27 static ulong timestamp;
28 static ulong last_time;
31 int irq_flags; /* needed by asm-blackfin/system.h */
33 /* Functions just to satisfy the linker */
36 * This function is derived from PowerPC code (read timebase as long long).
37 * On Blackfin it just returns the timer value.
39 unsigned long long get_ticks(void)
45 * This function is derived from PowerPC code (timebase clock frequency).
46 * On Blackfin it returns the number of timer ticks per second.
52 tbclk = CONFIG_SYS_HZ;
56 void enable_interrupts(void)
58 local_irq_restore(int_flag);
61 int disable_interrupts(void)
63 local_irq_save(int_flag);
67 void __udelay(unsigned long usec)
69 unsigned long delay, start, stop;
71 cclk = (CONFIG_CCLK_HZ);
77 * how many clock ticks to delay?
78 * - request(in useconds) * clock_ticks(Hz) / useconds/second
81 delay = (usec * (cclk / 244)) >> 12;
84 delay = (1000 * (cclk / 244)) >> 12;
88 asm volatile (" %0 = CYCLES;" : "=r" (start));
90 asm volatile (" %0 = CYCLES; " : "=r" (stop));
91 } while (stop - start < delay);
97 #define MAX_TIM_LOAD 0xFFFFFFFF
100 bfin_write_TCNTL(0x1);
102 bfin_write_TSCALE(0x0);
103 bfin_write_TCOUNT(MAX_TIM_LOAD);
104 bfin_write_TPERIOD(MAX_TIM_LOAD);
105 bfin_write_TCNTL(0x7);
115 * Any network command or flash
116 * command is started get_timer shall
117 * be called before TCOUNT gets reset,
118 * to implement the accurate timeouts.
120 * How ever milliconds doesn't return
121 * the number that has been elapsed from
124 * As get_timer is used in the u-boot
125 * only for timeouts this should be
128 ulong get_timer(ulong base)
132 /* Number of clocks elapsed */
133 ulong clocks = (MAX_TIM_LOAD - bfin_read_TCOUNT());
136 * Find if the TCOUNT is reset
137 * timestamp gives the number of times
140 if (clocks < last_time)
144 /* Get the number of milliseconds */
145 milisec = clocks / (CONFIG_CCLK_HZ / 1000);
148 * Find the number of millisonds that
149 * got elapsed before this TCOUNT cycle
151 milisec += timestamp * (MAX_TIM_LOAD / (CONFIG_CCLK_HZ / 1000));
153 return (milisec - base);