ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
log_store.h File Reference

Flight-log store: ring of sectors on a NOR flash (format in log_format.h). More...

#include <stdint.h>
#include "log_format.h"
Include dependency graph for log_store.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  log_flash_t
 flash backend; addresses in bytes from the start of the log area More...
 
struct  log_entry_t
 

Macros

#define LOG_LIST_MAX   64u
 

Functions

int log_mount (const log_flash_t *f)
 0 = ok (empty flash is ok)
 
uint8_t log_count (void)
 
const log_entry_t * log_entry (uint8_t index)
 oldest first
 
const log_entry_t * log_find (uint16_t id)
 
uint8_t log_used_pct (void)
 
int log_open (uint32_t t0_ms)
 0 = ok
 
int log_append (uint8_t type, const void *payload, uint8_t len)
 
int log_close (void)
 
uint8_t log_is_open (void)
 
int log_read (uint16_t id, uint32_t offset, void *buf, uint32_t n)
 bytes of a closed log 'id' from 'offset' (sectors concatenated, headers included)
 
uint32_t log_size (uint16_t id)
 nsect × LOG_SECTOR, 0 unknown
 
int log_erase_all (void)
 erases every sector that holds data; logs restart from id 1
 

Detailed Description

Flight-log store: ring of sectors on a NOR flash (format in log_format.h).

The store works on any flash described by log_flash_t: the W25Q128JV of the ACwing FC (drivers/w25q) or a RAM area on the bench (bsp/log_flash_ram.c). It is used by one task only (the LogTask), so it has no locks. Host-testable.

  • log_mount() reads every sector header once and rebuilds the list of logs and the write position (newest sector serial + 1).
  • log_open() starts a new log at a fresh sector; log_append() packs records into a page buffer and programs whole pages; log_close() flushes the last page. A power loss loses at most the page in RAM.
  • When the ring wraps, the oldest sector is erased: the oldest log becomes "truncated" or disappears.

Definition in file log_store.h.

Macro Definition Documentation

◆ LOG_LIST_MAX

#define LOG_LIST_MAX   64u

Definition at line 25 of file log_store.h.

Function Documentation

◆ log_mount()

int log_mount ( const log_flash_t *  f)

0 = ok (empty flash is ok)

Definition at line 82 of file log_store.c.

References F, log_entry_t::first, log_entry_t::id, is_used(), log_sector_hdr_t::log_id, LOG_LIST_MAX, LOG_SECTOR, next(), log_entry_t::nsect, read_hdr(), s, s_last_id, s_list, s_n, s_nsect, s_open, s_serial, s_used, s_wp, log_sector_hdr_t::seq, log_sector_hdr_t::serial, set_used(), log_flash_t::size, log_sector_hdr_t::t0_ms, log_entry_t::t0_ms, and log_entry_t::truncated.

Referenced by cmd(), and log_task_init().

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

◆ log_count()

uint8_t log_count ( void  )

Definition at line 120 of file log_store.c.

References s_n.

Referenced by cmd(), cmd_list(), and last_log().

Here is the caller graph for this function:

◆ log_entry()

const log_entry_t * log_entry ( uint8_t  index)

oldest first

Definition at line 121 of file log_store.c.

References s_list, and s_n.

Referenced by cmd_list(), and last_log().

Here is the caller graph for this function:

◆ log_find()

const log_entry_t * log_find ( uint16_t  id)

Definition at line 124 of file log_store.c.

References s_list, and s_n.

Referenced by log_read(), and log_size().

Here is the caller graph for this function:

◆ log_used_pct()

uint8_t log_used_pct ( void  )

Definition at line 130 of file log_store.c.

References is_used(), n, s, and s_nsect.

Referenced by log_task_init(), and log_task_step().

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

◆ log_open()

int log_open ( uint32_t  t0_ms)

0 = ok

Definition at line 182 of file log_store.c.

References F, s_last_id, s_open, s_seq, s_t0, and start_sector().

Referenced by open_log().

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

◆ log_append()

int log_append ( uint8_t  type,
const void *  payload,
uint8_t  len 
)

Definition at line 193 of file log_store.c.

References log_entry_t::active, flush_page(), log_crc8(), LOG_PAGE, LOG_REC_MAX, LOG_REC_OVERHEAD, LOG_SECTOR, n, s_list, s_n, s_open, s_page, s_page_base, s_pos, and start_sector().

Referenced by append_time(), drain(), and open_log().

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

◆ log_close()

int log_close ( void  )

Definition at line 214 of file log_store.c.

References log_entry_t::active, flush_page(), s_list, s_n, and s_open.

Referenced by close_log().

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

◆ log_is_open()

uint8_t log_is_open ( void  )

Definition at line 122 of file log_store.c.

References s_open.

Referenced by append_time(), close_log(), drain(), and recording().

Here is the caller graph for this function:

◆ log_read()

int log_read ( uint16_t  id,
uint32_t  offset,
void *  buf,
uint32_t  n 
)

bytes of a closed log 'id' from 'offset' (sectors concatenated, headers included)

Definition at line 230 of file log_store.c.

References log_entry_t::active, addr(), b, log_flash_t::ctx, F, log_entry_t::first, log_find(), LOG_SECTOR, n, log_entry_t::nsect, off, log_flash_t::read, and s_nsect.

Referenced by read_stream().

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

◆ log_size()

uint32_t log_size ( uint16_t  id)

nsect × LOG_SECTOR, 0 unknown

Definition at line 224 of file log_store.c.

References log_find(), LOG_SECTOR, and log_entry_t::nsect.

Referenced by cmd().

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

◆ log_erase_all()

int log_erase_all ( void  )

erases every sector that holds data; logs restart from id 1

Definition at line 246 of file log_store.c.

References addr(), log_flash_t::ctx, log_flash_t::erase, F, is_used(), s, s_last_id, s_n, s_nsect, s_open, s_wp, and set_used().

Referenced by cmd().

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