HPM SDK
HPMicro Software Development Kit
hpm_log.h File Reference
#include <stdint.h>
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  hpm_log_engine_config
 
struct  hpm_log_config
 

Macros

#define HPM_LOG_CONFIG_MAX_ENGINE_NUM   1
 Maximum number of log engines. More...
 
#define HPM_LOG_CONFIG_MAX_MESSAGE_LEN   256
 Maximum length of a log message. More...
 
#define HPM_LOG_CONFIG_ENABLE_TIMESTAMP   1
 Enable timestamp in log messages. More...
 
#define HPM_LOG_CONFIG_ENABLE_FUNC_NAME   1
 Enable function name in log messages. More...
 
#define HPM_LOG_CONFIG_LEVEL   HPM_LOG_LEVEL_DEBUG
 Log level configuration. More...
 
#define HPM_LOG_FAST_FUNC
 Indicate fast functions. More...
 
#define HPM_LOG_LEVEL_DEBUG   4
 Debug log level. More...
 
#define HPM_LOG_LEVEL_INFO   3
 Information log level. More...
 
#define HPM_LOG_LEVEL_WARN   2
 Warning log level. More...
 
#define HPM_LOG_LEVEL_ERR   1
 Error log level. More...
 
#define HPM_LOG_PRINTF(fmt, ...)   hpm_log_printf(fmt, ##__VA_ARGS__);
 Macro to print a formatted log message. More...
 
#define HPM_LOG_DEBUG(fmt, ...)
 Macro to log a debug message. More...
 
#define HPM_LOG_INFO(fmt, ...)
 Macro to log an information message. More...
 
#define HPM_LOG_WARN(fmt, ...)
 Macro to log a warning message. More...
 
#define HPM_LOG_ERR(fmt, ...)
 Macro to log an error message. More...
 

Typedefs

typedef struct hpm_log_engine hpm_log_engine_t
 Forward declaration of the log engine structure. More...
 
typedef struct hpm_log_engine_config hpm_log_engine_config_t
 
typedef struct hpm_log_config hpm_log_config_t
 

Functions

hpm_log_engine_thpm_log_engine_create (hpm_log_engine_config_t *cfg)
 Create a log engine. More...
 
int hpm_log_engine_destroy (hpm_log_engine_t *engine)
 Destroy a log engine. More...
 
void hpm_log_engine_enable (hpm_log_engine_t *engine)
 Enable a log engine. More...
 
void hpm_log_engine_disable (hpm_log_engine_t *engine)
 Disable a log engine. More...
 
void hpm_log_engine_transfer_finish (hpm_log_engine_t *engine)
 Indicate that the transfer of a log message is finished. More...
 
void hpm_log_engine_dump (hpm_log_engine_t *engine)
 Dump all log messages in the FIFO buffer. More...
 
void hpm_log_init (hpm_log_config_t *cfg)
 Initialize the log module. More...
 
void hpm_log_printf (const char *fmt,...)
 Print a formatted log message. More...
 
void hpm_log_write (int level, const char *func, const int line, const char *fmt,...)
 Write a log message with a specified level. More...
 

Macro Definition Documentation

◆ HPM_LOG_CONFIG_ENABLE_FUNC_NAME

#define HPM_LOG_CONFIG_ENABLE_FUNC_NAME   1

Enable function name in log messages.

This macro controls whether function names are included in log messages. If set to 1, function names will be included; if set to 0, they will be omitted. If not defined externally, the default value is 1.

◆ HPM_LOG_CONFIG_ENABLE_TIMESTAMP

#define HPM_LOG_CONFIG_ENABLE_TIMESTAMP   1

Enable timestamp in log messages.

This macro controls whether timestamps are included in log messages. If set to 1, timestamps will be included; if set to 0, they will be omitted. If not defined externally, the default value is 1.

◆ HPM_LOG_CONFIG_LEVEL

#define HPM_LOG_CONFIG_LEVEL   HPM_LOG_LEVEL_DEBUG

Log level configuration.

This macro defines the current log level. Log messages with a level lower than this configuration will be ignored. If not defined externally, the default value is HPM_LOG_LEVEL_DEBUG.

◆ HPM_LOG_CONFIG_MAX_ENGINE_NUM

#define HPM_LOG_CONFIG_MAX_ENGINE_NUM   1

Maximum number of log engines.

This macro defines the maximum number of log engines that can be created. If not defined externally, the default value is 1.

◆ HPM_LOG_CONFIG_MAX_MESSAGE_LEN

#define HPM_LOG_CONFIG_MAX_MESSAGE_LEN   256

Maximum length of a log message.

This macro defines the maximum length of a log message. If not defined externally, the default value is 256.

◆ HPM_LOG_DEBUG

#define HPM_LOG_DEBUG (   fmt,
  ... 
)
Value:
({\
hpm_log_write(HPM_LOG_LEVEL_DEBUG, __func__, __LINE__, fmt, ##__VA_ARGS__);\
})
#define HPM_LOG_LEVEL_DEBUG
Debug log level.
Definition: hpm_log.h:87

Macro to log a debug message.

This macro logs a debug message if the current log level is set to HPM_LOG_LEVEL_DEBUG or higher.

Parameters
fmtFormat string for the debug message.
...Variable arguments corresponding to the format string.

◆ HPM_LOG_ERR

#define HPM_LOG_ERR (   fmt,
  ... 
)
Value:
({\
hpm_log_write(HPM_LOG_LEVEL_ERR, __func__, __LINE__, fmt, ##__VA_ARGS__);\
})
#define HPM_LOG_LEVEL_ERR
Error log level.
Definition: hpm_log.h:111

Macro to log an error message.

This macro logs an error message if the current log level is set to HPM_LOG_LEVEL_ERR or higher.

Parameters
fmtFormat string for the error message.
...Variable arguments corresponding to the format string.

◆ HPM_LOG_FAST_FUNC

#define HPM_LOG_FAST_FUNC

Indicate fast functions.

This macro is used to mark functions that are expected to be fast.

◆ HPM_LOG_INFO

#define HPM_LOG_INFO (   fmt,
  ... 
)
Value:
({\
hpm_log_write(HPM_LOG_LEVEL_INFO, __func__, __LINE__, fmt, ##__VA_ARGS__);\
})
#define HPM_LOG_LEVEL_INFO
Information log level.
Definition: hpm_log.h:95

Macro to log an information message.

This macro logs an information message if the current log level is set to HPM_LOG_LEVEL_INFO or higher.

Parameters
fmtFormat string for the information message.
...Variable arguments corresponding to the format string.

◆ HPM_LOG_LEVEL_DEBUG

#define HPM_LOG_LEVEL_DEBUG   4

Debug log level.

This macro represents the debug log level. It is used for detailed debugging information.

◆ HPM_LOG_LEVEL_ERR

#define HPM_LOG_LEVEL_ERR   1

Error log level.

This macro represents the error log level. It is used for critical error messages.

◆ HPM_LOG_LEVEL_INFO

#define HPM_LOG_LEVEL_INFO   3

Information log level.

This macro represents the information log level. It is used for general information messages.

◆ HPM_LOG_LEVEL_WARN

#define HPM_LOG_LEVEL_WARN   2

Warning log level.

This macro represents the warning log level. It is used for non-critical warnings.

◆ HPM_LOG_PRINTF

#define HPM_LOG_PRINTF (   fmt,
  ... 
)    hpm_log_printf(fmt, ##__VA_ARGS__);

Macro to print a formatted log message.

This macro calls the hpm_log_printf function with the specified format string and arguments.

Parameters
fmtFormat string for the log message.
...Variable arguments corresponding to the format string.

◆ HPM_LOG_WARN

#define HPM_LOG_WARN (   fmt,
  ... 
)
Value:
({\
hpm_log_write(HPM_LOG_LEVEL_WARN, __func__, __LINE__, fmt, ##__VA_ARGS__);\
})
#define HPM_LOG_LEVEL_WARN
Warning log level.
Definition: hpm_log.h:103

Macro to log a warning message.

This macro logs a warning message if the current log level is set to HPM_LOG_LEVEL_WARN or higher.

Parameters
fmtFormat string for the warning message.
...Variable arguments corresponding to the format string.

Typedef Documentation

◆ hpm_log_config_t

◆ hpm_log_engine_config_t

◆ hpm_log_engine_t

Forward declaration of the log engine structure.

Function Documentation

◆ hpm_log_engine_create()

hpm_log_engine_t* hpm_log_engine_create ( hpm_log_engine_config_t cfg)

Create a log engine.

This function creates a new log engine with the specified configuration.

Parameters
cfgPointer to the log engine configuration structure.
Returns
Pointer to the created log engine, or NULL if creation fails.

◆ hpm_log_engine_destroy()

int hpm_log_engine_destroy ( hpm_log_engine_t engine)

Destroy a log engine.

This function destroys the specified log engine and releases its resources.

Parameters
enginePointer to the log engine to be destroyed.
Returns
0 success, or -1 if destroy fails.

◆ hpm_log_engine_disable()

void hpm_log_engine_disable ( hpm_log_engine_t engine)

Disable a log engine.

This function disables the specified log engine, preventing it from processing log messages.

Parameters
enginePointer to the log engine to be disabled.

◆ hpm_log_engine_dump()

void hpm_log_engine_dump ( hpm_log_engine_t engine)

Dump all log messages in the FIFO buffer.

This function transfers all log messages currently in the FIFO buffer of the specified log engine.

Parameters
enginePointer to the log engine whose FIFO buffer should be dumped.

◆ hpm_log_engine_enable()

void hpm_log_engine_enable ( hpm_log_engine_t engine)

Enable a log engine.

This function enables the specified log engine, allowing it to start processing log messages.

Parameters
enginePointer to the log engine to be enabled.

◆ hpm_log_engine_transfer_finish()

void hpm_log_engine_transfer_finish ( hpm_log_engine_t engine)

Indicate that the transfer of a log message is finished.

This function is called to indicate that the transfer of a log message has finished. It may trigger the transfer of the next message in the FIFO buffer.

Parameters
enginePointer to the log engine for which the transfer has finished.

◆ hpm_log_init()

void hpm_log_init ( hpm_log_config_t cfg)

Initialize the log module.

This function initializes the log module with the specified configuration.

Parameters
cfgPointer to the log module configuration structure. if NULL, the default is used.

◆ hpm_log_printf()

void hpm_log_printf ( const char *  fmt,
  ... 
)

Print a formatted log message.

This function prints a formatted log message using the specified format string and arguments.

Parameters
fmtFormat string for the log message.
...Variable arguments corresponding to the format string.

◆ hpm_log_write()

void hpm_log_write ( int  level,
const char *  func,
const int  line,
const char *  fmt,
  ... 
)

Write a log message with a specified level.

This function writes a log message with the specified log level, function name, line number, and format string and arguments.

Parameters
levelLog level of the message.
funcName of the function where the log message is generated.
lineLine number in the source file where the log message is generated.
fmtFormat string for the log message.
...Variable arguments corresponding to the format string.