1 /* 2 * Copyright (c) 2011-2015 Wind River Systems, Inc. 3 * Copyright (c) 2017 Oticon A/S 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 /** 8 * @file CPU power management code for POSIX 9 * 10 * This module provides: 11 * 12 * An implementation of the architecture-specific 13 * arch_cpu_idle() primitive required by the kernel idle loop component. 14 * It can be called within an implementation of _pm_save_idle(), 15 * which is provided for the kernel by the platform. 16 * 17 * An implementation of arch_cpu_atomic_idle(), which 18 * atomically re-enables interrupts and enters low power mode. 19 * 20 * A weak stub for sys_arch_reboot(), which does nothing 21 */ 22 23 #include "posix_core.h" 24 #include "posix_board_if.h" 25 #include <zephyr/arch/posix/posix_soc_if.h> 26 #include <zephyr/tracing/tracing.h> 27 28 #if !defined(CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT) 29 #error "The POSIX architecture needs a custom busy_wait implementation. \ 30 CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT must be selected" 31 /* Each POSIX arch board (or SOC) must provide an implementation of 32 * arch_busy_wait() 33 */ 34 #endif 35 arch_cpu_idle(void)36void arch_cpu_idle(void) 37 { 38 sys_trace_idle(); 39 posix_irq_full_unlock(); 40 posix_halt_cpu(); 41 } 42 arch_cpu_atomic_idle(unsigned int key)43void arch_cpu_atomic_idle(unsigned int key) 44 { 45 sys_trace_idle(); 46 posix_atomic_halt_cpu(key); 47 } 48 49 #if defined(CONFIG_REBOOT) 50 /** 51 * @brief Stub for sys_arch_reboot 52 * 53 * Does nothing 54 */ sys_arch_reboot(int type)55void __weak sys_arch_reboot(int type) 56 { 57 posix_print_warning("%s called with type %d. Exiting\n", 58 __func__, type); 59 posix_exit(1); 60 } 61 #endif /* CONFIG_REBOOT */ 62