1 //*****************************************************************************
2 //
3 //! @file am_util_debug.h
4 //!
5 //! @brief Useful functions for debugging.
6 //!
7 //! These functions and macros were created to assist with debugging. They are
8 //! intended to be as unintrusive as possible and designed to be removed from
9 //! the compilation of a project when they are no longer needed.
10 //!
11 //! @addtogroup debug Debug
12 //! @ingroup utils
13 //! @{
14 //
15 //*****************************************************************************
16 
17 //*****************************************************************************
18 //
19 // Copyright (c) 2023, Ambiq Micro, Inc.
20 // All rights reserved.
21 //
22 // Redistribution and use in source and binary forms, with or without
23 // modification, are permitted provided that the following conditions are met:
24 //
25 // 1. Redistributions of source code must retain the above copyright notice,
26 // this list of conditions and the following disclaimer.
27 //
28 // 2. Redistributions in binary form must reproduce the above copyright
29 // notice, this list of conditions and the following disclaimer in the
30 // documentation and/or other materials provided with the distribution.
31 //
32 // 3. Neither the name of the copyright holder nor the names of its
33 // contributors may be used to endorse or promote products derived from this
34 // software without specific prior written permission.
35 //
36 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
37 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
40 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
41 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46 // POSSIBILITY OF SUCH DAMAGE.
47 //
48 // This is part of revision release_sdk_4_4_0-3c5977e664 of the AmbiqSuite Development Package.
49 //
50 //*****************************************************************************
51 #ifndef AM_UTIL_DEBUG_H
52 #define AM_UTIL_DEBUG_H
53 
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif
58 
59 //*****************************************************************************
60 //
61 //! @name Debug printf macros.
62 //! @{
63 //
64 //*****************************************************************************
65 #ifdef AM_DEBUG_PRINTF
66 
67 #define am_util_debug_printf_init(x)                                          \
68     am_util_stdio_printf_init(x);
69 
70 #define am_util_debug_printf(...)                                             \
71     am_util_stdio_printf(__VA_ARGS__);
72 
73 #else
74 
75 #define am_util_debug_printf_init(...)
76 #define am_util_debug_printf(...)
77 
78 #endif // AM_DEBUG_PRINTF
79 //! @}
80 
81 //*****************************************************************************
82 //
83 //! @name Debug trace macros.
84 //! @{
85 //
86 //*****************************************************************************
87 #ifdef AM_DEBUG_TRACE
88 
89 #define am_util_debug_trace_init(PinNumber)                                   \
90     do                                                                        \
91     {                                                                         \
92         am_hal_gpio_out_bit_clear(PinNumber);                                 \
93         am_hal_gpio_pin_config(PinNumber, AM_HAL_GPIO_OUTPUT);                \
94     }                                                                         \
95     while (0)
96 
97 
98 #define am_util_debug_trace_start(PinNumber)                                  \
99     am_hal_gpio_out_bit_set(PinNumber)
100 
101 #define am_util_debug_trace_end(PinNumber)                                    \
102     am_hal_gpio_out_bit_clear(PinNumber)
103 
104 #else
105 
106 #define am_util_debug_trace_init(PinNumber)
107 #define am_util_debug_trace_start(PinNumber)
108 #define am_util_debug_trace_end(PinNumber)
109 
110 #endif // AM_DEBUG_TRACE
111 //! @}
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif // AM_UTIL_DEBUG_H
118 
119 //*****************************************************************************
120 //
121 // End Doxygen group.
122 //! @}
123 //
124 //*****************************************************************************
125 
126