interrupt.c 2.8 KB

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