Cordio Stack and Cordio Profiles  r2p3-02rel0
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  * Arm Ltd. confidential and proprietary.
9  *
10  * IMPORTANT. Your use of this file is governed by a Software License Agreement
11  * ("Agreement") that must be accepted in order to download or otherwise receive a
12  * copy of this file. You may not use or copy this file for any purpose other than
13  * as described in the Agreement. If you do not agree to all of the terms of the
14  * Agreement do not use this file and delete all copies in your possession or control;
15  * if you do not have a copy of the Agreement, you must contact Arm Ltd. prior
16  * to any use, copying or further distribution of this software.
17  */
18 /*************************************************************************************************/
19 #ifndef WSF_ASSERT_H
20 #define WSF_ASSERT_H
21 
22 #include "wsf_trace.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /*! \addtogroup WSF_ASSERT_API
29  * \{ */
30 
31 /**************************************************************************************************
32  Function Prototypes
33 **************************************************************************************************/
34 
35 #if WSF_TOKEN_ENABLED == TRUE
36 /*************************************************************************************************/
37 /*!
38  * \brief Perform an assert action.
39  *
40  * \param modId Name of file originating assert.
41  * \param line Line number of assert statement.
42  *
43  * \return None.
44  */
45 /*************************************************************************************************/
46 void WsfAssert(uint16_t modId, uint16_t line);
47 #else
48 void WsfAssert(const char *pFile, uint16_t line);
49 #endif
50 
51 /*************************************************************************************************/
52 /*!
53  * \brief Get number of asserts.
54  *
55  * \return Number of asserts.
56  */
57 /*************************************************************************************************/
59 
60 /*************************************************************************************************/
61 /*!
62  * \brief Enable assert trap.
63  *
64  * \param enaAssertTrap TRUE to enable assert trap.
65  *
66  * \return None.
67  */
68 /*************************************************************************************************/
69 void WsfAssertTrapEnable(bool_t enaAssertTrap);
70 
71 /**************************************************************************************************
72  Macros
73 **************************************************************************************************/
74 
75 #ifndef WSF_ASSERT_ENABLED
76 /*! \brief Enable assertion statements. */
77 #define WSF_ASSERT_ENABLED FALSE
78 #endif
79 
80 #ifndef WSF_TOKEN_ENABLED
81 /*! \brief Enable tokenized tracing. */
82 #define WSF_TOKEN_ENABLED FALSE
83 #endif
84 
85 /*************************************************************************************************/
86 /*!
87  * \brief Run-time assert macro. The assert executes when the expression is FALSE.
88  *
89  * \param expr Boolean expression to be tested.
90  *
91  * \return None
92  */
93 /*************************************************************************************************/
94 #if WSF_ASSERT_ENABLED == TRUE
95 #if WSF_TOKEN_ENABLED == TRUE
96 #define WSF_ASSERT(expr) if (!(expr)) {WsfAssert(MODULE_ID, (uint16_t) __LINE__);}
97 #else
98 #define WSF_ASSERT(expr) if (!(expr)) {WsfAssert(__FILE__, (uint16_t) __LINE__);}
99 #endif
100 #else
101 #define WSF_ASSERT(expr)
102 #endif
103 
104 /*************************************************************************************************/
105 /*!
106  * \brief Compile-time assert macro. This macro causes a compiler error when the
107  * expression is FALSE. Note that this macro is generally used at file scope to
108  * test constant expressions. Errors may result of it is used in executing code.
109  *
110  * \param expr Boolean expression to be tested.
111  *
112  * \return None
113  */
114 /*************************************************************************************************/
115 #define WSF_CT_ASSERT(expr) extern char wsf_ct_assert[(expr) ? 1 : -1]
116 
117 /*************************************************************************************************/
118 /*!
119  * \brief Register assert handler.
120  *
121  * \param cback Callback called upon assert condition.
122  *
123  * \return None
124  */
125 /*************************************************************************************************/
126 void WsfAssertRegister(void (*cback)(void));
127 
128 /*! \} */ /* WSF_ASSERT_API */
129 
130 #ifdef __cplusplus
131 };
132 #endif
133 
134 #endif /* WSF_ASSERT_H */
void WsfAssert(uint16_t modId, uint16_t line)
Perform an assert action.
void WsfAssertRegister(void(*cback)(void))
Register assert handler.
uint8_t bool_t
Boolean data type.
Definition: wsf_types.h:78
Trace message interface.
uint16_t WsfAssertNum(void)
Get number of asserts.
void WsfAssertTrapEnable(bool_t enaAssertTrap)
Enable assert trap.
unsigned short uint16_t
Unsigned 16-bit value.
Definition: wsf_types.h:67