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

Flight-log store (see log_store.h). More...

#include "log_store.h"
#include <string.h>
Include dependency graph for log_store.c:

Go to the source code of this file.

Functions

uint8_t log_crc8 (const uint8_t *p, uint32_t n)
 
uint16_t log_crc16 (const uint8_t *p, uint32_t n)
 
static uint32_t addr (uint16_t sect)
 
static uint16_t next (uint16_t s)
 
static void set_used (uint16_t s, uint8_t on)
 
static uint8_t is_used (uint16_t s)
 
static int hdr_ok (const log_sector_hdr_t *h)
 
static int read_hdr (uint16_t s, log_sector_hdr_t *h)
 
static void forget_sector (uint16_t sect)
 
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 i)
 oldest first
 
uint8_t log_is_open (void)
 
const log_entry_t * log_find (uint16_t id)
 
uint8_t log_used_pct (void)
 
static int flush_page (void)
 
static int start_sector (void)
 
int log_open (uint32_t t0)
 0 = ok
 
int log_append (uint8_t type, const void *payload, uint8_t len)
 
int log_close (void)
 
uint32_t log_size (uint16_t id)
 nsect × LOG_SECTOR, 0 unknown
 
int log_read (uint16_t id, uint32_t off, void *buf, uint32_t n)
 bytes of a closed log 'id' from 'offset' (sectors concatenated, headers included)
 
int log_erase_all (void)
 erases every sector that holds data; logs restart from id 1
 

Variables

static const log_flash_t * F
 
static uint16_t s_nsect
 
static uint16_t s_wp
 
static uint32_t s_serial
 
static uint16_t s_last_id
 
static uint8_t s_used [4096/8]
 
static log_entry_t s_list [LOG_LIST_MAX]
 
static uint8_t s_n
 
static uint8_t s_open
 
static uint16_t s_cur
 
static uint16_t s_seq
 
static uint32_t s_t0
 
static uint32_t s_pos
 
static uint8_t s_page [LOG_PAGE]
 
static uint32_t s_page_base
 

Detailed Description

Flight-log store (see log_store.h).

Definition in file log_store.c.

Function Documentation

◆ log_crc8()

uint8_t log_crc8 ( const uint8_t *  p,
uint32_t  n 
)

Definition at line 28 of file log_store.c.

References n.

Referenced by log_append().

Here is the caller graph for this function:

◆ log_crc16()

uint16_t log_crc16 ( const uint8_t *  p,
uint32_t  n 
)

Definition at line 38 of file log_store.c.

References n.

Referenced by hdr_ok(), and start_sector().

Here is the caller graph for this function:

◆ addr()

static uint32_t addr ( uint16_t  sect)
static

Definition at line 49 of file log_store.c.

References LOG_SECTOR.

Referenced by baro_setup(), flush_page(), log_erase_all(), log_read(), read_hdr(), single_op(), start_sector(), USBD_LL_SetUSBAddress(), w25q_erase_sector(), w25q_prog(), and w25q_read().

Here is the caller graph for this function:

◆ next()

static uint16_t next ( uint16_t  s)
static

Definition at line 50 of file log_store.c.

References s, and s_nsect.

Referenced by BattTask(), forget_sector(), log_mount(), and start_sector().

Here is the caller graph for this function:

◆ set_used()

static void set_used ( uint16_t  s,
uint8_t  on 
)
static

Definition at line 51 of file log_store.c.

References on, s, and s_used.

Referenced by forget_sector(), log_erase_all(), log_mount(), and start_sector().

Here is the caller graph for this function:

◆ is_used()

static uint8_t is_used ( uint16_t  s)
static

Definition at line 55 of file log_store.c.

References s, and s_used.

Referenced by forget_sector(), log_erase_all(), log_mount(), and log_used_pct().

Here is the caller graph for this function:

◆ hdr_ok()

static int hdr_ok ( const log_sector_hdr_t *  h)
static

Definition at line 57 of file log_store.c.

References log_sector_hdr_t::crc, log_sector_hdr_t::format, log_crc16(), LOG_FORMAT, LOG_HDR_SIZE, LOG_MAGIC, and log_sector_hdr_t::magic.

Referenced by read_hdr().

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

◆ read_hdr()

static int read_hdr ( uint16_t  s,
log_sector_hdr_t *  h 
)
static

Definition at line 63 of file log_store.c.

References addr(), log_flash_t::ctx, F, hdr_ok(), log_flash_t::read, and s.

Referenced by log_mount().

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

◆ forget_sector()

static void forget_sector ( uint16_t  sect)
static

Definition at line 70 of file log_store.c.

References log_entry_t::first, is_used(), next(), s_list, s_n, set_used(), and log_entry_t::truncated.

Referenced by start_sector().

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

◆ 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  i)

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_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_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:

◆ flush_page()

static int flush_page ( void  )
static

Definition at line 139 of file log_store.c.

References addr(), log_flash_t::ctx, F, log_flash_t::prog, s_cur, s_page, s_page_base, s_pos, and used.

Referenced by log_append(), and log_close().

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

◆ start_sector()

static int start_sector ( void  )
static

Definition at line 150 of file log_store.c.

References log_entry_t::active, addr(), log_sector_hdr_t::crc, log_flash_t::ctx, log_flash_t::erase, F, log_entry_t::first, forget_sector(), log_sector_hdr_t::format, log_entry_t::id, log_crc16(), LOG_FORMAT, LOG_HDR_SIZE, log_sector_hdr_t::log_id, LOG_LIST_MAX, LOG_MAGIC, log_sector_hdr_t::magic, next(), log_entry_t::nsect, s_cur, s_last_id, s_list, s_n, s_nsect, s_page, s_page_base, s_pos, s_seq, s_serial, s_t0, s_wp, log_sector_hdr_t::seq, log_sector_hdr_t::serial, set_used(), log_sector_hdr_t::t0_ms, and log_entry_t::t0_ms.

Referenced by log_append(), and log_open().

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

◆ log_open()

int log_open ( uint32_t  t0)

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_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_read()

int log_read ( uint16_t  id,
uint32_t  off,
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_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:

Variable Documentation

◆ F

const log_flash_t* F
static

◆ s_nsect

uint16_t s_nsect
static

Definition at line 9 of file log_store.c.

Referenced by log_erase_all(), log_mount(), log_read(), log_used_pct(), next(), and start_sector().

◆ s_wp

uint16_t s_wp
static

Definition at line 10 of file log_store.c.

Referenced by log_erase_all(), log_mount(), and start_sector().

◆ s_serial

uint32_t s_serial
static

Definition at line 11 of file log_store.c.

Referenced by log_mount(), and start_sector().

◆ s_last_id

uint16_t s_last_id
static

Definition at line 12 of file log_store.c.

Referenced by log_erase_all(), log_mount(), log_open(), and start_sector().

◆ s_used

uint8_t s_used[4096/8]
static

Definition at line 13 of file log_store.c.

Referenced by is_used(), log_mount(), and set_used().

◆ s_list

log_entry_t s_list[LOG_LIST_MAX]
static

◆ s_n

uint8_t s_n
static

◆ s_open

uint8_t s_open
static

Definition at line 19 of file log_store.c.

Referenced by log_append(), log_close(), log_erase_all(), log_is_open(), log_mount(), and log_open().

◆ s_cur

uint16_t s_cur
static

Definition at line 20 of file log_store.c.

Referenced by flush_page(), and start_sector().

◆ s_seq

uint16_t s_seq
static

Definition at line 21 of file log_store.c.

Referenced by log_open(), and start_sector().

◆ s_t0

uint32_t s_t0
static

Definition at line 22 of file log_store.c.

Referenced by log_open(), and start_sector().

◆ s_pos

uint32_t s_pos
static

Definition at line 23 of file log_store.c.

Referenced by flush_page(), log_append(), and start_sector().

◆ s_page

uint8_t s_page[LOG_PAGE]
static

Definition at line 24 of file log_store.c.

Referenced by flush_page(), log_append(), and start_sector().

◆ s_page_base

uint32_t s_page_base
static

Definition at line 25 of file log_store.c.

Referenced by flush_page(), log_append(), and start_sector().