1 /* int-sethandler.c - register an interrupt handler in XTOS */
4 * Copyright (c) 1999-2006 Tensilica Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include <xtensa/config/core.h>
27 #include <xtensa/config/specreg.h>
28 #include "xtos-internal.h"
31 #if XCHAL_HAVE_INTERRUPTS
33 * Table of interrupt handlers.
34 * NOTE: if the NSA/NSAU instructions are configured, then to save
35 * a few cycles in the interrupt dispatcher code, the
36 * _xtos_interrupt_table[] array is filled in reverse.
37 * IMPORTANT: Use the MAPINT() macro defined in xtos-internal.h to index entries in this array.
39 extern XtosIntHandlerEntry _xtos_interrupt_table[XCHAL_NUM_INTERRUPTS];
40 extern void _xtos_unhandled_interrupt();
44 _xtos_handler _xtos_set_interrupt_handler_arg( int n, _xtos_handler f, void *arg )
46 #if XCHAL_HAVE_INTERRUPTS
47 XtosIntHandlerEntry *entry;
50 if( n < 0 || n >= XCHAL_NUM_INTERRUPTS )
51 return 0; /* invalid interrupt number */
52 if( Xthal_intlevel[n] > XTOS_LOCKLEVEL )
53 return 0; /* priority level too high to safely handle in C */
54 entry = _xtos_interrupt_table + MAPINT(n);
60 entry->handler = &_xtos_unhandled_interrupt;
61 entry->arg = (void*)n;
63 return ((old == &_xtos_unhandled_interrupt) ? 0 : old);
70 _xtos_handler _xtos_set_interrupt_handler( int n, _xtos_handler f )
72 return _xtos_set_interrupt_handler_arg( n, f, (void*) n );
78 * User vector mode exception handler for the LEVEL1_INTERRUPT cause.
79 * NOTE: this is now implemented in assembler for performance.
80 * This C handler is left as an example interrupt dispatcher written in C.
81 * The actual handler in int-lowpri-dispatcher.S is more fully featured.
83 UserFrame* _xtos_p_level1int_handler( UserFrame* uf /*, int cause */ )
85 #if XCHAL_HAVE_INTERRUPTS
89 ints = xthal_get_interrupt();
90 # if XTOS_VIRTUAL_INTENABLE
91 ints &= _xtos_enabled;
93 ints &= xthal_get_intenable();
95 for( index = 0 ; ints != 0 ; ints >>= 1, index++ )
102 * Clear interrupt (in case it's edge-triggered or software or write-error).
103 * This must be done *before* processing the interrupt.
105 xthal_set_intclear( 1 << index );
107 f = _xtos_interrupt_table[MAPINT(index)].handler;
109 f( _xtos_interrupt_table[MAPINT(index)].arg /*, uf, index*/ );
112 #endif /*XCHAL_HAVE_INTERRUPTS*/