interrupt.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. /*****************************************************************************
  27. * Include Section
  28. * add all #include here
  29. *****************************************************************************/
  30. #include "interrupt.h"
  31. #include "fh_def.h"
  32. #include "fh_arch.h"
  33. #include "libraries/inc/fh_ictl.h"
  34. /*****************************************************************************
  35. * Define section
  36. * add all #define here
  37. *****************************************************************************/
  38. #define MAX_HANDLERS (NR_INTERNAL_IRQS+NR_EXTERNAL_IRQS)
  39. /****************************************************************************
  40. * ADT section
  41. * add definition of user defined Data Type that only be used in this file here
  42. ***************************************************************************/
  43. /******************************************************************************
  44. * Function prototype section
  45. * add prototypes for all functions called by this file,execepting those
  46. * declared in header file
  47. *****************************************************************************/
  48. /*****************************************************************************
  49. * Global variables section - Exported
  50. * add declaration of global variables that will be exported here
  51. * e.g.
  52. * int8_t foo;
  53. ****************************************************************************/
  54. extern rt_uint32_t rt_interrupt_nest;
  55. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  56. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  57. rt_uint32_t rt_thread_switch_interrupt_flag;
  58. /*****************************************************************************
  59. * Global variables section - Local
  60. * define global variables(will be refered only in this file) here,
  61. * static keyword should be used to limit scope of local variable to this file
  62. * e.g.
  63. * static uint8_t ufoo;
  64. *****************************************************************************/
  65. /* function body */
  66. /*****************************************************************************
  67. * Description:
  68. * add funtion description here
  69. * Parameters:
  70. * description for each argument, new argument starts at new line
  71. * Return:
  72. * what does this function returned?
  73. *****************************************************************************/
  74. rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector, void *param)
  75. {
  76. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  77. return RT_NULL;
  78. }
  79. /**
  80. * This function will initialize hardware interrupt
  81. */
  82. void rt_hw_interrupt_init(void)
  83. {
  84. rt_int32_t i;
  85. register rt_uint32_t idx;
  86. fh_intc *p = (fh_intc *)INTC_REG_BASE;
  87. ictl_close_all_isr(p);
  88. /* init exceptions table */
  89. for(idx=0; idx < MAX_HANDLERS; idx++)
  90. {
  91. irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
  92. irq_desc[idx].param = RT_NULL;
  93. #ifdef RT_USING_INTERRUPT_INFO
  94. rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
  95. irq_desc[idx].counter = 0;
  96. #endif
  97. }
  98. /* init interrupt nest, and context in thread sp */
  99. rt_interrupt_nest = 0;
  100. rt_interrupt_from_thread = 0;
  101. rt_interrupt_to_thread = 0;
  102. rt_thread_switch_interrupt_flag = 0;
  103. }
  104. /**
  105. * This function will mask a interrupt.
  106. * @param vector the interrupt number
  107. */
  108. void rt_hw_interrupt_mask(int irq)
  109. {
  110. fh_intc *p = (fh_intc *)INTC_REG_BASE;
  111. /* Disable irq on AIC */
  112. ictl_mask_isr(p,irq);
  113. // if (irq < 32)
  114. // p->IRQ_EN_L &= ~(1 << irq);
  115. // else
  116. // p->IRQ_EN_H &= ~(1 << (irq - 32));
  117. }
  118. void rt_hw_interrupt_umask(int irq)
  119. {
  120. fh_intc *p = (fh_intc *)INTC_REG_BASE;
  121. /* Enable irq on AIC */
  122. ictl_unmask_isr(p,irq);
  123. // if (irq < 32)
  124. // p->IRQ_EN_L |= 1 << irq;
  125. // else
  126. // p->IRQ_EN_H |= 1 << (irq - 32);
  127. }
  128. /**
  129. * This function will install a interrupt service routine to a interrupt.
  130. * @param vector the interrupt number
  131. * @param handler the interrupt service routine to be installed
  132. * @param param the interrupt service function parameter
  133. * @param name the interrupt name
  134. * @return old handler
  135. */
  136. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  137. void *param, const char *name)
  138. {
  139. rt_isr_handler_t old_handler = RT_NULL;
  140. if(vector < MAX_HANDLERS)
  141. {
  142. old_handler = irq_desc[vector].handler;
  143. if (handler != RT_NULL)
  144. {
  145. irq_desc[vector].handler = (rt_isr_handler_t)handler;
  146. irq_desc[vector].param = param;
  147. #ifdef RT_USING_INTERRUPT_INFO
  148. rt_snprintf(irq_desc[vector].name, RT_NAME_MAX - 1, "%s", name);
  149. irq_desc[vector].counter = 0;
  150. #endif
  151. }
  152. }
  153. return old_handler;
  154. }
  155. #ifdef RT_USING_FINSH
  156. void list_irq(void)
  157. {
  158. #ifdef RT_USING_INTERRUPT_INFO
  159. int irq;
  160. rt_kprintf("number\tcount\tname\n");
  161. for (irq = 0; irq < MAX_HANDLERS; irq++)
  162. {
  163. if (rt_strncmp(irq_desc[irq].name, "default", sizeof("default")))
  164. {
  165. rt_kprintf("%02ld: %10ld %s\n", irq, irq_desc[irq].counter, irq_desc[irq].name);
  166. }
  167. }
  168. #else
  169. rt_kprintf("please open 'RT_USING_INTERRUPT_INFO'\n");
  170. #endif
  171. }
  172. #include <finsh.h>
  173. FINSH_FUNCTION_EXPORT(list_irq, list system irq);
  174. #endif