interrupt.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 = 0;
  25. rt_uint32_t rt_interrupt_to_thread = 0;
  26. rt_uint32_t rt_thread_switch_interrupt_flag = 0;
  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. }
  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. }