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

84 lines
1.9 KiB
C
Raw Normal View History

/*
* Copyright (C) 2015 INRIA
* Copyright (C) 2015 Eistec AB
2015-05-29 17:17:11 +02:00
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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>
2015-09-20 13:47:39 +02:00
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
2015-05-29 17:17:11 +02:00
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#include <string.h>
#include <stdio.h>
#include "assert.h"
2016-02-27 01:12:02 +01:00
#include "attributes.h"
#include "cpu.h"
#include "irq.h"
#include "lpm.h"
#include "panic.h"
#include "arch/panic_arch.h"
2015-09-29 13:41:33 +02:00
#include "reboot.h"
2015-09-12 12:43:15 +02:00
#if defined(DEVELHELP) && defined(MODULE_PS)
2015-05-09 18:28:57 +02:00
#include "ps.h"
#endif
2015-11-27 18:08:59 +01:00
const char assert_crash_message[] = "FAILED ASSERTION.";
/* flag preventing "recursive crash printing loop" */
static int crashed = 0;
/* WARNING: this function NEVER returns! */
2015-08-26 16:01:04 +02:00
NORETURN void core_panic(core_panic_t crash_code, const char *message)
{
(void) crash_code;
if (crashed == 0) {
2015-05-29 17:17:11 +02:00
/* print panic message to console (if possible) */
crashed = 1;
#ifndef NDEBUG
if (crash_code == PANIC_ASSERT_FAIL) {
cpu_print_last_instruction();
}
#endif
2015-11-27 18:08:59 +01:00
puts("*** RIOT kernel panic:");
puts(message);
2015-11-27 18:08:59 +01:00
puts("");
2015-09-12 12:43:15 +02:00
#ifdef DEVELHELP
2015-05-09 18:28:57 +02:00
#ifdef MODULE_PS
ps();
puts("");
#endif
2015-05-29 17:17:11 +02:00
puts("*** halted.\n");
#else
2015-05-29 17:17:11 +02:00
puts("*** rebooting...\n\n");
#endif
}
/* disable watchdog and all possible sources of interrupts */
disableIRQ();
panic_arch();
#ifndef DEVELHELP
/* DEVELHELP not set => reboot system */
2015-09-29 13:41:33 +02:00
reboot();
#endif
/* tell the compiler that we won't return from this function
(even if we actually won't even get here...) */
UNREACHABLE();
}