interrupt.c 2.5 KB

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