2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
6 * Scott McNutt <smcnutt@psyent.com>
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,
30 #include <asm/ptrace.h>
33 #ifdef CONFIG_STATUS_LED
34 #include <status_led.h>
37 /****************************************************************************/
40 interrupt_handler_t *handler;
45 static struct irq_action irq_vecs[64];
47 /*************************************************************************/
48 volatile ulong timestamp = 0;
50 void reset_timer (void)
55 ulong get_timer (ulong base)
57 return (timestamp - base);
60 void set_timer (ulong t)
66 /* The board must handle this interrupt if a timer is not
69 #if defined(CFG_NIOS_TMRBASE)
70 void timer_interrupt (struct pt_regs *regs)
72 /* Interrupt is cleared by writing anything to the
75 nios_timer_t *tmr = (nios_timer_t *)CFG_NIOS_TMRBASE;
77 timestamp += CFG_NIOS_TMRMS;
78 #ifdef CONFIG_STATUS_LED
79 status_led_tick(timestamp);
84 /*************************************************************************/
85 int disable_interrupts (void)
89 /* Writing anything to CLR_IE disables interrupts */
90 val = rdctl (CTL_STATUS);
91 wrctl (CTL_CLR_IE, 0);
92 return (val & STATUS_IE);
95 void enable_interrupts( void )
97 /* Writing anything SET_IE enables interrupts */
98 wrctl (CTL_SET_IE, 0);
101 void external_interrupt (struct pt_regs *regs)
105 vec = (regs->status & STATUS_IPRI) >> 9; /* ipri */
107 irq_vecs[vec].count++;
108 if (irq_vecs[vec].handler != NULL) {
109 (*irq_vecs[vec].handler)(irq_vecs[vec].arg);
111 /* A sad side-effect of masking a bogus interrupt is
112 * that lower priority interrupts will also be disabled.
113 * This is probably not what we want ... so hang insted.
115 printf ("Unhandled interrupt: 0x%x\n", vec);
116 disable_interrupts ();
121 /*************************************************************************/
122 int interrupt_init (void)
126 #if defined(CFG_NIOS_TMRBASE)
127 nios_timer_t *tmr = (nios_timer_t *)CFG_NIOS_TMRBASE;
129 tmr->control &= ~NIOS_TIMER_ITO;
130 tmr->control |= NIOS_TIMER_STOP;
133 for (vec=0; vec<64; vec++ ) {
134 irq_vecs[vec].handler = NULL;
135 irq_vecs[vec].arg = NULL;
136 irq_vecs[vec].count = 0;
139 /* Need timus interruptus -- start the lopri timer */
140 #if defined(CFG_NIOS_TMRBASE)
141 tmr->control |= ( NIOS_TIMER_ITO |
144 ipri (CFG_NIOS_TMRIRQ + 1);
146 enable_interrupts ();
150 void irq_install_handler (int vec, interrupt_handler_t *handler, void *arg)
152 struct irq_action *irqa = irq_vecs;
156 if (irqa[i].handler != NULL) {
157 printf ("Interrupt vector %d: handler 0x%x "
159 vec, (uint)handler, (uint)irqa[i].handler);
162 flag = disable_interrupts ();
163 irqa[i].handler = handler;
166 enable_interrupts ();
169 /*************************************************************************/
170 #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
171 int do_irqinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
175 printf ("\nInterrupt-Information:\n");
176 printf ("Nr Routine Arg CouIt's ok to cnt\n");
178 for (vec=0; vec<64; vec++) {
179 if (irq_vecs[vec].handler != NULL) {
180 printf ("%02d %08lx %08lx %d\n",
182 (ulong)irq_vecs[vec].handler<<1,
183 (ulong)irq_vecs[vec].arg,
184 irq_vecs[vec].count);
190 #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */