1 /*
2  * Copyright (C) 2024 Nordic Semiconductor ASA
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #include <zephyr/irq.h>
7 #include <zephyr/sys/barrier.h>
8 #include <zephyr/tracing/tracing.h>
9 
10 /*
11  * Due to a HW issue, VPR requires MSTATUS.MIE to be enabled when entering sleep.
12  * Otherwise it would not wake up.
13  */
arch_cpu_idle(void)14 void arch_cpu_idle(void)
15 {
16 	sys_trace_idle();
17 	barrier_dsync_fence_full();
18 	irq_unlock(MSTATUS_IEN);
19 	__asm__ volatile("wfi");
20 }
21 
arch_cpu_atomic_idle(unsigned int key)22 void arch_cpu_atomic_idle(unsigned int key)
23 {
24 	sys_trace_idle();
25 	barrier_dsync_fence_full();
26 	irq_unlock(MSTATUS_IEN);
27 	__asm__ volatile("wfi");
28 
29 	/* Disable interrupts if needed. */
30 	__asm__ volatile ("csrc mstatus, %0"
31 			  :
32 			  : "r" (~key & MSTATUS_IEN)
33 			  : "memory");
34 }
35