Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_debug.h @ 11adbe34

History | View | Annotate | Download (3.025 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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 <aosconf.h>
31
#include <ch.h>
32

    
33
#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__)
34

    
35
/**
36
 * @brief   Function parameters check.
37
 * @details If the condition check fails, the kernel panics and halts.
38
 *
39
 * @param[in] c The condition to be verified to be true.
40
 */
41
#define aosDbgCheck(c)                chDbgCheck(c)
42

    
43
/**
44
 * @brief   Condition assertion.
45
 * @details If the condition check fails, the kernel panics with a message and halts.
46
 * @note    As a limitation of ChibiOS, the remark string is not currently used.
47
 *
48
 * @param[in] c The condition to be verified to be true.
49
 */
50
#define aosDbgAssert(c)               chDbgAssert(c, "__FILE__(__LINE__): aosDbgAssert failed")
51

    
52
/**
53
 * @brief   Condition assertion.
54
 * @details If the condition check fails, the kernel panics with a message and halts.
55
 * @note    As a limitation of ChibiOS, the remark string is not currently used.
56
 *
57
 * @param[in] c The condition to be verified to be true.
58
 * @param[in] r A custom remark string.
59
 */
60
#define aosDbgAssertMsg(c, r) {                           \
61
  (void)r;                                                \
62
  chDbgAssert(c, r);                                      \
63
}
64

    
65
/**
66
 * @brief   Printf function for messages only printed in debug builds.
67
 *
68
 * @param[in] fmt   Formatted string to print.
69
 */
70
#define aosDbgPrintf(fmt, ...)           chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
71

    
72
#else /* (AMIROOS_CFG_DBG != true) */
73

    
74
#define aosDbgCheck(c) {                                  \
75
  (void)(c);                                              \
76
  }
77

    
78
#define aosDbgAssert(c) {                                 \
79
  (void)(c);                                              \
80
}
81

    
82
#define aosDbgAssertMsg(c, r) {                           \
83
  (void)(c);                                              \
84
  (void)(r);                                              \
85
}
86

    
87
#define aosDbgPrintf(fmt, ...) {                          \
88
  (void)(fmt);                                            \
89
}
90

    
91
#endif
92

    
93
#ifdef __cplusplus
94
extern "C" {
95
#endif
96
  void aosPrintHaltErrorCode(const char* reason);
97
#ifdef __cplusplus
98
}
99
#endif
100

    
101
#endif /* _AMIROOS_DEBUG_H_ */
102

    
103
/** @} */