Skip to content
Snippets Groups Projects
Commit 35eb99a4 authored by Hauke Petersen's avatar Hauke Petersen
Browse files

Merge pull request #3984 from kaspar030/simplify_reboot

core: cpu: sys: simplify reboot()
parents 7dc6afe4 938ff5c5
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* 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 interface rebooting
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
*/
#ifndef REBOOT_ARCH_H
#define REBOOT_ARCH_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Reboot the system
*
* @param[in] mode the argument is ignored and only used for conformity
* with existing reboot implementations for now.
*
* @return this call never returns when successful. -1 is returned otherwise.
*/
int reboot_arch(int mode);
#ifdef __cplusplus
}
#endif
#endif /* REBOOT_ARCH_H */
/** @} */
......@@ -64,23 +64,6 @@ extern config_t sysconfig;
/* ------------------------------------------------------------------------- */
/**
* @brief Immediately reboots the system.
*
* This function is used by core_panic() when the DEVELHELP macro is not defined.
*
* @param mode The reboot mode (unused for now)
*
* @return This call never returns when successful. -1 is returned otherwise.
*/
int reboot(int mode);
/**
* @def RB_AUTOBOOT
* @brief Reboot the system in the usual fashion
*/
#define RB_AUTOBOOT 0
#ifdef __cplusplus
}
#endif
......
/*
* Copyright (C) 2014 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
* Copyright (C) 2016 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
......@@ -7,25 +7,32 @@
*/
/**
* @ingroup core_util
* @addtogroup core_internal
* @{
*
* @file
* @brief Reboot function
*
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de
*
* @}
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#include "kernel.h"
#include "arch/reboot_arch.h"
#ifndef REBOOT_H_
#define REBOOT_H_
#ifdef __cplusplus
extern "C" {
#endif
int reboot(int mode)
{
if (mode != RB_AUTOBOOT) {
return -1;
}
/**
* @brief Immediately reboots the system.
*
* This function is used by core_panic() when the DEVELHELP macro is not defined.
*/
void reboot(void);
return reboot_arch(mode);
#ifdef __cplusplus
}
#endif
#endif /* REBOOT_H_ */
/** @} */
......@@ -30,6 +30,7 @@
#include "lpm.h"
#include "panic.h"
#include "arch/panic_arch.h"
#include "reboot.h"
#if defined(DEVELHELP) && defined(MODULE_PS)
#include "ps.h"
......@@ -72,7 +73,7 @@ NORETURN void core_panic(core_panic_t crash_code, const char *message)
panic_arch();
#ifndef DEVELHELP
/* DEVELHELP not set => reboot system */
(void) reboot(RB_AUTOBOOT);
reboot();
#endif
/* tell the compiler that we won't return from this function
......
......@@ -90,13 +90,9 @@ void thread_print_stack(void)
printf("STACK (%d)= %X \n", i, *s);
}
int reboot_arch(int mode)
void reboot(void)
{
(void) mode;
while (1) {
arm_reset();
}
return -1;
}
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
*
* 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
......@@ -14,27 +15,22 @@
* @brief Implementation of the kernels reboot interface
*
* @author Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stdio.h>
#include <avr/wdt.h>
#include "arch/reboot_arch.h"
#include "kernel.h"
#include "cpu.h"
int reboot_arch(int mode)
void reboot(void)
{
printf("Going into reboot, mode %i\n", mode);
/*
* Since the AVR doesn't support a real software reset, we set the Watchdog
* Timer on a 250ms timeout. Consider this a kludge.
*/
wdt_enable(WDTO_250MS);
return 0;
while(1);
}
......@@ -22,15 +22,10 @@
#include <stdio.h>
#include "arch/reboot_arch.h"
#include "kernel.h"
#include "cpu.h"
int reboot_arch(int mode)
void reboot(void)
{
printf("Going into reboot, mode %i\n", mode);
/* wait a while to make sure the printf is finished */
volatile int n = 100000;
while(n--);
NVIC_SystemReset();
return -1;
}
/*
* Copyright (C) 2015 Freie Universität Berlin
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* 2015 Freie Universität Berlin
*
* 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
......@@ -14,20 +15,17 @@
* @brief Implementation of the kernels reboot interface
*
* @author Paul RATHGEB <paul.rathgeb@skynet.be>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stdio.h>
#include "arch/reboot_arch.h"
#include "reboot.h"
#include "cpu.h"
#include "log.h"
int reboot_arch(int mode)
void reboot(void)
{
printf("Going into reboot, mode %i\n", mode);
LOG_INFO("RIOT rebooting...\n");
NVIC_SystemReset();
return 0;
}
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* 2014 Freie Universität Berlin
*
* 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
......@@ -15,20 +16,17 @@
*
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stdio.h>
#include "arch/reboot_arch.h"
#include "kernel.h"
#include "cpu.h"
int reboot_arch(int mode)
void reboot(void)
{
printf("Going into reboot, mode %i\n", mode);
NVIC_SystemReset();
return 0;
}
/*
* Copyright (C) 2014, Freie Universitaet Berlin (FUB) & INRIA.
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* 2014, Freie Universitaet Berlin (FUB) & INRIA.
* All rights reserved.
*
* This file is subject to the terms and conditions of the GNU Lesser
......@@ -93,15 +94,11 @@ char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_sta
/******************************************************************************/
/* System reboot */
int reboot_arch(int mode)
void reboot(void)
{
(void) mode;
/* force an hardware reboot ("Power-Up Clear"), by writing
an illegal value to the watchdog control register */
while (1) {
WDTCTL = 0x0000;
}
return -1;
}
/**
* Native CPU kernel_intern.h and sched.h implementation
*
* in-process preemptive context switching utilizes POSIX ucontexts.
* (ucontext provides for architecture independent stack handling)
*
* Copyright (C) 2013 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
/*
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* 2013 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.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 native_cpu
* @{
*
* @file
* @brief Native CPU kernel_intern.h and sched.h implementation
*
* in-process preemptive context switching utilizes POSIX ucontexts.
* (ucontext provides for architecture independent stack handling)
*
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#include <stdio.h>
......@@ -62,23 +67,6 @@ extern netdev2_tap_t netdev2_tap;
ucontext_t end_context;
char __end_stack[SIGSTKSZ];
int reboot_arch(int mode)
{
(void) mode;
printf("\n\n\t\t!! REBOOT !!\n\n");
#ifdef MODULE_NETDEV2_TAP
netdev2_tap_cleanup(&netdev2_tap);
#endif
if (real_execve(_native_argv[0], _native_argv, NULL) == -1) {
err(EXIT_FAILURE, "reboot: execve");
}
errx(EXIT_FAILURE, "reboot: this should not have been reached");
}
/**
* TODO: implement
*/
......
/*
* Copyright (C) 2016 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 native_cpu
* @{
* @file
* @brief native reboot() implementation
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @}
*/
#include <err.h>
#include <stdlib.h>
#include "native_internal.h"
#include "netdev2_tap.h"
void reboot(void)
{
printf("\n\n\t\t!! REBOOT !!\n\n");
#ifdef MODULE_NETDEV2_TAP
netdev2_tap_cleanup(&netdev2_tap);
#endif
if (real_execve(_native_argv[0], _native_argv, NULL) == -1) {
err(EXIT_FAILURE, "reboot: execve");
}
errx(EXIT_FAILURE, "reboot: this should not have been reached");
}
/*
* Copyright (C) 2014 René Kijewski <rene.kijewski@fu-berlin.de>
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
* 2014 René Kijewski <rene.kijewski@fu-berlin.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -24,6 +25,7 @@
* @brief Configurable reboot handler for x86.
*
* @author René Kijewski <rene.kijewski@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
......@@ -84,22 +86,16 @@ void NORETURN x86_kbc_reboot(void)
static x86_reboot_t reboot_fun;
static bool reboot_twice;
int reboot_arch(int mode)
void reboot(void)
{
switch (mode) {
case RB_AUTOBOOT:
asm volatile ("cli");
if (!reboot_twice) {
reboot_twice = true;
if (reboot_fun) {
reboot_fun();
}
}
x86_kbc_reboot();
default:
return -1;
asm volatile ("cli");
if (!reboot_twice) {
reboot_twice = true;
if (reboot_fun) {
reboot_fun();
}
}
x86_kbc_reboot();
}
void x86_set_reboot_fun(x86_reboot_t fun)
......
......@@ -33,8 +33,9 @@
#include "cpu.h"
#include "board.h"
#include "thread.h"
#include "kernel.h"
#include "reboot.h"
#include "irq.h"
#include "log.h"
#include "uart_stdio.h"
......@@ -77,8 +78,8 @@ void _fini(void)
*/
void _exit(int n)
{
printf("#! exit %i: resetting\n", n);
reboot(n);
LOG_INFO("#! exit %i: resetting\n", n);
reboot();
while(1);
}
......
......@@ -18,14 +18,14 @@
* @}
*/
#include "kernel.h"
#include "reboot.h"
int _reboot_handler(int argc, char **argv)
{
(void) argc;
(void) argv;
(void) reboot(RB_AUTOBOOT);
reboot();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment