no-OS
Loading...
Searching...
No Matches
gmsl_dbg.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file gmsl_dbg.h
3 * @brief Header file of GMSL debug module.
4 * @author Automotive Software and Systems team, Bangalore, India
5********************************************************************************
6 * Copyright 2025(c) Analog Devices, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25 * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*******************************************************************************/
33#ifndef DBG_H
34#define DBG_H
35
36#include <stdbool.h>
37#include <stdint.h>
38#include <string.h>
39#include <stdio.h>
40
41/* Max size of individual log message */
42#define MAX_LOG_MSG_SIZE (2200u)
43
44#define GMSL_LOG_LEVEL_ERR 0x0
45#define GMSL_LOG_LEVEL_WARNING 0x1
46#define GMSL_LOG_LEVEL_INFO 0x2
47#define GMSL_LOG_LEVEL_DEBUG 0x3
48
49#ifdef _DEBUG
50
51/* To be implemented by application*/
52extern uint8_t gmsl_uc_log_msg_buffer[MAX_LOG_MSG_SIZE];
53extern uint32_t gmsl_uc_log_msg_buf_length;
54extern void gmsl_uc_log_error(uint8_t *tx_data, uint32_t size);
55extern void gmsl_uc_log_debug(uint8_t *tx_data, uint32_t size);
56extern void gmsl_uc_log_info(uint8_t *tx_data, uint32_t size);
57extern void gmsl_uc_log_warning(uint8_t *tx_data, uint32_t size);
58extern void gmsl_uc_set_fatal_error(void);
59
60#if (defined(GMSL_LOG_LEVEL) && (GMSL_LOG_LEVEL >= GMSL_LOG_LEVEL_ERR) && (GMSL_LOG_LEVEL <= GMSL_LOG_LEVEL_DEBUG))
61#define GMSL_LOG_ERROR(msg, ...) do {\
62 /* Create the log string */\
63 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, (char *)(msg), ##__VA_ARGS__); \
64 /* Send the data over UART */\
65 gmsl_uc_log_error(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length); \
66} while (false)
67#else
68#define GMSL_LOG_ERROR(msg, ...)
69#endif
70
71#if (defined(GMSL_LOG_LEVEL) && (GMSL_LOG_LEVEL >= GMSL_LOG_LEVEL_WARNING) && (GMSL_LOG_LEVEL <= GMSL_LOG_LEVEL_DEBUG))
72#define GMSL_LOG_WARNING(msg, ...) do {\
73 /* Create the log string */\
74 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, (char *)(msg), ##__VA_ARGS__); \
75 /* Send the data over UART */\
76 gmsl_uc_log_warning(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length); \
77} while (false)
78#else
79#define GMSL_LOG_WARNING(msg, ...)
80#endif
81
82#if (defined(GMSL_LOG_LEVEL) && (GMSL_LOG_LEVEL >= GMSL_LOG_LEVEL_INFO) && (GMSL_LOG_LEVEL <= GMSL_LOG_LEVEL_DEBUG))
83#define GMSL_LOG_INFO(msg, ...) do {\
84 /* Create the log string */\
85 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, (char *)(msg), ##__VA_ARGS__); \
86 /* Send the data over UART */\
87 gmsl_uc_log_info(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length); \
88} while (false)
89#else
90#define GMSL_LOG_INFO(msg, ...)
91#endif
92
93#if (defined(GMSL_LOG_LEVEL) && (GMSL_LOG_LEVEL >= GMSL_LOG_LEVEL_DEBUG) && (GMSL_LOG_LEVEL <= GMSL_LOG_LEVEL_DEBUG))
94#define GMSL_LOG_DEBUG(msg, ...) do {\
95 /* Create the log string */\
96 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, (char *)(msg), ##__VA_ARGS__); \
97 /* Send the data over UART */\
98 gmsl_uc_log_debug(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length); \
99} while (false)
100#else
101#define GMSL_LOG_DEBUG(msg, ...)
102#endif
103
104#if (defined(GMSL_LOG_LEVEL) && (GMSL_LOG_LEVEL >= GMSL_LOG_LEVEL_INFO) && (GMSL_LOG_LEVEL <= GMSL_LOG_LEVEL_DEBUG))
105#define GMSL_LOG_DIAG(current_diag_err, dev_name_str, dev_addr, msg, ...) do {\
106 if(true == current_diag_err)\
107 {\
108 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, "[%s-0x%x]"msg, dev_name_str, dev_addr, ##__VA_ARGS__); \
109 gmsl_uc_log_error(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length); \
110 }\
111 else \
112 {\
113 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, "[%s-0x%x]"msg, dev_name_str, dev_addr, ##__VA_ARGS__); \
114 gmsl_uc_log_info(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length); \
115 }\
116} while (false)
117#else
118#define GMSL_LOG_DIAG(current_diag_err, dev_name_str, dev_addr, msg, ...) do {\
119 if(true == current_diag_err)\
120 {\
121 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, "[%s-0x%x]"msg, dev_name_str, dev_addr, ##__VA_ARGS__); \
122 gmsl_uc_log_error(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length); \
123 }\
124} while (false)
125#endif
126
127#define GMSL_LOG_DEV_ERROR(dev_name_str, dev_addr, msg, ...)\
128{\
129 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, "[%s-0x%x]"msg, dev_name_str, dev_addr, ##__VA_ARGS__);\
130 gmsl_uc_log_error(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length);\
131}
132
133#define GMSL_LOG_DEV_INFO(dev_name_str, dev_addr, msg, ...)\
134{\
135 gmsl_uc_log_msg_buf_length = (uint32_t)snprintf((char*)&gmsl_uc_log_msg_buffer[0u], MAX_LOG_MSG_SIZE, "[%s-0x%x]"msg, dev_name_str, dev_addr, ##__VA_ARGS__);\
136 gmsl_uc_log_info(gmsl_uc_log_msg_buffer, gmsl_uc_log_msg_buf_length);\
137}
138
139#define GMSL_DBG_ERROR() {\
140 GMSL_LOG_ERROR("Fatal error!");\
141 gmsl_uc_set_fatal_error();\
142}
143
144#define GMSL_DBG_REQUIRE(cond, errMsg) {\
145 if(!(cond)) {\
146 GMSL_LOG_ERROR("Precondition error: " errMsg);\
147 gmsl_uc_set_fatal_error();\
148 }\
149}
150
151/*=========== Macros to en/dis log printing =============*/
152
153#else
154#define GMSL_LOG_ERROR(msg, ...)
155#define GMSL_LOG_WARNING(msg, ...)
156#define GMSL_LOG_INFO(msg, ...)
157#define GMSL_LOG_DEBUG(msg, ...)
158
159#define GMSL_LOG_DIAG(current_diag_err, dev_name_str, dev_addr, msg, ...)
160#define GMSL_LOG_DEV_ERROR(dev_name_str, dev_addr, msg, ...)
161#define GMSL_LOG_DEV_INFO(dev_name_str, dev_addr, msg, ...)
162#define GMSL_DBG_REQUIRE(cond, errMsg)
163#define GMSL_DBG_ERROR()
164
165#endif
166
167#endif
#define MAX_LOG_MSG_SIZE
Definition gmsl_dbg.h:42