trap.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * File : trap.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-01-13 weety modified from mini2440
  13. */
  14. #include <rtthread.h>
  15. #include <rthw.h>
  16. #include "at91sam926x.h"
  17. /**
  18. * @addtogroup AT91SAM926X
  19. */
  20. /*@{*/
  21. extern struct rt_thread *rt_current_thread;
  22. #ifdef RT_USING_FINSH
  23. extern long list_thread(void);
  24. #endif
  25. /**
  26. * this function will show registers of CPU
  27. *
  28. * @param regs the registers point
  29. */
  30. void rt_hw_show_register (struct rt_hw_register *regs)
  31. {
  32. rt_kprintf("Execption:\n");
  33. rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
  34. rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
  35. rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
  36. rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
  37. rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
  38. rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
  39. }
  40. /**
  41. * When ARM7TDMI comes across an instruction which it cannot handle,
  42. * it takes the undefined instruction trap.
  43. *
  44. * @param regs system registers
  45. *
  46. * @note never invoke this function in application
  47. */
  48. void rt_hw_trap_udef(struct rt_hw_register *regs)
  49. {
  50. rt_hw_show_register(regs);
  51. rt_kprintf("undefined instruction\n");
  52. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  53. #ifdef RT_USING_FINSH
  54. list_thread();
  55. #endif
  56. rt_hw_cpu_shutdown();
  57. }
  58. /**
  59. * The software interrupt instruction (SWI) is used for entering
  60. * Supervisor mode, usually to request a particular supervisor
  61. * function.
  62. *
  63. * @param regs system registers
  64. *
  65. * @note never invoke this function in application
  66. */
  67. void rt_hw_trap_swi(struct rt_hw_register *regs)
  68. {
  69. rt_hw_show_register(regs);
  70. rt_kprintf("software interrupt\n");
  71. rt_hw_cpu_shutdown();
  72. }
  73. /**
  74. * An abort indicates that the current memory access cannot be completed,
  75. * which occurs during an instruction prefetch.
  76. *
  77. * @param regs system registers
  78. *
  79. * @note never invoke this function in application
  80. */
  81. void rt_hw_trap_pabt(struct rt_hw_register *regs)
  82. {
  83. rt_hw_show_register(regs);
  84. rt_kprintf("prefetch abort\n");
  85. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  86. #ifdef RT_USING_FINSH
  87. list_thread();
  88. #endif
  89. rt_hw_cpu_shutdown();
  90. }
  91. /**
  92. * An abort indicates that the current memory access cannot be completed,
  93. * which occurs during a data access.
  94. *
  95. * @param regs system registers
  96. *
  97. * @note never invoke this function in application
  98. */
  99. void rt_hw_trap_dabt(struct rt_hw_register *regs)
  100. {
  101. rt_hw_show_register(regs);
  102. rt_kprintf("data abort\n");
  103. rt_kprintf("thread - %s stack:\n", rt_current_thread->name);
  104. #ifdef RT_USING_FINSH
  105. list_thread();
  106. #endif
  107. rt_hw_cpu_shutdown();
  108. }
  109. /**
  110. * Normally, system will never reach here
  111. *
  112. * @param regs system registers
  113. *
  114. * @note never invoke this function in application
  115. */
  116. void rt_hw_trap_resv(struct rt_hw_register *regs)
  117. {
  118. rt_kprintf("not used\n");
  119. rt_hw_show_register(regs);
  120. rt_hw_cpu_shutdown();
  121. }
  122. extern rt_isr_handler_t isr_table[];
  123. void rt_hw_trap_irq()
  124. {
  125. rt_isr_handler_t isr_func;
  126. rt_uint32_t irqstat, irq, mask;
  127. //rt_kprintf("irq interrupt request\n");
  128. /* get irq number */
  129. irq = at91_sys_read(AT91_AIC_IVR);
  130. /* clear pending register */
  131. irqstat = at91_sys_read(AT91_AIC_ISR);
  132. if (irqstat == 0)
  133. {
  134. rt_kprintf("No interrupt occur\n");
  135. at91_sys_write(AT91_AIC_EOICR, 0);
  136. return;
  137. }
  138. //at91_sys_write(AT91_AIC_EOICR, 0x55555555);
  139. /* get interrupt service routine */
  140. isr_func = isr_table[irq];
  141. /* turn to interrupt service routine */
  142. isr_func(irq);
  143. at91_sys_write(AT91_AIC_EOICR, 0x55555555); //EIOCR must be write any value after interrupt, or else can't response next interrupt
  144. }
  145. void rt_hw_trap_fiq()
  146. {
  147. rt_kprintf("fast interrupt request\n");
  148. }
  149. /*@}*/