interrupt.c 2.5 KB

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