interrupt.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * File : interrupt.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, 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. * 2009-01-05 Bernard first version
  13. */
  14. #include <rtthread.h>
  15. #include <asm/ppc4xx.h>
  16. #include <asm/processor.h>
  17. /* interrupt nest */
  18. extern volatile rt_uint8_t rt_interrupt_nest;
  19. /* exception and interrupt handler table */
  20. #define MAX_HANDLERS 32
  21. rt_isr_handler_t isr_table[MAX_HANDLERS];
  22. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  23. rt_uint32_t rt_thread_switch_interrput_flag;
  24. rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector)
  25. {
  26. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  27. return RT_NULL;
  28. }
  29. void uic_irq_ack(unsigned int vec)
  30. {
  31. mtdcr(uic0sr, UIC_MASK(vec));
  32. }
  33. void uic_int_handler (unsigned int vec)
  34. {
  35. rt_interrupt_enter();
  36. /* Allow external interrupts to the CPU. */
  37. if (isr_table [vec] != 0)
  38. {
  39. (*isr_table[vec])(vec);
  40. }
  41. uic_irq_ack(vec);
  42. rt_interrupt_leave();
  43. }
  44. /* handler for UIC interrupt */
  45. void uic_interrupt(rt_uint32_t uic_base, int vec_base)
  46. {
  47. int vec;
  48. rt_uint32_t uic_msr;
  49. rt_uint32_t msr_shift;
  50. /*
  51. * Read masked interrupt status register to determine interrupt source
  52. */
  53. uic_msr = get_dcr(uic_base + UIC_MSR);
  54. msr_shift = uic_msr;
  55. vec = vec_base;
  56. while (msr_shift != 0)
  57. {
  58. if (msr_shift & 0x80000000)
  59. uic_int_handler(vec);
  60. /*
  61. * Shift msr to next position and increment vector
  62. */
  63. msr_shift <<= 1;
  64. vec++;
  65. }
  66. }
  67. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  68. {
  69. int intVal;
  70. if (((int)vector < 0) || ((int) vector >= MAX_HANDLERS))
  71. {
  72. return; /* out of range */
  73. }
  74. /* install the handler in the system interrupt table */
  75. intVal = rt_hw_interrupt_disable (); /* lock interrupts to prevent races */
  76. if (*old_handler != RT_NULL) *old_handler = isr_table[vector];
  77. if (new_handler != RT_NULL) isr_table[vector] = new_handler;
  78. rt_hw_interrupt_enable (intVal);
  79. }
  80. void rt_hw_interrupt_mask(int vector)
  81. {
  82. mtdcr(uic0er, mfdcr(uic0er) & ~UIC_MASK(vector));
  83. }
  84. void rt_hw_interrupt_unmask(int vector)
  85. {
  86. mtdcr(uic0er, mfdcr(uic0er) | UIC_MASK(vector));
  87. }
  88. void rt_hw_interrupt_init()
  89. {
  90. int vector;
  91. rt_uint32_t pit_value;
  92. pit_value = RT_TICK_PER_SECOND * (100000000 / RT_CPU_FREQ);
  93. /* enable pit */
  94. mtspr(SPRN_PIT, pit_value);
  95. mtspr(SPRN_TCR, 0x4400000);
  96. /* set default interrupt handler */
  97. for (vector = 0; vector < MAX_HANDLERS; vector++)
  98. {
  99. isr_table [vector] = (rt_isr_handler_t)rt_hw_interrupt_handle;
  100. }
  101. /* initialize interrupt nest, and context in thread sp */
  102. rt_interrupt_nest = 0;
  103. rt_interrupt_from_thread = 0;
  104. rt_interrupt_to_thread = 0;
  105. rt_thread_switch_interrput_flag = 0;
  106. }
  107. /*@}*/