1 |
2 |
alfik |
/******************************************************************************
|
2 |
|
|
* *
|
3 |
|
|
* License Agreement *
|
4 |
|
|
* *
|
5 |
|
|
* Copyright (c) 2009 Altera Corporation, San Jose, California, USA. *
|
6 |
|
|
* All rights reserved. *
|
7 |
|
|
* *
|
8 |
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
9 |
|
|
* copy of this software and associated documentation files (the "Software"), *
|
10 |
|
|
* to deal in the Software without restriction, including without limitation *
|
11 |
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
12 |
|
|
* and/or sell copies of the Software, and to permit persons to whom the *
|
13 |
|
|
* Software is furnished to do so, subject to the following conditions: *
|
14 |
|
|
* *
|
15 |
|
|
* The above copyright notice and this permission notice shall be included in *
|
16 |
|
|
* all copies or substantial portions of the Software. *
|
17 |
|
|
* *
|
18 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
19 |
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
20 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
21 |
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
22 |
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
23 |
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
24 |
|
|
* DEALINGS IN THE SOFTWARE. *
|
25 |
|
|
* *
|
26 |
|
|
* This agreement shall be governed in all respects by the laws of the State *
|
27 |
|
|
* of California and by the laws of the United States of America. *
|
28 |
|
|
* *
|
29 |
|
|
* Altera does not recommend, suggest or require that this reference design *
|
30 |
|
|
* file be used in conjunction or combination with any other product. *
|
31 |
|
|
******************************************************************************/
|
32 |
|
|
#include <errno.h>
|
33 |
|
|
#include "system.h"
|
34 |
|
|
|
35 |
|
|
/*
|
36 |
|
|
* This interrupt registry mechanism works with the Nios II internal interrupt
|
37 |
|
|
* controller (IIC) only. Systems with an external interrupt controller (EIC),
|
38 |
|
|
* or those with the IIC who are using the enhanced interrupt API will
|
39 |
|
|
* utilize the alt_ic_isr_register() routine to register an interrupt.
|
40 |
|
|
*/
|
41 |
|
|
#ifndef NIOS2_EIC_PRESENT
|
42 |
|
|
|
43 |
|
|
#include "sys/alt_irq.h"
|
44 |
|
|
#include "priv/alt_legacy_irq.h"
|
45 |
|
|
#include "os/alt_hooks.h"
|
46 |
|
|
|
47 |
|
|
#include "alt_types.h"
|
48 |
|
|
|
49 |
|
|
/*
|
50 |
|
|
* The header, alt_irq_entry.h, contains the exception entry point, and is
|
51 |
|
|
* provided by the processor component. It is included here, so that the code
|
52 |
|
|
* will be added to the executable only if alt_irq_register() is present, i.e.
|
53 |
|
|
* if no interrupts are registered - there's no need to provide any
|
54 |
|
|
* interrupt handling.
|
55 |
|
|
*/
|
56 |
|
|
|
57 |
|
|
#include "sys/alt_irq_entry.h"
|
58 |
|
|
|
59 |
|
|
/*
|
60 |
|
|
* The header, alt_irq_table.h contains a table describing which function
|
61 |
|
|
* handles each interrupt.
|
62 |
|
|
*/
|
63 |
|
|
|
64 |
|
|
#include "priv/alt_irq_table.h"
|
65 |
|
|
|
66 |
|
|
/*
|
67 |
|
|
* alt_irq_handler() is called to register an interrupt handler. If the
|
68 |
|
|
* function is succesful, then the requested interrupt will be enabled upon
|
69 |
|
|
* return. Registering a NULL handler will disable the interrupt.
|
70 |
|
|
*
|
71 |
|
|
* The return value is 0 if the interrupt handler was registered and the
|
72 |
|
|
* interrupt was enabled, otherwise it is negative.
|
73 |
|
|
*/
|
74 |
|
|
|
75 |
|
|
int alt_irq_register (alt_u32 id,
|
76 |
|
|
void* context,
|
77 |
|
|
alt_isr_func handler)
|
78 |
|
|
{
|
79 |
|
|
int rc = -EINVAL;
|
80 |
|
|
alt_irq_context status;
|
81 |
|
|
|
82 |
|
|
if (id < ALT_NIRQ)
|
83 |
|
|
{
|
84 |
|
|
/*
|
85 |
|
|
* interrupts are disabled while the handler tables are updated to ensure
|
86 |
|
|
* that an interrupt doesn't occur while the tables are in an inconsistant
|
87 |
|
|
* state.
|
88 |
|
|
*/
|
89 |
|
|
|
90 |
|
|
status = alt_irq_disable_all ();
|
91 |
|
|
|
92 |
|
|
alt_irq[id].handler = handler;
|
93 |
|
|
alt_irq[id].context = context;
|
94 |
|
|
|
95 |
|
|
rc = (handler) ? alt_irq_enable (id): alt_irq_disable (id);
|
96 |
|
|
|
97 |
|
|
alt_irq_enable_all(status);
|
98 |
|
|
}
|
99 |
|
|
return rc;
|
100 |
|
|
}
|
101 |
|
|
#endif /* NIOS2_EIC_PRESENT */
|
102 |
|
|
|