interrupt.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * File : interrupt.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2013-2014, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2013-07-06 Bernard first version
  13. * 2014-04-03 Grissiom port to VMM
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include "realview.h"
  18. #include "gic.h"
  19. #ifdef RT_USING_VMM
  20. #include <vmm.h>
  21. #endif
  22. #define MAX_HANDLERS NR_IRQS_PBA8
  23. extern volatile rt_uint8_t rt_interrupt_nest;
  24. /* exception and interrupt handler table */
  25. struct rt_irq_desc isr_table[MAX_HANDLERS];
  26. /* Those varibles will be accessed in ISR, so we need to share them. */
  27. rt_uint32_t rt_interrupt_from_thread SECTION(".bss.share.int");
  28. rt_uint32_t rt_interrupt_to_thread SECTION(".bss.share.int");
  29. rt_uint32_t rt_thread_switch_interrupt_flag SECTION(".bss.share.int");
  30. const unsigned int VECTOR_BASE = 0x00;
  31. extern void rt_cpu_vector_set_base(unsigned int addr);
  32. extern int system_vectors;
  33. static void rt_hw_vector_init(void)
  34. {
  35. #ifndef RT_USING_VMM
  36. unsigned int *dest = (unsigned int *)VECTOR_BASE;
  37. unsigned int *src = (unsigned int *)&system_vectors;
  38. rt_memcpy(dest, src, 16 * 4);
  39. rt_cpu_vector_set_base(VECTOR_BASE);
  40. #endif
  41. }
  42. /**
  43. * This function will initialize hardware interrupt
  44. */
  45. void rt_hw_interrupt_init(void)
  46. {
  47. rt_uint32_t gic_cpu_base;
  48. rt_uint32_t gic_dist_base;
  49. /* initialize vector table */
  50. rt_hw_vector_init();
  51. /* initialize exceptions table */
  52. rt_memset(isr_table, 0x00, sizeof(isr_table));
  53. /* initialize ARM GIC */
  54. #ifdef RT_USING_VMM
  55. gic_dist_base = vmm_find_iomap("GIC_DIST");
  56. gic_cpu_base = vmm_find_iomap("GIC_CPU");
  57. #else
  58. gic_dist_base = REALVIEW_GIC_DIST_BASE;
  59. gic_cpu_base = REALVIEW_GIC_CPU_BASE;
  60. #endif
  61. arm_gic_dist_init(0, gic_dist_base, 0);
  62. arm_gic_cpu_init(0, gic_cpu_base);
  63. /*arm_gic_dump_type(0);*/
  64. /* init interrupt nest, and context in thread sp */
  65. rt_interrupt_nest = 0;
  66. rt_interrupt_from_thread = 0;
  67. rt_interrupt_to_thread = 0;
  68. rt_thread_switch_interrupt_flag = 0;
  69. }
  70. /**
  71. * This function will mask a interrupt.
  72. * @param vector the interrupt number
  73. */
  74. void rt_hw_interrupt_mask(int vector)
  75. {
  76. arm_gic_mask(0, vector);
  77. }
  78. /**
  79. * This function will un-mask a interrupt.
  80. * @param vector the interrupt number
  81. */
  82. void rt_hw_interrupt_umask(int vector)
  83. {
  84. arm_gic_umask(0, vector);
  85. }
  86. /**
  87. * This function will install a interrupt service routine to a interrupt.
  88. * @param vector the interrupt number
  89. * @param new_handler the interrupt service routine to be installed
  90. * @param old_handler the old interrupt service routine
  91. */
  92. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  93. void *param, char *name)
  94. {
  95. rt_isr_handler_t old_handler = RT_NULL;
  96. if (vector < MAX_HANDLERS)
  97. {
  98. old_handler = isr_table[vector].handler;
  99. if (handler != RT_NULL)
  100. {
  101. #ifdef RT_USING_INTERRUPT_INFO
  102. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  103. #endif /* RT_USING_INTERRUPT_INFO */
  104. isr_table[vector].handler = handler;
  105. isr_table[vector].param = param;
  106. }
  107. }
  108. return old_handler;
  109. }
  110. /**
  111. * Trigger a software IRQ
  112. *
  113. * Since we are running in single core, the target CPU are always CPU0.
  114. */
  115. void rt_hw_interrupt_trigger(int vector)
  116. {
  117. arm_gic_trigger(0, 1, vector);
  118. }
  119. void rt_hw_interrupt_clear(int vector)
  120. {
  121. arm_gic_clear_sgi(0, 1, vector);
  122. }