interrupt.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2021, Shenzhen Academy of Aerospace Technology
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-11-16 Dystopia the first version
  9. */
  10. #include "interrupt.h"
  11. #include "c66xx.h"
  12. #include "trap.h"
  13. #define MAX_HANDLERS 128
  14. extern volatile rt_uint8_t rt_interrupt_nest;
  15. struct rt_irq_desc isr_table[MAX_HANDLERS];
  16. rt_uint32_t rt_interrupt_from_thread;
  17. rt_uint32_t rt_interrupt_to_thread;
  18. rt_uint32_t rt_thread_switch_interrupt_flag;
  19. /**
  20. * This function will initialize hardware interrupt
  21. */
  22. void rt_hw_interrupt_init(void)
  23. {
  24. // initial system trap
  25. //rt_trap_init();
  26. /* init exceptions table */
  27. rt_memset(isr_table, 0x00, sizeof(isr_table));
  28. /* init interrupt nest, and context in thread sp */
  29. rt_interrupt_nest = 0;
  30. rt_interrupt_from_thread = 0;
  31. rt_interrupt_to_thread = 0;
  32. rt_thread_switch_interrupt_flag = 0;
  33. }
  34. /**
  35. * This function will mask a interrupt.
  36. * @param vector the interrupt number
  37. */
  38. void rt_hw_interrupt_mask(int vector)
  39. {
  40. if (vector < 0 || vector >= MAX_HANDLERS)
  41. {
  42. return;
  43. }
  44. }
  45. /**
  46. * This function will un-mask a interrupt.
  47. * @param vector the interrupt number
  48. */
  49. void rt_hw_interrupt_umask(int vector)
  50. {
  51. if (vector < 0 || vector >= MAX_HANDLERS)
  52. {
  53. return;
  54. }
  55. ICR = vector;
  56. IER |= vector;
  57. //enable GIE
  58. TSR = TSR | 1;
  59. }
  60. /**
  61. * This function will install a interrupt service routine to a interrupt.
  62. * @param vector the interrupt number
  63. * @param new_handler the interrupt service routine to be installed
  64. * @param old_handler the old interrupt service routine
  65. */
  66. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  67. void *param, const char *name)
  68. {
  69. rt_isr_handler_t old_handler = RT_NULL;
  70. if (vector < MAX_HANDLERS && vector >= 0)
  71. {
  72. old_handler = isr_table[vector].handler;
  73. if (handler != RT_NULL)
  74. {
  75. #ifdef RT_USING_INTERRUPT_INFO
  76. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  77. #endif /* RT_USING_INTERRUPT_INFO */
  78. isr_table[vector].handler = handler;
  79. isr_table[vector].param = param;
  80. }
  81. }
  82. return old_handler;
  83. }
  84. void rt_hw_interrupt_clear(int vector)
  85. {
  86. if (vector < 0 || vector >= MAX_HANDLERS)
  87. {
  88. return;
  89. }
  90. }