1 |
8 |
alfik |
#ifndef __ALT_LEGACY_IRQ_H__
|
2 |
|
|
#define __ALT_LEGACY_IRQ_H__
|
3 |
|
|
|
4 |
|
|
/******************************************************************************
|
5 |
|
|
* *
|
6 |
|
|
* License Agreement *
|
7 |
|
|
* *
|
8 |
|
|
* Copyright (c) 2009 Altera Corporation, San Jose, California, USA. *
|
9 |
|
|
* All rights reserved. *
|
10 |
|
|
* *
|
11 |
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
12 |
|
|
* copy of this software and associated documentation files (the "Software"), *
|
13 |
|
|
* to deal in the Software without restriction, including without limitation *
|
14 |
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
15 |
|
|
* and/or sell copies of the Software, and to permit persons to whom the *
|
16 |
|
|
* Software is furnished to do so, subject to the following conditions: *
|
17 |
|
|
* *
|
18 |
|
|
* The above copyright notice and this permission notice shall be included in *
|
19 |
|
|
* all copies or substantial portions of the Software. *
|
20 |
|
|
* *
|
21 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
22 |
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
23 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
24 |
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
25 |
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
26 |
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
27 |
|
|
* DEALINGS IN THE SOFTWARE. *
|
28 |
|
|
* *
|
29 |
|
|
* This agreement shall be governed in all respects by the laws of the State *
|
30 |
|
|
* of California and by the laws of the United States of America. *
|
31 |
|
|
* *
|
32 |
|
|
******************************************************************************/
|
33 |
|
|
|
34 |
|
|
/*
|
35 |
|
|
* This file provides prototypes and inline implementations of certain routines
|
36 |
|
|
* used by the legacy interrupt API. Do not include this in your driver or
|
37 |
|
|
* application source files, use "sys/alt_irq.h" instead to access the proper
|
38 |
|
|
* public API.
|
39 |
|
|
*/
|
40 |
|
|
|
41 |
|
|
#include <errno.h>
|
42 |
|
|
#include "system.h"
|
43 |
|
|
|
44 |
|
|
#ifndef NIOS2_EIC_PRESENT
|
45 |
|
|
|
46 |
|
|
#include "nios2.h"
|
47 |
|
|
#include "alt_types.h"
|
48 |
|
|
|
49 |
|
|
#include "sys/alt_irq.h"
|
50 |
|
|
|
51 |
|
|
#ifdef __cplusplus
|
52 |
|
|
extern "C"
|
53 |
|
|
{
|
54 |
|
|
#endif /* __cplusplus */
|
55 |
|
|
|
56 |
|
|
/*
|
57 |
|
|
* alt_irq_register() can be used to register an interrupt handler. If the
|
58 |
|
|
* function is succesful, then the requested interrupt will be enabled upon
|
59 |
|
|
* return.
|
60 |
|
|
*/
|
61 |
|
|
extern int alt_irq_register (alt_u32 id,
|
62 |
|
|
void* context,
|
63 |
|
|
alt_isr_func handler);
|
64 |
|
|
|
65 |
|
|
/*
|
66 |
|
|
* alt_irq_disable() disables the individual interrupt indicated by "id".
|
67 |
|
|
*/
|
68 |
|
|
static ALT_INLINE int ALT_ALWAYS_INLINE alt_irq_disable (alt_u32 id)
|
69 |
|
|
{
|
70 |
|
|
alt_irq_context status;
|
71 |
|
|
extern volatile alt_u32 alt_irq_active;
|
72 |
|
|
|
73 |
|
|
status = alt_irq_disable_all ();
|
74 |
|
|
|
75 |
|
|
alt_irq_active &= ~(1 << id);
|
76 |
|
|
NIOS2_WRITE_IENABLE (alt_irq_active);
|
77 |
|
|
|
78 |
|
|
alt_irq_enable_all(status);
|
79 |
|
|
|
80 |
|
|
return 0;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
/*
|
84 |
|
|
* alt_irq_enable() enables the individual interrupt indicated by "id".
|
85 |
|
|
*/
|
86 |
|
|
static ALT_INLINE int ALT_ALWAYS_INLINE alt_irq_enable (alt_u32 id)
|
87 |
|
|
{
|
88 |
|
|
alt_irq_context status;
|
89 |
|
|
extern volatile alt_u32 alt_irq_active;
|
90 |
|
|
|
91 |
|
|
status = alt_irq_disable_all ();
|
92 |
|
|
|
93 |
|
|
alt_irq_active |= (1 << id);
|
94 |
|
|
NIOS2_WRITE_IENABLE (alt_irq_active);
|
95 |
|
|
|
96 |
|
|
alt_irq_enable_all(status);
|
97 |
|
|
|
98 |
|
|
return 0;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
#ifndef ALT_EXCEPTION_STACK
|
102 |
|
|
/*
|
103 |
|
|
* alt_irq_initerruptable() should only be called from within an ISR. It is used
|
104 |
|
|
* to allow higer priority interrupts to interrupt the current ISR. The input
|
105 |
|
|
* argument, "priority", is the priority, i.e. interrupt number of the current
|
106 |
|
|
* interrupt.
|
107 |
|
|
*
|
108 |
|
|
* If this function is called, then the ISR is required to make a call to
|
109 |
|
|
* alt_irq_non_interruptible() before returning. The input argument to
|
110 |
|
|
* alt_irq_non_interruptible() is the return value from alt_irq_interruptible().
|
111 |
|
|
*
|
112 |
|
|
* Care should be taken when using this pair of functions, since they increasing
|
113 |
|
|
* the system overhead associated with interrupt handling.
|
114 |
|
|
*
|
115 |
|
|
* If you are using an exception stack then nested interrupts won't work, so
|
116 |
|
|
* these functions are not available in that case.
|
117 |
|
|
*/
|
118 |
|
|
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_irq_interruptible (alt_u32 priority)
|
119 |
|
|
{
|
120 |
|
|
extern volatile alt_u32 alt_priority_mask;
|
121 |
|
|
extern volatile alt_u32 alt_irq_active;
|
122 |
|
|
|
123 |
|
|
alt_u32 old_priority;
|
124 |
|
|
|
125 |
|
|
old_priority = alt_priority_mask;
|
126 |
|
|
alt_priority_mask = (1 << priority) - 1;
|
127 |
|
|
|
128 |
|
|
NIOS2_WRITE_IENABLE (alt_irq_active & alt_priority_mask);
|
129 |
|
|
|
130 |
|
|
NIOS2_WRITE_STATUS (1);
|
131 |
|
|
|
132 |
|
|
return old_priority;
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
/*
|
136 |
|
|
* See Comments above for alt_irq_interruptible() for an explanation of the use of this
|
137 |
|
|
* function.
|
138 |
|
|
*/
|
139 |
|
|
static ALT_INLINE void ALT_ALWAYS_INLINE alt_irq_non_interruptible (alt_u32 mask)
|
140 |
|
|
{
|
141 |
|
|
extern volatile alt_u32 alt_priority_mask;
|
142 |
|
|
extern volatile alt_u32 alt_irq_active;
|
143 |
|
|
|
144 |
|
|
NIOS2_WRITE_STATUS (0);
|
145 |
|
|
|
146 |
|
|
alt_priority_mask = mask;
|
147 |
|
|
|
148 |
|
|
NIOS2_WRITE_IENABLE (mask & alt_irq_active);
|
149 |
|
|
}
|
150 |
|
|
#endif /* ALT_EXCEPTION_STACK */
|
151 |
|
|
|
152 |
|
|
#ifdef __cplusplus
|
153 |
|
|
}
|
154 |
|
|
#endif /* __cplusplus */
|
155 |
|
|
|
156 |
|
|
#endif /* NIOS2_EIC_PRESENT */
|
157 |
|
|
|
158 |
|
|
#endif /* __ALT_LEGACY_IRQ_H__ */
|