Branch data Line data Source code
1 : : /* 2 : : * Copyright (c) 2013-2014 Wind River Systems, Inc. 3 : : * 4 : : * SPDX-License-Identifier: Apache-2.0 5 : : */ 6 : : 7 : : /** 8 : : * @file 9 : : * @brief NMI handler infrastructure 10 : : * 11 : : * Provides a boot time handler that simply hangs in a sleep loop, and a run 12 : : * time handler that resets the CPU. Also provides a mechanism for hooking a 13 : : * custom run time handler. 14 : : */ 15 : : 16 : : #include <kernel.h> 17 : : #include <arch/cpu.h> 18 : : #include <sys/printk.h> 19 : : #include <sys/reboot.h> 20 : : #include <toolchain.h> 21 : : #include <linker/sections.h> 22 : : 23 : : extern void z_SysNmiOnReset(void); 24 : : #if !defined(CONFIG_RUNTIME_NMI) 25 : : #define handler z_SysNmiOnReset 26 : : #endif 27 : : 28 : : #ifdef CONFIG_RUNTIME_NMI 29 : : typedef void (*_NmiHandler_t)(void); 30 : : static _NmiHandler_t handler = z_SysNmiOnReset; 31 : : 32 : : /** 33 : : * 34 : : * @brief Default NMI handler installed when kernel is up 35 : : * 36 : : * The default handler outputs a error message and reboots the target. It is 37 : : * installed by calling z_arm_nmi_init(); 38 : : * 39 : : */ 40 : : 41 : : static void DefaultHandler(void) 42 : : { 43 : : printk("NMI received! Rebooting...\n"); 44 : : /* In ARM implementation sys_reboot ignores the parameter */ 45 : : sys_reboot(0); 46 : : } 47 : : 48 : : /** 49 : : * 50 : : * @brief Install default runtime NMI handler 51 : : * 52 : : * Meant to be called by platform code if they want to install a simple NMI 53 : : * handler that reboots the target. It should be installed after the console is 54 : : * initialized. 55 : : * 56 : : */ 57 : : 58 : : void z_arm_nmi_init(void) 59 : : { 60 : : handler = DefaultHandler; 61 : : } 62 : : 63 : : /** 64 : : * 65 : : * @brief Install a custom runtime NMI handler 66 : : * 67 : : * Meant to be called by platform code if they want to install a custom NMI 68 : : * handler that reboots. It should be installed after the console is 69 : : * initialized if it is meant to output to the console. 70 : : * 71 : : */ 72 : : 73 : : void z_NmiHandlerSet(void (*pHandler)(void)) 74 : : { 75 : : handler = pHandler; 76 : : } 77 : : #endif /* CONFIG_RUNTIME_NMI */ 78 : : 79 : : /** 80 : : * 81 : : * @brief Handler installed in the vector table 82 : : * 83 : : * Simply call what is installed in 'static void(*handler)(void)'. 84 : : * 85 : : */ 86 : : 87 : 0 : void z_arm_nmi(void) 88 : : { 89 : 0 : handler(); 90 : 0 : z_arm_int_exit(); 91 : 0 : }