core: unified core_panic implementation

dev/timer
Oleg Hahm 8 years ago
parent 828839316b
commit cb1f047f59

@ -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 */
/** @} */

@ -0,0 +1,71 @@
/*
* 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 core_util
* @{
*
* @file
* @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>
*/
#include <string.h>
#include <stdio.h>
#include "cpu.h"
#include "irq.h"
#include "lpm.h"
#include "panic.h"
#include "arch/panic_arch.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();
panic_arch();
#ifndef DEVELHELP
/* 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();
}

@ -1,67 +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.
* 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
* @ingroup arm7_common
* @{
*
* @file panic.c
* @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 "cpu.h"
#include "lpm.h"
#include "panic.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)
void panic_arch(void)
{
/* 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();
}

@ -18,45 +18,11 @@
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
#include <string.h>
#include <stdio.h>
#include "cpu.h"
#include "irq.h"
#include "lpm.h"
#include "panic.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)
void panic_arch(void)
{
/* 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");
@ -64,12 +30,5 @@ NORETURN void core_panic(int crash_code, const char *message)
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();
}

@ -18,45 +18,11 @@
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
#include <string.h>
#include <stdio.h>
#include "cpu.h"
#include "irq.h"
#include "lpm.h"
#include "panic.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)
void panic_arch(void)
{
/* 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");
@ -64,12 +30,5 @@ NORETURN void core_panic(int crash_code, const char *message)
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();
}

@ -18,45 +18,11 @@
* @author Joakim Gebart <joakim.gebart@eistec.se>
*/
#include <string.h>
#include <stdio.h>
#include "cpu.h"
#include "irq.h"
#include "lpm.h"
#include "panic.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)
void panic_arch(void)
{
/* 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");
@ -64,12 +30,5 @@ NORETURN void core_panic(int crash_code, const char *message)
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();
}

@ -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
@ -7,61 +7,28 @@
*/
/**
* @ingroup core_util
* @ingroup msp430
* @{
*
* @file panic.c
* @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"
#include "panic.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)
void panic_arch(void)
{
/* 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();
}

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Freie Universitaet Berlin (FUB) and INRIA
* 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
@ -7,59 +7,27 @@
*/
/**
* @ingroup core_util
* @ingroup native_cpu
* @{
*
* @file panic.c
* @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 <string.h>
#include <stdio.h>
#include "panic.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)
void panic_arch(void)
{
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();
}

Loading…
Cancel
Save