interrupt.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <lwp_arch.h>
  14. #include "tick.h"
  15. #include "encoding.h"
  16. #include "riscv.h"
  17. #include "interrupt.h"
  18. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  19. static rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector, void *param)
  20. {
  21. rt_kprintf("UN-handled interrupt %d occurred!!!\n", vector);
  22. return RT_NULL;
  23. }
  24. int rt_hw_plic_irq_enable(int irq_number)
  25. {
  26. plic_irq_enable(irq_number);
  27. return 0;
  28. }
  29. int rt_hw_plic_irq_disable(int irq_number)
  30. {
  31. plic_irq_disable(irq_number);
  32. return 0;
  33. }
  34. /**
  35. * This function will un-mask a interrupt.
  36. * @param vector the interrupt number
  37. */
  38. void rt_hw_interrupt_umask(int vector)
  39. {
  40. plic_set_priority(vector, 1);
  41. rt_hw_plic_irq_enable(vector);
  42. }
  43. /**
  44. * This function will install a interrupt service routine to a interrupt.
  45. * @param vector the interrupt number
  46. * @param new_handler the interrupt service routine to be installed
  47. * @param old_handler the old interrupt service routine
  48. */
  49. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  50. void *param, const char *name)
  51. {
  52. rt_isr_handler_t old_handler = RT_NULL;
  53. if(vector < MAX_HANDLERS)
  54. {
  55. old_handler = irq_desc[vector].handler;
  56. if (handler != RT_NULL)
  57. {
  58. irq_desc[vector].handler = (rt_isr_handler_t)handler;
  59. irq_desc[vector].param = param;
  60. #ifdef RT_USING_INTERRUPT_INFO
  61. rt_snprintf(irq_desc[vector].name, RT_NAME_MAX - 1, "%s", name);
  62. irq_desc[vector].counter = 0;
  63. #endif
  64. }
  65. }
  66. return old_handler;
  67. }
  68. void rt_hw_interrupt_init()
  69. {
  70. /* Enable machine external interrupts. */
  71. // set_csr(sie, SIP_SEIP);
  72. int idx = 0;
  73. /* init exceptions table */
  74. for (idx = 0; idx < MAX_HANDLERS; idx++)
  75. {
  76. irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
  77. irq_desc[idx].param = RT_NULL;
  78. #ifdef RT_USING_INTERRUPT_INFO
  79. rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
  80. irq_desc[idx].counter = 0;
  81. #endif
  82. }
  83. plic_set_threshold(0);
  84. }