1 /*
2 * Copyright (c) 2006-2018, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2008-12-11 XuXinming first version
9 */
10
11 #include <rtthread.h>
12 #include <rthw.h>
13
14 #include "LPC24xx.h"
15
16 //#define BSP_INT_DEBUG
17
18 /**
19 * @addtogroup LPC2478
20 */
21 /*@{*/
22
23 /**
24 * this function will show registers of CPU
25 *
26 * @param regs the registers point
27 */
rt_hw_show_register(struct rt_hw_register * regs)28 void rt_hw_show_register (struct rt_hw_register *regs)
29 {
30 rt_kprintf("Execption:\n");
31 rt_kprintf("r00:0x%08x r01:0x%08x r02:0x%08x r03:0x%08x\n", regs->r0, regs->r1, regs->r2, regs->r3);
32 rt_kprintf("r04:0x%08x r05:0x%08x r06:0x%08x r07:0x%08x\n", regs->r4, regs->r5, regs->r6, regs->r7);
33 rt_kprintf("r08:0x%08x r09:0x%08x r10:0x%08x\n", regs->r8, regs->r9, regs->r10);
34 rt_kprintf("fp :0x%08x ip :0x%08x\n", regs->fp, regs->ip);
35 rt_kprintf("sp :0x%08x lr :0x%08x pc :0x%08x\n", regs->sp, regs->lr, regs->pc);
36 rt_kprintf("cpsr:0x%08x\n", regs->cpsr);
37 }
38
39 /**
40 * When ARM7TDMI comes across an instruction which it cannot handle,
41 * it takes the undefined instruction trap.
42 *
43 * @param regs system registers
44 *
45 * @note never invoke this function in application
46 */
rt_hw_trap_udef(struct rt_hw_register * regs)47 void rt_hw_trap_udef(struct rt_hw_register *regs)
48 {
49 rt_kprintf("undefined instruction\n");
50 rt_hw_show_register(regs);
51 if (rt_thread_self() != RT_NULL)
52 rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
53 rt_hw_cpu_shutdown();
54 }
55
56 /**
57 * The software interrupt instruction (SWI) is used for entering
58 * Supervisor mode, usually to request a particular supervisor
59 * function.
60 *
61 * @param regs system registers
62 *
63 * @note never invoke this function in application
64 */
rt_hw_trap_swi(struct rt_hw_register * regs)65 void rt_hw_trap_swi(struct rt_hw_register *regs)
66 {
67 rt_kprintf("software interrupt\n");
68 rt_hw_show_register(regs);
69 if (rt_thread_self() != RT_NULL)
70 rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
71 rt_hw_cpu_shutdown();
72 }
73
74 /**
75 * An abort indicates that the current memory access cannot be completed,
76 * which occurs during an instruction prefetch.
77 *
78 * @param regs system registers
79 *
80 * @note never invoke this function in application
81 */
rt_hw_trap_pabt(struct rt_hw_register * regs)82 void rt_hw_trap_pabt(struct rt_hw_register *regs)
83 {
84 rt_kprintf("prefetch abort\n");
85 rt_hw_show_register(regs);
86 if (rt_thread_self() != RT_NULL)
87 rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
88 rt_hw_cpu_shutdown();
89 }
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 */
rt_hw_trap_dabt(struct rt_hw_register * regs)99 void rt_hw_trap_dabt(struct rt_hw_register *regs)
100 {
101 rt_kprintf("Data Abort ");
102 rt_hw_show_register(regs);
103 if (rt_thread_self() != RT_NULL)
104 rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
105 rt_hw_cpu_shutdown();
106 }
107
108 /**
109 * Normally, system will never reach here
110 *
111 * @param regs system registers
112 *
113 * @note never invoke this function in application
114 */
rt_hw_trap_resv(struct rt_hw_register * regs)115 void rt_hw_trap_resv(struct rt_hw_register *regs)
116 {
117 rt_kprintf("not used\n");
118 rt_hw_show_register(regs);
119 if (rt_thread_self() != RT_NULL)
120 rt_kprintf("Current Thread: %s\n", rt_thread_self()->name);
121 rt_hw_cpu_shutdown();
122 }
123
124 extern rt_isr_handler_t isr_table[];
rt_hw_trap_irq(void)125 void rt_hw_trap_irq(void)
126 {
127 int irqno;
128 struct rt_irq_desc* irq;
129 extern struct rt_irq_desc irq_desc[];
130
131 irq = (struct rt_irq_desc*) VICVectAddr;
132 irqno = ((rt_uint32_t) irq - (rt_uint32_t) &irq_desc[0])/sizeof(struct rt_irq_desc);
133
134 /* invoke isr */
135 irq->handler(irqno, irq->param);
136 }
137
rt_hw_trap_fiq(void)138 void rt_hw_trap_fiq(void)
139 {
140 rt_kprintf("fast interrupt request\n");
141 }
142
143 /*@}*/
144