interrupt.c 4.9 KB

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