alt_legacy_irq.h 5.5 KB

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