interrupt.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * File : trap.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-09-06 XuXinming first version
  13. * 2006-09-15 Bernard add interrupt bank 0..3 for more effective
  14. * in irq trap
  15. */
  16. #include <rtthread.h>
  17. #include "s3c44b0.h"
  18. #define MAX_HANDLERS 26
  19. extern rt_uint32_t rt_interrupt_nest;
  20. /* exception and interrupt handler table */
  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. unsigned char interrupt_bank0[256];
  25. unsigned char interrupt_bank1[256];
  26. unsigned char interrupt_bank2[256];
  27. unsigned char interrupt_bank3[256];
  28. /**
  29. * @addtogroup S3C44B0
  30. */
  31. /*@{*/
  32. void rt_hw_interrupt_handle(int vector)
  33. {
  34. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  35. }
  36. /**
  37. * This function will initialize hardware interrupt
  38. */
  39. void rt_hw_interrupt_init()
  40. {
  41. register int i;
  42. /* all interrupt disabled include global bit */
  43. INTMSK = 0x07ffffff;
  44. /* clear pending register */
  45. I_ISPC = 0x03ffffff;
  46. /* non-vector mode IRQ enable */
  47. INTCON = 0x5;
  48. /* all IRQ mode */
  49. INTMOD = 0x0;
  50. /* init exceptions table */
  51. for(i=0; i<MAX_HANDLERS; i++)
  52. {
  53. isr_table[i] = rt_hw_interrupt_handle;
  54. }
  55. for ( i = 0; i < 256; i++)
  56. {
  57. interrupt_bank0[i] = 0;
  58. interrupt_bank1[i] = 0;
  59. interrupt_bank2[i] = 0;
  60. interrupt_bank3[i] = 0;
  61. }
  62. /* setup interrupt bank table */
  63. interrupt_bank0[1] = 0;
  64. interrupt_bank0[2] = 1;
  65. interrupt_bank0[4] = 2;
  66. interrupt_bank0[8] = 3;
  67. interrupt_bank0[16] = 4;
  68. interrupt_bank0[32] = 5;
  69. interrupt_bank0[64] = 6;
  70. interrupt_bank0[128]= 7;
  71. interrupt_bank1[1] = 8;
  72. interrupt_bank1[2] = 9;
  73. interrupt_bank1[4] = 10;
  74. interrupt_bank1[8] = 11;
  75. interrupt_bank1[16] = 12;
  76. interrupt_bank1[32] = 13;
  77. interrupt_bank1[64] = 14;
  78. interrupt_bank1[128]= 15;
  79. interrupt_bank2[1] = 16;
  80. interrupt_bank2[2] = 17;
  81. interrupt_bank2[4] = 18;
  82. interrupt_bank2[8] = 19;
  83. interrupt_bank2[16] = 20;
  84. interrupt_bank2[32] = 21;
  85. interrupt_bank2[64] = 22;
  86. interrupt_bank2[128]= 23;
  87. interrupt_bank3[1] = 24;
  88. interrupt_bank3[2] = 25;
  89. /* init interrupt nest, and context in thread sp */
  90. rt_interrupt_nest = 0;
  91. rt_interrupt_from_thread = 0;
  92. rt_interrupt_to_thread = 0;
  93. rt_thread_switch_interrput_flag = 0;
  94. }
  95. /**
  96. * This function will mask a interrupt.
  97. * @param vector the interrupt number
  98. */
  99. void rt_hw_interrupt_mask(int vector)
  100. {
  101. INTMSK |= 1 << vector;
  102. }
  103. /**
  104. * This function will un-mask a interrupt.
  105. * @param vector the interrupt number
  106. */
  107. void rt_hw_interrupt_umask(int vector)
  108. {
  109. INTMSK &= ~(1 << vector);
  110. }
  111. /**
  112. * This function will install a interrupt service routine to a interrupt.
  113. * @param vector the interrupt number
  114. * @param new_handler the interrupt service routine to be installed
  115. * @param old_handler the old interrupt service routine
  116. */
  117. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  118. {
  119. if(vector < MAX_HANDLERS)
  120. {
  121. if (old_handler != RT_NULL) *old_handler = isr_table[vector];
  122. if (new_handler != RT_NULL) isr_table[vector] = new_handler;
  123. }
  124. }
  125. /*@}*/