1
0

interrupt.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * 2008-12-11 XuXinming first version
  9. * 2013-03-29 aozima Modify the interrupt interface implementations.
  10. */
  11. #include <rtthread.h>
  12. #include <rthw.h>
  13. #include <sys_vim.h>
  14. #include <system.h>
  15. #include "armv7.h"
  16. #define MAX_HANDLERS 96
  17. /* exception and interrupt handler table */
  18. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  19. extern volatile rt_uint8_t rt_interrupt_nest;
  20. /* exception and interrupt handler table */
  21. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  22. rt_uint32_t rt_thread_switch_interrupt_flag;
  23. /**
  24. * @addtogroup RM48x50
  25. */
  26. /*@{*/
  27. static void rt_hw_int_not_handle(int vector, void *param)
  28. {
  29. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  30. }
  31. #define vimRAM (0xFFF82000U)
  32. void rt_hw_interrupt_init(void)
  33. {
  34. register int i;
  35. rt_uint32_t *vect_addr;
  36. /* the initialization is done in sys_startup.c */
  37. /* init exceptions table */
  38. rt_memset(irq_desc, 0x00, sizeof(irq_desc));
  39. for(i=0; i < MAX_HANDLERS; i++)
  40. {
  41. irq_desc[i].handler = rt_hw_int_not_handle;
  42. vect_addr = (rt_uint32_t *)(vimRAM + i*4);
  43. *vect_addr = (rt_uint32_t)&irq_desc[i];
  44. }
  45. /* init interrupt nest, and context in thread sp */
  46. rt_interrupt_nest = 0;
  47. rt_interrupt_from_thread = 0;
  48. rt_interrupt_to_thread = 0;
  49. rt_thread_switch_interrupt_flag = 0;
  50. }
  51. void rt_hw_interrupt_mask(int vector)
  52. {
  53. vimDisableInterrupt(vector);
  54. }
  55. void rt_hw_interrupt_umask(int vector)
  56. {
  57. vimEnableInterrupt(vector, SYS_IRQ);
  58. }
  59. /**
  60. * This function will install a interrupt service routine to a interrupt.
  61. * @param vector the interrupt number
  62. * @param handler the interrupt service routine to be installed
  63. * @param param the parameter for interrupt service routine
  64. * @name unused.
  65. *
  66. * @return the old handler
  67. */
  68. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  69. void *param, const char *name)
  70. {
  71. rt_isr_handler_t old_handler = RT_NULL;
  72. if(vector >= 0 && vector < MAX_HANDLERS)
  73. {
  74. old_handler = irq_desc[vector].handler;
  75. if (handler != RT_NULL)
  76. {
  77. irq_desc[vector].handler = handler;
  78. irq_desc[vector].param = param;
  79. }
  80. }
  81. return old_handler;
  82. }
  83. /*@}*/