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

LogTask: owns the log flash, writes the flight log and serves the log download over USB. More...

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

Go to the source code of this file.

Data Structures

struct  log_task_cfg_t
 
struct  log_cmd_t
 a log command received over BLE (op, seq, arguments as written by the app) More...
 
struct  log_msg_t
 an answer frame for BLE: type and payload (LOG_ENTRY, LOG_DATA, ACK) More...
 

Macros

#define LOG_POSTROLL_MS   1000u
 keep logging after DISARM

 
#define LOG_TIME_MIN_UNIX   1704067200u
 2024-01-01: SET_TIME before this is refused
 
#define LOG_USB_PAUSE_MS   5000u
 no recording after a log command (USB or BLE)
 

Functions

void log_task_init (const log_task_cfg_t *cfg)
 
void log_task_step (uint32_t now_ms)
 
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)
 
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.
 
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
 
void log_task_start (const log_task_cfg_t *cfg)
 

Detailed Description

LogTask: owns the log flash, writes the flight log and serves the log download over USB.

  • Recording. Producers (ImuTask, BattTask) put records in their own queue (log/log_queue.h); the LogTask drains them into the store (log/log_store.h). Parameter logMode: 0 off, 1 from ARM to 1 s after DISARM (one log per flight), 2 always (one log per power-on).
  • Download. USB CDC carries protocol v2 frames (telemetry/usb_link.h): LOG_LIST (0x50) → LOG_ENTRY frames, LOG_READ (0x51) → LOG_DATA frames, LOG_ERASE (0x52, "WIPE"); every command is answered with an ACK, sent after its data (so the ACK means "complete"). Recording pauses (the open log is closed) while the PC talks to the drone and for 5 s after; LOG_READ and LOG_ERASE are refused when armed.
  • Download over BLE: the last flight only. The AppTask forwards LOG_LIST / LOG_READ received on the BLE CMD characteristic (log_task_ble_cmd()) and sends the answer frames on the BLE HI ring (log_task_ble_take()), so the AppTask stays the only producer of that ring. Over BLE, LOG_LIST lists only the newest log, LOG_READ accepts only that log, LOG_LIST is refused when armed and LOG_ERASE is UNSUPPORTED: the whole memory and the erase go over USB.

log_task_step() is plain C (host test); the RTOS loop is at the end of log_task.c.

Definition in file log_task.h.

Macro Definition Documentation

◆ LOG_POSTROLL_MS

#define LOG_POSTROLL_MS   1000u

keep logging after DISARM

Definition at line 35 of file log_task.h.

◆ LOG_TIME_MIN_UNIX

#define LOG_TIME_MIN_UNIX   1704067200u

2024-01-01: SET_TIME before this is refused

Definition at line 36 of file log_task.h.

◆ LOG_USB_PAUSE_MS

#define LOG_USB_PAUSE_MS   5000u

no recording after a log command (USB or BLE)

Definition at line 37 of file log_task.h.

Function Documentation

◆ 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_step()

void log_task_step ( uint32_t  now_ms)

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:

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

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

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