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

BattTask: owns the battery ADC and the battery monitor (battery.c). More...

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

Go to the source code of this file.

Data Structures

struct  batt_task_cfg_t
 
struct  batt_flight_t
 last flight summary (AppTask persists it for the BATTERY calibration) More...
 

Macros

#define BATT_TASK_PERIOD_MS   20u
 

Functions

void batt_task_init (const batt_task_cfg_t *cfg)
 
void batt_task_step (uint32_t now_ms)
 
int batt_task_post_scales (float scale_v, float scale_i)
 AppTask -> BattTask: new calibration scales; 0 = queued.
 
void batt_task_last_flight (batt_flight_t *out)
 last flight (any task, seqlock)
 
void batt_task_start (const batt_task_cfg_t *cfg)
 

Detailed Description

BattTask: owns the battery ADC and the battery monitor (battery.c).

A task of its own, so the battery logic stays out of the flight loop:

  • every 20 ms it reads the two ADC pins (board binding), runs batt_step() and publishes the battery state (batt_read(), seqlock);
  • when the warning level or the presence changes it signals the flight core with fc_batt_signal() (SPSC queue drained in fc_service());
  • every step it refreshes the heartbeat (fc_batt_heartbeat()): if the task stops, the flight core treats the battery as unknown;
  • BATTERY calibration scales arrive from the AppTask through an SPSC queue (batt_task_post_scales()).

The flight core keeps the decisions (land, RTH, events), because it owns the flight state. batt_task_step() is plain C and runs on the host; the RTOS loop is at the end of batt_task.c.

Definition in file batt_task.h.

Macro Definition Documentation

◆ BATT_TASK_PERIOD_MS

#define BATT_TASK_PERIOD_MS   20u

Definition at line 26 of file batt_task.h.

Function Documentation

◆ batt_task_init()

void batt_task_init ( const batt_task_cfg_t *  cfg)

Definition at line 27 of file batt_task.c.

References batt_task_cfg_t::batt, batt_init(), s_cfg, s_fl, s_fl_seq, s_have_last, s_sig_level, s_sig_present, s_used_at_arm, s_was_armed, and spsc_reset().

Referenced by batt_task_start().

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

◆ batt_task_step()

void batt_task_step ( uint32_t  now_ms)

Definition at line 58 of file batt_task.c.

References batt_task_cfg_t::adc_read, fc_state_t::armed, b, batt_get_cfg(), batt_set_scales(), batt_state(), batt_step(), BATT_TASK_PERIOD_MS, batt_flight_t::count, fc_batt_heartbeat(), fc_batt_signal(), fc_snapshot(), L, logf_power(), P_BATT_CAPACITY, P_BATT_CELLS, P_BATT_CRIT, P_BATT_EMERG, P_BATT_WARN, PARAM, fc_batt_sig_t::present, s_cfg, s_fl, s_fl_seq, s_have_last, s_last, s_log_div, s_sig_level, s_sig_present, s_used_at_arm, s_was_armed, scales_t::scale_i, batt_flight_t::scale_i, batt_cfg_t::scale_i, scales_t::scale_v, SPSC_BARRIER, spsc_pop(), and batt_flight_t::used_mah.

Referenced by BattTask().

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

◆ batt_task_post_scales()

int batt_task_post_scales ( float  scale_v,
float  scale_i 
)

AppTask -> BattTask: new calibration scales; 0 = queued.

Definition at line 40 of file batt_task.c.

References s, and spsc_push().

Referenced by cal_apply().

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

◆ batt_task_last_flight()

void batt_task_last_flight ( batt_flight_t *  out)

last flight (any task, seqlock)

Definition at line 46 of file batt_task.c.

References s_fl, s_fl_seq, and SPSC_BARRIER.

Referenced by battery_flight().

Here is the caller graph for this function:

◆ batt_task_start()

void batt_task_start ( const batt_task_cfg_t *  cfg)

Definition at line 124 of file batt_task.c.

References batt_task_init(), and BattTask().

Referenced by app_start().

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