interrupt.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * 2018/5/3 Bernard first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "cp15.h"
  13. #include <board.h>
  14. #define MAX_HANDLERS 64
  15. extern volatile rt_uint8_t rt_interrupt_nest;
  16. /* exception and interrupt handler table */
  17. struct rt_irq_desc isr_table[MAX_HANDLERS];
  18. rt_uint32_t rt_interrupt_from_thread;
  19. rt_uint32_t rt_interrupt_to_thread;
  20. rt_uint32_t rt_thread_switch_interrupt_flag;
  21. extern void rt_cpu_vector_set_base(unsigned int addr);
  22. extern int system_vectors;
  23. void rt_hw_vector_init(void)
  24. {
  25. rt_cpu_vector_set_base((unsigned int)&system_vectors);
  26. }
  27. static void default_isr_handler(int vector, void *param)
  28. {
  29. rt_kprintf("unhandled irq: %d\n", vector);
  30. }
  31. /**
  32. * This function will initialize hardware interrupt
  33. */
  34. void rt_hw_interrupt_init(void)
  35. {
  36. uint32_t index;
  37. /* mask all of interrupts */
  38. IRQ_DISABLE_BASIC = 0x000000ff;
  39. IRQ_DISABLE1 = 0xffffffff;
  40. IRQ_DISABLE2 = 0xffffffff;
  41. for (index = 0; index < MAX_HANDLERS; index ++)
  42. {
  43. isr_table[index].handler = default_isr_handler;
  44. isr_table[index].param = NULL;
  45. #ifdef RT_USING_INTERRUPT_INFO
  46. rt_strncpy(isr_table[index].name, "unknown", RT_NAME_MAX);
  47. isr_table[index].counter = 0;
  48. #endif
  49. }
  50. /* init interrupt nest, and context in thread sp */
  51. rt_interrupt_nest = 0;
  52. rt_interrupt_from_thread = 0;
  53. rt_interrupt_to_thread = 0;
  54. rt_thread_switch_interrupt_flag = 0;
  55. }
  56. /**
  57. * This function will mask a interrupt.
  58. * @param vector the interrupt number
  59. */
  60. void rt_hw_interrupt_mask(int vector)
  61. {
  62. if (vector < 8)
  63. {
  64. IRQ_DISABLE_BASIC = (1 << vector);
  65. }
  66. else if (vector < 32)
  67. {
  68. IRQ_DISABLE1 = (1 << vector);
  69. }
  70. else
  71. {
  72. vector = vector % 32;
  73. IRQ_DISABLE2 = (1 << vector);
  74. }
  75. }
  76. /**
  77. * This function will un-mask a interrupt.
  78. * @param vector the interrupt number
  79. */
  80. void rt_hw_interrupt_umask(int vector)
  81. {
  82. if (vector < 8)
  83. {
  84. IRQ_ENABLE_BASIC = (1 << vector);
  85. }
  86. else if (vector < 32)
  87. {
  88. IRQ_ENABLE1 = (1 << vector);
  89. }
  90. else
  91. {
  92. vector = vector % 32;
  93. IRQ_ENABLE2 = (1 << vector);
  94. }
  95. }
  96. /**
  97. * This function will install a interrupt service routine to a interrupt.
  98. * @param vector the interrupt number
  99. * @param new_handler the interrupt service routine to be installed
  100. * @param old_handler the old interrupt service routine
  101. */
  102. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  103. void *param, const char *name)
  104. {
  105. rt_isr_handler_t old_handler = RT_NULL;
  106. if (vector < MAX_HANDLERS)
  107. {
  108. old_handler = isr_table[vector].handler;
  109. if (handler != RT_NULL)
  110. {
  111. #ifdef RT_USING_INTERRUPT_INFO
  112. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  113. #endif /* RT_USING_INTERRUPT_INFO */
  114. isr_table[vector].handler = handler;
  115. isr_table[vector].param = param;
  116. }
  117. }
  118. return old_handler;
  119. }