跳转至

lib/logger/uart_adapts/uart_inits.c

Functions

Name
CFBD_UARTHandle * asUARTNative(void * native_handle)
void log_native_sync(void * native_handle, const char * buffer, const uint16_t buffer_size)
void log_native_async(void * native_handle, const char * buffer, const uint16_t buffer_size)
uint32_t log_timestamp(void * _)
void CFBD_InitLoggerWithUART(CFBD_Logger * logger, CFBD_UARTHandle * uart_handle, cfbd_log_level_t filter_level, CFBD_Bool async_ok)

Attributes

Name
uint8_t[CFBD_LOG_BUFFER_SZ] logger_buffer
CFBD_NativeLoggerOperations sync_ops
CFBD_NativeLoggerOperations async_ops

Functions Documentation

function asUARTNative

static inline CFBD_UARTHandle * asUARTNative(
    void * native_handle
)

function log_native_sync

static void log_native_sync(
    void * native_handle,
    const char * buffer,
    const uint16_t buffer_size
)

function log_native_async

static void log_native_async(
    void * native_handle,
    const char * buffer,
    const uint16_t buffer_size
)

function log_timestamp

static uint32_t log_timestamp(
    void * _
)

function CFBD_InitLoggerWithUART

void CFBD_InitLoggerWithUART(
    CFBD_Logger * logger,
    CFBD_UARTHandle * uart_handle,
    cfbd_log_level_t filter_level,
    CFBD_Bool async_ok
)

Attributes Documentation

variable logger_buffer

static uint8_t[CFBD_LOG_BUFFER_SZ] logger_buffer;

variable sync_ops

static CFBD_NativeLoggerOperations sync_ops = {.log_native = log_native_sync,
                                               .timestamp = log_timestamp};

variable async_ops

static CFBD_NativeLoggerOperations async_ops = {.log_native = log_native_async,
                                                .timestamp = log_timestamp};

Source code

#pragma once
#include <stdint.h>

#include "app.h"
#include "cfbd_define.h"
#include "cfbd_log.h"
#include "cfbd_log_configs.h"
#include "uart.h"

static uint8_t logger_buffer[CFBD_LOG_BUFFER_SZ];

static inline CFBD_UARTHandle* asUARTNative(void* native_handle)
{
    return (CFBD_UARTHandle*) native_handle;
}

static void log_native_sync(void* native_handle, const char* buffer, const uint16_t buffer_size)
{
    CFBD_UARTHandle* uart = asUARTNative(native_handle);
    uart->ops->sync_send(uart, (uint8_t*) buffer, buffer_size);
}

static void log_native_async(void* native_handle, const char* buffer, const uint16_t buffer_size)
{
    CFBD_UARTHandle* uart = asUARTNative(native_handle);
    uart->ops->async_send(uart, (uint8_t*) buffer, buffer_size);
}

static uint32_t log_timestamp(void* _)
{
    return getApp(CFBD_FALSE)->tick_provider();
}

static CFBD_NativeLoggerOperations sync_ops = {.log_native = log_native_sync,
                                               .timestamp = log_timestamp};

static CFBD_NativeLoggerOperations async_ops = {.log_native = log_native_async,
                                                .timestamp = log_timestamp};

void CFBD_InitLoggerWithUART(CFBD_Logger* logger,
                             CFBD_UARTHandle* uart_handle,
                             cfbd_log_level_t filter_level,
                             CFBD_Bool async_ok)
{
    if (async_ok) {
        CFBD_InitLogger(logger,
                        &async_ops,
                        uart_handle,
                        filter_level,
                        logger_buffer,
                        CFBD_LOG_BUFFER_SZ);
    }
    else {
        CFBD_InitLogger(logger,
                        &sync_ops,
                        uart_handle,
                        filter_level,
                        logger_buffer,
                        CFBD_LOG_BUFFER_SZ);
    }
}

Updated on 2026-02-03 at 13:21:55 +0000