interrupt.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * 2013-07-06 Bernard first version
  9. * 2014-04-03 Grissiom port to VMM
  10. */
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include "realview.h"
  14. #include "gic.h"
  15. #define MAX_HANDLERS NR_IRQS_PBA8
  16. extern volatile rt_atomic_t rt_interrupt_nest;
  17. /* exception and interrupt handler table */
  18. struct rt_irq_desc isr_table[MAX_HANDLERS];
  19. /* Those varibles will be accessed in ISR, so we need to share them. */
  20. rt_uint32_t rt_interrupt_from_thread rt_section(".bss.share.int");
  21. rt_uint32_t rt_interrupt_to_thread rt_section(".bss.share.int");
  22. rt_uint32_t rt_thread_switch_interrupt_flag rt_section(".bss.share.int");
  23. const unsigned int VECTOR_BASE = 0x00;
  24. extern void rt_cpu_vector_set_base(unsigned int addr);
  25. extern int system_vectors;
  26. static void rt_hw_vector_init(void)
  27. {
  28. }
  29. /**
  30. * This function will initialize hardware interrupt
  31. */
  32. void rt_hw_interrupt_init(void)
  33. {
  34. rt_uint32_t gic_cpu_base;
  35. rt_uint32_t gic_dist_base;
  36. /* initialize vector table */
  37. rt_hw_vector_init();
  38. /* initialize exceptions table */
  39. rt_memset(isr_table, 0x00, sizeof(isr_table));
  40. /* initialize ARM GIC */
  41. gic_dist_base = REALVIEW_GIC_DIST_BASE;
  42. gic_cpu_base = REALVIEW_GIC_CPU_BASE;
  43. arm_gic_dist_init(0, gic_dist_base, 0);
  44. arm_gic_cpu_init(0, gic_cpu_base);
  45. /*arm_gic_dump_type(0);*/
  46. /* init interrupt nest, and context in thread sp */
  47. rt_interrupt_nest = 0;
  48. rt_interrupt_from_thread = 0;
  49. rt_interrupt_to_thread = 0;
  50. rt_thread_switch_interrupt_flag = 0;
  51. }
  52. /**
  53. * This function will mask a interrupt.
  54. * @param vector the interrupt number
  55. */
  56. void rt_hw_interrupt_mask(int vector)
  57. {
  58. arm_gic_mask(0, vector);
  59. }
  60. /**
  61. * This function will un-mask a interrupt.
  62. * @param vector the interrupt number
  63. */
  64. void rt_hw_interrupt_umask(int vector)
  65. {
  66. arm_gic_umask(0, vector);
  67. }
  68. /**
  69. * This function will install a interrupt service routine to a interrupt.
  70. * @param vector the interrupt number
  71. * @param new_handler the interrupt service routine to be installed
  72. * @param old_handler the old interrupt service routine
  73. */
  74. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  75. void *param, const char *name)
  76. {
  77. rt_isr_handler_t old_handler = RT_NULL;
  78. if (vector < MAX_HANDLERS)
  79. {
  80. old_handler = isr_table[vector].handler;
  81. if (handler != RT_NULL)
  82. {
  83. #ifdef RT_USING_INTERRUPT_INFO
  84. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  85. #endif /* RT_USING_INTERRUPT_INFO */
  86. isr_table[vector].handler = handler;
  87. isr_table[vector].param = param;
  88. }
  89. }
  90. return old_handler;
  91. }
  92. /**
  93. * Trigger a software IRQ
  94. *
  95. * Since we are running in single core, the target CPU are always CPU0.
  96. */
  97. void rt_hw_interrupt_trigger(int vector)
  98. {
  99. arm_gic_trigger(0, 1, vector);
  100. }
  101. void rt_hw_interrupt_clear(int vector)
  102. {
  103. arm_gic_clear_sgi(0, 1, vector);
  104. }