/** ****************************************************************************** * @file logging.h * @author ST67 Application Team * @brief This file is part of the FreeRTOS logging interface ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** * Portions of this file are based on FreeRTOS, which is licensed under the MIT license as indicated below. * See https://www.FreeRTOS.org/logging.html for more information. * * Reference source: * https://github.com/FreeRTOS/FreeRTOS/blob/main/FreeRTOS-Plus/Source/Utilities/logging/logging.h */ /* * FreeRTOS V202212.00 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * https://www.FreeRTOS.org * https://github.com/FreeRTOS * */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef LOGGING_H #define LOGGING_H #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /* Includes ------------------------------------------------------------------*/ #include #include "logging_config.h" #include "logging_levels.h" /* Exported macros -----------------------------------------------------------*/ /** @defgroup ST67W6X_Utilities_Logging_Macros ST67W6X Utility Logging Macros * @ingroup ST67W6X_Utilities_Logging * @{ */ /** * \def LogError( ... ) * Send a message to the log with level ::LOG_ERROR. */ /** * \def LogErrorEx( line, file, ... ) * Send a message with line number and file name to the log with level ::LOG_ERROR. */ /** * \def LogInfo( ... ) * Send a message to the log with level ::LOG_INFO. */ /** * \def LogWarn( ... ) * Send a message to the log with level ::LOG_WARN. */ /** * \def LogDebug( ... ) * Send a message to the log with level ::LOG_DEBUG. */ #ifndef LOG_LEVEL /** Global verbosity level (LOG_NONE, LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG) */ #define LOG_LEVEL LOG_INFO #endif /* LOG_LEVEL */ /* Get rid of extra C89 style parentheses generated by core FreeRTOS libraries */ /** Macro to remove the extra parentheses. */ #define REMOVE /** Convert a macro parameter to a string. */ #define STR_( ... ) REM ## __VA_ARGS__ /** Convert a macro parameter to a string. */ #define STR( ... ) STR_( __VA_ARGS__ ) /** Removes at most one outer set of parentheses from its arguments. */ #define OVE( ... ) OVE __VA_ARGS__ /** Removes at most one outer set of parentheses from its arguments. */ #define REMOVE_PARENS( ... ) STR( OVE __VA_ARGS__ ) #if defined(__ICCARM__) || defined(__ICCRX__) /* For IAR Compiler */ #ifndef __FILE_NAME__ /* coverity[misra_c_2012_rule_21_1_violation : FALSE] */ /* coverity[misra_c_2012_rule_21_2_violation : FALSE] */ #define __FILE_NAME__ __FILE__ #endif /* ! __FILE_NAME__ */ #endif /* __ICCARM__ */ /** * Disable definition of logging interface macros when generating doxygen output, * to avoid conflict with documentation of macros at the end of the file. */ /* Check that LOG_LEVEL is defined and has a valid value. */ #if !defined( LOG_LEVEL ) || \ ( ( LOG_LEVEL != LOG_NONE ) && \ ( LOG_LEVEL != LOG_ERROR ) && \ ( LOG_LEVEL != LOG_WARN ) && \ ( LOG_LEVEL != LOG_INFO ) && \ ( LOG_LEVEL != LOG_DEBUG ) ) #error "Please define LOG_LEVEL as either LOG_NONE, LOG_ERROR, LOG_WARN, LOG_INFO, or LOG_DEBUG." #else #if ( LOG_LEVEL >= LOG_ERROR ) #define LogError( ... ) vLoggingPrintf( LOG_ERROR, 1U, __LINE__, __FILE_NAME__, REMOVE_PARENS( __VA_ARGS__ ) ) #define LogErrorEx(line, file, ... ) vLoggingPrintf( LOG_ERROR, 1U, line, file, REMOVE_PARENS( __VA_ARGS__ ) ) #else #define LogError( ... ) #define LogErrorEx(line, file, ... ) #endif /* ( LOG_LEVEL >= LOG_ERROR ) */ #if ( LOG_LEVEL >= LOG_WARN ) #define LogWarn( ... ) vLoggingPrintf( LOG_WARN, 1U, __LINE__, __FILE_NAME__, REMOVE_PARENS( __VA_ARGS__ ) ) #else #define LogWarn( ... ) #endif /* ( LOG_LEVEL >= LOG_WARN ) */ #if ( LOG_LEVEL >= LOG_INFO ) #define LogInfo( ... ) vLoggingPrintf( LOG_INFO, 0U, 0U, (void *)0, REMOVE_PARENS( __VA_ARGS__ ) ) #else #define LogInfo( ... ) #endif /* ( LOG_LEVEL >= LOG_INFO ) */ #if ( LOG_LEVEL >= LOG_DEBUG ) #define LogDebug( ... ) vLoggingPrintf( LOG_DEBUG, 0U, 0U, (void *)0, REMOVE_PARENS( __VA_ARGS__ ) ) #else #define LogDebug( ... ) #endif /* ( LOG_LEVEL >= LOG_DEBUG ) */ #endif /* LOG_LEVEL */ /** @} */ /* Exported functions ------------------------------------------------------- */ /** @defgroup ST67W6X_Utilities_Logging_Functions ST67W6X Utility Logging Functions * @ingroup ST67W6X_Utilities_Logging * @{ */ /** * @brief Printf like function to print a message in the log. The application should not use it directly, * but it must uses the log macros: * - LogError * - LogWarn * - LogInfo * - LogDebug * @param log_level specifies the type of log entry * @param metadata_print specifies if the metadata should be printed * @param line_number specifies the line number in the compilation unit generating the log message. \ * is automatically generated by the log macros. * @param p_file_name specifies the name of the file generating the log message. \ * is automatically generated by the log macros. * @param p_format printf like format string */ void vLoggingPrintf(uint32_t log_level, const uint8_t metadata_print, const uint32_t line_number, const char *const p_file_name, const char *const p_format, ...); /** * @brief Initialize the logging service * @param LogOutput_cb [IN] specifies the callback to output the message. \ * The callback shall not return until it is completed * @return NULL in case of error, a pointer to the logging service otherwise */ void *vLoggingInit(void (*LogOutput_cb)(const char *message)); /** * @brief Reset the logging service */ void vLoggingDeInit(void); /** * @brief Set the verbose level * @param level [IN] the maximum log level to be printed */ void vLoggingSetVerbosity(uint32_t level); /** @} */ #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* LOGGING_H */