1 /*
2 * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017, 2022-2023 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #include "fsl_common.h"
11 #include "fsl_assert.h"
12 #include "fsl_debug_console.h"
13
14 /* User can implement its own asser handler (dump logs, registers, etc) by reimplementing the function fsl_assert_hook() */
fsl_assert_hook(const char * failedExpr,const char * file,int line)15 __attribute__ ((weak)) int fsl_assert_hook(const char *failedExpr, const char *file, int line)
16 {
17 (void)failedExpr;
18 (void)file;
19 (void)line;
20
21 return 0;
22 }
23
24 #ifndef NDEBUG
25 #if (defined(__CC_ARM)) || (defined(__ARMCC_VERSION)) || (defined(__ICCARM__))
__aeabi_assert(const char * failedExpr,const char * file,int line)26 void __aeabi_assert(const char *failedExpr, const char *file, int line)
27 {
28 #if SDK_DEBUGCONSOLE == DEBUGCONSOLE_DISABLE
29 PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" \n", failedExpr, file, line);
30 #else
31 (void)PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" \n", failedExpr, file, line);
32 #endif
33
34 (void)fsl_assert_hook(failedExpr, file, line);
35
36 for (;;)
37 {
38 __BKPT(0);
39 }
40 }
41 #elif (defined(__GNUC__))
42 #if defined(__REDLIB__)
__assertion_failed(char * failedExpr)43 void __assertion_failed(char *failedExpr)
44 {
45 const char *file = NULL;
46 int line = -1;
47
48 (void)PRINTF("ASSERT ERROR \" %s \n", failedExpr);
49
50 (void)fsl_assert_hook(failedExpr, file, line);
51
52 for (;;)
53 {
54 __BKPT(0);
55 }
56 }
57 #else
__assert_func(const char * file,int line,const char * func,const char * failedExpr)58 void __assert_func(const char *file, int line, const char *func, const char *failedExpr)
59 {
60 (void)PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file, line,
61 func);
62
63 (void)fsl_assert_hook(failedExpr, file, line);
64
65 for (;;)
66 {
67 __BKPT(0);
68 }
69 }
70 #endif /* defined(__REDLIB__) */
71 #else /* (defined(__CC_ARM) || (defined(__ICCARM__)) || (defined(__ARMCC_VERSION)) */
72
73 #if (defined(__DSC__) && defined(__CW__))
74
__msl_assertion_failed(char const * failedExpr,char const * file,char const * func,int line)75 void __msl_assertion_failed(char const *failedExpr, char const *file, char const *func, int line)
76 {
77 PRINTF("\r\nASSERT ERROR\r\n");
78 PRINTF(" File : %s\r\n", file);
79 PRINTF(" Function : %s\r\n", func); /*compiler not support func name yet*/
80 PRINTF(" Line : %u\r\n", (uint32_t)line);
81 PRINTF(" failedExpr: %s\r\n", failedExpr);
82 asm(DEBUGHLT);
83 }
84
85 #endif /* (defined(__DSC__) && defined (__CW__)) */
86
87 #endif /* (defined(__CC_ARM) || (defined(__ICCARM__)) || (defined(__ARMCC_VERSION)) */
88 #endif /* NDEBUG */
89