Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
2// Copyright (C) 2013-2026 Efinix Inc. All rights reserved.
3// Full license header: bsp/efinix/EfxSapphireSocRV64/include/LICENSE.MD
5
6#ifndef DEBUG_H
7#define DEBUG_H
8
19
20#include <stdio.h> /* Required for printf */
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/* Forward declaration for the character output function used in Assertion */
27extern void bsp_putChar(char c);
28
70
71/* ========================================================================== */
72/* SECTION 1: CONSTANTS & DEFINITIONS */
73/* ========================================================================== */
74
81
86 #define ANSI_RESET "\033[0m"
87 #define ANSI_RED "\033[31m"
88 #define ANSI_GREEN "\033[32m"
89 #define ANSI_YELLOW "\033[33m"
90 #define ANSI_BLUE "\033[34m"
91 #define ANSI_MAGENTA "\033[35m"
92 #define ANSI_CYAN "\033[36m"
93 #define ANSI_BOLD "\033[1m"
94 #define ANSI_UNDER "\033[4m"
96
102 #define DBG_MOD_SYS (1 << 0)
103 #define DBG_MOD_IRQ (1 << 1)
104 #define DBG_MOD_FAULT (1 << 2)
105 #define DBG_MOD_UART (1 << 3)
106 #define DBG_MOD_I2C (1 << 4)
107 #define DBG_MOD_SPI (1 << 5)
108 #define DBG_MOD_SPI_FLASH (1 << 6)
109 #define DBG_MOD_RTC (1 << 7)
110 #define DBG_MOD_CAM (1 << 8)
111 #define DBG_MOD_SENSOR (1 << 9)
112
114 #define DBG_MOD_ALL (DBG_MOD_SYS | DBG_MOD_IRQ | DBG_MOD_FAULT | \
115 DBG_MOD_UART | DBG_MOD_I2C | DBG_MOD_SPI | \
116 DBG_MOD_SPI_FLASH | DBG_MOD_RTC | DBG_MOD_SENSOR)
117
118
124 #define DBG_LVL_ALL 0
125 #define DBG_LVL_WARN 1
126 #define DBG_LVL_ERR 2
127 #define DBG_LVL_NONE 3
129 // End of DEBUG_Const
131
132
133/* ========================================================================== */
134/* SECTION 2: CONFIGURATION & MACROS */
135/* ========================================================================== */
136
149#include "userDef.h"
150
151 /* * FAILSAFE: We check defined(__DOXYGEN__) so these macros appear in
152 * documentation even if DEBUG_MODE is not set in Doxyfile.
153 */
154 #if (DEBUG_MODE == 1) || defined(__DOXYGEN__)
155
156 /* -----------------------------------------------------------------------------*/
157 /* DEFAULT CONFIGURATION */
158 /* -----------------------------------------------------------------------------*/
159 #if !defined(ACTIVE_DEBUG_MOD) || !defined(ACTIVE_MIN_LVL)
160 /* Use safe defaults if userDef.h is missing values */
161 #define ACTIVE_DEBUG_MOD 0
162 #define ACTIVE_MIN_LVL DBG_LVL_NONE
163
164 /* Only trigger warning during real compilation, not documentation generation */
165 #ifndef __DOXYGEN__
166 #warning "Missing ACTIVE_DEBUG or ACTIVE_MIN_LVL in userDef.h! Disabling Debug."
167 #endif
168 #endif
169
170 /* -----------------------------------------------------------------------------*/
171 /* ASSERTION MACRO */
172 /* -----------------------------------------------------------------------------*/
178 #define BSP_ASSERT(cond, msg) \
179 do { \
180 if (!(cond)) { \
181 const char *p = (msg); \
182 while (*p) { \
183 bsp_putChar(*p); \
184 p++; \
185 } \
186 /* Hang forever */ \
187 while(1); \
188 } \
189 } while(0)
190
191 /* -----------------------------------------------------------------------------*/
192 /* LOGGING MACROS */
193 /* -----------------------------------------------------------------------------*/
194
198 #define SHOULD_LOG(debug, lvl) \
199 ( ((ACTIVE_DEBUG_MOD) & (debug)) && ((lvl) >= (ACTIVE_MIN_LVL)) )
200
207 #define LOG_INFO(debug, fmt, ...) \
208 do { \
209 if (SHOULD_LOG(debug, DBG_LVL_ALL)) { \
210 printf(ANSI_GREEN "INFO: " fmt ANSI_RESET "\n", ##__VA_ARGS__); \
211 } \
212 } while(0)
213
217 #define LOG_WARN(debug, fmt, ...) \
218 do { \
219 if (SHOULD_LOG(debug, DBG_LVL_WARN)) { \
220 printf(ANSI_YELLOW "WRN: " fmt ANSI_RESET "\n", ##__VA_ARGS__); \
221 } \
222 } while(0)
223
227 #define LOG_ERR(debug, fmt, ...) \
228 do { \
229 if (SHOULD_LOG(debug, DBG_LVL_ERR)) { \
230 printf(ANSI_RED "ERR: " fmt ANSI_RESET "\n", ##__VA_ARGS__); \
231 } \
232 } while(0)
233
234 #else // DEBUG_MODE == 0
235
236 #define BSP_ASSERT(cond, msg) ((void)0)
237 #define LOG_INFO(debug, fmt, ...) ((void)0)
238 #define LOG_WARN(debug, fmt, ...) ((void)0)
239 #define LOG_ERR(debug, fmt, ...) ((void)0)
240
241 #endif
242 // End of DEBUG_Config group
244
245#ifdef __cplusplus
246}
247#endif // C_plusplus
248 // End of MAIN DEBUG Group
250
251#endif // DEBUG_H
#define bsp_putChar(c)
Definition bsp.h:42