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

Receive side of the ACwing Pilot link (HANDOVER_FW.md §2 and §6). More...

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

Go to the source code of this file.

Data Structures

struct  appl_cmd_t
 
struct  appl_rc_t
 

Macros

#define APPL_CMD_MAX   20u
 
#define APPL_QUEUE_LEN   16u
 power of 2, >= 8 required by the handover
 

Functions

void appl_reset (void)
 
void appl_on_cmd_write (const uint8_t *data, uint16_t len, uint32_t now_ms)
 
void appl_on_connect (void)
 
void appl_on_disconnect (void)
 
int appl_pop (appl_cmd_t *out)
 1 if a command was taken
 
uint32_t appl_queue_dropped (void)
 
uint8_t appl_ever (void)
 1 once any CMD frame arrived
 
uint32_t appl_last_ms (void)
 time of the last CMD frame

 
uint8_t appl_link_down (void)
 GAP disconnected since then

 
uint32_t appl_silence_ms (uint32_t now_ms, uint32_t down_floor_ms)
 Silence seen by the failsafe: now - last CMD frame, at least 'down_floor_ms' while the link is reported down; UINT32_MAX if nothing ever arrived.
 
int appl_rc_read (appl_rc_t *out, uint32_t *t_ms)
 Latest RC values and their arrival time.
 

Detailed Description

Receive side of the ACwing Pilot link (HANDOVER_FW.md §2 and §6).

The BLE CMD write callback (HCI user-event thread of the stack) calls appl_on_cmd_write() and NOTHING else happens in that context:

  • the arrival time is stored from a monotonic hardware tick (one aligned 32-bit store: atomic on Cortex-M, no lock);
  • RC (0x11) values are stored behind a sequence counter (seqlock): the reader in the flight core never waits, it retries or keeps the previous values;
  • HEARTBEAT (0x10) only refreshes the time;
  • every other v2 opcode (>= 0x10) is copied (<= 20 bytes) into a single-producer single-consumer queue drained by the AppTask. Legacy 0x01/0x02 are still handled inline by tlm_ble_on_command().

Only CMD frames refresh the app-link time: connection events, CCCD writes, notifications sent or link-layer keep-alives do not (they never call this). A GAP disconnection only marks the link down, which can make the failsafe start earlier, never later (appl_silence_ms()).

Host-testable: no HAL, no RTOS.

Definition in file app_link.h.

Macro Definition Documentation

◆ APPL_CMD_MAX

#define APPL_CMD_MAX   20u

Definition at line 29 of file app_link.h.

◆ APPL_QUEUE_LEN

#define APPL_QUEUE_LEN   16u

power of 2, >= 8 required by the handover

Definition at line 30 of file app_link.h.

Function Documentation

◆ appl_reset()

void appl_reset ( void  )

Definition at line 32 of file app_link.c.

References s_down, s_ever, s_head, s_last_ms, s_qdrop, s_rc, s_rc_ever, s_rc_ms, s_rc_seq, and s_tail.

◆ appl_on_cmd_write()

void appl_on_cmd_write ( const uint8_t *  data,
uint16_t  len,
uint32_t  now_ms 
)

Definition at line 41 of file app_link.c.

References APPL_BARRIER, APPL_CMD_MAX, APPL_QUEUE_LEN, appl_cmd_t::b, appl_rc_t::buttons, appl_cmd_t::len, appl_rc_t::pitch, PV2_OP_HEARTBEAT, PV2_OP_RC, pv2_rd_i16(), QMASK, appl_rc_t::roll, s_down, s_ever, s_head, s_last_ms, s_q, s_qdrop, s_rc, s_rc_ever, s_rc_ms, s_rc_seq, s_tail, appl_rc_t::thr, and appl_rc_t::yaw.

Here is the call graph for this function:

◆ appl_on_connect()

void appl_on_connect ( void  )

Definition at line 81 of file app_link.c.

◆ appl_on_disconnect()

void appl_on_disconnect ( void  )

Definition at line 82 of file app_link.c.

References s_down.

◆ appl_pop()

int appl_pop ( appl_cmd_t *  out)

1 if a command was taken

Definition at line 85 of file app_link.c.

References APPL_BARRIER, QMASK, s_head, s_q, and s_tail.

Referenced by commands().

Here is the caller graph for this function:

◆ appl_queue_dropped()

uint32_t appl_queue_dropped ( void  )

Definition at line 96 of file app_link.c.

References s_qdrop.

◆ appl_ever()

uint8_t appl_ever ( void  )

1 once any CMD frame arrived

Definition at line 99 of file app_link.c.

References s_ever.

◆ appl_last_ms()

uint32_t appl_last_ms ( void  )

time of the last CMD frame

Definition at line 100 of file app_link.c.

References s_last_ms.

◆ appl_link_down()

uint8_t appl_link_down ( void  )

GAP disconnected since then

Definition at line 101 of file app_link.c.

References s_down.

◆ appl_silence_ms()

uint32_t appl_silence_ms ( uint32_t  now_ms,
uint32_t  down_floor_ms 
)

Silence seen by the failsafe: now - last CMD frame, at least 'down_floor_ms' while the link is reported down; UINT32_MAX if nothing ever arrived.

Definition at line 103 of file app_link.c.

References s, s_down, s_ever, and s_last_ms.

Referenced by app_link_failsafe(), and calibration().

Here is the caller graph for this function:

◆ appl_rc_read()

int appl_rc_read ( appl_rc_t *  out,
uint32_t *  t_ms 
)

Latest RC values and their arrival time.

Returns 1 with a consistent copy, 0 if no RC ever arrived (out untouched).

Definition at line 112 of file app_link.c.

References APPL_BARRIER, s_rc, s_rc_ever, s_rc_ms, and s_rc_seq.

Referenced by build_checks(), and update_sticks().

Here is the caller graph for this function: