Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_debug.h @ 7de0cc90

History | View | Annotate | Download (5.226 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
/**
20
 * @file    aos_debug.h
21
 * @brief   Macros used for debugging.
22
 *
23
 * @addtogroup aos_debug
24
 * @{
25
 */
26

    
27
#ifndef AMIROOS_DEBUG_H
28
#define AMIROOS_DEBUG_H
29

    
30
#include <amiroos.h>
31

    
32
/******************************************************************************/
33
/* CONSTANTS                                                                  */
34
/******************************************************************************/
35

    
36
/******************************************************************************/
37
/* SETTINGS                                                                   */
38
/******************************************************************************/
39

    
40
/******************************************************************************/
41
/* CHECKS                                                                     */
42
/******************************************************************************/
43

    
44
/******************************************************************************/
45
/* DATA STRUCTURES AND TYPES                                                  */
46
/******************************************************************************/
47

    
48
/******************************************************************************/
49
/* MACROS                                                                     */
50
/******************************************************************************/
51

    
52
#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__)
53

    
54
/**
55
 * @brief   Printf function for messages only printed in debug builds.
56
 *
57
 * @param[in] fmt   Formatted string to print.
58
 */
59
#define aosDbgPrintf(fmt, ...)        aosprintf(fmt, ##__VA_ARGS__)
60

    
61
/**
62
 * @brief   Function parameters check.
63
 * @details If the condition check fails, the thread complains and exits.
64
 *
65
 * @param[in] c The condition to be verified to be true.
66
 */
67
#define aosDbgCheck(c) {                                                      \
68
  if (!(c)) {                                                                 \
69
    aosDbgPrintf("%s(%u): aosDbgCheck failed", __FILE__, __LINE__);           \
70
    chThdExit(MSG_RESET);                                                     \
71
  }                                                                           \
72
}
73

    
74
/**
75
 * @brief   Condition assertion.
76
 * @details If the condition check fails, the thread complains and exits.
77
 *
78
 * @param[in] c The condition to be verified to be true.
79
 */
80
#define aosDbgAssert(c) {                                                     \
81
  if (!(c)) {                                                                 \
82
    aosDbgPrintf("%s(%u): aosDbgAssert failed", __FILE__, __LINE__);          \
83
    chThdExit(MSG_RESET);                                                     \
84
  }                                                                           \
85
}
86

    
87
/**
88
 * @brief   Condition assertion.
89
 * @details If the condition check fails, the thread complains and exits.
90
 *
91
 * @param[in] c The condition to be verified to be true.
92
 * @param[in] r A custom remark string.
93
 */
94
#define aosDbgAssertMsg(c, fmt, ...) {                                        \
95
  if (!(c)) {                                                                 \
96
    aosDbgPrintf(fmt, ##__VA_ARGS__);                                         \
97
    chThdExit(MSG_RESET);                                                     \
98
  }                                                                           \
99
}
100

    
101
#else /* (AMIROOS_CFG_DBG == true) */
102

    
103
#define aosDbgPrintf(fmt, ...) {                          \
104
  (void)(fmt);                                            \
105
}
106

    
107
#define aosDbgCheck(c) {                                  \
108
  (void)(c);                                              \
109
  }
110

    
111
#define aosDbgAssert(c) {                                 \
112
  (void)(c);                                              \
113
}
114

    
115
#define aosDbgAssertMsg(c, r) {                           \
116
  (void)(c);                                              \
117
  (void)(r);                                              \
118
}
119

    
120
#endif /* (AMIROOS_CFG_DBG == true) */
121

    
122
/******************************************************************************/
123
/* EXTERN DECLARATIONS                                                        */
124
/******************************************************************************/
125

    
126
/******************************************************************************/
127
/* INLINE FUNCTIONS                                                           */
128
/******************************************************************************/
129

    
130
#endif /* AMIROOS_DEBUG_H */
131

    
132
/** @} */