interrupt.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "s3c24x0.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. /* all clear source pending */
  39. SRCPND = 0x0;
  40. /* all clear sub source pending */
  41. SUBSRCPND = 0x0;
  42. /* all=IRQ mode */
  43. INTMOD = 0x0;
  44. /* all interrupt disabled include global bit */
  45. INTMSK = BIT_ALLMSK;
  46. /* all sub interrupt disable */
  47. INTSUBMSK = BIT_SUB_ALLMSK;
  48. /* all clear interrupt pending */
  49. INTPND = BIT_ALLMSK;
  50. /* init exceptions table */
  51. rt_memset(isr_table, 0x00, sizeof(isr_table));
  52. for(idx=0; idx < MAX_HANDLERS; idx++)
  53. {
  54. isr_table[idx].handler = rt_hw_interrupt_handle;
  55. }
  56. /* init interrupt nest, and context in thread sp */
  57. rt_interrupt_nest = 0;
  58. rt_interrupt_from_thread = 0;
  59. rt_interrupt_to_thread = 0;
  60. rt_thread_switch_interrupt_flag = 0;
  61. }
  62. /**
  63. * This function will mask a interrupt.
  64. * @param vector the interrupt number
  65. */
  66. void rt_hw_interrupt_mask(int vector)
  67. {
  68. if (!_interrupt_vector_is_valid(vector))
  69. {
  70. return;
  71. }
  72. INTMSK |= 1 << vector;
  73. }
  74. /**
  75. * This function will un-mask a interrupt.
  76. * @param vector the interrupt number
  77. */
  78. void rt_hw_interrupt_umask(int vector)
  79. {
  80. if (!_interrupt_vector_is_valid(vector))
  81. {
  82. return;
  83. }
  84. if (vector == INTNOTUSED6)
  85. {
  86. rt_kprintf("Interrupt vec %d is not used!\n", vector);
  87. // while(1);
  88. }
  89. else if (vector == INTGLOBAL)
  90. INTMSK = 0x0;
  91. else
  92. INTMSK &= ~(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. /*@}*/