interrupt.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2006-08-23 Bernard first version
  9. * 2013-03-29 aozima Modify the interrupt interface implementations.
  10. */
  11. #include <rtthread.h>
  12. #include <rthw.h>
  13. #include "AT91SAM7X256.h"
  14. #define MAX_HANDLERS 32
  15. rt_inline rt_bool_t _interrupt_vector_is_valid(int vector)
  16. {
  17. return (vector >= 0) && (vector < MAX_HANDLERS);
  18. }
  19. /* exception and interrupt handler table */
  20. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  21. extern rt_atomic_t rt_interrupt_nest;
  22. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  23. rt_uint32_t rt_thread_switch_interrupt_flag;
  24. /**
  25. * @addtogroup AT91SAM7
  26. */
  27. /*@{*/
  28. static void rt_hw_interrupt_handler(int vector, void *param)
  29. {
  30. rt_kprintf("Unhandled interrupt %d occurred!!!\n", vector);
  31. }
  32. /**
  33. * This function will initialize hardware interrupt
  34. */
  35. void rt_hw_interrupt_init(void)
  36. {
  37. rt_base_t index;
  38. /* init exceptions table */
  39. for(index=0; index < MAX_HANDLERS; index++)
  40. {
  41. irq_desc[index].handler = (rt_isr_handler_t)rt_hw_interrupt_handler;
  42. irq_desc[index].param = RT_NULL;
  43. }
  44. for (index = 0; index < MAX_HANDLERS; index ++)
  45. {
  46. AT91C_BASE_AIC->AIC_SVR[index] = (rt_uint32_t)rt_hw_interrupt_handler;
  47. }
  48. /* init interrupt nest, and context in thread sp */
  49. rt_interrupt_nest = 0;
  50. rt_interrupt_from_thread = 0;
  51. rt_interrupt_to_thread = 0;
  52. rt_thread_switch_interrupt_flag = 0;
  53. }
  54. /**
  55. * This function will mask a interrupt.
  56. * @param vector the interrupt number
  57. */
  58. void rt_hw_interrupt_mask(int vector)
  59. {
  60. if (!_interrupt_vector_is_valid(vector))
  61. {
  62. return;
  63. }
  64. /* disable interrupt */
  65. AT91C_BASE_AIC->AIC_IDCR = 1 << vector;
  66. /* clear interrupt */
  67. AT91C_BASE_AIC->AIC_ICCR = 1 << vector;
  68. }
  69. /**
  70. * This function will un-mask a interrupt.
  71. * @param vector the interrupt number
  72. */
  73. void rt_hw_interrupt_umask(int vector)
  74. {
  75. if (!_interrupt_vector_is_valid(vector))
  76. {
  77. return;
  78. }
  79. AT91C_BASE_AIC->AIC_IECR = 1 << vector;
  80. }
  81. /**
  82. * This function will install a interrupt service routine to a interrupt.
  83. * @param vector the interrupt number
  84. * @param handler the interrupt service routine to be installed
  85. * @param param the parameter for interrupt service routine
  86. * @name unused.
  87. *
  88. * @return the old handler
  89. */
  90. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  91. void *param, const char *name)
  92. {
  93. rt_isr_handler_t old_handler = RT_NULL;
  94. if(vector >= 0 && vector < MAX_HANDLERS)
  95. {
  96. old_handler = irq_desc[vector].handler;
  97. if (handler != RT_NULL)
  98. {
  99. irq_desc[vector].handler = (rt_isr_handler_t)handler;
  100. irq_desc[vector].param = param;
  101. }
  102. }
  103. return old_handler;
  104. }
  105. /*@}*/