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

LogTask (see log_task.h). More...

#include "log_task.h"
#include "log_queue.h"
#include "usb_link.h"
#include "proto_v2.h"
#include "fc_core.h"
#include "params.h"
#include "spsc.h"
#include "app_link.h"
#include <string.h>
#include "cmsis_os2.h"
Include dependency graph for log_task.c:

Go to the source code of this file.

Macros

#define PRE_EVENTS   8u
 
#define PRE_EVENT_MS   2000u
 

Enumerations

enum  { PORT_USB = 0 , PORT_BLE = 1 }
 

Functions

 SPSC_DEFINE (s_blein, log_cmd_t, 4u)
 
 SPSC_DEFINE (s_bleout, log_msg_t, 8u)
 
 SPSC_DEFINE (s_usbapp, appl_cmd_t, 8u)
 
void log_task_init (const log_task_cfg_t *cfg)
 
int log_task_ble_cmd (const log_cmd_t *c)
 0 = queued, -1 = full (answer BUSY)
 
int log_task_ble_take (log_msg_t *m)
 1 if a frame was taken
 
int log_task_usb_app_take (appl_cmd_t *c)
 1 if a command was taken
 
uint8_t log_task_pct (void)
 flash used %, 0xFF = no log flash (SYSTEM.log); any task
 
uint8_t log_task_busy (void)
 1 while a transfer is in progress (the task runs faster)
 
static void pump (void)
 
static int port_send (uint8_t port, uint8_t type, const void *p, uint8_t len)
 
static int port_room (uint8_t port)
 
static int port_room_ack (uint8_t port)
 
static void ack (uint8_t port, uint8_t op, uint8_t seq, uint8_t res, uint8_t why)
 
int log_task_wallclock (uint32_t now, uint32_t *unix_s, uint16_t *ms)
 wall clock set by the app (PV2_OP_SET_TIME): 0 and UTC time at uptime 'now', -1 if not set since reset.
 
static void append_time (uint32_t now)
 
static void close_log (void)
 
static void open_log (uint32_t now)
 
static void drain (uint32_t now)
 
static void recording (uint32_t now, uint8_t armed)
 
static void entry_of (const log_entry_t *e, uint8_t index, uint8_t count, pv2_log_entry_t *m)
 
static const log_entry_t * last_log (void)
 
static void cmd_list (uint8_t port, uint8_t seq)
 
static void cmd (uint8_t port, const uint8_t *c, uint32_t n, uint8_t armed, uint32_t now)
 
static void read_stream (uint8_t armed)
 
static int is_log_op (uint8_t op)
 
static int pauses (uint8_t op)
 
static void to_app (const uint8_t *c, uint32_t n)
 
void log_task_step (uint32_t now)
 
static void LogTask (void *arg)
 
void log_task_start (const log_task_cfg_t *cfg)
 

Variables

static log_task_cfg_t s_cfg
 
static uint8_t s_mounted
 
static volatile uint8_t s_pct = 0xFFu
 
static uint8_t s_was_armed
 
static uint32_t s_disarm_ms
 
static uint32_t s_cmd_ms
 
static uint8_t s_have_cmd
 
static log_event_t s_pre [PRE_EVENTS]
 
static uint8_t s_npre
 
struct { 
 
   uint8_t   set 
 
   uint32_t   up_ms 
 
   uint32_t   unix_s 
 
   uint16_t   ms 
 
   int16_t   tz_min 
 
} s_clk 
 
struct { 
 
   uint8_t   on 
 
   uint8_t   seq 
 
   uint8_t   port 
 
   uint16_t   id 
 
   uint32_t   off 
 
   uint32_t   end 
 
} s_rd 
 

Detailed Description

LogTask (see log_task.h).

Definition in file log_task.c.

Macro Definition Documentation

◆ PRE_EVENTS

#define PRE_EVENTS   8u

Definition at line 32 of file log_task.c.

◆ PRE_EVENT_MS

#define PRE_EVENT_MS   2000u

Definition at line 33 of file log_task.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PORT_USB 
PORT_BLE 

Definition at line 16 of file log_task.c.

Function Documentation

◆ SPSC_DEFINE() [1/3]

SPSC_DEFINE ( s_blein  ,
log_cmd_t  ,
4u   
)

◆ SPSC_DEFINE() [2/3]

SPSC_DEFINE ( s_bleout  ,
log_msg_t  ,
8u   
)

◆ SPSC_DEFINE() [3/3]

SPSC_DEFINE ( s_usbapp  ,
appl_cmd_t  ,
8u   
)

◆ log_task_init()

void log_task_init ( const log_task_cfg_t *  cfg)

Definition at line 53 of file log_task.c.

References log_task_cfg_t::flash, log_mount(), log_q_reset(), log_used_pct(), s_cfg, s_clk, s_disarm_ms, s_have_cmd, s_mounted, s_npre, s_pct, s_rd, s_was_armed, spsc_reset(), and usbl_reset().

Referenced by log_task_start().

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

◆ log_task_ble_cmd()

int log_task_ble_cmd ( const log_cmd_t *  c)

0 = queued, -1 = full (answer BUSY)

Definition at line 66 of file log_task.c.

References spsc_push().

Referenced by commands().

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

◆ log_task_ble_take()

int log_task_ble_take ( log_msg_t *  m)

1 if a frame was taken

Definition at line 67 of file log_task.c.

References spsc_pop().

Referenced by log_ble_out().

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

◆ log_task_usb_app_take()

int log_task_usb_app_take ( appl_cmd_t *  c)

1 if a command was taken

Definition at line 68 of file log_task.c.

References spsc_pop().

Referenced by usb_commands().

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

◆ log_task_pct()

uint8_t log_task_pct ( void  )

flash used %, 0xFF = no log flash (SYSTEM.log); any task

Definition at line 70 of file log_task.c.

References s_pct.

Referenced by app_start().

Here is the caller graph for this function:

◆ log_task_busy()

uint8_t log_task_busy ( void  )

1 while a transfer is in progress (the task runs faster)

Definition at line 71 of file log_task.c.

References s_rd.

Referenced by LogTask().

Here is the caller graph for this function:

◆ pump()

static void pump ( void  )
static

Definition at line 73 of file log_task.c.

References s_cfg, and log_task_cfg_t::usb_pump.

Referenced by ack(), cmd_list(), log_task_step(), and read_stream().

Here is the caller graph for this function:

◆ port_send()

static int port_send ( uint8_t  port,
uint8_t  type,
const void *  p,
uint8_t  len 
)
static

Definition at line 75 of file log_task.c.

References log_msg_t::len, log_msg_t::p, port, PORT_USB, spsc_push(), log_msg_t::type, and usbl_send().

Referenced by ack(), cmd_list(), and read_stream().

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

◆ port_room()

static int port_room ( uint8_t  port)
static

Definition at line 85 of file log_task.c.

References port, PORT_USB, PV2_LOG_DATA_MAX, spsc_count(), and usbl_tx_free().

Referenced by read_stream().

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

◆ port_room_ack()

static int port_room_ack ( uint8_t  port)
static

Definition at line 91 of file log_task.c.

References port, PORT_USB, spsc_count(), and usbl_tx_free().

Referenced by read_stream().

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

◆ ack()

static void ack ( uint8_t  port,
uint8_t  op,
uint8_t  seq,
uint8_t  res,
uint8_t  why 
)
static

Definition at line 97 of file log_task.c.

References port, port_send(), PORT_USB, pump(), PV2_FT_ACK, and seq.

Referenced by cmd(), cmd_list(), read_stream(), and to_app().

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

◆ log_task_wallclock()

int log_task_wallclock ( uint32_t  now_ms,
uint32_t *  unix_s,
uint16_t *  ms 
)

wall clock set by the app (PV2_OP_SET_TIME): 0 and UTC time at uptime 'now', -1 if not set since reset.

LogTask only.

Definition at line 105 of file log_task.c.

References ms, s_clk, and unix_s.

Referenced by append_time().

Here is the caller graph for this function:

◆ append_time()

static void append_time ( uint32_t  now)
static

Definition at line 114 of file log_task.c.

References log_append(), log_is_open(), log_task_wallclock(), LR_TIME, log_time_t::ms, s_clk, log_time_t::t_ms, log_time_t::tz_min, and log_time_t::unix_s.

Referenced by cmd(), and open_log().

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

◆ close_log()

static void close_log ( void  )
static

Definition at line 123 of file log_task.c.

References log_close(), and log_is_open().

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

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

◆ open_log()

static void open_log ( uint32_t  now)
static

Definition at line 129 of file log_task.c.

References append_time(), log_info_t::format, log_task_cfg_t::fw, log_info_t::fw, log_task_cfg_t::hw_rev, log_info_t::hw_rev, log_append(), LOG_FORMAT, log_open(), LR_EVENT, LR_INFO, PRE_EVENT_MS, s_cfg, s_npre, s_pre, log_task_cfg_t::sensors, log_info_t::sensors, and log_info_t::t0_ms.

Referenced by recording().

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

◆ drain()

static void drain ( uint32_t  now)
static

Definition at line 146 of file log_task.c.

References log_append(), log_is_open(), log_q_get(), log_q_take_drops(), LOG_REC_MAX, LOG_SRC_COUNT, LR_DROP, LR_EVENT, PRE_EVENTS, s_npre, and s_pre.

Referenced by recording().

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

◆ recording()

static void recording ( uint32_t  now,
uint8_t  armed 
)
static

Definition at line 166 of file log_task.c.

References close_log(), drain(), log_is_open(), LOG_POSTROLL_MS, log_q_set_active(), LOG_USB_PAUSE_MS, open_log(), P_LOG_MODE, PARAM, PARAM_LOG_ALWAYS, PARAM_LOG_ARMED, PARAM_LOG_OFF, s_cmd_ms, s_disarm_ms, s_have_cmd, and s_was_armed.

Referenced by log_task_step().

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

◆ entry_of()

static void entry_of ( const log_entry_t *  e,
uint8_t  index,
uint8_t  count,
pv2_log_entry_t *  m 
)
static

Definition at line 186 of file log_task.c.

References log_entry_t::active, pv2_log_entry_t::bytes, pv2_log_entry_t::count, pv2_log_entry_t::flags, log_entry_t::id, pv2_log_entry_t::id, pv2_log_entry_t::index, LOG_SECTOR, log_entry_t::nsect, pv2_log_entry_t::sectors, log_entry_t::t0_ms, pv2_log_entry_t::t0_ms, and log_entry_t::truncated.

Referenced by cmd_list().

Here is the caller graph for this function:

◆ last_log()

static const log_entry_t * last_log ( void  )
static

Definition at line 195 of file log_task.c.

References close_log(), log_count(), log_entry(), and n.

Referenced by cmd(), and cmd_list().

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

◆ cmd_list()

static void cmd_list ( uint8_t  port,
uint8_t  seq 
)
static

Definition at line 202 of file log_task.c.

References ack(), entry_of(), last_log(), log_count(), log_entry(), n, port, PORT_BLE, port_send(), pump(), PV2_ACK_OK, PV2_FT_LOG_ENTRY, PV2_OP_LOG_LIST, PV2_R_NONE, seq, and usbl_send().

Referenced by cmd().

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

◆ cmd()

static void cmd ( uint8_t  port,
const uint8_t *  c,
uint32_t  n,
uint8_t  armed,
uint32_t  now 
)
static

Definition at line 222 of file log_task.c.

References ack(), append_time(), close_log(), cmd_list(), log_task_cfg_t::erase_chip, log_task_cfg_t::flash, id, log_entry_t::id, last_log(), log_count(), log_erase_all(), log_mount(), log_size(), ms, n, off, port, PORT_BLE, PV2_ACK_BUSY, PV2_ACK_IN_PROGRESS, PV2_ACK_INVALID, PV2_ACK_OK, PV2_ACK_REJECTED, PV2_ACK_UNSUPPORTED, PV2_OP_HEARTBEAT, PV2_OP_LOG_ERASE, PV2_OP_LOG_LIST, PV2_OP_LOG_READ, PV2_OP_SET_TIME, PV2_R_ARMED, PV2_R_NONE, PV2_R_OUT_OF_RANGE, PV2_R_SENSOR_MISSING, s_cfg, s_clk, s_mounted, s_rd, and seq.

Referenced by a24(), itf_control(), log_task_step(), and usbl_poll().

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

◆ read_stream()

static void read_stream ( uint8_t  armed)
static

Definition at line 289 of file log_task.c.

References ack(), pv2_log_data_hdr_t::id, log_read(), port, port_room(), port_room_ack(), port_send(), PORT_USB, pump(), PV2_ACK_OK, PV2_ACK_REJECTED, PV2_FT_LOG_DATA, PV2_LOG_DATA_MAX, PV2_OP_LOG_READ, PV2_R_ARMED, PV2_R_NONE, and s_rd.

Referenced by log_task_step().

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

◆ is_log_op()

static int is_log_op ( uint8_t  op)
static

Definition at line 322 of file log_task.c.

References PV2_OP_LOG_ERASE, PV2_OP_LOG_LIST, and PV2_OP_LOG_READ.

Referenced by log_task_step(), and pauses().

Here is the caller graph for this function:

◆ pauses()

static int pauses ( uint8_t  op)
static

Definition at line 323 of file log_task.c.

References is_log_op().

Referenced by log_task_step().

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

◆ to_app()

static void to_app ( const uint8_t *  c,
uint32_t  n 
)
static

Definition at line 326 of file log_task.c.

References ack(), APPL_CMD_MAX, appl_cmd_t::b, appl_cmd_t::len, n, PORT_USB, PV2_ACK_BUSY, PV2_R_NONE, and spsc_push().

Referenced by log_task_step().

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

◆ log_task_step()

void log_task_step ( uint32_t  now)

Definition at line 334 of file log_task.c.

References fc_state_t::armed, b, cmd(), fc_snapshot(), is_log_op(), log_cmd_t::len, log_q_get(), log_q_take_drops(), LOG_REC_MAX, LOG_SRC_COUNT, log_used_pct(), n, log_cmd_t::op, log_cmd_t::p, pauses(), PORT_BLE, PORT_USB, pump(), PV2_OP_HEARTBEAT, PV2_OP_SET_TIME, read_stream(), recording(), s_cmd_ms, s_have_cmd, s_mounted, s_pct, log_cmd_t::seq, spsc_pop(), to_app(), USBL_CMD_MAX, and usbl_poll().

Referenced by LogTask().

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

◆ LogTask()

static void LogTask ( void *  arg)
static

Definition at line 376 of file log_task.c.

References log_task_busy(), log_task_step(), and usbl_open().

Referenced by log_task_start().

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

◆ log_task_start()

void log_task_start ( const log_task_cfg_t *  cfg)

Definition at line 385 of file log_task.c.

References log_task_init(), and LogTask().

Referenced by app_start().

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

Variable Documentation

◆ s_cfg

log_task_cfg_t s_cfg
static

Definition at line 24 of file log_task.c.

Referenced by cmd(), log_task_init(), open_log(), and pump().

◆ s_mounted

uint8_t s_mounted
static

Definition at line 25 of file log_task.c.

Referenced by cmd(), log_task_init(), and log_task_step().

◆ s_pct

volatile uint8_t s_pct = 0xFFu
static

Definition at line 26 of file log_task.c.

Referenced by log_task_init(), log_task_pct(), and log_task_step().

◆ s_was_armed

uint8_t s_was_armed
static

Definition at line 27 of file log_task.c.

Referenced by log_task_init(), and recording().

◆ s_disarm_ms

uint32_t s_disarm_ms
static

Definition at line 28 of file log_task.c.

Referenced by log_task_init(), and recording().

◆ s_cmd_ms

uint32_t s_cmd_ms
static

Definition at line 28 of file log_task.c.

Referenced by log_task_step(), and recording().

◆ s_have_cmd

uint8_t s_have_cmd
static

Definition at line 29 of file log_task.c.

Referenced by log_task_init(), log_task_step(), and recording().

◆ s_pre

log_event_t s_pre[PRE_EVENTS]
static

Definition at line 34 of file log_task.c.

Referenced by drain(), and open_log().

◆ s_npre

uint8_t s_npre
static

Definition at line 35 of file log_task.c.

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

◆ set

uint8_t set

Definition at line 39 of file log_task.c.

Referenced by apply(), cal_apply(), and fsh_apply_post().

◆ up_ms

uint32_t up_ms

Definition at line 40 of file log_task.c.

◆ unix_s

uint32_t unix_s

Definition at line 41 of file log_task.c.

Referenced by log_task_wallclock().

◆ ms

uint16_t ms

Definition at line 42 of file log_task.c.

Referenced by cmd(), dly(), dly(), dly(), dly(), exec(), log_task_wallclock(), on_state(), sh_run_once(), and USBD_LL_Delay().

◆ tz_min

int16_t tz_min

Definition at line 43 of file log_task.c.

◆ [struct]

struct { ... } s_clk

◆ on

uint8_t on

Definition at line 48 of file log_task.c.

Referenced by log_q_set_active(), set_used(), usbl_set_configured(), and usbl_set_dtr().

◆ seq

◆ port

uint8_t port

Definition at line 48 of file log_task.c.

Referenced by ack(), analog_pin(), cmd(), cmd_list(), port_room(), port_room_ack(), port_send(), and read_stream().

◆ id

uint16_t id

Definition at line 49 of file log_task.c.

Referenced by cmd(), mat3_inv(), put(), and pv2_param().

◆ off

uint32_t off

Definition at line 50 of file log_task.c.

Referenced by accel_fit(), cfg_flash_write(), cmd(), and log_read().

◆ end

uint32_t end

Definition at line 50 of file log_task.c.

◆ [struct]

struct { ... } s_rd