1 /*
2  * Copyright (c) 2015 Wind River Systems, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/cache.h>
8 #include <zephyr/drivers/timer/system_timer.h>
9 #include <zephyr/sys/reboot.h>
10 #include <zephyr/kernel.h>
11 #include <zephyr/sys/printk.h>
12 #include <zephyr/debug/gcov.h>
13 
14 extern void sys_arch_reboot(int type);
15 
sys_reboot(int type)16 FUNC_NORETURN void sys_reboot(int type)
17 {
18 #ifdef CONFIG_COVERAGE_DUMP
19 	gcov_coverage_dump();
20 #endif /* CONFIG_COVERAGE_DUMP */
21 
22 	(void)irq_lock();
23 
24 	/* Disable caches to ensure all data is flushed */
25 #if defined(CONFIG_ARCH_CACHE)
26 #if defined(CONFIG_DCACHE)
27 	sys_cache_data_disable();
28 #endif /* CONFIG_DCACHE */
29 
30 #if defined(CONFIG_ICACHE)
31 	sys_cache_instr_disable();
32 #endif /* CONFIG_ICACHE */
33 #endif /* CONFIG_ARCH_CACHE */
34 
35 	if (IS_ENABLED(CONFIG_SYSTEM_TIMER_HAS_DISABLE_SUPPORT)) {
36 		sys_clock_disable();
37 	}
38 
39 	sys_arch_reboot(type);
40 
41 	/* should never get here */
42 	printk("Failed to reboot: spinning endlessly...\n");
43 	for (;;) {
44 		k_cpu_idle();
45 	}
46 }
47