Change reboot signature.

Change from `void reboot(void)` to `int reboot(int mode)`.
Move reboot definition to core, rename architecture implementations
from reboot to reboot_arch.
Declare reboot mode(s) in kernel.h, reboot_arch in kernel_internal.h
Currently only one reboot mode is handled, its use is enforced.

Rationale:
A reboot function is already defined in <unistd.h> on BSD systems.
(See: http://www.openbsd.org/cgi-bin/man.cgi?query=reboot&sektion=2)
This patch not only allows native to build sensibly on these systems
but also streamlines RIOTs compatability with existing software.
This commit is contained in:
Ludwig Ortmann 2014-03-01 09:36:17 +01:00
parent 0c9fd83693
commit 063a15ce9b
12 changed files with 75 additions and 12 deletions

View File

@ -13,7 +13,7 @@
* @file kernel.h * @file kernel.h
* @brief Kernel compile time configuration * @brief Kernel compile time configuration
* *
* A reboot() function is also provided (and used by core_panic() when needed). * A int reboot(int mode) function is also provided (and used by core_panic() when needed).
* *
* @author Freie Universität Berlin, Computer Systems & Telematics * @author Freie Universität Berlin, Computer Systems & Telematics
* @author Kaspar Schleiser <kaspar@schleiser.de> * @author Kaspar Schleiser <kaspar@schleiser.de>
@ -89,9 +89,13 @@ extern config_t sysconfig;
* *
* This function is used by core_panic() when the DEVELHELP macro is not defined. * This function is used by core_panic() when the DEVELHELP macro is not defined.
* *
* @return WARNING: this function NEVER returns! * @param mode The reboot mode (unused for now)
*
* @return This call never returns when successful. -1 is returned otherwise.
*/ */
NORETURN void reboot(void); int reboot(int mode);
#define RB_AUTOBOOT 0 /* << Reboot the system in the usual fashion */
/** @} */ /** @} */
#endif /* KERNEL_H_ */ #endif /* KERNEL_H_ */

View File

@ -51,5 +51,15 @@ void sched_task_exit(void);
*/ */
void thread_print_stack(void); void thread_print_stack(void);
/**
* @brief Reboot the system
*
* @param 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);
/** @} */ /** @} */
#endif /* KERNEL_INTERNAL_H_ */ #endif /* KERNEL_INTERNAL_H_ */

31
core/reboot.c Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2014 Ludwig Ortmann
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup core_util
* @{
*
* @file reboot.c
* @brief Reboot function
*
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de
*
* @}
*/
#include "kernel.h"
#include "kernel_internal.h"
int reboot(int mode)
{
if (mode != RB_AUTOBOOT) {
return -1;
}
return reboot_arch(mode);
}

View File

@ -86,9 +86,13 @@ void thread_print_stack(void)
printf("STACK (%u)= %X \n", i, *s); printf("STACK (%u)= %X \n", i, *s);
} }
NORETURN void reboot(void) int reboot_arch(int mode)
{ {
(void) mode;
while (1) { while (1) {
arm_reset(); arm_reset();
} }
return -1;
} }

View File

@ -58,6 +58,6 @@ NORETURN void core_panic(int crash_code, const char *message)
} }
#else #else
/* DEVELHELP not set => reboot system */ /* DEVELHELP not set => reboot system */
reboot(); (void) reboot(RB_AUTOBOOT);
#endif #endif
} }

View File

@ -126,9 +126,13 @@ __attribute__((naked,noreturn)) void arm_reset(void)
); );
} }
NORETURN void reboot(void) int reboot_arch(int mode)
{ {
(void) mode;
while (1) { while (1) {
arm_reset(); arm_reset();
} }
return -1;
} }

View File

@ -59,6 +59,6 @@ NORETURN void core_panic(int crash_code, const char *message)
} }
#else #else
/* DEVELHELP not set => reboot system */ /* DEVELHELP not set => reboot system */
reboot(); (void) reboot(RB_AUTOBOOT);
#endif #endif
} }

View File

@ -90,11 +90,15 @@ int inISR()
/******************************************************************************/ /******************************************************************************/
/* System reboot */ /* System reboot */
NORETURN void reboot(void) int reboot_arch(int mode)
{ {
(void) mode;
/* force an hardware reboot ("Power-Up Clear"), by writing /* force an hardware reboot ("Power-Up Clear"), by writing
an illegal value to the watchdog control register */ an illegal value to the watchdog control register */
while (1) { while (1) {
WDTCTL = 0x0000; WDTCTL = 0x0000;
} }
return -1;
} }

View File

@ -58,6 +58,6 @@ NORETURN void core_panic(int crash_code, const char *message)
} }
#else #else
/* DEVELHELP not set => reboot system */ /* DEVELHELP not set => reboot system */
reboot(); (void) reboot(RB_AUTOBOOT);
#endif #endif
} }

View File

@ -55,7 +55,7 @@ NORETURN void core_panic(int crash_code, const char *message)
just use the (developer-)friendly core-dump feature */ just use the (developer-)friendly core-dump feature */
kill(getpid(), SIGTRAP); kill(getpid(), SIGTRAP);
#else #else
reboot(); (void) reboot(RB_AUTOBOOT);
#endif #endif
/* proove the compiler that we won't return from this function /* proove the compiler that we won't return from this function

View File

@ -63,13 +63,19 @@ char __end_stack[SIGSTKSZ];
fd_set _native_rfds; fd_set _native_rfds;
#endif #endif
NORETURN void reboot(void) int reboot_arch(int mode)
{ {
(void) mode;
printf("\n\n\t\t!! REBOOT !!\n\n"); printf("\n\n\t\t!! REBOOT !!\n\n");
if (execve(_native_argv[0], _native_argv, NULL) == -1) { if (execve(_native_argv[0], _native_argv, NULL) == -1) {
err(EXIT_FAILURE, "reboot: execve"); err(EXIT_FAILURE, "reboot: execve");
} }
errx(EXIT_FAILURE, "reboot: this should not habe been reached"); errx(EXIT_FAILURE, "reboot: this should not habe been reached");
return -1;
} }
/** /**

View File

@ -22,5 +22,5 @@ void _reboot_handler(int argc, char **argv)
(void) argc; (void) argc;
(void) argv; (void) argv;
reboot(); (void) reboot(RB_AUTOBOOT);
} }