1
0

interrupt.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-01-13 weety first version
  9. * 2015-04-27 ArdaFu Port bsp from at91sam9260 to asm9260t
  10. */
  11. #include <rthw.h>
  12. #include "asm9260t.h"
  13. #include "interrupt.h"
  14. #define MAX_HANDLERS (64)
  15. extern rt_uint32_t rt_interrupt_nest;
  16. /* exception and interrupt handler table */
  17. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  18. rt_uint32_t rt_interrupt_from_thread;
  19. rt_uint32_t rt_interrupt_to_thread;
  20. rt_uint32_t rt_thread_switch_interrupt_flag;
  21. /* --------------------------------------------------------------------
  22. * Interrupt initialization
  23. * -------------------------------------------------------------------- */
  24. /*
  25. * The default interrupt priority levels (0 = lowest, 3 = highest).
  26. */
  27. static rt_uint32_t default_irq_priority[MAX_HANDLERS/4] =
  28. {
  29. 0x00000000UL, /* INT3 - INT0 */
  30. 0x00000000UL, /* INT7 - INT4 */
  31. 0x00000000UL, /* INT11 - INT8 */
  32. 0x02000000UL, /* INT15 - INT12 */
  33. 0x02020202UL, /* INT19 - INT16 */
  34. 0x02020202UL, /* INT23 - INT20 */
  35. 0x00000002UL, /* INT27 - INT24 */
  36. 0x01010100UL, /* INT31 - INT28 */
  37. 0x00000001UL, /* INT35 - INT32 */
  38. 0x00000000UL, /* INT39 - INT36 */
  39. 0x00000000UL, /* INT43 - INT40 */
  40. 0x00000000UL, /* INT47 - INT44 */
  41. 0x00000000UL, /* INT51 - INT48 */
  42. 0x00000000UL, /* INT55 - INT52 */
  43. 0x00000000UL, /* INT59 - INT56 */
  44. 0x00000000UL, /* INT63 - INT60 */
  45. };
  46. void rt_hw_interrupt_mask(int irq);
  47. void rt_hw_interrupt_umask(int irq);
  48. rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector, void *param)
  49. {
  50. rt_kprintf("UN-handled interrupt %d occurred!!!\n", vector);
  51. return RT_NULL;
  52. }
  53. /**
  54. * This function will initialize hardware interrupt
  55. */
  56. void rt_hw_interrupt_init(void)
  57. {
  58. register rt_uint32_t idx;
  59. /* Initialize the ICOLL interrupt controller */
  60. outl((1<<8), REG_SET(HW_AHBCLKCTRL1)); // Enable ICOLL clock
  61. outl((1<<8), REG_CLR(HW_PRESETCTRL1)); // Reset ICOLL start
  62. outl((1<<8), REG_SET(HW_PRESETCTRL1)); // Reset ICOLL stop
  63. for(idx = 0; idx < (MAX_HANDLERS/4); idx++)
  64. {
  65. rt_uint32_t reg = (HW_ICOLL_PRIORITY0 + 0x10*idx);
  66. outl(default_irq_priority[idx], REG_VAL(reg));
  67. }
  68. /* init exceptions table */
  69. for(idx=0; idx < MAX_HANDLERS; idx++)
  70. {
  71. irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
  72. irq_desc[idx].param = RT_NULL;
  73. #ifdef RT_USING_INTERRUPT_INFO
  74. rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
  75. irq_desc[idx].counter = 0;
  76. #endif
  77. }
  78. /* init interrupt nest, and context in thread sp */
  79. rt_interrupt_nest = 0;
  80. rt_interrupt_from_thread = 0;
  81. rt_interrupt_to_thread = 0;
  82. rt_thread_switch_interrupt_flag = 0;
  83. outl(0x00000000, REG_CLR(HW_ICOLL_VBASE)); //todo: fix this bug
  84. outl(0x00020000, REG_CLR(HW_ICOLL_CTRL)); // Clear CTRL REG
  85. outl(0x00050000, REG_SET(HW_ICOLL_CTRL));
  86. outl(0x00000004, HW_ICOLL_UNDEF_VECTOR);
  87. outl(~0UL, REG_CLR(HW_ICOLL_CLEAR0));
  88. outl(~0UL, REG_CLR(HW_ICOLL_CLEAR1));
  89. }
  90. /**
  91. * This function will mask a interrupt.
  92. * @param vector the interrupt number
  93. */
  94. void rt_hw_interrupt_mask(int irq)
  95. {
  96. rt_uint32_t reg = HW_ICOLL_PRIORITY0 + ((irq & 0x3CUL) << 2);
  97. rt_uint32_t bit = 4UL << ((irq & 3UL)<<3);
  98. outl(bit, REG_CLR(reg));
  99. }
  100. /**
  101. * This function will un-mask a interrupt.
  102. * @param vector the interrupt number
  103. */
  104. void rt_hw_interrupt_umask(int irq)
  105. {
  106. rt_uint32_t reg = HW_ICOLL_PRIORITY0 + ((irq & 0x3CUL) << 2);
  107. rt_uint32_t bit = 4UL << ((irq & 3UL)<<3);
  108. outl(bit, REG_SET(reg));
  109. }
  110. /**
  111. * This function will install a interrupt service routine to a interrupt.
  112. * @param vector the interrupt number
  113. * @param handler the interrupt service routine to be installed
  114. * @param param the interrupt service function parameter
  115. * @param name the interrupt name
  116. * @return old handler
  117. */
  118. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  119. void *param, const char *name)
  120. {
  121. rt_isr_handler_t old_handler = RT_NULL;
  122. if(vector < MAX_HANDLERS)
  123. {
  124. old_handler = irq_desc[vector].handler;
  125. if (handler != RT_NULL)
  126. {
  127. irq_desc[vector].handler = (rt_isr_handler_t)handler;
  128. irq_desc[vector].param = param;
  129. #ifdef RT_USING_INTERRUPT_INFO
  130. rt_snprintf(irq_desc[vector].name, RT_NAME_MAX - 1, "%s", name);
  131. irq_desc[vector].counter = 0;
  132. #endif
  133. }
  134. }
  135. return old_handler;
  136. }
  137. rt_uint32_t rt_hw_interrupt_get_active(rt_uint32_t fiq_irq)
  138. {
  139. //volatile rt_uint32_t irqstat;
  140. rt_uint32_t id;
  141. /* AIC need this dummy read */
  142. inl(HW_ICOLL_VECTOR);
  143. /* get irq number */
  144. id = inl(HW_ICOLL_STAT);
  145. /* clear pending register */
  146. //irqstat = inl(HW_ICOLL_VECTOR);
  147. return id;
  148. }
  149. void rt_hw_interrupt_ack(rt_uint32_t fiq_irq, rt_uint32_t id)
  150. {
  151. rt_uint32_t reg = HW_ICOLL_PRIORITY0 + ((id & 0x3CUL) << 2);
  152. rt_uint32_t level = 1UL << (0x3 & (inl(REG_VAL(reg)) >>((id & 3UL)<<3)));
  153. if(id & 0x20)
  154. outl((1UL<<(id&0x1F)), REG_SET(HW_ICOLL_CLEAR1));
  155. else
  156. outl((1UL<<id), REG_SET(HW_ICOLL_CLEAR0));
  157. outl(level, HW_ICOLL_LEVELACK);
  158. }
  159. #ifdef RT_USING_FINSH
  160. void list_irq(void)
  161. {
  162. int irq;
  163. rt_kprintf("number\tcount\tname\n");
  164. for (irq = 0; irq < MAX_HANDLERS; irq++)
  165. {
  166. if (rt_strncmp(irq_desc[irq].name, "default", sizeof("default")))
  167. {
  168. rt_kprintf("%02ld: %10ld %s\n",
  169. irq, irq_desc[irq].counter, irq_desc[irq].name);
  170. }
  171. }
  172. }
  173. #include <finsh.h>
  174. FINSH_FUNCTION_EXPORT(list_irq, list system irq);
  175. #endif