]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cpu/nios/interrupts.c
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 /****************************************************************************/
37 interrupt_handler_t
*handler
;
42 static struct irq_action irq_vecs
[64];
44 /*************************************************************************/
45 volatile ulong timestamp
= 0;
47 void reset_timer (void)
52 ulong
get_timer (ulong base
)
54 return (timestamp
- base
);
57 void set_timer (ulong t
)
63 /* The board must handle this interrupt if a timer is not
66 #if defined(CFG_NIOS_TMRBASE)
67 void timer_interrupt (struct pt_regs
*regs
)
69 /* Interrupt is cleared by writing anything to the
72 nios_timer_t
*tmr
= (nios_timer_t
*)CFG_NIOS_TMRBASE
;
74 timestamp
+= CFG_NIOS_TMRMS
;
78 /*************************************************************************/
79 int disable_interrupts (void)
83 /* Writing anything to CLR_IE disables interrupts */
84 val
= rdctl (CTL_STATUS
);
85 wrctl (CTL_CLR_IE
, 0);
86 return (val
& STATUS_IE
);
89 void enable_interrupts( void )
91 /* Writing anything SET_IE enables interrupts */
92 wrctl (CTL_SET_IE
, 0);
95 void external_interrupt (struct pt_regs
*regs
)
99 vec
= (regs
->status
& STATUS_IPRI
) >> 9; /* ipri */
101 irq_vecs
[vec
].count
++;
102 if (irq_vecs
[vec
].handler
!= NULL
) {
103 (*irq_vecs
[vec
].handler
)(irq_vecs
[vec
].arg
);
105 /* A sad side-effect of masking a bogus interrupt is
106 * that lower priority interrupts will also be disabled.
107 * This is probably not what we want ... so hang insted.
109 printf ("Unhandled interrupt: 0x%x\n", vec
);
110 disable_interrupts ();
115 /*************************************************************************/
116 int interrupt_init (void)
120 #if defined(CFG_NIOS_TMRBASE)
121 nios_timer_t
*tmr
= (nios_timer_t
*)CFG_NIOS_TMRBASE
;
123 tmr
->control
&= ~NIOS_TIMER_ITO
;
124 tmr
->control
|= NIOS_TIMER_STOP
;
127 for (vec
=0; vec
<64; vec
++ ) {
128 irq_vecs
[vec
].handler
= NULL
;
129 irq_vecs
[vec
].arg
= NULL
;
130 irq_vecs
[vec
].count
= 0;
133 /* Need timus interruptus -- start the lopri timer */
134 #if defined(CFG_NIOS_TMRBASE)
135 tmr
->control
|= ( NIOS_TIMER_ITO
|
138 ipri (CFG_NIOS_TMRIRQ
+ 1);
140 enable_interrupts ();
144 void irq_install_handler (int vec
, interrupt_handler_t
*handler
, void *arg
)
146 struct irq_action
*irqa
= irq_vecs
;
150 if (irqa
[i
].handler
!= NULL
) {
151 printf ("Interrupt vector %d: handler 0x%x "
153 vec
, (uint
)handler
, (uint
)irqa
[i
].handler
);
156 flag
= disable_interrupts ();
157 irqa
[i
].handler
= handler
;
160 enable_interrupts ();
163 /*************************************************************************/
164 #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
165 int do_irqinfo (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
169 printf ("\nInterrupt-Information:\n");
170 printf ("Nr Routine Arg CouIt's ok to cnt\n");
172 for (vec
=0; vec
<64; vec
++) {
173 if (irq_vecs
[vec
].handler
!= NULL
) {
174 printf ("%02d %08lx %08lx %d\n",
176 (ulong
)irq_vecs
[vec
].handler
<<1,
177 (ulong
)irq_vecs
[vec
].arg
,
178 irq_vecs
[vec
].count
);
184 #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */