interrupt.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * File : interrupt.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-07-09 Bernard first version
  13. */
  14. #include <rtthread.h>
  15. #include "jz47xx.h"
  16. #include "interrupt.h"
  17. #define JZ47XX_MAX_INTR 32
  18. extern rt_uint32_t rt_interrupt_nest;
  19. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  20. rt_uint32_t rt_thread_switch_interrput_flag;
  21. static rt_isr_handler_t irq_handle_table[JZ47XX_MAX_INTR];
  22. /**
  23. * @addtogroup Jz47xx
  24. */
  25. /*@{*/
  26. void rt_hw_interrupt_handler(int vector)
  27. {
  28. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  29. }
  30. /**
  31. * This function will initialize hardware interrupt
  32. */
  33. void rt_hw_interrupt_init()
  34. {
  35. rt_int32_t index;
  36. for (index = 0; index < JZ47XX_MAX_INTR; index ++)
  37. {
  38. irq_handle_table[index] = (rt_isr_handler_t)rt_hw_interrupt_handler;
  39. }
  40. /* init interrupt nest, and context in thread sp */
  41. rt_interrupt_nest = 0;
  42. rt_interrupt_from_thread = 0;
  43. rt_interrupt_to_thread = 0;
  44. rt_thread_switch_interrput_flag = 0;
  45. }
  46. /**
  47. * This function will mask a interrupt.
  48. * @param vector the interrupt number
  49. */
  50. void rt_hw_interrupt_mask(int vector)
  51. {
  52. /* mask interrupt */
  53. INTC_IMSR = (1 << vector);
  54. }
  55. /**
  56. * This function will un-mask a interrupt.
  57. * @param vector the interrupt number
  58. */
  59. void rt_hw_interrupt_umask(int vector)
  60. {
  61. INTC_IMCR = (1 << vector);
  62. }
  63. /**
  64. * This function will install a interrupt service routine to a interrupt.
  65. * @param vector the interrupt number
  66. * @param new_handler the interrupt service routine to be installed
  67. * @param old_handler the old interrupt service routine
  68. */
  69. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  70. {
  71. if (vector >= 0 && vector < JZ47XX_MAX_INTR)
  72. {
  73. if (old_handler != RT_NULL)
  74. *old_handler = irq_handle_table[vector];
  75. if (new_handler != RT_NULL)
  76. irq_handle_table[vector] = (rt_isr_handler_t)new_handler;
  77. }
  78. }
  79. void rt_interrupt_dispatch(void *ptreg)
  80. {
  81. int i;
  82. rt_isr_handler_t irq_func;
  83. static rt_uint32_t pending = 0;
  84. /* the hardware interrupt */
  85. pending |= INTC_IPR;
  86. if (!pending) return;
  87. for (i = JZ47XX_MAX_INTR; i > 0; --i)
  88. {
  89. if ((pending & (1<<i)))
  90. {
  91. pending &= ~(1<<i);
  92. irq_func = irq_handle_table[i];
  93. /* do interrupt */
  94. (*irq_func)(i);
  95. /* ack interrupt */
  96. INTC_IPR = (1 << i);
  97. }
  98. }
  99. }
  100. /*@}*/