ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
fc_shared.c
Go to the documentation of this file.
1
4#include "fc_shared.h"
5#include "spsc.h"
6
7volatile uint8_t g_fsh_cal_want;
8
9static volatile uint32_t s_seq;
11
14
15void fsh_reset(void)
16{
17 s_seq = 0u;
18 g_fsh_cal_want = 0u;
19 spsc_reset(&s_calq);
20 spsc_reset(&s_appq);
21}
22
24{
25 s_seq++;
27 s_est = *s;
29 s_seq++;
30}
31
33{
34 for (int tries = 0; tries < 8; ++tries) {
35 const uint32_t s0 = s_seq;
36 if (s0 & 1u) continue;
38 const fsh_est_t v = s_est;
40 if (s_seq == s0) { *out = v; return; }
41 }
42}
43
44int fsh_cal_push(const cal_sample_t *s) { return spsc_push(&s_calq, s); }
45int fsh_cal_pop(cal_sample_t *s) { return spsc_pop(&s_calq, s); }
46
47int fsh_apply_post(uint8_t type, const cal_set_t *set)
48{
50 a.type = type;
51 a.set = *set;
52 return spsc_push(&s_appq, &a);
53}
54
55int fsh_apply_take(fsh_apply_t *a) { return spsc_pop(&s_appq, a); }
static batt_state_t s
Definition battery.c:21
int fsh_cal_push(const cal_sample_t *s)
Definition fc_shared.c:44
void fsh_reset(void)
Definition fc_shared.c:15
int fsh_apply_take(fsh_apply_t *a)
Definition fc_shared.c:55
volatile uint8_t g_fsh_cal_want
calibration samples (ImuTask -> AppTask)
Definition fc_shared.c:7
int fsh_apply_post(uint8_t type, const cal_set_t *set)
Definition fc_shared.c:47
void fsh_est_write(const fsh_est_t *s)
ImuTask.
Definition fc_shared.c:23
int fsh_cal_pop(cal_sample_t *s)
Definition fc_shared.c:45
static volatile uint32_t s_seq
Definition fc_shared.c:9
static fsh_est_t s_est
Definition fc_shared.c:10
void fsh_est_read(fsh_est_t *out)
AppTask: keeps *out on a race.
Definition fc_shared.c:32
Data exchanged between the flight context (ImuTask) and the AppTask.
uint8_t set
Definition log_task.c:39
Lock-free single-producer single-consumer queue of fixed-size items.
#define SPSC_BARRIER()
Definition spsc.h:18
#define SPSC_DEFINE(name, type, n)
Definition spsc.h:29
static int spsc_push(spsc_t *q, const void *it)
Definition spsc.h:35
static void spsc_reset(spsc_t *q)
Definition spsc.h:33
static int spsc_pop(spsc_t *q, void *it)
Definition spsc.h:45
calibration to apply (AppTask -> ImuTask)
Definition fc_shared.h:46
uint8_t type
Definition fc_shared.h:46
cal_set_t set
Definition fc_shared.h:46