interrupt.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * 2018-11-22 Jesven add smp support
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include "realview.h"
  18. #include "gic.h"
  19. #define MAX_HANDLERS NR_IRQS_PBA8
  20. /* exception and interrupt handler table */
  21. struct rt_irq_desc isr_table[MAX_HANDLERS];
  22. #ifndef RT_USING_SMP
  23. /* Those varibles will be accessed in ISR, so we need to share them. */
  24. rt_uint32_t rt_interrupt_from_thread;
  25. rt_uint32_t rt_interrupt_to_thread;
  26. rt_uint32_t rt_thread_switch_interrupt_flag;
  27. #endif
  28. const unsigned int VECTOR_BASE = 0x00;
  29. extern void rt_cpu_vector_set_base(unsigned int addr);
  30. extern int system_vectors;
  31. void rt_hw_vector_init(void)
  32. {
  33. rt_cpu_vector_set_base((unsigned int)&system_vectors);
  34. }
  35. /**
  36. * This function will initialize hardware interrupt
  37. */
  38. void rt_hw_interrupt_init(void)
  39. {
  40. rt_uint32_t gic_cpu_base;
  41. rt_uint32_t gic_dist_base;
  42. /* initialize vector table */
  43. rt_hw_vector_init();
  44. /* initialize exceptions table */
  45. rt_memset(isr_table, 0x00, sizeof(isr_table));
  46. /* initialize ARM GIC */
  47. gic_dist_base = REALVIEW_GIC_DIST_BASE;
  48. gic_cpu_base = REALVIEW_GIC_CPU_BASE;
  49. arm_gic_dist_init(0, gic_dist_base, 0);
  50. arm_gic_cpu_init(0, gic_cpu_base);
  51. /* init interrupt nest, and context in thread sp */
  52. #ifndef RT_USING_SMP
  53. rt_interrupt_from_thread = 0;
  54. rt_interrupt_to_thread = 0;
  55. rt_thread_switch_interrupt_flag = 0;
  56. #endif
  57. }
  58. /**
  59. * This function will mask a interrupt.
  60. * @param vector the interrupt number
  61. */
  62. void rt_hw_interrupt_mask(int vector)
  63. {
  64. arm_gic_mask(0, vector);
  65. }
  66. /**
  67. * This function will un-mask a interrupt.
  68. * @param vector the interrupt number
  69. */
  70. void rt_hw_interrupt_umask(int vector)
  71. {
  72. arm_gic_umask(0, vector);
  73. }
  74. /**
  75. * This function will install a interrupt service routine to a interrupt.
  76. * @param vector the interrupt number
  77. * @param new_handler the interrupt service routine to be installed
  78. * @param old_handler the old interrupt service routine
  79. */
  80. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  81. void *param, const char *name)
  82. {
  83. rt_isr_handler_t old_handler = RT_NULL;
  84. if (vector < MAX_HANDLERS)
  85. {
  86. old_handler = isr_table[vector].handler;
  87. if (handler != RT_NULL)
  88. {
  89. #ifdef RT_USING_INTERRUPT_INFO
  90. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  91. #endif /* RT_USING_INTERRUPT_INFO */
  92. isr_table[vector].handler = handler;
  93. isr_table[vector].param = param;
  94. }
  95. }
  96. return old_handler;
  97. }