interrupt.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018/10/01 Bernard The first version
  9. * 2018/12/27 Jesven Change irq enable/disable to cpu0
  10. */
  11. #include <plic.h>
  12. #include <mmu.h>
  13. #include "tick.h"
  14. #include "encoding.h"
  15. #include "riscv.h"
  16. #include "interrupt.h"
  17. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  18. static rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector, void *param)
  19. {
  20. rt_kprintf("UN-handled interrupt %d occurred!!!\n", vector);
  21. return RT_NULL;
  22. }
  23. int rt_hw_plic_irq_enable(int irq_number)
  24. {
  25. plic_irq_enable(irq_number);
  26. return 0;
  27. }
  28. int rt_hw_plic_irq_disable(int irq_number)
  29. {
  30. plic_irq_disable(irq_number);
  31. return 0;
  32. }
  33. /**
  34. * This function will un-mask a interrupt.
  35. * @param vector the interrupt number
  36. */
  37. void rt_hw_interrupt_umask(int vector)
  38. {
  39. plic_set_priority(vector, 1);
  40. rt_hw_plic_irq_enable(vector);
  41. }
  42. /**
  43. * This function will install a interrupt service routine to a interrupt.
  44. * @param vector the interrupt number
  45. * @param new_handler the interrupt service routine to be installed
  46. * @param old_handler the old interrupt service routine
  47. */
  48. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  49. void *param, const char *name)
  50. {
  51. rt_isr_handler_t old_handler = RT_NULL;
  52. if(vector < MAX_HANDLERS)
  53. {
  54. old_handler = irq_desc[vector].handler;
  55. if (handler != RT_NULL)
  56. {
  57. irq_desc[vector].handler = (rt_isr_handler_t)handler;
  58. irq_desc[vector].param = param;
  59. #ifdef RT_USING_INTERRUPT_INFO
  60. rt_snprintf(irq_desc[vector].name, RT_NAME_MAX - 1, "%s", name);
  61. irq_desc[vector].counter = 0;
  62. #endif
  63. }
  64. }
  65. return old_handler;
  66. }
  67. void rt_hw_interrupt_init()
  68. {
  69. /* Enable machine external interrupts. */
  70. // set_csr(sie, SIP_SEIP);
  71. int idx = 0;
  72. /* init exceptions table */
  73. for (idx = 0; idx < MAX_HANDLERS; idx++)
  74. {
  75. irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
  76. irq_desc[idx].param = RT_NULL;
  77. #ifdef RT_USING_INTERRUPT_INFO
  78. rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
  79. irq_desc[idx].counter = 0;
  80. #endif
  81. }
  82. plic_set_threshold(0);
  83. }