interrupt.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2020-2020, Bluetrum Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020/11/18 greedyhao Bluetrum RISC-V porting code.
  9. */
  10. #include <rtthread.h>
  11. #include <stdbool.h>
  12. #include <rthw.h>
  13. #include "ab32vgx.h"
  14. uint32_t irq_mask;
  15. void *tbl_irq_vector[IRQ_TOTAL_NUM];
  16. void (*cpu_irq_comm_hook)(void);
  17. void set_cpu_irq_comm(void (*irq_hook)(void))
  18. {
  19. cpu_irq_comm_hook = irq_hook;
  20. }
  21. void cpu_irq_comm_do(void)
  22. {
  23. void (*pfnct)(void);
  24. uint32_t irq_pend = PICPND & irq_mask;
  25. for (int i = 0; i < IRQ_TOTAL_NUM; i++) {
  26. if (irq_pend & BIT(i)) {
  27. pfnct = tbl_irq_vector[i];
  28. if (pfnct) {
  29. pfnct(); /* call ISR */
  30. }
  31. }
  32. }
  33. }
  34. void rt_hw_irq_enable(int vector)
  35. {
  36. if (vector < IRQ_TOTAL_NUM) {
  37. PICEN |= BIT(vector);
  38. }
  39. }
  40. void rt_hw_irq_disable(int vector)
  41. {
  42. if (vector < IRQ_TOTAL_NUM) {
  43. PICEN &= ~BIT(vector);
  44. }
  45. }
  46. void rt_hw_interrupt_init(void)
  47. {
  48. }
  49. /**
  50. * @brief This function will install a interrupt service routine to a interrupt.
  51. *
  52. * @param vector
  53. * @param handler
  54. * @param param
  55. * @param name
  56. * @return rt_isr_handler_t
  57. */
  58. rt_isr_handler_t rt_hw_interrupt_install(int vector,
  59. rt_isr_handler_t handler,
  60. void *param,
  61. const char *name)
  62. {
  63. rt_isr_handler_t old_handler = RT_NULL;
  64. if (vector < IRQ_TOTAL_NUM) {
  65. uint32_t cpu_ie = PICCON & BIT(0);
  66. PICCON &= ~BIT(0);
  67. old_handler = tbl_irq_vector[vector];
  68. tbl_irq_vector[vector] = handler;
  69. irq_mask |= BIT(vector);
  70. PICCON |= cpu_ie;
  71. PICPR &= ~BIT(vector);
  72. PICEN |= BIT(vector);
  73. }
  74. return old_handler;
  75. }