2015-09-29 13:41:33 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*
|
2017-01-09 17:41:58 +01:00
|
|
|
* 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.
|
2015-09-29 13:41:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-06-01 12:17:51 +02:00
|
|
|
* @ingroup cpu_native
|
2017-06-22 15:43:17 +02:00
|
|
|
* @ingroup drivers_periph_pm
|
2015-09-29 13:41:33 +02:00
|
|
|
* @{
|
2017-01-09 17:41:58 +01:00
|
|
|
*
|
2015-09-29 13:41:33 +02:00
|
|
|
* @file
|
2017-01-09 17:41:58 +01:00
|
|
|
* @brief native Power Management implementation
|
|
|
|
*
|
2015-09-29 13:41:33 +02:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <err.h>
|
2017-01-09 17:41:58 +01:00
|
|
|
#include <stdio.h>
|
2015-09-29 13:41:33 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-01-09 17:41:58 +01:00
|
|
|
#include "periph/pm.h"
|
2015-09-29 13:41:33 +02:00
|
|
|
#include "native_internal.h"
|
2016-07-07 17:29:44 +02:00
|
|
|
#include "async_read.h"
|
2015-12-09 09:29:47 +01:00
|
|
|
#include "tty_uart.h"
|
2015-09-29 13:41:33 +02:00
|
|
|
|
2019-04-06 06:24:22 +02:00
|
|
|
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
|
|
|
#include "spidev_linux.h"
|
|
|
|
#endif
|
2019-10-04 15:48:46 +02:00
|
|
|
#ifdef MODULE_PERIPH_GPIO_LINUX
|
|
|
|
#include "gpiodev_linux.h"
|
|
|
|
#endif
|
2019-04-06 06:24:22 +02:00
|
|
|
|
2020-10-22 11:34:00 +02:00
|
|
|
#define ENABLE_DEBUG 0
|
2017-01-09 17:41:58 +01:00
|
|
|
#include "debug.h"
|
|
|
|
|
2024-02-22 16:06:32 +01:00
|
|
|
unsigned _native_retval = EXIT_SUCCESS;
|
|
|
|
|
2020-12-08 18:13:01 +01:00
|
|
|
static void _native_sleep(void)
|
2017-01-09 17:41:58 +01:00
|
|
|
{
|
2018-02-05 11:39:41 +01:00
|
|
|
_native_in_syscall++; /* no switching here */
|
2017-01-09 17:41:58 +01:00
|
|
|
real_pause();
|
|
|
|
_native_in_syscall--;
|
|
|
|
|
|
|
|
if (_native_sigpend > 0) {
|
|
|
|
_native_in_syscall++;
|
|
|
|
_native_syscall_leave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 18:13:01 +01:00
|
|
|
#if !defined(MODULE_PM_LAYERED)
|
|
|
|
void pm_set_lowest(void)
|
|
|
|
{
|
|
|
|
_native_sleep();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void pm_set(unsigned mode)
|
|
|
|
{
|
|
|
|
if (mode == 0) {
|
|
|
|
_native_sleep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 17:41:58 +01:00
|
|
|
void pm_off(void)
|
|
|
|
{
|
|
|
|
puts("\nnative: exiting");
|
2019-04-06 06:24:22 +02:00
|
|
|
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
|
|
|
spidev_linux_teardown();
|
2019-10-04 15:48:46 +02:00
|
|
|
#endif
|
|
|
|
#ifdef MODULE_PERIPH_GPIO_LINUX
|
|
|
|
gpio_linux_teardown();
|
2023-03-03 13:39:09 +01:00
|
|
|
#endif
|
|
|
|
#ifdef MODULE_VFS_DEFAULT
|
|
|
|
extern void auto_unmount_vfs(void);
|
|
|
|
auto_unmount_vfs();
|
2019-04-06 06:24:22 +02:00
|
|
|
#endif
|
2024-02-22 16:06:32 +01:00
|
|
|
real_exit(_native_retval);
|
2017-01-09 17:41:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void pm_reboot(void)
|
2015-09-29 13:41:33 +02:00
|
|
|
{
|
|
|
|
printf("\n\n\t\t!! REBOOT !!\n\n");
|
|
|
|
|
2016-07-07 17:29:44 +02:00
|
|
|
native_async_read_cleanup();
|
2019-04-06 06:24:22 +02:00
|
|
|
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
|
|
|
spidev_linux_teardown();
|
|
|
|
#endif
|
2019-10-04 15:48:46 +02:00
|
|
|
#ifdef MODULE_PERIPH_GPIO_LINUX
|
|
|
|
gpio_linux_teardown();
|
|
|
|
#endif
|
2023-03-03 13:39:09 +01:00
|
|
|
#ifdef MODULE_VFS_DEFAULT
|
|
|
|
extern void auto_unmount_vfs(void);
|
|
|
|
auto_unmount_vfs();
|
|
|
|
#endif
|
2015-12-09 09:29:47 +01:00
|
|
|
|
2015-09-29 13:41:33 +02:00
|
|
|
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");
|
|
|
|
}
|