interrupt.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * File : interrupt.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2011, 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. * 2013-07-06 Bernard first version
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "am33xx.h"
  17. #include "interrupt.h"
  18. #define AINTC_BASE AM33XX_AINTC_REGS
  19. #define MAX_HANDLERS 128
  20. extern volatile rt_uint8_t rt_interrupt_nest;
  21. /* exception and interrupt handler table */
  22. struct rt_irq_desc isr_table[MAX_HANDLERS];
  23. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  24. rt_uint32_t rt_thread_switch_interrupt_flag;
  25. /**
  26. * @addtogroup AM33xx
  27. */
  28. /*@{*/
  29. void rt_dump_aintc(void)
  30. {
  31. int k;
  32. rt_kprintf("active irq %d", INTC_SIR_IRQ(AINTC_BASE));
  33. rt_kprintf("\n--- hw mask ---\n");
  34. for (k = 0; k < 4; k++)
  35. {
  36. rt_kprintf("0x%08x, ", INTC_MIR(AINTC_BASE, k));
  37. }
  38. rt_kprintf("\n--- hw itr ---\n");
  39. for (k = 0; k < 4; k++)
  40. {
  41. rt_kprintf("0x%08x, ", INTC_ITR(AINTC_BASE, k));
  42. }
  43. rt_kprintf("\n");
  44. }
  45. const unsigned int AM335X_VECTOR_BASE = 0x4030FC00;
  46. extern void rt_cpu_vector_set_base(unsigned int addr);
  47. extern int system_vectors;
  48. static void rt_hw_vector_init(void)
  49. {
  50. unsigned int *dest = (unsigned int *)AM335X_VECTOR_BASE;
  51. unsigned int *src = (unsigned int *)&system_vectors;
  52. rt_memcpy(dest, src, 16 * 4);
  53. rt_cpu_vector_set_base(AM335X_VECTOR_BASE);
  54. }
  55. /**
  56. * This function will initialize hardware interrupt
  57. */
  58. void rt_hw_interrupt_init(void)
  59. {
  60. /* initialize vector table */
  61. rt_hw_vector_init();
  62. /* init exceptions table */
  63. rt_memset(isr_table, 0x00, sizeof(isr_table));
  64. /* init interrupt nest, and context in thread sp */
  65. rt_interrupt_nest = 0;
  66. rt_interrupt_from_thread = 0;
  67. rt_interrupt_to_thread = 0;
  68. rt_thread_switch_interrupt_flag = 0;
  69. }
  70. /**
  71. * This function will mask a interrupt.
  72. * @param vector the interrupt number
  73. */
  74. void rt_hw_interrupt_mask(int vector)
  75. {
  76. INTC_MIR_SET(AINTC_BASE, vector >> 0x05) = 0x1 << (vector & 0x1f);
  77. }
  78. /**
  79. * This function will un-mask a interrupt.
  80. * @param vector the interrupt number
  81. */
  82. void rt_hw_interrupt_umask(int vector)
  83. {
  84. INTC_MIR_CLEAR(AINTC_BASE, vector >> 0x05) = 0x1 << (vector & 0x1f);
  85. }
  86. /**
  87. * This function will control the interrupt attribute.
  88. * @param vector the interrupt number
  89. */
  90. void rt_hw_interrupt_control(int vector, int priority, int route)
  91. {
  92. int fiq;
  93. if (route == 0)
  94. fiq = 0;
  95. else
  96. fiq = 1;
  97. INTC_ILR(AINTC_BASE, vector) = ((priority << 0x02) & 0x1FC) | fiq ;
  98. }
  99. int rt_hw_interrupt_get_active(int fiq_irq)
  100. {
  101. int ir;
  102. if (fiq_irq == INT_FIQ)
  103. {
  104. ir = INTC_SIR_FIQ(AINTC_BASE) & 0x7f;
  105. }
  106. else
  107. {
  108. ir = INTC_SIR_IRQ(AINTC_BASE) & 0x7f;
  109. }
  110. return ir;
  111. }
  112. void rt_hw_interrupt_ack(int fiq_irq)
  113. {
  114. if (fiq_irq == INT_FIQ)
  115. {
  116. /* new FIQ generation */
  117. INTC_CONTROL(AINTC_BASE) |= 0x02;
  118. }
  119. else
  120. {
  121. /* new IRQ generation */
  122. INTC_CONTROL(AINTC_BASE) |= 0x01;
  123. }
  124. }
  125. /**
  126. * This function will install a interrupt service routine to a interrupt.
  127. * @param vector the interrupt number
  128. * @param new_handler the interrupt service routine to be installed
  129. * @param old_handler the old interrupt service routine
  130. */
  131. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  132. void *param, char *name)
  133. {
  134. rt_isr_handler_t old_handler = RT_NULL;
  135. if(vector < MAX_HANDLERS)
  136. {
  137. old_handler = isr_table[vector].handler;
  138. if (handler != RT_NULL)
  139. {
  140. #ifdef RT_USING_INTERRUPT_INFO
  141. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  142. #endif /* RT_USING_INTERRUPT_INFO */
  143. isr_table[vector].handler = handler;
  144. isr_table[vector].param = param;
  145. }
  146. }
  147. return old_handler;
  148. }
  149. /**
  150. * This function will trigger an interrupt.
  151. * @param vector the interrupt number
  152. */
  153. void rt_hw_interrupt_trigger(int vector)
  154. {
  155. INTC_ISR_SET(AINTC_BASE, vector>>5) = 1 << (vector & 0x1f);
  156. }
  157. void rt_hw_interrupt_clear(int vector)
  158. {
  159. INTC_ISR_CLEAR(AINTC_BASE, vector>>5) = 1 << (vector & 0x1f);
  160. }
  161. void rt_dump_isr_table(void)
  162. {
  163. int idx;
  164. for(idx = 0; idx < MAX_HANDLERS; idx++)
  165. {
  166. #ifdef RT_USING_INTERRUPT_INFO
  167. rt_kprintf("nr:%4d, name: %*.s, handler: 0x%p, param: 0x%08x\r\n",
  168. idx, RT_NAME_MAX, isr_table[idx].name,
  169. isr_table[idx].handler, isr_table[idx].param);
  170. #else
  171. rt_kprintf("nr:%4d, handler: 0x%p, param: 0x%08x\r\n",
  172. idx, isr_table[idx].handler, isr_table[idx].param);
  173. #endif
  174. }
  175. }
  176. /*@}*/