From 4c54db68bd37ebe4f6a995e69bace6529a0cdaec Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 4 Jul 2015 07:22:38 -0600 Subject: [PATCH] Implementment board_power_off() for the simulation platform. --- ChangeLog | 2 ++ arch/Kconfig | 1 + arch/sim/src/up_head.c | 57 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index dd680489c5..10693ce3bb 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10663,3 +10663,5 @@ * sched/sched/sched_waitpid.c: Implement WNOHANG for waitpid() only and for the case of CONFIG_SCHED_HAVE_PARENT not selected. From Max Neklyudov (2015-07-02). + * arch/sim/src/up_head.S: Implement board_power_off() for the simulation + platform (2015-07-04). diff --git a/arch/Kconfig b/arch/Kconfig index ff47215965..b34385c708 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -54,6 +54,7 @@ config ARCH_SH config ARCH_SIM bool "Simulation" select ARCH_HAVE_TICKLESS + select ARCH_HAVE_POWEROFF ---help--- Linux/Cywgin user-mode simulation. diff --git a/arch/sim/src/up_head.c b/arch/sim/src/up_head.c index 24c7646360..2b9fdb4598 100644 --- a/arch/sim/src/up_head.c +++ b/arch/sim/src/up_head.c @@ -47,6 +47,7 @@ #include #include +#include #include /**************************************************************************** @@ -54,11 +55,20 @@ ****************************************************************************/ static jmp_buf sim_abort; +static int retcode = 0; /**************************************************************************** * Global Functions ****************************************************************************/ +/**************************************************************************** + * Name: main + * + * Description: + * This is the main entry point into the simulation. + * + ****************************************************************************/ + int main(int argc, char **argv, char **envp) { /* Power management should be initialized early in the (simulated) boot @@ -75,16 +85,61 @@ int main(int argc, char **argv, char **envp) { os_start(); } - return 0; + + return retcode; } +/**************************************************************************** + * Name: up_assert + * + * Description: + * Called to terminate the simulation abnormally in the event of a failed + * assertion. + * + ****************************************************************************/ + void up_assert(const uint8_t *filename, int line) { + /* Show the location of the failed assertion */ + fprintf(stderr, "Assertion failed at file:%s line: %d\n", filename, line); + /* Allow for any board/configuration specific crash information */ + #ifdef CONFIG_BOARD_CRASHDUMP board_crashdump(up_getsp(), g_readytorun.head, filename, line); #endif + /* Exit the simulation */ + + retcode = EXIT_FAILURE; longjmp(sim_abort, 1); } + +/**************************************************************************** + * Name: board_power_off + * + * Description: + * Power off the board. This function may or may not be supported by a + * particular board architecture. + * + * Input Parameters: + * status - Status information provided with the power off event. + * + * Returned Value: + * If this function returns, then it was not possible to power-off the + * board due to some constraints. The return value int this case is a + * board-specific reason for the failure to shutdown. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARDCTL_POWEROFF +int board_power_off(int status) +{ + /* Save the return code and exit the simulation */ + + retcode = status; + longjmp(sim_abort, 1); +} +#endif +