1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #2949 from OlegHahm/crash_panic_foobar

core: panic unification
This commit is contained in:
Oleg Hahm 2015-05-10 21:54:43 +02:00
commit 69f07c601f
25 changed files with 262 additions and 377 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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 <oliver.hahm@inria.fr>
*/
#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 */
/** @} */

View File

@ -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 <Kevin.Roussel@inria.fr>
*/
#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 */
/** @} */

View File

@ -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 <Kevin.Roussel@inria.fr>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
@ -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

View File

@ -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 <Kevin.Roussel@inria.fr>
*/
#include "cpu.h"
#include "lpm.h"
#include "crash.h"
#include <string.h>
#include <stdio.h>
/* "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();
}

30
cpu/arm7_common/panic.c Normal file
View File

@ -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 <Kevin.Roussel@inria.fr>
* @author Oliver Hahm <oliver.hahm@inria.fr>
*/
#include "lpm.h"
void panic_arch(void)
{
#if DEVELHELP
/* enter infinite loop, into deepest possible sleep mode */
while (1) {
lpm_set(LPM_OFF);
}
#endif
}

View File

@ -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 <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
#include <string.h>
#include <stdio.h>
#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();
}

View File

@ -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 <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
#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
}

View File

@ -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 <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
#include <string.h>
#include <stdio.h>
#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();
}

View File

@ -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 <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
#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
}

View File

@ -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 <oliver.hahm@inria.fr>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
#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
}

View File

@ -21,7 +21,7 @@
*/
#include <stdint.h>
#include "crash.h"
#include "panic.h"
#include "fault_handlers.h"
void isr_nmi(void)

View File

@ -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 <Kevin.Roussel@inria.fr>
*/
#include "cpu.h"
#include "lpm.h"
#include "crash.h"
#include <string.h>
#include <stdio.h>
/* "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();
}

View File

@ -24,7 +24,7 @@
#include <stdint.h>
#include "cpu.h"
#include "crash.h"
#include "panic.h"
#include "hwtimer.h"
#include "arch/hwtimer_arch.h"

34
cpu/msp430-common/panic.c Normal file
View File

@ -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 <Kevin.Roussel@inria.fr>
* @author Oliver Hahm <oliver.hahm@inria.fr>
*/
#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
}

View File

@ -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 <ludwig.ortmann@fu-berlin.de>
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
*/
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#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();
}

33
cpu/native/panic.c Normal file
View File

@ -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 <ludwig.ortmann@fu-berlin.de>
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
* @author Oliver Hahm <oliver.hahm@inria.fr>
*/
#include <unistd.h>
#include <signal.h>
#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
}

View File

@ -22,7 +22,7 @@
#include "board.h"
#include "cpu.h"
#include "crash.h"
#include "panic.h"
/**
* memory markers as defined in the linker script

View File

@ -20,7 +20,7 @@
#include <stdint.h>
#include "crash.h"
#include "panic.h"
/**
* memory markers as defined in the linker script

View File

@ -20,7 +20,7 @@
#include <stdint.h>
#include "crash.h"
#include "panic.h"
/**
* memory markers as defined in the linker script

View File

@ -20,7 +20,7 @@
*/
#include <stdint.h>
#include "crash.h"
#include "panic.h"
/**

View File

@ -20,7 +20,7 @@
*/
#include <stdint.h>
#include "crash.h"
#include "panic.h"
/**

View File

@ -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"