interrupt.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <rthw.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_interrupt_flag;
  20. static struct rt_irq_desc 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. rt_memset(irq_handle_table, 0x00, sizeof(irq_handle_table));
  36. for (index = 0; index < JZ47XX_MAX_INTR; index ++)
  37. {
  38. irq_handle_table[index].handler = (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_interrupt_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 handler the interrupt service routine to be installed
  67. * @param param the interrupt service function parameter
  68. * @param name the interrupt name
  69. * @return old handler
  70. */
  71. rt_isr_handler_t rt_hw_interrupt_install(int vector,
  72. rt_isr_handler_t handler,
  73. void *param,
  74. char *name)
  75. {
  76. rt_isr_handler_t old_handler = RT_NULL;
  77. if (vector >= 0 && vector < JZ47XX_MAX_INTR)
  78. {
  79. old_handler = irq_handle_table[vector].handler;
  80. #ifdef RT_USING_INTERRUPT_INFO
  81. rt_strncpy(irq_handle_table[vector].name, name, RT_NAME_MAX);
  82. #endif /* RT_USING_INTERRUPT_INFO */
  83. irq_handle_table[vector].handler = handler;
  84. irq_handle_table[vector].param = param;
  85. }
  86. return old_handler;
  87. }
  88. void rt_interrupt_dispatch(void *ptreg)
  89. {
  90. int i;
  91. rt_isr_handler_t irq_func;
  92. static rt_uint32_t pending = 0;
  93. /* the hardware interrupt */
  94. pending |= INTC_IPR;
  95. if (!pending) return;
  96. for (i = JZ47XX_MAX_INTR; i > 0; --i)
  97. {
  98. if ((pending & (1<<i)))
  99. {
  100. pending &= ~(1<<i);
  101. irq_func = irq_handle_table[i].handler;
  102. /* do interrupt */
  103. (*irq_func)(i, irq_handle_table[i].param);
  104. #ifdef RT_USING_INTERRUPT_INFO
  105. irq_handle_table[i].counter++;
  106. #endif /* RT_USING_INTERRUPT_INFO */
  107. /* ack interrupt */
  108. INTC_IPR = (1 << i);
  109. }
  110. }
  111. }
  112. /*@}*/