alt_iic.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /******************************************************************************
  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. ******************************************************************************/
  30. #include "system.h"
  31. /*
  32. * This file implements the HAL Enhanced interrupt API for Nios II processors
  33. * with an internal interrupt controller (IIC). For most routines, this serves
  34. * as a wrapper layer over the legacy interrupt API (which must be used with
  35. * the IIC only).
  36. *
  37. * Use of the enhanced API is recommended so that application and device
  38. * drivers are compatible with a Nios II system configured with an external
  39. * interrupt controller (EIC), or IIC. This will afford maximum portability.
  40. *
  41. * If an EIC is present, the EIC device driver must provide these routines,
  42. * because their operation will be specific to that EIC type.
  43. */
  44. #ifndef NIOS2_EIC_PRESENT
  45. #ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
  46. #include "sys/alt_irq.h"
  47. #include "priv/alt_iic_isr_register.h"
  48. #include "priv/alt_legacy_irq.h"
  49. /** @Function Description: This function registers an interrupt handler.
  50. * If the function is succesful, then the requested interrupt will be enabled upon
  51. * return. Registering a NULL handler will disable the interrupt.
  52. * @API Type: External
  53. * @param ic_id Ignored.
  54. * @param irq IRQ number
  55. * @return 0 if successful, else error (-1)
  56. */
  57. int alt_ic_isr_register(alt_u32 ic_id, alt_u32 irq, alt_isr_func isr,
  58. void *isr_context, void *flags)
  59. {
  60. return alt_iic_isr_register(ic_id, irq, isr, isr_context, flags);
  61. }
  62. /** @Function Description: This function enables a single interrupt.
  63. * @API Type: External
  64. * @param ic_id Ignored.
  65. * @param irq IRQ number
  66. * @return 0 if successful, else error (-1)
  67. */
  68. int alt_ic_irq_enable (alt_u32 ic_id, alt_u32 irq)
  69. {
  70. return alt_irq_enable(irq);
  71. }
  72. /** @Function Description: This function disables a single interrupt.
  73. * @API Type: External
  74. * @param ic_id Ignored.
  75. * @param irq IRQ number
  76. * @return 0 if successful, else error (-1)
  77. */
  78. int alt_ic_irq_disable(alt_u32 ic_id, alt_u32 irq)
  79. {
  80. return alt_irq_disable(irq);
  81. }
  82. /** @Function Description: This function to determine if corresponding
  83. * interrupt is enabled.
  84. * @API Type: External
  85. * @param ic_id Ignored.
  86. * @param irq IRQ number
  87. * @return Zero if corresponding interrupt is disabled and
  88. * non-zero otherwise.
  89. */
  90. alt_u32 alt_ic_irq_enabled(alt_u32 ic_id, alt_u32 irq)
  91. {
  92. alt_u32 irq_enabled;
  93. NIOS2_READ_IENABLE(irq_enabled);
  94. return (irq_enabled & (1 << irq)) ? 1: 0;
  95. }
  96. #endif /* ALT_ENHANCED_INTERRUPT_API_PRESENT */
  97. #endif /* NIOS2_EIC_PRESENT */