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

CMD reception: arrival time, RC store, command queue (see app_link.h). More...

#include "app_link.h"
#include "proto_v2.h"
#include <string.h>
Include dependency graph for app_link.c:

Go to the source code of this file.

Macros

#define APPL_BARRIER()   __sync_synchronize()
 
#define QMASK   (APPL_QUEUE_LEN - 1u)
 

Functions

void appl_reset (void)
 
void appl_on_cmd_write (const uint8_t *d, 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.
 

Variables

static appl_cmd_t s_q [APPL_QUEUE_LEN]
 
static volatile uint32_t s_head
 
static volatile uint32_t s_tail
 
static volatile uint32_t s_qdrop
 
static volatile uint32_t s_last_ms
 
static volatile uint8_t s_ever
 
static volatile uint8_t s_down
 
static volatile uint32_t s_rc_seq
 
static volatile uint32_t s_rc_ms
 
static volatile uint8_t s_rc_ever
 
static appl_rc_t s_rc
 

Detailed Description

CMD reception: arrival time, RC store, command queue (see app_link.h).

Definition in file app_link.c.

Macro Definition Documentation

◆ APPL_BARRIER

#define APPL_BARRIER ( )    __sync_synchronize()

Definition at line 12 of file app_link.c.

◆ QMASK

#define QMASK   (APPL_QUEUE_LEN - 1u)

Definition at line 15 of file app_link.c.

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 *  d,
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:

Variable Documentation

◆ s_q

Definition at line 20 of file app_link.c.

Referenced by appl_on_cmd_write(), appl_pop(), ext_init(), ext_step(), and ext_take().

◆ s_head

volatile uint32_t s_head
static

Definition at line 21 of file app_link.c.

Referenced by appl_on_cmd_write(), appl_pop(), and appl_reset().

◆ s_tail

volatile uint32_t s_tail
static

Definition at line 21 of file app_link.c.

Referenced by appl_on_cmd_write(), appl_pop(), and appl_reset().

◆ s_qdrop

volatile uint32_t s_qdrop
static

Definition at line 21 of file app_link.c.

Referenced by appl_on_cmd_write(), appl_queue_dropped(), and appl_reset().

◆ s_last_ms

volatile uint32_t s_last_ms
static

Definition at line 23 of file app_link.c.

Referenced by appl_last_ms(), appl_on_cmd_write(), appl_reset(), and appl_silence_ms().

◆ s_ever

volatile uint8_t s_ever
static

Definition at line 24 of file app_link.c.

Referenced by appl_ever(), appl_on_cmd_write(), appl_reset(), and appl_silence_ms().

◆ s_down

volatile uint8_t s_down
static

◆ s_rc_seq

volatile uint32_t s_rc_seq
static

Definition at line 27 of file app_link.c.

Referenced by appl_on_cmd_write(), appl_rc_read(), and appl_reset().

◆ s_rc_ms

volatile uint32_t s_rc_ms
static

Definition at line 28 of file app_link.c.

Referenced by appl_on_cmd_write(), appl_rc_read(), and appl_reset().

◆ s_rc_ever

volatile uint8_t s_rc_ever
static

Definition at line 29 of file app_link.c.

Referenced by appl_on_cmd_write(), appl_rc_read(), and appl_reset().

◆ s_rc

appl_rc_t s_rc
static

Definition at line 30 of file app_link.c.

Referenced by appl_on_cmd_write(), appl_rc_read(), and appl_reset().