1 /*!
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2018 NXP
4 *
5 * ile
6 *
7 * This is the source file for the Panic module.
8 *
9 * SPDX-License-Identifier: BSD-3-Clause
10 */
11
12 /*! *********************************************************************************
13 *************************************************************************************
14 * Include
15 *************************************************************************************
16 ********************************************************************************** */
17 #include "fsl_common.h"
18 #include "fsl_component_panic.h"
19 #if (defined(PANIC_ENABLE_LOG) && (PANIC_ENABLE_LOG > 0U))
20 #include "fsl_debug_console.h"
21 #endif
22
23 /*! *********************************************************************************
24 *************************************************************************************
25 * Private memory declarations
26 *************************************************************************************
27 ********************************************************************************** */
28 #if (defined(PANIC_ENABLE_LOG) && (PANIC_ENABLE_LOG > 0U))
29 static panic_data_t panic_data;
30 #endif
31 /*! *********************************************************************************
32 *************************************************************************************
33 * Private macros
34 *************************************************************************************
35 ********************************************************************************** */
36 #if defined(__IAR_SYSTEMS_ICC__)
37 /* __get_LR() declaration not included to avoid issues with different versions of IAR compiler */
38 #elif defined(__GNUC__)
39 #define __get_LR() __builtin_return_address(0)
40 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
41 #if (__ARMCC_VERSION >= 6010050)
42 #define __get_LR() __builtin_return_address(0)
43 #else
44 #define __get_LR() __return_address()
45 #endif
46 #endif
47 /*! *********************************************************************************
48 *************************************************************************************
49 * Public functions
50 *************************************************************************************
51 ********************************************************************************** */
52
53 /*! *********************************************************************************
54 * \brief This function will halt the system
55 *
56 * \param[in] id Description of the param2 in parameter
57 * \param[in] location address where the Panic occurred
58 * \param[in] extra1 parameter to be stored in Panic structure
59 * \param[in] extra2 parameter to be stored in Panic structure
60 *
61 ********************************************************************************** */
62
panic(panic_id_t id,uint32_t location,uint32_t extra1,uint32_t extra2)63 void panic(panic_id_t id, uint32_t location, uint32_t extra1, uint32_t extra2)
64 {
65 #if (defined(PANIC_ENABLE_LOG) && (PANIC_ENABLE_LOG > 0U))
66 panic_data.id = id;
67 panic_data.location = location;
68 panic_data.extra1 = extra1;
69 panic_data.extra2 = extra2;
70 panic_data.linkRegister = (uint32_t)((uint32_t *)__get_LR());
71 panic_data.cpsr_contents = 0;
72
73 (void)PRINTF("System Panic happen:\r\n");
74 (void)PRINTF("Panic id: 0x%x\r\n", id);
75 (void)PRINTF("Panic location: 0x%x\r\n", location);
76 (void)PRINTF("Panic extra1: 0x%x\r\n", extra1);
77 (void)PRINTF("Panic extra2: 0x%x\r\n", extra2);
78 (void)PRINTF("Panic linkRegister: 0x%x\r\n", panic_data.linkRegister);
79 #endif
80
81 (void)DisableGlobalIRQ(); /* disable interrupts */
82
83 /* infinite loop just to ensure this routine never returns */
84 for (;;)
85 {
86 }
87 }
88