48 for (
int tries = 0; tries < 8; ++tries) {
50 if (s0 & 1u)
continue;
54 if (
s_fl_seq == s0) { *out = v;
return; }
67 memset(&f, 0,
sizeof f);
70 float pv = 0.0f, pi = 0.0f;
82 const float mv =
b->cell_v * 1000.0f;
111#include "cmsis_os2.h"
116 uint32_t
next = osKernelGetTickCount();
120 (void)osDelayUntil(
next);
129 static const osThreadAttr_t a = { .name =
"batt", .priority = osPriorityNormal,
131 (void)osThreadNew(
BattTask, NULL, &a);
static uint8_t s_sig_level
static batt_task_cfg_t s_cfg
static float s_used_at_arm
void batt_task_last_flight(batt_flight_t *out)
last flight (any task, seqlock)
int batt_task_post_scales(float sv, float si)
AppTask -> BattTask: new calibration scales; 0 = queued.
void batt_task_step(uint32_t now)
void batt_task_init(const batt_task_cfg_t *cfg)
static void BattTask(void *arg)
static uint8_t s_was_armed
static uint8_t s_have_last
static batt_flight_t s_fl
void batt_task_start(const batt_task_cfg_t *cfg)
static uint8_t s_sig_present
static volatile uint32_t s_fl_seq
BattTask: owns the battery ADC and the battery monitor (battery.c).
#define BATT_TASK_PERIOD_MS
void batt_init(const batt_cfg_t *cfg)
const batt_state_t * batt_state(void)
state as computed by the last step (same context)
void batt_get_cfg(batt_cfg_t *out)
void batt_set_scales(float sv, float si)
void batt_step(float pin_v, float cur_pin_v, uint32_t dt_ms, uint8_t armed, const batt_limits_t *L)
one sample: pin voltages, time step, armed flag (flight-control context)
int fc_batt_signal(const fc_batt_sig_t *b)
0 = queued, -1 = full
void fc_batt_heartbeat(uint32_t now)
every BattTask step
void fc_snapshot(fc_state_t *out)
Flight core: arming, modes, automatic actions, failsafes, motor test (HANDOVER_FW....
void logf_power(uint32_t t, const batt_state_t *b)
Producers' side of the flight log: build a record from the values the task already has and queue it (...
static uint16_t next(uint16_t s)
Drone parameters of protocol v2 (HANDOVER_FW.md ยง8, ids.ts PARAMS).
ACwing Pilot app protocol v2: identifiers and frame layouts.
Lock-free single-producer single-consumer queue of fixed-size items.
#define SPSC_DEFINE(name, type, n)
static int spsc_push(spsc_t *q, const void *it)
static void spsc_reset(spsc_t *q)
static int spsc_pop(spsc_t *q, void *it)
float scale_i
current multiplier (1 = nominal sensor)
last flight summary (AppTask persists it for the BATTERY calibration)
float used_mah
charge used between ARM and DISARM
uint16_t count
flights finished since boot
float scale_i
current scale it was counted with
thresholds and settings (from the parameters)
int(* adc_read)(float *vbat_pin, float *cur_pin)
ADC binding: pin voltages of VBAT and CUR; 0 = sample ready.
batt_cfg_t batt
sensor gains, scales at boot
battery signal (BattTask -> core): sent when the level or presence changes
uint8_t present
battery connected
published state (AppTask builds FLIGHT / MOTORS from it)