alt_iic_isr_register.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * 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. * Provides an interrupt registry mechanism for the any CPUs internal interrupt
  36. * controller (IIC) when the enhanced interrupt API is active.
  37. */
  38. #ifndef ALT_CPU_EIC_PRESENT
  39. #ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
  40. #include "alt_types.h"
  41. #include "sys/alt_irq.h"
  42. #include "priv/alt_iic_isr_register.h"
  43. /*
  44. * The header, alt_irq_entry.h, contains the exception entry point, and is
  45. * provided by the processor component. It is included here, so that the code
  46. * will be added to the executable only if alt_irq_register() is present, i.e.
  47. * if no interrupts are registered - there's no need to provide any
  48. * interrupt handling.
  49. */
  50. #include "sys/alt_irq_entry.h"
  51. /*
  52. * The header, alt_irq_table.h contains a table describing which function
  53. * handles each interrupt.
  54. */
  55. #include "priv/alt_irq_table.h"
  56. /** @Function Description: This function registers an interrupt handler.
  57. * If the function is succesful, then the requested interrupt will be enabled
  58. * upon return. Registering a NULL handler will disable the interrupt.
  59. *
  60. * @API Type: External
  61. * @param ic_id Interrupt controller ID
  62. * @param irq IRQ ID number
  63. * @param isr Pointer to interrupt service routine
  64. * @param isr_context Opaque pointer passed to ISR
  65. * @param flags
  66. * @return 0 if successful, else error (-1)
  67. */
  68. int alt_iic_isr_register(alt_u32 ic_id, alt_u32 irq, alt_isr_func isr,
  69. void *isr_context, void *flags)
  70. {
  71. int rc = -EINVAL;
  72. int id = irq; /* IRQ interpreted as the interrupt ID. */
  73. alt_irq_context status;
  74. if (id < ALT_NIRQ)
  75. {
  76. /*
  77. * interrupts are disabled while the handler tables are updated to ensure
  78. * that an interrupt doesn't occur while the tables are in an inconsistant
  79. * state.
  80. */
  81. status = alt_irq_disable_all();
  82. alt_irq[id].handler = isr;
  83. alt_irq[id].context = isr_context;
  84. rc = (isr) ? alt_ic_irq_enable(ic_id, id) : alt_ic_irq_disable(ic_id, id);
  85. alt_irq_enable_all(status);
  86. }
  87. return rc;
  88. }
  89. #endif /* ALT_ENHANCED_INTERRUPT_API_PRESENT */
  90. #endif /* ALT_CPU_EIC_PRESENT */