interrupt.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "LPC24xx.h"
  14. #define MAX_HANDLERS 32
  15. rt_inline rt_bool_t _interrupt_vector_is_valid(int vector)
  16. {
  17. return (vector >= 0) && (vector < MAX_HANDLERS);
  18. }
  19. /* exception and interrupt handler table */
  20. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  21. extern rt_atomic_t rt_interrupt_nest;
  22. /* exception and interrupt handler table */
  23. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  24. rt_uint32_t rt_thread_switch_interrupt_flag;
  25. /**
  26. * @addtogroup LPC2478
  27. */
  28. /*@{*/
  29. void rt_hw_interrupt_handler(int vector, void *param)
  30. {
  31. rt_kprintf("Unhandled interrupt %d occurred!!!\n", vector);
  32. }
  33. void rt_hw_interrupt_init(void)
  34. {
  35. register int i;
  36. rt_uint32_t *vect_addr, *vect_cntl;
  37. /* initialize VIC*/
  38. VICIntEnClr = 0xffffffff;
  39. VICVectAddr = 0;
  40. VICIntSelect = 0;
  41. /* init exceptions table */
  42. rt_memset(irq_desc, 0x00, sizeof(irq_desc));
  43. for(i=0; i < MAX_HANDLERS; i++)
  44. {
  45. irq_desc[i].handler = rt_hw_interrupt_handler;
  46. vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + i*4);
  47. vect_cntl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + i*4);
  48. *vect_addr = (rt_uint32_t)&irq_desc[i];
  49. *vect_cntl = 0xF;
  50. }
  51. /* init interrupt nest, and context in thread sp */
  52. rt_interrupt_nest = 0;
  53. rt_interrupt_from_thread = 0;
  54. rt_interrupt_to_thread = 0;
  55. rt_thread_switch_interrupt_flag = 0;
  56. }
  57. void rt_hw_interrupt_mask(int vector)
  58. {
  59. if (!_interrupt_vector_is_valid(vector))
  60. {
  61. return;
  62. }
  63. VICIntEnClr = (1 << vector);
  64. }
  65. void rt_hw_interrupt_umask(int vector)
  66. {
  67. if (!_interrupt_vector_is_valid(vector))
  68. {
  69. return;
  70. }
  71. VICIntEnable = (1 << vector);
  72. }
  73. /**
  74. * This function will install a interrupt service routine to a interrupt.
  75. * @param vector the interrupt number
  76. * @param handler the interrupt service routine to be installed
  77. * @param param the parameter for interrupt service routine
  78. * @name unused.
  79. *
  80. * @return the old handler
  81. */
  82. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  83. void *param, const char *name)
  84. {
  85. rt_isr_handler_t old_handler = RT_NULL;
  86. if(vector >= 0 && vector < MAX_HANDLERS)
  87. {
  88. old_handler = irq_desc[vector].handler;
  89. if (handler != RT_NULL)
  90. {
  91. irq_desc[vector].handler = handler;
  92. irq_desc[vector].param = param;
  93. }
  94. }
  95. return old_handler;
  96. }
  97. /*@}*/