| 1 |
2 |
alfik |
#ifndef __ALT_IRQ_H__
|
| 2 |
|
|
#define __ALT_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 |
|
|
* alt_irq.h is the Nios II specific implementation of the interrupt controller
|
| 36 |
|
|
* interface.
|
| 37 |
|
|
*
|
| 38 |
|
|
* Nios II includes optional support for an external interrupt controller.
|
| 39 |
|
|
* When an external controller is present, the "Enhanced" interrupt API
|
| 40 |
|
|
* must be used to manage individual interrupts. The enhanced API also
|
| 41 |
|
|
* supports the processor's internal interrupt controller. Certain API
|
| 42 |
|
|
* members are accessible from either the "legacy" or "enhanced" interrpt
|
| 43 |
|
|
* API.
|
| 44 |
|
|
*
|
| 45 |
|
|
* Regardless of which API is in use, this file should be included by
|
| 46 |
|
|
* application code and device drivers that register ISRs or manage interrpts.
|
| 47 |
|
|
*/
|
| 48 |
|
|
#include <errno.h>
|
| 49 |
|
|
|
| 50 |
|
|
#include "nios2.h"
|
| 51 |
|
|
#include "alt_types.h"
|
| 52 |
|
|
#include "system.h"
|
| 53 |
|
|
|
| 54 |
|
|
#ifdef __cplusplus
|
| 55 |
|
|
extern "C"
|
| 56 |
|
|
{
|
| 57 |
|
|
#endif /* __cplusplus */
|
| 58 |
|
|
|
| 59 |
|
|
/*
|
| 60 |
|
|
* Macros used by alt_irq_enabled
|
| 61 |
|
|
*/
|
| 62 |
|
|
#define ALT_IRQ_ENABLED 1
|
| 63 |
|
|
#define ALT_IRQ_DISABLED 0
|
| 64 |
|
|
|
| 65 |
|
|
/*
|
| 66 |
|
|
* Number of available interrupts in internal interrupt controller.
|
| 67 |
|
|
*/
|
| 68 |
|
|
#define ALT_NIRQ NIOS2_NIRQ
|
| 69 |
|
|
|
| 70 |
|
|
/*
|
| 71 |
|
|
* Used by alt_irq_disable_all() and alt_irq_enable_all().
|
| 72 |
|
|
*/
|
| 73 |
|
|
typedef int alt_irq_context;
|
| 74 |
|
|
|
| 75 |
|
|
/* ISR Prototype */
|
| 76 |
|
|
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
| 77 |
|
|
typedef void (*alt_isr_func)(void* isr_context);
|
| 78 |
|
|
#else
|
| 79 |
|
|
typedef void (*alt_isr_func)(void* isr_context, alt_u32 id);
|
| 80 |
|
|
#endif
|
| 81 |
|
|
|
| 82 |
|
|
/*
|
| 83 |
|
|
* The following protypes and routines are supported by both
|
| 84 |
|
|
* the enhanced and legacy interrupt APIs
|
| 85 |
|
|
*/
|
| 86 |
|
|
|
| 87 |
|
|
/*
|
| 88 |
|
|
* alt_irq_enabled can be called to determine if the processor's global
|
| 89 |
|
|
* interrupt enable is asserted. The return value is zero if interrupts
|
| 90 |
|
|
* are disabled, and non-zero otherwise.
|
| 91 |
|
|
*
|
| 92 |
|
|
* Whether the internal or external interrupt controller is present,
|
| 93 |
|
|
* individual interrupts may still be disabled. Use the other API to query
|
| 94 |
|
|
* a specific interrupt.
|
| 95 |
|
|
*/
|
| 96 |
|
|
static ALT_INLINE int ALT_ALWAYS_INLINE alt_irq_enabled (void)
|
| 97 |
|
|
{
|
| 98 |
|
|
int status;
|
| 99 |
|
|
|
| 100 |
|
|
NIOS2_READ_STATUS (status);
|
| 101 |
|
|
|
| 102 |
|
|
return status & NIOS2_STATUS_PIE_MSK;
|
| 103 |
|
|
}
|
| 104 |
|
|
|
| 105 |
|
|
/*
|
| 106 |
|
|
* alt_irq_disable_all()
|
| 107 |
|
|
*
|
| 108 |
|
|
* This routine inhibits all interrupts by negating the status register PIE
|
| 109 |
|
|
* bit. It returns the previous contents of the CPU status register (IRQ
|
| 110 |
|
|
* context) which can be used to restore the status register PIE bit to its
|
| 111 |
|
|
* state before this routine was called.
|
| 112 |
|
|
*/
|
| 113 |
|
|
static ALT_INLINE alt_irq_context ALT_ALWAYS_INLINE
|
| 114 |
|
|
alt_irq_disable_all (void)
|
| 115 |
|
|
{
|
| 116 |
|
|
alt_irq_context context;
|
| 117 |
|
|
|
| 118 |
|
|
NIOS2_READ_STATUS (context);
|
| 119 |
|
|
|
| 120 |
|
|
NIOS2_WRITE_STATUS (context & ~NIOS2_STATUS_PIE_MSK);
|
| 121 |
|
|
|
| 122 |
|
|
return context;
|
| 123 |
|
|
}
|
| 124 |
|
|
|
| 125 |
|
|
/*
|
| 126 |
|
|
* alt_irq_enable_all()
|
| 127 |
|
|
*
|
| 128 |
|
|
* Enable all interrupts that were previously disabled by alt_irq_disable_all()
|
| 129 |
|
|
*
|
| 130 |
|
|
* This routine accepts a context to restore the CPU status register PIE bit
|
| 131 |
|
|
* to the state prior to a call to alt_irq_disable_all().
|
| 132 |
|
|
|
| 133 |
|
|
* In the case of nested calls to alt_irq_disable_all()/alt_irq_enable_all(),
|
| 134 |
|
|
* this means that alt_irq_enable_all() does not necessarily re-enable
|
| 135 |
|
|
* interrupts.
|
| 136 |
|
|
*
|
| 137 |
|
|
* This routine will perform a read-modify-write sequence to restore only
|
| 138 |
|
|
* status.PIE if the processor is configured with options that add additional
|
| 139 |
|
|
* writeable status register bits. These include the MMU, MPU, the enhanced
|
| 140 |
|
|
* interrupt controller port, and shadow registers. Otherwise, as a performance
|
| 141 |
|
|
* enhancement, status is overwritten with the prior context.
|
| 142 |
|
|
*/
|
| 143 |
|
|
static ALT_INLINE void ALT_ALWAYS_INLINE
|
| 144 |
|
|
alt_irq_enable_all (alt_irq_context context)
|
| 145 |
|
|
{
|
| 146 |
|
|
#if (NIOS2_NUM_OF_SHADOW_REG_SETS > 0) || (defined NIOS2_EIC_PRESENT) || \
|
| 147 |
|
|
(defined NIOS2_MMU_PRESENT) || (defined NIOS2_MPU_PRESENT)
|
| 148 |
|
|
alt_irq_context status;
|
| 149 |
|
|
|
| 150 |
|
|
NIOS2_READ_STATUS (status);
|
| 151 |
|
|
|
| 152 |
|
|
status &= ~NIOS2_STATUS_PIE_MSK;
|
| 153 |
|
|
status |= (context & NIOS2_STATUS_PIE_MSK);
|
| 154 |
|
|
|
| 155 |
|
|
NIOS2_WRITE_STATUS (status);
|
| 156 |
|
|
#else
|
| 157 |
|
|
NIOS2_WRITE_STATUS (context);
|
| 158 |
|
|
#endif
|
| 159 |
|
|
}
|
| 160 |
|
|
|
| 161 |
|
|
/*
|
| 162 |
|
|
* The function alt_irq_init() is defined within the auto-generated file
|
| 163 |
|
|
* alt_sys_init.c. This function calls the initilization macros for all
|
| 164 |
|
|
* interrupt controllers in the system at config time, before any other
|
| 165 |
|
|
* non-interrupt controller driver is initialized.
|
| 166 |
|
|
*
|
| 167 |
|
|
* The "base" parameter is ignored and only present for backwards-compatibility.
|
| 168 |
|
|
* It is recommended that NULL is passed in for the "base" parameter.
|
| 169 |
|
|
*/
|
| 170 |
|
|
extern void alt_irq_init (const void* base);
|
| 171 |
|
|
|
| 172 |
|
|
/*
|
| 173 |
|
|
* alt_irq_cpu_enable_interrupts() enables the CPU to start taking interrupts.
|
| 174 |
|
|
*/
|
| 175 |
|
|
static ALT_INLINE void ALT_ALWAYS_INLINE
|
| 176 |
|
|
alt_irq_cpu_enable_interrupts ()
|
| 177 |
|
|
{
|
| 178 |
|
|
NIOS2_WRITE_STATUS(NIOS2_STATUS_PIE_MSK
|
| 179 |
|
|
#if defined(NIOS2_EIC_PRESENT) && (NIOS2_NUM_OF_SHADOW_REG_SETS > 0)
|
| 180 |
|
|
| NIOS2_STATUS_RSIE_MSK
|
| 181 |
|
|
#endif
|
| 182 |
|
|
);
|
| 183 |
|
|
}
|
| 184 |
|
|
|
| 185 |
|
|
|
| 186 |
|
|
/*
|
| 187 |
|
|
* Prototypes for the enhanced interrupt API.
|
| 188 |
|
|
*/
|
| 189 |
|
|
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
| 190 |
|
|
/*
|
| 191 |
|
|
* alt_ic_isr_register() can be used to register an interrupt handler. If the
|
| 192 |
|
|
* function is succesful, then the requested interrupt will be enabled upon
|
| 193 |
|
|
* return.
|
| 194 |
|
|
*/
|
| 195 |
|
|
extern int alt_ic_isr_register(alt_u32 ic_id,
|
| 196 |
|
|
alt_u32 irq,
|
| 197 |
|
|
alt_isr_func isr,
|
| 198 |
|
|
void *isr_context,
|
| 199 |
|
|
void *flags);
|
| 200 |
|
|
|
| 201 |
|
|
/*
|
| 202 |
|
|
* alt_ic_irq_enable() and alt_ic_irq_disable() enable/disable a specific
|
| 203 |
|
|
* interrupt by using IRQ port and interrupt controller instance.
|
| 204 |
|
|
*/
|
| 205 |
|
|
int alt_ic_irq_enable (alt_u32 ic_id, alt_u32 irq);
|
| 206 |
|
|
int alt_ic_irq_disable(alt_u32 ic_id, alt_u32 irq);
|
| 207 |
|
|
|
| 208 |
|
|
/*
|
| 209 |
|
|
* alt_ic_irq_enabled() indicates whether a specific interrupt, as
|
| 210 |
|
|
* specified by IRQ port and interrupt controller instance is enabled.
|
| 211 |
|
|
*/
|
| 212 |
|
|
alt_u32 alt_ic_irq_enabled(alt_u32 ic_id, alt_u32 irq);
|
| 213 |
|
|
|
| 214 |
|
|
#else
|
| 215 |
|
|
/*
|
| 216 |
|
|
* Prototypes for the legacy interrupt API.
|
| 217 |
|
|
*/
|
| 218 |
|
|
#include "priv/alt_legacy_irq.h"
|
| 219 |
|
|
#endif
|
| 220 |
|
|
|
| 221 |
|
|
|
| 222 |
|
|
/*
|
| 223 |
|
|
* alt_irq_pending() returns a bit list of the current pending interrupts.
|
| 224 |
|
|
* This is used by alt_irq_handler() to determine which registered interrupt
|
| 225 |
|
|
* handlers should be called.
|
| 226 |
|
|
*
|
| 227 |
|
|
* This routine is only available for the Nios II internal interrupt
|
| 228 |
|
|
* controller.
|
| 229 |
|
|
*/
|
| 230 |
|
|
#ifndef NIOS2_EIC_PRESENT
|
| 231 |
|
|
static ALT_INLINE alt_u32 ALT_ALWAYS_INLINE alt_irq_pending (void)
|
| 232 |
|
|
{
|
| 233 |
|
|
alt_u32 active;
|
| 234 |
|
|
|
| 235 |
|
|
NIOS2_READ_IPENDING (active);
|
| 236 |
|
|
|
| 237 |
|
|
return active;
|
| 238 |
|
|
}
|
| 239 |
|
|
#endif
|
| 240 |
|
|
|
| 241 |
|
|
#ifdef __cplusplus
|
| 242 |
|
|
}
|
| 243 |
|
|
#endif /* __cplusplus */
|
| 244 |
|
|
|
| 245 |
|
|
#endif /* __ALT_IRQ_H__ */
|