Mistake on this page?
Report an issue in GitHub or email us
wsf_assert.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file wsf_assert.h
4  *
5  * \brief Assert macro.
6  *
7  * Copyright (c) 2009-2018 Arm Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019-2020 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 #ifndef WSF_ASSERT_H
25 #define WSF_ASSERT_H
26 
27 #include "wsf_trace.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*! \addtogroup WSF_ASSERT_API
34  * \{ */
35 
36 /**************************************************************************************************
37  Function Prototypes
38 **************************************************************************************************/
39 
40 #if WSF_TOKEN_ENABLED == TRUE
41 /*************************************************************************************************/
42 /*!
43  * \brief Perform an assert action.
44  *
45  * \param modId Name of file originating assert.
46  * \param line Line number of assert statement.
47  */
48 /*************************************************************************************************/
49 void WsfAssert(uint16_t modId, uint16_t line);
50 #else
51 void WsfAssert(const char *pFile, uint16_t line);
52 #endif
53 
54 /*************************************************************************************************/
55 /*!
56  * \brief Get number of asserts.
57  *
58  * \return Number of asserts.
59  */
60 /*************************************************************************************************/
61 uint16_t WsfAssertNum(void);
62 
63 /*************************************************************************************************/
64 /*!
65  * \brief Enable assert trap.
66  *
67  * \param enaAssertTrap TRUE to enable assert trap.
68  */
69 /*************************************************************************************************/
70 void WsfAssertTrapEnable(bool_t enaAssertTrap);
71 
72 /**************************************************************************************************
73  Macros
74 **************************************************************************************************/
75 
76 #ifndef WSF_ASSERT_ENABLED
77 /*! \brief Enable assertion statements. */
78 #define WSF_ASSERT_ENABLED FALSE
79 #endif
80 
81 #ifndef WSF_TOKEN_ENABLED
82 /*! \brief Enable tokenized tracing. */
83 #define WSF_TOKEN_ENABLED FALSE
84 #endif
85 
86 /*************************************************************************************************/
87 /*!
88  * \brief Run-time assert macro. The assert executes when the expression is FALSE.
89  *
90  * \param expr Boolean expression to be tested.
91  */
92 /*************************************************************************************************/
93 #if WSF_ASSERT_ENABLED == TRUE
94 #if WSF_TOKEN_ENABLED == TRUE
95 #define WSF_ASSERT(expr) if (!(expr)) {WsfAssert(MODULE_ID, (uint16_t) __LINE__);}
96 #else
97 #define WSF_ASSERT(expr) if (!(expr)) {WsfAssert(__FILE__, (uint16_t) __LINE__);}
98 #endif
99 #else
100 #define WSF_ASSERT(expr) (void)(expr);
101 #endif
102 
103 /*************************************************************************************************/
104 /*!
105  * \brief Compile-time assert macro. This macro causes a compiler error when the
106  * expression is FALSE. Note that this macro is generally used at file scope to
107  * test constant expressions. Errors may result of it is used in executing code.
108  *
109  * \param expr Boolean expression to be tested.
110  */
111 /*************************************************************************************************/
112 #define WSF_CT_ASSERT(expr) extern char wsf_ct_assert[(expr) ? 1 : -1]
113 
114 /*! \} */ /* WSF_ASSERT_API */
115 
116 #ifdef __cplusplus
117 };
118 #endif
119 
120 #endif /* WSF_ASSERT_H */
void WsfAssert(uint16_t modId, uint16_t line)
Perform an assert action.
Trace message interface.
uint16_t WsfAssertNum(void)
Get number of asserts.
void WsfAssertTrapEnable(bool_t enaAssertTrap)
Enable assert trap.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.