From 3639ae9b2560bb5c03011076377b44703f5ab11f Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Wed, 11 Jun 2014 14:23:27 +0200 Subject: [PATCH] cpu:cortex_common: add core_panic function --- cpu/cortexm_common/crash.c | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 cpu/cortexm_common/crash.c diff --git a/cpu/cortexm_common/crash.c b/cpu/cortexm_common/crash.c new file mode 100644 index 0000000000..3265c0f707 --- /dev/null +++ b/cpu/cortexm_common/crash.c @@ -0,0 +1,67 @@ +/* + * 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 Cortex-based MCUs + * + * @author Oliver Hahm + */ + +#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(); +}