CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
lazy_file_log_sink.c File Reference
#include <stdint.h>
#include <stdio.h>
#include "log/log_a_logging_error.h"
#include "log/lazy_file_log_sink.h"
#include "log/log.h"
#include "timekeeping/timekeeping.h"
#include "littlefs/lfs.h"
#include "littlefs/littlefs_helper.h"
#include "main.h"
Include dependency graph for lazy_file_log_sink.c:

Classes

struct  LOG_file_context_struct_t

Functions

static int8_t LOG_close_current_log_file (void)
 Closed the current log file.
static int8_t LOG_open_new_log_file_and_set_as_current (void)
 Opens a new timestamped log file, and sets it as the current log file.
static int8_t LOG_ensure_current_log_file_is_open ()
static int8_t LOG_write_to_current_log_file (const char *msg, uint16_t msg_length)
 Writes to the current log file.
void LOG_to_file_lazy (const char filename[], const char msg[])
 Write a log message to an LFS log file.
int8_t LOG_sync_current_log_file (void)
 Syncs the current log file.
int8_t LOG_emergency_sync_current_log_file (void)
 Syncs the current log file as minimally as possible.
void LOG_subtask_handle_sync_and_close_of_current_log_file ()
 Flush the current LittleFS log file(s), forcing a write to flash.

Variables

uint32_t LOG_file_flush_interval_sec = 60
 Interval in seconds at which to flush the log file to the filesystem.
uint32_t LOG_file_rotation_interval_sec = 1800
 Interval in seconds where a new dated log file is created, and the old file is closed.
static uint8_t lfs_log_cache_buffer [FLASH_CHIP_PAGE_SIZE_BYTES]
static struct lfs_attr lfs_log_file_attr
static struct lfs_file_config lfs_log_file_config
static LOG_file_context_struct_t LOG_current_log_file_ctx

Function Documentation

◆ LOG_close_current_log_file()

int8_t LOG_close_current_log_file ( void )
static

Closed the current log file.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_emergency_sync_current_log_file()

int8_t LOG_emergency_sync_current_log_file ( void )

Syncs the current log file as minimally as possible.

Note
Intended to be used in exception handlers (recovery) and similar.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_ensure_current_log_file_is_open()

int8_t LOG_ensure_current_log_file_is_open ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_open_new_log_file_and_set_as_current()

int8_t LOG_open_new_log_file_and_set_as_current ( void )
static

Opens a new timestamped log file, and sets it as the current log file.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_subtask_handle_sync_and_close_of_current_log_file()

void LOG_subtask_handle_sync_and_close_of_current_log_file ( )

Flush the current LittleFS log file(s), forcing a write to flash.

Note
This function is meant to be called periodically in an RTOS task.
This function can be called very frequently. It tracks its own internal configuration.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_sync_current_log_file()

int8_t LOG_sync_current_log_file ( void )

Syncs the current log file.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_to_file_lazy()

void LOG_to_file_lazy ( const char filename[],
const char msg[] )

Write a log message to an LFS log file.

Parameters
msgThe message to be logged
Note
LFS files are not updated until the file is closed or synced. Syncing is done periodically in the rtos_background_upkeep task.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_write_to_current_log_file()

int8_t LOG_write_to_current_log_file ( const char * msg,
uint16_t msg_length )
static

Writes to the current log file.

Returns
0 on success, negative LFS error codes on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ lfs_log_cache_buffer

uint8_t lfs_log_cache_buffer[FLASH_CHIP_PAGE_SIZE_BYTES]
static

◆ lfs_log_file_attr

struct lfs_attr lfs_log_file_attr
static

◆ lfs_log_file_config

struct lfs_file_config lfs_log_file_config
static
Initial value:
= {
.attrs = &lfs_log_file_attr,
.attr_count = 0
}
static uint8_t lfs_log_cache_buffer[FLASH_CHIP_PAGE_SIZE_BYTES]
Definition lazy_file_log_sink.c:24
static struct lfs_attr lfs_log_file_attr
Definition lazy_file_log_sink.c:25

◆ LOG_current_log_file_ctx

LOG_file_context_struct_t LOG_current_log_file_ctx
static

◆ LOG_file_flush_interval_sec

uint32_t LOG_file_flush_interval_sec = 60

Interval in seconds at which to flush the log file to the filesystem.

Note
Nominal: 60 seconds = 1 minute.

◆ LOG_file_rotation_interval_sec

uint32_t LOG_file_rotation_interval_sec = 1800

Interval in seconds where a new dated log file is created, and the old file is closed.

Note
Nominal: 1800 seconds = 30 minutes.