interrupt.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #define JZ47XX_MAX_INTR 32
  17. extern rt_uint32_t rt_interrupt_nest;
  18. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  19. rt_uint32_t rt_thread_switch_interrput_flag;
  20. static rt_isr_handler_t irq_handle_table[JZ47XX_MAX_INTR];
  21. /**
  22. * @addtogroup Jz47xx
  23. */
  24. /*@{*/
  25. void rt_hw_interrupt_handler(int vector)
  26. {
  27. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  28. }
  29. /**
  30. * This function will initialize hardware interrupt
  31. */
  32. void rt_hw_interrupt_init()
  33. {
  34. rt_int32_t index;
  35. for (index = 0; index < JZ47XX_MAX_INTR; index ++)
  36. {
  37. irq_handle_table[index] = (rt_isr_handler_t)rt_hw_interrupt_handler;
  38. }
  39. /* init interrupt nest, and context in thread sp */
  40. rt_interrupt_nest = 0;
  41. rt_interrupt_from_thread = 0;
  42. rt_interrupt_to_thread = 0;
  43. rt_thread_switch_interrput_flag = 0;
  44. }
  45. /**
  46. * This function will mask a interrupt.
  47. * @param vector the interrupt number
  48. */
  49. void rt_hw_interrupt_mask(int vector)
  50. {
  51. /* mask interrupt */
  52. INTC_IMSR = (1 << vector);
  53. }
  54. /**
  55. * This function will un-mask a interrupt.
  56. * @param vector the interrupt number
  57. */
  58. void rt_hw_interrupt_umask(int vector)
  59. {
  60. INTC_IMCR = (1 << vector);
  61. }
  62. /**
  63. * This function will install a interrupt service routine to a interrupt.
  64. * @param vector the interrupt number
  65. * @param new_handler the interrupt service routine to be installed
  66. * @param old_handler the old interrupt service routine
  67. */
  68. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  69. {
  70. if (vector >= 0 && vector < JZ47XX_MAX_INTR)
  71. {
  72. if (old_handler != RT_NULL)
  73. *old_handler = irq_handle_table[vector];
  74. if (new_handler != RT_NULL)
  75. irq_handle_table[vector] = (rt_isr_handler_t)new_handler;
  76. }
  77. }
  78. void rt_interrupt_dispatch(void *ptreg)
  79. {
  80. int i;
  81. rt_isr_handler_t irq_func;
  82. static rt_uint32_t pending = 0;
  83. /* the hardware interrupt */
  84. pending |= INTC_IPR;
  85. if (!pending) return;
  86. for (i = JZ47XX_MAX_INTR; i > 0; --i)
  87. {
  88. if ((pending & (1<<i)))
  89. {
  90. pending &= ~(1<<i);
  91. irq_func = irq_handle_table[i];
  92. /* do interrupt */
  93. (*irq_func)(i);
  94. /* ack interrupt */
  95. INTC_IPR = (1 << i);
  96. }
  97. }
  98. }
  99. /*@}*/