HPM SDK
HPMicro Software Development Kit
hpm_log.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <hpm_l1c_drv.h>
#include <hpm_interrupt.h>
#include <hpm_sysctl_drv.h>
#include <hpm_clock_drv.h>
#include "hpm_log.h"

Data Structures

struct  hpm_log_fifo
 
struct  hpm_log_engine
 
struct  hpm_log
 

Typedefs

typedef struct hpm_log hpm_log_t
 
typedef struct hpm_log_fifo hpm_log_fifo_t
 

Functions

static void hpm_log_fifo_init (hpm_log_fifo_t *fifo, char *buf, uint32_t size)
 
static uint32_t hpm_log_fifo_get_len (hpm_log_fifo_t *fifo)
 
static void hpm_log_fifo_push (hpm_log_fifo_t *fifo, char *buf, uint32_t len)
 
static uint32_t hpm_log_fifo_pop (hpm_log_fifo_t *fifo, char *buf, uint32_t len)
 
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...
 
static void hpm_log_engine_transfer_start (hpm_log_engine_t *engine)
 
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...
 
static void hpm_log_transfer_start_all (hpm_log_t *ctx)
 
static void hpm_log_fifo_push_all (hpm_log_t *ctx, char *message, uint32_t messge_len)
 
void hpm_log_write (int level, const char *func, const int line, const char *fmt,...)
 Write a log message with a specified level. More...
 
void hpm_log_printf (const char *fmt,...)
 Print a formatted log message. More...
 
static uint64_t hpm_log_cpu_get_us (void)
 
static long hpm_log_lock (void)
 
static void hpm_log_unlock (long restore)
 
void hpm_log_init (hpm_log_config_t *cfg)
 Initialize the log module. More...
 

Variables

static hpm_log_t hpm_log_ctx
 

Typedef Documentation

◆ hpm_log_fifo_t

typedef struct hpm_log_fifo hpm_log_fifo_t

◆ hpm_log_t

typedef struct hpm_log hpm_log_t

Function Documentation

◆ hpm_log_cpu_get_us()

static uint64_t hpm_log_cpu_get_us ( void  )
static

◆ 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_engine_transfer_start()

static void hpm_log_engine_transfer_start ( hpm_log_engine_t engine)
static

◆ hpm_log_fifo_get_len()

static uint32_t hpm_log_fifo_get_len ( hpm_log_fifo_t fifo)
static

◆ hpm_log_fifo_init()

static void hpm_log_fifo_init ( hpm_log_fifo_t fifo,
char *  buf,
uint32_t  size 
)
static

◆ hpm_log_fifo_pop()

static uint32_t hpm_log_fifo_pop ( hpm_log_fifo_t fifo,
char *  buf,
uint32_t  len 
)
static

◆ hpm_log_fifo_push()

static void hpm_log_fifo_push ( hpm_log_fifo_t fifo,
char *  buf,
uint32_t  len 
)
static

◆ hpm_log_fifo_push_all()

static void hpm_log_fifo_push_all ( hpm_log_t ctx,
char *  message,
uint32_t  messge_len 
)
static

◆ 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_lock()

static long hpm_log_lock ( void  )
static

◆ 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_transfer_start_all()

static void hpm_log_transfer_start_all ( hpm_log_t ctx)
static

◆ hpm_log_unlock()

static void hpm_log_unlock ( long  restore)
static

◆ 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.

Variable Documentation

◆ hpm_log_ctx

hpm_log_t hpm_log_ctx
static