diff options
| author | [email protected] <[email protected]> | 2012-12-29 09:36:16 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-12-29 09:36:16 +0000 |
| commit | 68fadd9edc61b9b62406961de28f54354f2bfea9 (patch) | |
| tree | cee99e702ede8ca2451c5698fbe64c42ecc34963 /libcpu | |
| parent | d573786d522a4c5316210bcef22a417ba40f92c8 (diff) | |
Add exception hook function.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2551 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'libcpu')
| -rw-r--r-- | libcpu/arm/cortex-m3/cpuport.c | 48 | ||||
| -rw-r--r-- | libcpu/arm/cortex-m4/cpuport.c | 29 |
2 files changed, 60 insertions, 17 deletions
diff --git a/libcpu/arm/cortex-m3/cpuport.c b/libcpu/arm/cortex-m3/cpuport.c index 334ccf5a96..b85e9a0956 100644 --- a/libcpu/arm/cortex-m3/cpuport.c +++ b/libcpu/arm/cortex-m3/cpuport.c @@ -13,6 +13,7 @@ * 2011-02-14 onelife Modify for EFM32 * 2011-06-17 onelife Merge all of the C source code into cpuport.c * 2012-12-23 aozima stack addr align to 8byte. + * 2012-12-29 Bernard Add exception hook. */ #include <rtthread.h> @@ -47,6 +48,8 @@ struct stack_frame /* flag in interrupt handling */ rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; rt_uint32_t rt_thread_switch_interrupt_flag; +/* exception hook */ +static rt_err_t (*rt_exception_hook)(void *context) = RT_NULL; /** * This function will initialize thread stack @@ -92,23 +95,41 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, return stk; } -extern long list_thread(void); -extern rt_thread_t rt_current_thread; /** - * fault exception handling + * This function set the hook, which is invoked on fault exception handling. + * + * @param exception_handle the exception handling hook function. + */ +void rt_hw_exception_install(rt_err_t (*exception_handle)(void* context)) +{ + rt_exception_hook = exception_handle; +} + +/* + * fault exception handler */ -void rt_hw_hard_fault_exception(struct exception_stack_frame* contex) +void rt_hw_hard_fault_exception(struct exception_stack_frame* context) { - rt_kprintf("psr: 0x%08x\n", contex->psr); - rt_kprintf(" pc: 0x%08x\n", contex->pc); - rt_kprintf(" lr: 0x%08x\n", contex->lr); - rt_kprintf("r12: 0x%08x\n", contex->r12); - rt_kprintf("r03: 0x%08x\n", contex->r3); - rt_kprintf("r02: 0x%08x\n", contex->r2); - rt_kprintf("r01: 0x%08x\n", contex->r1); - rt_kprintf("r00: 0x%08x\n", contex->r0); + extern long list_thread(void); + + if (rt_exception_hook != RT_NULL) + { + rt_err_t result; + + result = rt_exception_hook(context); + if (result == RT_EOK) return; + } - rt_kprintf("hard fault on thread: %s\n", rt_current_thread->name); + rt_kprintf("psr: 0x%08x\n", context->psr); + rt_kprintf(" pc: 0x%08x\n", context->pc); + rt_kprintf(" lr: 0x%08x\n", context->lr); + rt_kprintf("r12: 0x%08x\n", context->r12); + rt_kprintf("r03: 0x%08x\n", context->r3); + rt_kprintf("r02: 0x%08x\n", context->r2); + rt_kprintf("r01: 0x%08x\n", context->r1); + rt_kprintf("r00: 0x%08x\n", context->r0); + + rt_kprintf("hard fault on thread: %s\n", rt_thread_self()->name); #ifdef RT_USING_FINSH list_thread(); @@ -126,3 +147,4 @@ void rt_hw_cpu_shutdown(void) RT_ASSERT(0); } + diff --git a/libcpu/arm/cortex-m4/cpuport.c b/libcpu/arm/cortex-m4/cpuport.c index 57e792a8d5..8f97758741 100644 --- a/libcpu/arm/cortex-m4/cpuport.c +++ b/libcpu/arm/cortex-m4/cpuport.c @@ -15,6 +15,7 @@ * 2012-01-01 aozima support context switch load/store FPU register. * 2012-12-11 lgnq fixed the coding style. * 2012-12-23 aozima stack addr align to 8byte. + * 2012-12-29 Bernard Add exception hook. */ #include <rtthread.h> @@ -27,6 +28,8 @@ rt_uint32_t rt_interrupt_from_thread; rt_uint32_t rt_interrupt_to_thread; rt_uint32_t rt_thread_switch_interrupt_flag; +/* exception hook */ +static rt_err_t (*rt_exception_hook)(void *context) = RT_NULL; struct exception_stack_frame { @@ -131,11 +134,28 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, return stk; } -extern void rt_hw_interrupt_thread_switch(void); -extern long list_thread(void); -extern rt_thread_t rt_current_thread; +/** + * This function set the hook, which is invoked on fault exception handling. + * + * @param exception_handle the exception handling hook function. + */ +void rt_hw_exception_install(rt_err_t (*exception_handle)(void* context)) +{ + rt_exception_hook = exception_handle; +} + void rt_hw_hard_fault_exception(struct exception_stack_frame *exception_stack) { + extern long list_thread(void); + + if (rt_exception_hook != RT_NULL) + { + rt_err_t result; + + result = rt_exception_hook(exception_stack); + if (result == RT_EOK) return; + } + rt_kprintf("psr: 0x%08x\n", exception_stack->psr); rt_kprintf(" pc: 0x%08x\n", exception_stack->pc); rt_kprintf(" lr: 0x%08x\n", exception_stack->lr); @@ -145,7 +165,7 @@ void rt_hw_hard_fault_exception(struct exception_stack_frame *exception_stack) rt_kprintf("r01: 0x%08x\n", exception_stack->r1); rt_kprintf("r00: 0x%08x\n", exception_stack->r0); - rt_kprintf("hard fault on thread: %s\n", rt_current_thread->name); + rt_kprintf("hard fault on thread: %s\n", rt_thread_self()->name); #ifdef RT_USING_FINSH list_thread(); @@ -160,3 +180,4 @@ void rt_hw_cpu_shutdown(void) RT_ASSERT(0); } + |
