interrupt.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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-03-13 Bernard first version
  9. * 2013-03-29 aozima Modify the interrupt interface implementations.
  10. */
  11. #include <rtthread.h>
  12. #include <rthw.h>
  13. #include <sep4020.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. extern rt_atomic_t rt_interrupt_nest;
  20. /* exception and interrupt handler table */
  21. struct rt_irq_desc isr_table[MAX_HANDLERS];
  22. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  23. rt_uint32_t rt_thread_switch_interrupt_flag;
  24. /**
  25. * @addtogroup S3C24X0
  26. */
  27. /*@{*/
  28. static void rt_hw_interrupt_handle(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. register rt_uint32_t idx;
  38. /*Make sure all intc registers in proper state*/
  39. /*mask all the irq*/
  40. *(RP)(INTC_IMR) = 0xFFFFFFFF;
  41. /*enable all the irq*/
  42. *(RP)(INTC_IER) = 0XFFFFFFFF;
  43. /*Dont use any forced irq*/
  44. *(RP)(INTC_IFR) = 0x0;
  45. /*Disable all the fiq*/
  46. *(RP)(INTC_FIER) = 0x0;
  47. /*Mask all the fiq*/
  48. *(RP)(INTC_FIMR) = 0x0F;
  49. /*Dont use forced fiq*/
  50. *(RP)(INTC_FIFR) = 0x0;
  51. /*Intrrupt priority register*/
  52. *(RP)(INTC_IPLR) = 0x0;
  53. /* init exceptions table */
  54. rt_memset(isr_table, 0x00, sizeof(isr_table));
  55. for(idx=0; idx < MAX_HANDLERS; idx++)
  56. {
  57. isr_table[idx].handler = rt_hw_interrupt_handle;
  58. }
  59. /* init interrupt nest, and context in thread sp */
  60. rt_interrupt_nest = 0;
  61. rt_interrupt_from_thread = 0;
  62. rt_interrupt_to_thread = 0;
  63. rt_thread_switch_interrupt_flag = 0;
  64. }
  65. /**
  66. * This function will mask a interrupt.
  67. * @param vector the interrupt number
  68. */
  69. void rt_hw_interrupt_mask(int vector)
  70. {
  71. if (!_interrupt_vector_is_valid(vector))
  72. {
  73. return;
  74. }
  75. *(RP)(INTC_IMR) |= 1 << vector;
  76. }
  77. /**
  78. * This function will un-mask a interrupt.
  79. * @param vector the interrupt number
  80. */
  81. void rt_hw_interrupt_umask(int vector)
  82. {
  83. if (!_interrupt_vector_is_valid(vector))
  84. {
  85. return;
  86. }
  87. if(vector == 16)
  88. {
  89. rt_kprintf("Interrupt vec %d is not used!\n", vector);
  90. }
  91. else
  92. *(RP)(INTC_IMR) &= ~(1 << vector);
  93. }
  94. /**
  95. * This function will install a interrupt service routine to a interrupt.
  96. * @param vector the interrupt number
  97. * @param new_handler the interrupt service routine to be installed
  98. * @param old_handler the old interrupt service routine
  99. */
  100. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  101. void *param, const char *name)
  102. {
  103. rt_isr_handler_t old_handler = RT_NULL;
  104. if(vector < MAX_HANDLERS)
  105. {
  106. old_handler = isr_table[vector].handler;
  107. if (handler != RT_NULL)
  108. {
  109. #ifdef RT_USING_INTERRUPT_INFO
  110. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  111. #endif /* RT_USING_INTERRUPT_INFO */
  112. isr_table[vector].handler = handler;
  113. isr_table[vector].param = param;
  114. }
  115. }
  116. return old_handler;
  117. }
  118. /*@}*/