trap.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * File : trap.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2011-01-13 weety modified from mini2440
  23. */
  24. #include <rtthread.h>
  25. #include <rthw.h>
  26. #include "at91sam926x.h"
  27. /**
  28. * @addtogroup AT91SAM926X
  29. */
  30. /*@{*/
  31. extern struct rt_thread *rt_current_thread;
  32. #ifdef RT_USING_FINSH
  33. extern long list_thread(void);
  34. #endif
  35. /**
  36. * this function will show registers of CPU
  37. *
  38. * @param regs the registers point
  39. */
  40. void rt_hw_show_register (struct rt_hw_register *regs)
  41. {
  42. rt_kprintf("Execption:\n");
  43. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  44. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  45. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  46. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  47. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  48. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  49. }
  50. /**
  51. * When ARM7TDMI comes across an instruction which it cannot handle,
  52. * it takes the undefined instruction trap.
  53. *
  54. * @param regs system registers
  55. *
  56. * @note never invoke this function in application
  57. */
  58. void rt_hw_trap_udef(struct rt_hw_register *regs)
  59. {
  60. rt_hw_show_register(regs);
  61. rt_kprintf("undefined instruction\n");
  62. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  63. #ifdef RT_USING_FINSH
  64. list_thread();
  65. #endif
  66. rt_hw_cpu_shutdown();
  67. }
  68. /**
  69. * The software interrupt instruction (SWI) is used for entering
  70. * Supervisor mode, usually to request a particular supervisor
  71. * function.
  72. *
  73. * @param regs system registers
  74. *
  75. * @note never invoke this function in application
  76. */
  77. void rt_hw_trap_swi(struct rt_hw_register *regs)
  78. {
  79. rt_hw_show_register(regs);
  80. rt_kprintf("software interrupt\n");
  81. rt_hw_cpu_shutdown();
  82. }
  83. /**
  84. * An abort indicates that the current memory access cannot be completed,
  85. * which occurs during an instruction prefetch.
  86. *
  87. * @param regs system registers
  88. *
  89. * @note never invoke this function in application
  90. */
  91. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  92. {
  93. rt_hw_show_register(regs);
  94. rt_kprintf("prefetch abort\n");
  95. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  96. #ifdef RT_USING_FINSH
  97. list_thread();
  98. #endif
  99. rt_hw_cpu_shutdown();
  100. }
  101. /**
  102. * An abort indicates that the current memory access cannot be completed,
  103. * which occurs during a data access.
  104. *
  105. * @param regs system registers
  106. *
  107. * @note never invoke this function in application
  108. */
  109. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  110. {
  111. rt_hw_show_register(regs);
  112. rt_kprintf("data abort\n");
  113. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  114. #ifdef RT_USING_FINSH
  115. list_thread();
  116. #endif
  117. rt_hw_cpu_shutdown();
  118. }
  119. /**
  120. * Normally, system will never reach here
  121. *
  122. * @param regs system registers
  123. *
  124. * @note never invoke this function in application
  125. */
  126. void rt_hw_trap_resv(struct rt_hw_register *regs)
  127. {
  128. rt_kprintf("not used\n");
  129. rt_hw_show_register(regs);
  130. rt_hw_cpu_shutdown();
  131. }
  132. extern struct rt_irq_desc irq_desc[];
  133. void rt_hw_trap_irq()
  134. {
  135. rt_isr_handler_t isr_func;
  136. rt_uint32_t irqstat, irq, mask;
  137. void *param;
  138. //rt_kprintf("irq interrupt request\n");
  139. /* get irq number */
  140. irq = at91_sys_read(AT91_AIC_IVR);
  141. /* clear pending register */
  142. irqstat = at91_sys_read(AT91_AIC_ISR);
  143. if (irqstat == 0)
  144. {
  145. rt_kprintf("No interrupt occur\n");
  146. at91_sys_write(AT91_AIC_EOICR, 0);
  147. return;
  148. }
  149. /* get interrupt service routine */
  150. isr_func = irq_desc[irq].handler;
  151. param = irq_desc[irq].param;
  152. /* turn to interrupt service routine */
  153. isr_func(irq, param);
  154. at91_sys_write(AT91_AIC_EOICR, 0x55555555); //EIOCR must be write any value after interrupt, or else can't response next interrupt
  155. irq_desc[irq].counter ++;
  156. }
  157. void rt_hw_trap_fiq()
  158. {
  159. rt_kprintf("fast interrupt request\n");
  160. }
  161. /*@}*/