diff --git a/boards/telosb/driver_cc2420.c b/boards/telosb/driver_cc2420.c index 638c8f6c1..eb0f27555 100644 --- a/boards/telosb/driver_cc2420.c +++ b/boards/telosb/driver_cc2420.c @@ -14,7 +14,7 @@ #include "cpu.h" #include "irq.h" #include "hwtimer.h" -#include "crash.h" +#include "panic.h" #include "cc2420.h" #include "cc2420_arch.h" diff --git a/boards/wsn430-v1_4/driver_cc2420.c b/boards/wsn430-v1_4/driver_cc2420.c index fbe0da06e..15407f5ef 100644 --- a/boards/wsn430-v1_4/driver_cc2420.c +++ b/boards/wsn430-v1_4/driver_cc2420.c @@ -14,7 +14,7 @@ #include "cpu.h" #include "irq.h" #include "hwtimer.h" -#include "crash.h" +#include "panic.h" #include "cc2420.h" #include "cc2420_arch.h" diff --git a/boards/z1/driver_cc2420.c b/boards/z1/driver_cc2420.c index f8e0fe13b..d912da685 100644 --- a/boards/z1/driver_cc2420.c +++ b/boards/z1/driver_cc2420.c @@ -28,7 +28,7 @@ #include "cpu.h" #include "irq.h" #include "hwtimer.h" -#include "crash.h" +#include "panic.h" #include "cc2420.h" #include "cc2420_arch.h" diff --git a/core/include/arch/panic_arch.h b/core/include/arch/panic_arch.h new file mode 100644 index 000000000..715d3877a --- /dev/null +++ b/core/include/arch/panic_arch.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2015 INRIA + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup core_arch + * @{ + * + * @file + * @brief Architecture dependent panic function + * + * @author Oliver Hahm + */ + +#ifndef PANIC_ARCH_H +#define PANIC_ARCH_H + +#ifdef __cplusplus + extern "C" { +#endif + + /** + * @brief architecture dependent handling of an panic case + * + * This function gives the CPU the possibility to execute architecture + * dependent code in case of an severe error. + */ +void panic_arch(void); + +#ifdef __cplusplus +} +#endif + +#endif /* REBOOT_ARCH_H */ +/** @} */ diff --git a/core/include/crash.h b/core/include/panic.h similarity index 88% rename from core/include/crash.h rename to core/include/panic.h index bbb422109..60c8e0199 100644 --- a/core/include/crash.h +++ b/core/include/panic.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 INRIA + * Copyright (C) 2014, 2015 INRIA * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -10,17 +10,17 @@ * @addtogroup core_util * @{ * - * @file crash.h + * @file * @brief Crash handling header * - * Define a core_panic() function that allows to stop/reboot the system + * Define a ::core_panic function that allows to stop/reboot the system * when an unrecoverable problem has occurred. * * @author Kévin Roussel */ -#ifndef CRASH_H -#define CRASH_H +#ifndef PANIC_H +#define PANIC_H #include "kernel.h" @@ -54,5 +54,5 @@ NORETURN void core_panic(int crash_code, const char *message); } #endif -#endif /* CRASH_H */ +#endif /* PANIC_H */ /** @} */ diff --git a/cpu/cortex-m4_common/crash.c b/core/panic.c similarity index 82% rename from cpu/cortex-m4_common/crash.c rename to core/panic.c index f10541300..91afac6e4 100644 --- a/cpu/cortex-m4_common/crash.c +++ b/core/panic.c @@ -8,12 +8,13 @@ */ /** - * @ingroup cortex-m4_common + * @ingroup core_util * @{ * * @file - * @brief Crash handling functions implementation for ARM Cortex-based MCUs + * @brief Crash handling functions * + * @author Kévin Roussel * @author Oliver Hahm * @author Joakim Gebart */ @@ -24,7 +25,8 @@ #include "cpu.h" #include "irq.h" #include "lpm.h" -#include "crash.h" +#include "panic.h" +#include "arch/panic_arch.h" #define PANIC_STR_SIZE 80 @@ -57,14 +59,8 @@ NORETURN void core_panic(int crash_code, const char *message) } /* disable watchdog and all possible sources of interrupts */ disableIRQ(); -#if DEVELHELP - /* The bkpt instruction will signal to the debugger to break here. */ - __ASM("bkpt #0"); - /* enter infinite loop, into deepest possible sleep mode */ - while (1) { - lpm_set(LPM_OFF); - } -#else + panic_arch(); +#ifndef DEVELHELP /* DEVELHELP not set => reboot system */ (void) reboot(RB_AUTOBOOT); #endif diff --git a/cpu/arm7_common/crash.c b/cpu/arm7_common/crash.c deleted file mode 100644 index 1899c6310..000000000 --- a/cpu/arm7_common/crash.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2014 INRIA - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup core_util - * @{ - * - * @file crash.c - * @brief Crash handling functions implementation for ARM-based MCUs - * - * @author Kévin Roussel - */ - -#include "cpu.h" -#include "lpm.h" -#include "crash.h" - -#include -#include - -/* "public" variables holding the crash data */ -char panic_str[80]; -int panic_code; - -/* flag preventing "recursive crash printing loop" */ -static int crashed = 0; - -/* WARNING: this function NEVER returns! */ -NORETURN void core_panic(int crash_code, const char *message) -{ - /* copy panic datas to "public" global variables */ - panic_code = crash_code; - strncpy(panic_str, message, 80); - /* print panic message to console (if possible) */ - if (crashed == 0) { - crashed = 1; - puts("******** SYSTEM FAILURE ********\n"); - puts(message); -#if DEVELHELP - puts("******** RIOT HALTS HERE ********\n"); -#else - puts("******** RIOT WILL REBOOT ********\n"); -#endif - puts("\n\n"); - } - /* disable watchdog and all possible sources of interrupts */ - //TODO - dINT(); -#if DEVELHELP - /* enter infinite loop, into deepest possible sleep mode */ - while (1) { - lpm_set(LPM_OFF); - } -#else - /* DEVELHELP not set => reboot system */ - (void) reboot(RB_AUTOBOOT); -#endif - - /* tell the compiler that we won't return from this function - (even if we actually won't even get here...) */ - UNREACHABLE(); -} diff --git a/cpu/arm7_common/panic.c b/cpu/arm7_common/panic.c new file mode 100644 index 000000000..3f99c50f4 --- /dev/null +++ b/cpu/arm7_common/panic.c @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2014 INRIA + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup arm7_common + * @{ + * + * @file + * @brief Crash handling functions implementation for ARM-based MCUs + * + * @author Kévin Roussel + * @author Oliver Hahm + */ + +#include "lpm.h" + +void panic_arch(void) +{ +#if DEVELHELP + /* enter infinite loop, into deepest possible sleep mode */ + while (1) { + lpm_set(LPM_OFF); + } +#endif +} diff --git a/cpu/cortex-m0_common/crash.c b/cpu/cortex-m0_common/crash.c deleted file mode 100644 index 03d71cba8..000000000 --- a/cpu/cortex-m0_common/crash.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2015 INRIA - * Copyright (C) 2015 Eistec AB - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for more - * details. - */ - -/** - * @ingroup cortex-m0_common - * @{ - * - * @file - * @brief Crash handling functions implementation for ARM Cortex-based MCUs - * - * @author Oliver Hahm - * @author Joakim Gebart - */ - -#include -#include - -#include "cpu.h" -#include "irq.h" -#include "lpm.h" -#include "crash.h" - -#define PANIC_STR_SIZE 80 - -/* "public" variables holding the crash data */ -char panic_str[PANIC_STR_SIZE]; -int panic_code; - -/* flag preventing "recursive crash printing loop" */ -static int crashed = 0; - -/* WARNING: this function NEVER returns! */ -NORETURN void core_panic(int crash_code, const char *message) -{ - /* copy panic datas to "public" global variables */ - panic_code = crash_code; - strncpy(panic_str, message, sizeof(panic_str)); - /* strncpy does not add any null-termination. */ - panic_str[sizeof(panic_str)-1] = '\0'; - /* print panic message to console (if possible) */ - if (crashed == 0) { - crashed = 1; - puts("******** SYSTEM FAILURE ********\n"); - puts(message); -#if DEVELHELP - puts("******** RIOT HALTS HERE ********\n"); -#else - puts("******** RIOT WILL REBOOT ********\n"); -#endif - puts("\n\n"); - } - /* disable watchdog and all possible sources of interrupts */ - disableIRQ(); -#if DEVELHELP - /* The bkpt instruction will signal to the debugger to break here. */ - __ASM("bkpt #0"); - /* enter infinite loop, into deepest possible sleep mode */ - while (1) { - lpm_set(LPM_OFF); - } -#else - /* DEVELHELP not set => reboot system */ - (void) reboot(RB_AUTOBOOT); -#endif - - /* tell the compiler that we won't return from this function - (even if we actually won't even get here...) */ - UNREACHABLE(); -} diff --git a/cpu/cortex-m0_common/panic.c b/cpu/cortex-m0_common/panic.c new file mode 100644 index 000000000..ddcbdc635 --- /dev/null +++ b/cpu/cortex-m0_common/panic.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 INRIA + * Copyright (C) 2015 Eistec AB + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup cortex-m0_common + * @{ + * + * @file + * @brief Crash handling functions implementation for ARM Cortex-based MCUs + * + * @author Oliver Hahm + * @author Joakim Gebart + */ + +#include "cpu.h" +#include "lpm.h" + +void panic_arch(void) +{ +#if DEVELHELP + /* The bkpt instruction will signal to the debugger to break here. */ + __ASM("bkpt #0"); + /* enter infinite loop, into deepest possible sleep mode */ + while (1) { + lpm_set(LPM_OFF); + } +#endif +} diff --git a/cpu/cortex-m3_common/crash.c b/cpu/cortex-m3_common/crash.c deleted file mode 100644 index 93e7ce471..000000000 --- a/cpu/cortex-m3_common/crash.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2014-2015 INRIA - * Copyright (C) 2015 Eistec AB - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for more - * details. - */ - -/** - * @ingroup cortex-m3_common - * @{ - * - * @file - * @brief Crash handling functions implementation for ARM Cortex-based MCUs - * - * @author Oliver Hahm - * @author Joakim Gebart - */ - -#include -#include - -#include "cpu.h" -#include "irq.h" -#include "lpm.h" -#include "crash.h" - -#define PANIC_STR_SIZE 80 - -/* "public" variables holding the crash data */ -char panic_str[PANIC_STR_SIZE]; -int panic_code; - -/* flag preventing "recursive crash printing loop" */ -static int crashed = 0; - -/* WARNING: this function NEVER returns! */ -NORETURN void core_panic(int crash_code, const char *message) -{ - /* copy panic datas to "public" global variables */ - panic_code = crash_code; - strncpy(panic_str, message, sizeof(panic_str)); - /* strncpy does not add any null-termination. */ - panic_str[sizeof(panic_str)-1] = '\0'; - /* print panic message to console (if possible) */ - if (crashed == 0) { - crashed = 1; - puts("******** SYSTEM FAILURE ********\n"); - puts(message); -#if DEVELHELP - puts("******** RIOT HALTS HERE ********\n"); -#else - puts("******** RIOT WILL REBOOT ********\n"); -#endif - puts("\n\n"); - } - /* disable watchdog and all possible sources of interrupts */ - disableIRQ(); -#if DEVELHELP - /* The bkpt instruction will signal to the debugger to break here. */ - __ASM("bkpt #0"); - /* enter infinite loop, into deepest possible sleep mode */ - while (1) { - lpm_set(LPM_OFF); - } -#else - /* DEVELHELP not set => reboot system */ - (void) reboot(RB_AUTOBOOT); -#endif - - /* tell the compiler that we won't return from this function - (even if we actually won't even get here...) */ - UNREACHABLE(); -} diff --git a/cpu/cortex-m3_common/panic.c b/cpu/cortex-m3_common/panic.c new file mode 100644 index 000000000..4f9aef455 --- /dev/null +++ b/cpu/cortex-m3_common/panic.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2014-2015 INRIA + * Copyright (C) 2015 Eistec AB + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup cortex-m3_common + * @{ + * + * @file + * @brief Crash handling functions implementation for ARM Cortex-based MCUs + * + * @author Oliver Hahm + * @author Joakim Gebart + */ + +#include "cpu.h" +#include "lpm.h" + +void panic_arch(void) +{ +#if DEVELHELP + /* The bkpt instruction will signal to the debugger to break here. */ + __ASM("bkpt #0"); + /* enter infinite loop, into deepest possible sleep mode */ + while (1) { + lpm_set(LPM_OFF); + } +#endif +} diff --git a/cpu/cortex-m4_common/panic.c b/cpu/cortex-m4_common/panic.c new file mode 100644 index 000000000..61a923eb5 --- /dev/null +++ b/cpu/cortex-m4_common/panic.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 INRIA + * Copyright (C) 2015 Eistec AB + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup cortex-m4_common + * @{ + * + * @file + * @brief Crash handling functions implementation for ARM Cortex-based MCUs + * + * @author Oliver Hahm + * @author Joakim Gebart + */ + +#include "cpu.h" +#include "lpm.h" + +void panic_arch(void) +{ +#if DEVELHELP + /* The bkpt instruction will signal to the debugger to break here. */ + __ASM("bkpt #0"); + /* enter infinite loop, into deepest possible sleep mode */ + while (1) { + lpm_set(LPM_OFF); + } +#endif +} diff --git a/cpu/kinetis_common/fault_handlers.c b/cpu/kinetis_common/fault_handlers.c index 9b98d54d9..10126c261 100644 --- a/cpu/kinetis_common/fault_handlers.c +++ b/cpu/kinetis_common/fault_handlers.c @@ -21,7 +21,7 @@ */ #include -#include "crash.h" +#include "panic.h" #include "fault_handlers.h" void isr_nmi(void) diff --git a/cpu/msp430-common/crash.c b/cpu/msp430-common/crash.c deleted file mode 100644 index 4784f910b..000000000 --- a/cpu/msp430-common/crash.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2014 INRIA - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup core_util - * @{ - * - * @file crash.c - * @brief Crash handling functions implementation for MSP430 MCUs - * - * @author Kévin Roussel - */ - -#include "cpu.h" -#include "lpm.h" -#include "crash.h" - -#include -#include - -/* "public" variables holding the crash data */ -char panic_str[80]; -int panic_code; - -/* flag preventing "recursive crash printing loop" */ -static int crashed = 0; - -/* WARNING: this function NEVER returns! */ -NORETURN void core_panic(int crash_code, const char *message) -{ - /* copy panic datas to "public" global variables */ - panic_code = crash_code; - strncpy(panic_str, message, 80); - /* (try to) print panic message to console */ - if (crashed == 0) { - crashed = 1; - puts("******** SYSTEM FAILURE ********\n"); - puts(message); -#if DEVELHELP - puts("******** RIOT HALTS HERE ********\n"); -#else - puts("******** RIOT WILL REBOOT ********\n"); -#endif - puts("\n\n"); - } - /* disable watchdog and all possible sources of interrupts */ - WDTCTL = WDTPW | WDTHOLD; - dINT(); -#if DEVELHELP - /* enter infinite loop, into deepest possible sleep mode */ - while (1) { - lpm_set(LPM_OFF); - } -#else - /* DEVELHELP not set => reboot system */ - (void) reboot(RB_AUTOBOOT); -#endif - - /* tell the compiler that we won't return from this function - (even if we actually won't even get here...) */ - UNREACHABLE(); -} diff --git a/cpu/msp430-common/hwtimer_cpu.c b/cpu/msp430-common/hwtimer_cpu.c index 511d34181..f9875d940 100644 --- a/cpu/msp430-common/hwtimer_cpu.c +++ b/cpu/msp430-common/hwtimer_cpu.c @@ -24,7 +24,7 @@ #include #include "cpu.h" -#include "crash.h" +#include "panic.h" #include "hwtimer.h" #include "arch/hwtimer_arch.h" diff --git a/cpu/msp430-common/panic.c b/cpu/msp430-common/panic.c new file mode 100644 index 000000000..9f461ab19 --- /dev/null +++ b/cpu/msp430-common/panic.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2014, 2015 INRIA + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup msp430 + * @{ + * + * @file + * @brief Crash handling functions implementation for MSP430 MCUs + * + * @author Kévin Roussel + * @author Oliver Hahm + */ + +#include "cpu.h" +#include "lpm.h" + +void panic_arch(void) +{ + /* disable watchdog and all possible sources of interrupts */ + WDTCTL = WDTPW | WDTHOLD; +#if DEVELHELP + /* enter infinite loop, into deepest possible sleep mode */ + while (1) { + lpm_set(LPM_OFF); + } +#endif + +} diff --git a/cpu/native/crash.c b/cpu/native/crash.c deleted file mode 100644 index 40b9c6d1b..000000000 --- a/cpu/native/crash.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universitaet Berlin (FUB) and INRIA - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup core_util - * @{ - * - * @file crash.c - * @brief Crash handling functions implementation for 'native' port - * - * @author Ludwig Ortmann - * @author Kévin Roussel - */ - -#include -#include -#include -#include - -#include "crash.h" -#include "native_internal.h" - -/* "public" variables holding the crash data (look for them in your debugger) */ -char panic_str[80]; -int panic_code; - -/* flag preventing "recursive crash printing loop" */ -static int crashed = 0; - -NORETURN void core_panic(int crash_code, const char *message) -{ - if (crashed == 0) { - crashed = 1; - /* copy the crash data to "long-lived" global variables */ - panic_code = crash_code; - strncpy(panic_str, message, 80); - /* try to print panic message to console (if possible) */ - puts("******** SYSTEM FAILURE ********\n"); - puts(message); -#if DEVELHELP - puts("******** RIOT HALTS HERE ********\n"); -#else - puts("******** RIOT WILL REBOOT ********\n"); -#endif - puts("\n\n"); - } - - dINT(); -#if DEVELHELP - /* since we're atop an Unix-like platform, - just use the (developer-)friendly core-dump feature */ - kill(_native_pid, SIGTRAP); -#else - (void) reboot(RB_AUTOBOOT); -#endif - - /* tell the compiler that we won't return from this function - (even if we actually won't even get here...) */ - UNREACHABLE(); -} diff --git a/cpu/native/panic.c b/cpu/native/panic.c new file mode 100644 index 000000000..357106691 --- /dev/null +++ b/cpu/native/panic.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2014, 2015 Freie Universitaet Berlin (FUB) and INRIA + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup native_cpu + * @{ + * + * @file + * @brief Crash handling functions implementation for 'native' port + * + * @author Ludwig Ortmann + * @author Kévin Roussel + * @author Oliver Hahm + */ + +#include +#include + +#include "native_internal.h" + +void panic_arch(void) +{ +#if DEVELHELP + /* since we're atop an Unix-like platform, + just use the (developer-)friendly core-dump feature */ + kill(_native_pid, SIGTRAP); +#endif +} diff --git a/cpu/nrf51822/startup.c b/cpu/nrf51822/startup.c index 4c58873c2..87676eb4a 100644 --- a/cpu/nrf51822/startup.c +++ b/cpu/nrf51822/startup.c @@ -22,7 +22,7 @@ #include "board.h" #include "cpu.h" -#include "crash.h" +#include "panic.h" /** * memory markers as defined in the linker script diff --git a/cpu/sam3x8e/startup.c b/cpu/sam3x8e/startup.c index 0df580f59..52278ccde 100644 --- a/cpu/sam3x8e/startup.c +++ b/cpu/sam3x8e/startup.c @@ -20,7 +20,7 @@ #include -#include "crash.h" +#include "panic.h" /** * memory markers as defined in the linker script diff --git a/cpu/stm32f0/startup.c b/cpu/stm32f0/startup.c index f4b4004c2..9dbe6497c 100644 --- a/cpu/stm32f0/startup.c +++ b/cpu/stm32f0/startup.c @@ -20,7 +20,7 @@ #include -#include "crash.h" +#include "panic.h" /** * memory markers as defined in the linker script diff --git a/cpu/stm32f1/startup.c b/cpu/stm32f1/startup.c index 0e1358359..612ade611 100644 --- a/cpu/stm32f1/startup.c +++ b/cpu/stm32f1/startup.c @@ -20,7 +20,7 @@ */ #include -#include "crash.h" +#include "panic.h" /** diff --git a/cpu/stm32l1/startup.c b/cpu/stm32l1/startup.c index 83f453bad..9802555c6 100644 --- a/cpu/stm32l1/startup.c +++ b/cpu/stm32l1/startup.c @@ -20,7 +20,7 @@ */ #include -#include "crash.h" +#include "panic.h" /** diff --git a/drivers/cc2420/cc2420.c b/drivers/cc2420/cc2420.c index 9adf0b18a..3190f051e 100644 --- a/drivers/cc2420/cc2420.c +++ b/drivers/cc2420/cc2420.c @@ -8,7 +8,7 @@ * directory for more details. */ -#include "crash.h" +#include "panic.h" #include "cc2420.h" #include "cc2420_spi.h" #include "cc2420_settings.h"