RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
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
99
100/* =========================================================================
101 * ANSI Colors
102 * ========================================================================= */
103
110 #define ANSI_RESET "\033[0m"
111 #define ANSI_RED "\033[31m"
112 #define ANSI_GREEN "\033[32m"
113 #define ANSI_YELLOW "\033[33m"
114 #define ANSI_BLUE "\033[34m"
115 #define ANSI_MAGENTA "\033[35m"
116 #define ANSI_CYAN "\033[36m"
117 #define ANSI_BOLD "\033[1m"
118 #define ANSI_UNDER "\033[4m"
120
121/* =========================================================================
122 * Debug Modules
123 * ========================================================================= */
124
137 #define DBG_MOD_SYS (1 << 0)
138 #define DBG_MOD_IRQ (1 << 1)
139 #define DBG_MOD_FAULT (1 << 2)
140 #define DBG_MOD_UART (1 << 3)
141 #define DBG_MOD_I2C (1 << 4)
142 #define DBG_MOD_SPI (1 << 5)
143 #define DBG_MOD_SPI_FLASH (1 << 6)
144 #define DBG_MOD_RTC (1 << 7)
145 #define DBG_MOD_CAM (1 << 8)
146 #define DBG_MOD_SENSOR (1 << 9)
147 #define DBG_MOD_MAIN (1 << 10)
148
150 #define DBG_MOD_ALL \
151 ( DBG_MOD_SYS | DBG_MOD_IRQ | DBG_MOD_FAULT | DBG_MOD_UART | \
152 DBG_MOD_I2C | DBG_MOD_SPI | DBG_MOD_SPI_FLASH | DBG_MOD_RTC | \
153 DBG_MOD_CAM | DBG_MOD_SENSOR | DBG_MOD_MAIN )
154
155
156/* =========================================================================
157 * Debug Levels
158 * ========================================================================= */
159
172 #define DBG_LVL_ALL 0
173 #define DBG_LVL_WARN 1
174 #define DBG_LVL_ERR 2
175 #define DBG_LVL_NONE 3
177
178/* =========================================================================
179 * Debug API Function
180 * ========================================================================= */
181
182#include "userDef.h"
183
184#if (DEBUG_MODE == 1) || defined(__DOXYGEN__)
185
186 /* --- Fallback defaults if userDef.h is incomplete --- */
187 #if !defined(ACTIVE_DEBUG_MOD) || !defined(ACTIVE_MIN_LVL)
191 #define ACTIVE_DEBUG_MOD 0
195 #define ACTIVE_MIN_LVL DBG_LVL_NONE
196 #ifndef __DOXYGEN__
197 #warning "Missing ACTIVE_DEBUG_MOD or ACTIVE_MIN_LVL in userDef.h — debug disabled."
198 #endif
199 #endif
200
207
209 #define SHOULD_LOG(mod, lvl) \
210 ( ((ACTIVE_DEBUG_MOD) & (mod)) && ((lvl) >= (ACTIVE_MIN_LVL)) )
212
218 #define BSP_ASSERT(cond, msg) \
219 do { \
220 if (!(cond)) { \
221 const char *_p = (msg); \
222 while (*_p) bsp_putChar(*_p++); \
223 while (1); \
224 } \
225 } while (0)
226
233 #define LOG_INFO(mod, fmt, ...) \
234 do { \
235 if (SHOULD_LOG(mod, DBG_LVL_ALL)) \
236 printf(ANSI_GREEN "INFO: " fmt ANSI_RESET "\n", ##__VA_ARGS__); \
237 } while (0)
238
245 #define LOG_WARN(mod, fmt, ...) \
246 do { \
247 if (SHOULD_LOG(mod, DBG_LVL_WARN)) \
248 printf(ANSI_YELLOW "WRN: " fmt ANSI_RESET "\n", ##__VA_ARGS__); \
249 } while (0)
250
257 #define LOG_ERR(mod, fmt, ...) \
258 do { \
259 if (SHOULD_LOG(mod, DBG_LVL_ERR)) \
260 printf(ANSI_RED "ERR: " fmt ANSI_RESET "\n", ##__VA_ARGS__); \
261 } while (0)
262 /* DBG_FUNC */
264
265#else /* DEBUG_MODE == 0 — optimize everything out */
266
268 #define BSP_ASSERT(cond, msg) ((void)0)
269 #define LOG_INFO(mod, fmt, ...) ((void)0)
270 #define LOG_WARN(mod, fmt, ...) ((void)0)
271 #define LOG_ERR(mod, fmt, ...) ((void)0)
273
274#endif /* DEBUG_MODE */
275 /* DEBUG */
277
278#ifdef __cplusplus
279}
280#endif
281
282#endif /* DEBUG_H */
#define bsp_putChar(c)
Map standard character output to the physical UART.
Definition bsp.h:95