2017-10-03 22:31:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011-2015 Wind River Systems, Inc.
|
|
|
|
* Copyright (c) 2017 Oticon A/S
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file CPU power management code for POSIX
|
|
|
|
*
|
|
|
|
* This module provides an implementation of the architecture-specific
|
|
|
|
* k_cpu_idle() primitive required by the kernel idle loop component.
|
|
|
|
* It can be called within an implementation of _sys_power_save_idle(),
|
|
|
|
* which is provided for the kernel by the platform.
|
|
|
|
*
|
|
|
|
* The module also provides an implementation of k_cpu_atomic_idle(), which
|
|
|
|
* atomically re-enables interrupts and enters low power mode.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "posix_core.h"
|
|
|
|
#include "posix_soc_if.h"
|
2018-04-06 19:48:53 +08:00
|
|
|
#include <tracing.h>
|
2017-10-03 22:31:55 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Power save idle routine for IA-32
|
|
|
|
*
|
|
|
|
* This function will be called by the kernel idle loop or possibly within
|
|
|
|
* an implementation of _sys_power_save_idle in the kernel when the
|
|
|
|
* '_sys_power_save_flag' variable is non-zero.
|
|
|
|
*
|
|
|
|
* This function is just a pass thru to the SOC one
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
|
|
|
void k_cpu_idle(void)
|
|
|
|
{
|
2018-04-06 09:06:33 +08:00
|
|
|
z_sys_trace_idle();
|
2017-10-03 22:31:55 +08:00
|
|
|
posix_irq_full_unlock();
|
|
|
|
posix_halt_cpu();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Atomically re-enable interrupts and enter low power mode
|
|
|
|
*
|
|
|
|
* INTERNAL
|
|
|
|
* The requirements for k_cpu_atomic_idle() are as follows:
|
|
|
|
* 1) The enablement of interrupts and entering a low-power mode needs to be
|
|
|
|
* atomic, i.e. there should be no period of time where interrupts are
|
|
|
|
* enabled before the processor enters a low-power mode. See the comments
|
|
|
|
* in k_lifo_get(), for example, of the race condition that
|
|
|
|
* occurs if this requirement is not met.
|
|
|
|
*
|
|
|
|
* 2) After waking up from the low-power mode, the interrupt lockout state
|
2018-09-26 05:54:25 +08:00
|
|
|
* must be restored as indicated in the 'key' input parameter.
|
2017-10-03 22:31:55 +08:00
|
|
|
*
|
|
|
|
* This function is just a pass thru to the SOC one
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
|
|
|
|
2018-09-26 05:54:25 +08:00
|
|
|
void k_cpu_atomic_idle(unsigned int key)
|
2017-10-03 22:31:55 +08:00
|
|
|
{
|
2018-04-06 09:06:33 +08:00
|
|
|
z_sys_trace_idle();
|
2018-09-26 05:54:25 +08:00
|
|
|
posix_atomic_halt_cpu(key);
|
2017-10-03 22:31:55 +08:00
|
|
|
}
|