interrupt.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-16 bigmagic first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <gic_pl400.h>
  13. #include <board.h>
  14. #include <armv8.h>
  15. #define MAX_HANDLERS 256
  16. #ifdef RT_USING_SMP
  17. #define rt_interrupt_nest rt_cpu_self()->irq_nest
  18. #else
  19. extern volatile rt_uint8_t rt_interrupt_nest;
  20. #endif
  21. extern int system_vectors;
  22. /* exception and interrupt handler table */
  23. struct rt_irq_desc isr_table[MAX_HANDLERS];
  24. rt_ubase_t rt_interrupt_from_thread;
  25. rt_ubase_t rt_interrupt_to_thread;
  26. rt_ubase_t rt_thread_switch_interrupt_flag;
  27. void rt_hw_vector_init(void)
  28. {
  29. rt_hw_set_current_vbar((rt_ubase_t)&system_vectors); // cpu_gcc.S
  30. }
  31. /**
  32. * This function will initialize hardware interrupt
  33. */
  34. void rt_hw_interrupt_init(void)
  35. {
  36. initIRQController();
  37. }
  38. /**
  39. * This function will install a interrupt service routine to a interrupt.
  40. * @param vector the interrupt number
  41. * @param new_handler the interrupt service routine to be installed
  42. * @param old_handler the old interrupt service routine
  43. */
  44. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  45. void *param, const char *name)
  46. {
  47. rt_isr_handler_t old_handler = RT_NULL;
  48. if (vector < MAX_HANDLERS)
  49. {
  50. old_handler = isr_table[vector].handler;
  51. if (handler != RT_NULL)
  52. {
  53. #ifdef RT_USING_INTERRUPT_INFO
  54. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  55. #endif /* RT_USING_INTERRUPT_INFO */
  56. isr_table[vector].handler = handler;
  57. isr_table[vector].param = param;
  58. }
  59. }
  60. return old_handler;
  61. }