1 /* USER CODE BEGIN Header */ 2 /** 3 ****************************************************************************** 4 * @file log_module.h 5 * @author MCD Application Team 6 * @brief Header file of the log module. 7 ****************************************************************************** 8 * @attention 9 * 10 * Copyright (c) 2024 STMicroelectronics. 11 * All rights reserved. 12 * 13 * This software is licensed under terms that can be found in the LICENSE file 14 * in the root directory of this software component. 15 * If no LICENSE file comes with this software, it is provided AS-IS. 16 * 17 ****************************************************************************** 18 */ 19 /* USER CODE END Header */ 20 21 /* Define to prevent recursive inclusion -------------------------------------*/ 22 #ifndef LOG_MODULE_H 23 #define LOG_MODULE_H 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include <stdarg.h> 31 #include <stdint.h> 32 #include <stdbool.h> 33 #include "log_module_conf.h" 34 35 /* Private includes ----------------------------------------------------------*/ 36 /* USER CODE BEGIN Includes */ 37 38 /* USER CODE END Includes */ 39 40 /* Exported types ------------------------------------------------------------*/ 41 /* Log module types */ 42 /** 43 * @brief Data type to initialize the module by calling Log_Module_Init. 44 * verbose_level : A value of type Log_Verbose_Level_t. 45 * region_mask : A mask based on Log_Region_t. 46 * You can directly assign it to LOG_REGION_ALL_REGIONS, 47 * or select only some regions : 48 * (1U << LOG_REGION_BLE | 1U << LOG_REGION_APP) 49 */ 50 typedef struct 51 { 52 Log_Verbose_Level_t verbose_level; 53 uint32_t region_mask; 54 } Log_Module_t; 55 56 /** 57 * @brief Callback function to insert Time Stamp. 58 * 59 * @param Data The data into which to insert the TimeStamp. 60 * @param SizeMax The maximum size for the TimeStamp insert. 61 * @param TimeStampSize Pointer to update with the size of the TimeStamp inserted into data. 62 */ 63 typedef void CallBack_TimeStamp(char * Data, uint16_t SizeMax, uint16_t * TimeStampSize); 64 65 /* USER CODE BEGIN ET */ 66 67 /* USER CODE END ET */ 68 69 /* Exported constants --------------------------------------------------------*/ 70 /* Global const struct variables to make the life of the user easier */ 71 /** 72 * @brief A const struct with default parameters for the log module. 73 * Its main use is to pass it as parameter to Log_Module_Init. 74 */ 75 extern const Log_Module_t LOG_MODULE_DEFAULT_CONFIGURATION; 76 77 /** 78 * @brief A const enum variable with the verbose level set to LOG_VERBOSE_ERROR. 79 * The levels include the lower levels in the logs. 80 * 81 * E.g. LOG_VERBOSE_ERROR means LOG_VERBOSE_ERROR logs will be printed, 82 * as well as LOG_VERBOSE_INFO, but not the others with higher values. 83 */ 84 extern const Log_Verbose_Level_t LOG_VERBOSE_DEFAULT; 85 86 /** 87 * @brief A const enum variable to include all regions in the logs. 88 */ 89 extern const Log_Region_t LOG_REGION_MASK_DEFAULT; 90 91 /* USER CODE BEGIN EC */ 92 93 /* USER CODE END EC */ 94 95 /* Exported functions prototypes ---------------------------------------------*/ 96 /* Module API - Module configuration */ 97 /** 98 * @brief Initialization of the log module. 99 * 100 * @param LogConfiguration The configuration of the log module, of type Log_Module_t. 101 * @return None. 102 */ 103 void Log_Module_Init(Log_Module_t LogConfiguration); 104 105 /** 106 * @brief DeInitialization of the log module. 107 * 108 * @param None. 109 * @return None. 110 */ 111 void Log_Module_DeInit(void); 112 113 /** 114 * @brief Set the verbose level of the log. 115 * The levels include the lower levels in the logs. 116 * 117 * E.g. LOG_VERBOSE_ERROR means LOG_VERBOSE_ERROR logs will be printed, 118 * as well as LOG_VERBOSE_INFO, but not the others with higher values. 119 * 120 * @param NewVerboseLevel The new verbose level to be set, of type Log_Verbose_Level_t 121 * @return None 122 */ 123 void Log_Module_Set_Verbose_Level(Log_Verbose_Level_t NewVerboseLevel); 124 125 /** 126 * @brief Replace the current regions in use and only set the given region. 127 * 128 * @param NewRegion The new region to use, of type Log_Region_t. 129 * @return None. 130 */ 131 void Log_Module_Set_Region(Log_Region_t NewRegion); 132 133 /** 134 * @brief Replace the current regions in use and set one or several as replacement. 135 * 136 * @param NewRegionMask A mask, of type uint32_t, where each bit corresponds to a region. 137 * You can directly assign it to LOG_REGION_ALL_REGIONS to enable all of them, 138 * or select only some regions, e.g. (1U << LOG_REGION_BLE | 1U << LOG_REGION_APP) 139 * @return None. 140 */ 141 void Log_Module_Set_Multiple_Regions(uint32_t NewRegionMask); 142 143 /** 144 * @brief Add to the current region mask the given region. 145 * 146 * @param NewRegion The new region to use, alongside the others, of type Log_Region_t. 147 * @return None. 148 */ 149 void Log_Module_Add_Region(Log_Region_t NewRegion); 150 151 /** 152 * @brief Remove from the current region mask the given region. 153 * 154 * @param Region The region to remove, of type Log_Region_t. 155 * @return None. 156 */ 157 void Log_Module_Remove_Region(Log_Region_t Region); 158 159 /** 160 * @brief Enable all the regions. 161 * 162 * @param None. 163 * @return None. 164 */ 165 void Log_Module_Enable_All_Regions(void); 166 167 /** 168 * @brief Set the color for a region. 169 * 170 * @param Region The region where apply the color, type Log_Region_t. 171 * @param Color The color to apply to selected region, of type Log_Color_t. 172 * @return None. 173 */ 174 void Log_Module_Set_Color(Log_Region_t Region, Log_Color_t Color); 175 176 /** 177 * @brief Register a callback function to insert the TimeStamp into the data. 178 * 179 * @param TimeStampFunction Callback function to insert TimeStamp. 180 * This function is typedef void (char * data, uint16_t size_max, uint16_t * timestamp_size); 181 * Where data is the location where to insert the new TimeStamp, and timestamp_size is the size of this insertion. 182 * @return None. 183 */ 184 void Log_Module_RegisterTimeStampFunction(CallBack_TimeStamp * TimeStampFunction); 185 186 /* Module API - Wrapper function */ 187 /** 188 * @brief Underlying function of all the LOG_xxx macros. 189 * 190 * @param VerboseLevel The level of verbose used for this Log, of type Log_Verbose_Level_t. 191 * @param Region The region set for this log, of type Log_Region_t. 192 * @param Text The text to be printed. 193 * @param ... Any other parameters to be printed with the text. 194 * E.g. an int variable. as 3rd parameter, as long as %d is in text. 195 * 196 * @return None. 197 */ 198 void Log_Module_Print(Log_Verbose_Level_t VerboseLevel, Log_Region_t Region, const char * Text, ...); 199 200 /** 201 * @brief Function of log with already a arg list. 202 * 203 * @param VerboseLevel The level of verbose used for this Log, of type Log_Verbose_Level_t. 204 * @param Region The region set for this log, of type Log_Region_t. 205 * @param Text The text to be printed 206 * @param Args Arguments list, of type va_list. 207 * 208 * @return None. 209 */ 210 void Log_Module_PrintWithArg(Log_Verbose_Level_t VerboseLevel, Log_Region_t Region, const char * Text, va_list Args); 211 212 /* USER CODE BEGIN EFP */ 213 214 /* USER CODE END EFP */ 215 216 #ifdef __cplusplus 217 } 218 #endif 219 220 #endif /* LOG_MODULE_H */ 221