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>
34 #ifdef CONFIG_STATUS_LED
35 #include <status_led.h>
38 /****************************************************************************/
41 interrupt_handler_t
*handler
;
46 static struct irq_action irq_vecs
[64];
48 /*************************************************************************/
49 volatile ulong timestamp
= 0;
51 void reset_timer (void)
56 ulong
get_timer (ulong base
)
59 return (timestamp
- base
);
62 void set_timer (ulong t
)
68 /* The board must handle this interrupt if a timer is not
71 #if defined(CFG_NIOS_TMRBASE)
72 void timer_interrupt (struct pt_regs
*regs
)
74 /* Interrupt is cleared by writing anything to the
77 nios_timer_t
*tmr
= (nios_timer_t
*)CFG_NIOS_TMRBASE
;
79 timestamp
+= CFG_NIOS_TMRMS
;
80 #ifdef CONFIG_STATUS_LED
81 status_led_tick(timestamp
);
86 /*************************************************************************/
87 int disable_interrupts (void)
91 /* Writing anything to CLR_IE disables interrupts */
92 val
= rdctl (CTL_STATUS
);
93 wrctl (CTL_CLR_IE
, 0);
94 return (val
& STATUS_IE
);
97 void enable_interrupts( void )
99 /* Writing anything SET_IE enables interrupts */
100 wrctl (CTL_SET_IE
, 0);
103 void external_interrupt (struct pt_regs
*regs
)
107 vec
= (regs
->status
& STATUS_IPRI
) >> 9; /* ipri */
109 irq_vecs
[vec
].count
++;
110 if (irq_vecs
[vec
].handler
!= NULL
) {
111 (*irq_vecs
[vec
].handler
)(irq_vecs
[vec
].arg
);
113 /* A sad side-effect of masking a bogus interrupt is
114 * that lower priority interrupts will also be disabled.
115 * This is probably not what we want ... so hang insted.
117 printf ("Unhandled interrupt: 0x%x\n", vec
);
118 disable_interrupts ();
123 /*************************************************************************/
124 int interrupt_init (void)
128 #if defined(CFG_NIOS_TMRBASE)
129 nios_timer_t
*tmr
= (nios_timer_t
*)CFG_NIOS_TMRBASE
;
131 tmr
->control
&= ~NIOS_TIMER_ITO
;
132 tmr
->control
|= NIOS_TIMER_STOP
;
133 #if defined(CFG_NIOS_TMRCNT)
134 tmr
->periodl
= CFG_NIOS_TMRCNT
& 0xffff;
135 tmr
->periodh
= (CFG_NIOS_TMRCNT
>> 16) & 0xffff;
139 for (vec
=0; vec
<64; vec
++ ) {
140 irq_vecs
[vec
].handler
= NULL
;
141 irq_vecs
[vec
].arg
= NULL
;
142 irq_vecs
[vec
].count
= 0;
145 /* Need timus interruptus -- start the lopri timer */
146 #if defined(CFG_NIOS_TMRBASE)
147 tmr
->control
|= ( NIOS_TIMER_ITO
|
150 ipri (CFG_NIOS_TMRIRQ
+ 1);
152 enable_interrupts ();
156 void irq_install_handler (int vec
, interrupt_handler_t
*handler
, void *arg
)
158 struct irq_action
*irqa
= irq_vecs
;
162 if (irqa
[i
].handler
!= NULL
) {
163 printf ("Interrupt vector %d: handler 0x%x "
165 vec
, (uint
)handler
, (uint
)irqa
[i
].handler
);
168 flag
= disable_interrupts ();
169 irqa
[i
].handler
= handler
;
172 enable_interrupts ();
175 /*************************************************************************/
176 #if defined(CONFIG_CMD_IRQ)
177 int do_irqinfo (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
181 printf ("\nInterrupt-Information:\n");
182 printf ("Nr Routine Arg Count\n");
184 for (vec
=0; vec
<64; vec
++) {
185 if (irq_vecs
[vec
].handler
!= NULL
) {
186 printf ("%02d %08lx %08lx %d\n",
188 (ulong
)irq_vecs
[vec
].handler
<<1,
189 (ulong
)irq_vecs
[vec
].arg
,
190 irq_vecs
[vec
].count
);