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

BLE telemetry queues and link state (see tlm_ble.h). More...

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

Go to the source code of this file.

Data Structures

struct  ring_t
 

Macros

#define APP_BLE_STATE_DECIM_DEFAULT   APP_BLE_STATE_DECIM
 
#define TLM_BARRIER()   __sync_synchronize()
 
#define RING_MASK   (TLM_BLE_RING_SIZE - 1u)
 

Enumerations

enum  { RHI = 0 , RLO = 1 , NRING = 2 }
 

Functions

void tlm_ble_reset (void)
 
static uint32_t level_pct (uint8_t type)
 
static int push (ring_t *r, const uint8_t *frame, uint16_t len)
 
int tlm_ble_push (const uint8_t *frame, uint16_t len)
 Queue a whole frame or nothing.
 
int tlm_ble_push_hi (const uint8_t *frame, uint16_t len)
 HI: AppTask

 
uint16_t tlm_ble_hi_free (void)
 bytes free in HI

 
int tlm_ble_want_state (uint16_t seq)
 1 if a STATE frame with this sequence number must go over BLE (decimation)
 
int tlm_ble_take_init_request (void)
 1 once after the legacy [0x01] command: send INIT now (TelemetryTask)
 
int tlm_ble_take_subscribe (void)
 1 once after a client enabled notifications (AppTask: CAPS, INIT, CHECKS)
 
void tlm_ble_open_streams (void)
 
static uint32_t avail (int i, const uint32_t *t)
 
uint16_t tlm_ble_queued (void)
 
uint16_t tlm_ble_peek (uint8_t *dst, uint16_t max)
 Copies up to max bytes of the next notification into dst without removing them; tlm_ble_consume(n) with the same n removes exactly those bytes.
 
void tlm_ble_consume (uint16_t n)
 
void tlm_ble_discard (void)
 drop everything queued (consumer side)
 
void tlm_ble_set_state (tlm_ble_state_t st)
 
void tlm_ble_set_mtu (uint16_t att_mtu)
 
void tlm_ble_set_error (uint8_t ble_status)
 last non-recoverable stack error
 
void tlm_ble_on_command (const uint8_t *data, uint16_t len)
 legacy 0x01/0x02
 
tlm_ble_state_t tlm_ble_state (void)
 
uint16_t tlm_ble_mtu (void)
 
uint16_t tlm_ble_chunk_max (void)
 ATT_MTU - 3.
 
uint32_t tlm_ble_dropped (void)
 
uint8_t tlm_ble_error (void)
 
uint8_t tlm_ble_state_decim (void)
 

Variables

static ring_t s_r [NRING]
 
static volatile uint32_t s_dropped
 
static volatile uint8_t s_state
 
static volatile uint16_t s_mtu = TLM_BLE_MTU_DEFAULT
 
static volatile uint8_t s_err
 
static volatile uint8_t s_initReq
 
static volatile uint8_t s_subReq
 
static volatile uint8_t s_open
 
static volatile uint8_t s_decim = APP_BLE_STATE_DECIM_DEFAULT
 
static uint16_t s_lastSeq
 
static uint8_t s_haveSeq
 
volatile uint8_t g_dbg_ble_stall
 Bench test of HANDOVER_FW.md §6 / §16.12 (debugger Live Expression): 1 = the BLE path stops on purpose (CMD writes ignored, TX thread idle).
 
static int8_t s_cur = -1
 
static uint16_t s_curRem
 
static uint32_t s_planTail [NRING]
 
static int8_t s_planCur
 
static uint16_t s_planRem
 
static uint16_t s_planTotal
 
static uint8_t s_planValid
 

Detailed Description

BLE telemetry queues and link state (see tlm_ble.h).

Definition in file tlm_ble.c.

Macro Definition Documentation

◆ APP_BLE_STATE_DECIM_DEFAULT

#define APP_BLE_STATE_DECIM_DEFAULT   APP_BLE_STATE_DECIM

Definition at line 11 of file tlm_ble.c.

◆ TLM_BARRIER

#define TLM_BARRIER ( )    __sync_synchronize()

Definition at line 17 of file tlm_ble.c.

◆ RING_MASK

#define RING_MASK   (TLM_BLE_RING_SIZE - 1u)

Definition at line 20 of file tlm_ble.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RHI 
RLO 
NRING 

Definition at line 25 of file tlm_ble.c.

Function Documentation

◆ tlm_ble_reset()

◆ level_pct()

static uint32_t level_pct ( uint8_t  type)
static

Definition at line 69 of file tlm_ble.c.

References PV2_FT_ACK, PV2_FT_CALIB, PV2_FT_CAPS, PV2_FT_CHECKS, PV2_FT_EVENT, PV2_FT_FLIGHT, PV2_FT_INIT, PV2_FT_LOG_DATA, PV2_FT_LOG_ENTRY, PV2_FT_NAV, PV2_FT_PARAM, PV2_FT_POWER, PV2_FT_STATE, and PV2_FT_STATUS.

Referenced by push().

Here is the caller graph for this function:

◆ push()

static int push ( ring_t *  r,
const uint8_t *  frame,
uint16_t  len 
)
static

Definition at line 83 of file tlm_ble.c.

References ring_t::buf, ring_t::head, level_pct(), pos, RING_MASK, s_dropped, ring_t::tail, TLM_BARRIER, TLM_BLE_RING_SIZE, and used.

Referenced by tlm_ble_push(), and tlm_ble_push_hi().

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

◆ tlm_ble_push()

int tlm_ble_push ( const uint8_t *  frame,
uint16_t  len 
)

Queue a whole frame or nothing.

0 = queued, 1 = no client streaming (or streams not open yet, LO only), -1 = refused (priority level or full, counted). LO: TelemetryTask

Definition at line 98 of file tlm_ble.c.

References push(), RLO, s_open, s_r, s_state, and TLM_BLE_STREAMING.

Referenced by TelemetryTask(), and tx_frame().

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

◆ tlm_ble_push_hi()

int tlm_ble_push_hi ( const uint8_t *  frame,
uint16_t  len 
)

HI: AppTask

Definition at line 104 of file tlm_ble.c.

References push(), RHI, s_r, s_state, and TLM_BLE_STREAMING.

Referenced by log_ble_out(), and tx().

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

◆ tlm_ble_hi_free()

uint16_t tlm_ble_hi_free ( void  )

bytes free in HI

Definition at line 110 of file tlm_ble.c.

References ring_t::head, RHI, s_r, ring_t::tail, and TLM_BLE_RING_SIZE.

Referenced by list_pace(), and log_ble_out().

Here is the caller graph for this function:

◆ tlm_ble_want_state()

int tlm_ble_want_state ( uint16_t  seq)

1 if a STATE frame with this sequence number must go over BLE (decimation)

Definition at line 115 of file tlm_ble.c.

References n, s_decim, s_haveSeq, s_lastSeq, s_open, s_state, seq, and TLM_BLE_STREAMING.

Referenced by tx_frame().

Here is the caller graph for this function:

◆ tlm_ble_take_init_request()

int tlm_ble_take_init_request ( void  )

1 once after the legacy [0x01] command: send INIT now (TelemetryTask)

Definition at line 128 of file tlm_ble.c.

References s_initReq.

Referenced by TelemetryTask().

Here is the caller graph for this function:

◆ tlm_ble_take_subscribe()

int tlm_ble_take_subscribe ( void  )

1 once after a client enabled notifications (AppTask: CAPS, INIT, CHECKS)

Definition at line 135 of file tlm_ble.c.

References s_subReq.

Referenced by app_step().

Here is the caller graph for this function:

◆ tlm_ble_open_streams()

void tlm_ble_open_streams ( void  )

Definition at line 142 of file tlm_ble.c.

References s_open.

Referenced by app_step().

Here is the caller graph for this function:

◆ avail()

static uint32_t avail ( int  i,
const uint32_t *  t 
)
static

Definition at line 145 of file tlm_ble.c.

References ring_t::head, and s_r.

Referenced by tlm_ble_peek().

Here is the caller graph for this function:

◆ tlm_ble_queued()

uint16_t tlm_ble_queued ( void  )

Definition at line 147 of file tlm_ble.c.

References ring_t::head, RHI, RLO, s_r, and ring_t::tail.

◆ tlm_ble_peek()

uint16_t tlm_ble_peek ( uint8_t *  dst,
uint16_t  max 
)

Copies up to max bytes of the next notification into dst without removing them; tlm_ble_consume(n) with the same n removes exactly those bytes.

Definition at line 152 of file tlm_ble.c.

References avail(), ring_t::buf, n, NRING, pos, RHI, RING_MASK, RLO, s_cur, s_curRem, s_planCur, s_planRem, s_planTail, s_planTotal, s_planValid, s_r, ring_t::tail, TLM_BARRIER, and TLM_BLE_RING_SIZE.

Here is the call graph for this function:

◆ tlm_ble_consume()

void tlm_ble_consume ( uint16_t  n)

Definition at line 180 of file tlm_ble.c.

References n, RHI, RLO, s_cur, s_curRem, s_planCur, s_planRem, s_planTail, s_planTotal, s_planValid, s_r, ring_t::tail, and TLM_BARRIER.

◆ tlm_ble_discard()

void tlm_ble_discard ( void  )

drop everything queued (consumer side)

Definition at line 190 of file tlm_ble.c.

References ring_t::head, RHI, RLO, s_cur, s_curRem, s_planValid, s_r, and ring_t::tail.

◆ tlm_ble_set_state()

void tlm_ble_set_state ( tlm_ble_state_t  st)

Definition at line 198 of file tlm_ble.c.

References s_haveSeq, s_mtu, s_open, s_state, s_subReq, st(), TLM_BLE_CONNECTED, TLM_BLE_MTU_DEFAULT, and TLM_BLE_STREAMING.

Here is the call graph for this function:

◆ tlm_ble_set_mtu()

void tlm_ble_set_mtu ( uint16_t  att_mtu)

Definition at line 211 of file tlm_ble.c.

References s_mtu, and TLM_BLE_MTU_DEFAULT.

◆ tlm_ble_set_error()

void tlm_ble_set_error ( uint8_t  ble_status)

last non-recoverable stack error

Definition at line 217 of file tlm_ble.c.

References s_err.

◆ tlm_ble_on_command()

void tlm_ble_on_command ( const uint8_t *  data,
uint16_t  len 
)

legacy 0x01/0x02

Definition at line 219 of file tlm_ble.c.

References s_decim, s_haveSeq, s_initReq, TLM_BLE_CMD_SEND_INIT, and TLM_BLE_CMD_STATE_DECIM.

◆ tlm_ble_state()

tlm_ble_state_t tlm_ble_state ( void  )

Definition at line 235 of file tlm_ble.c.

References s_state.

Referenced by app_step(), log_ble_out(), send_status(), and streams().

Here is the caller graph for this function:

◆ tlm_ble_mtu()

uint16_t tlm_ble_mtu ( void  )

Definition at line 236 of file tlm_ble.c.

References s_mtu.

Referenced by send_status().

Here is the caller graph for this function:

◆ tlm_ble_chunk_max()

uint16_t tlm_ble_chunk_max ( void  )

ATT_MTU - 3.

Definition at line 237 of file tlm_ble.c.

References s_mtu.

◆ tlm_ble_dropped()

uint32_t tlm_ble_dropped ( void  )

Definition at line 238 of file tlm_ble.c.

References s_dropped.

Referenced by send_status().

Here is the caller graph for this function:

◆ tlm_ble_error()

uint8_t tlm_ble_error ( void  )

Definition at line 239 of file tlm_ble.c.

References s_err.

Referenced by send_status().

Here is the caller graph for this function:

◆ tlm_ble_state_decim()

uint8_t tlm_ble_state_decim ( void  )

Definition at line 240 of file tlm_ble.c.

References s_decim.

Variable Documentation

◆ s_r

◆ s_dropped

volatile uint32_t s_dropped
static

Definition at line 34 of file tlm_ble.c.

Referenced by push(), tlm_ble_dropped(), and tlm_ble_reset().

◆ s_state

volatile uint8_t s_state
static

◆ s_mtu

volatile uint16_t s_mtu = TLM_BLE_MTU_DEFAULT
static

◆ s_err

volatile uint8_t s_err
static

Definition at line 37 of file tlm_ble.c.

Referenced by tlm_ble_error(), tlm_ble_reset(), and tlm_ble_set_error().

◆ s_initReq

volatile uint8_t s_initReq
static

Definition at line 38 of file tlm_ble.c.

Referenced by tlm_ble_on_command(), tlm_ble_reset(), and tlm_ble_take_init_request().

◆ s_subReq

volatile uint8_t s_subReq
static

Definition at line 38 of file tlm_ble.c.

Referenced by tlm_ble_reset(), tlm_ble_set_state(), and tlm_ble_take_subscribe().

◆ s_open

volatile uint8_t s_open
static

◆ s_decim

volatile uint8_t s_decim = APP_BLE_STATE_DECIM_DEFAULT
static

◆ s_lastSeq

uint16_t s_lastSeq
static

Definition at line 40 of file tlm_ble.c.

Referenced by tlm_ble_want_state().

◆ s_haveSeq

uint8_t s_haveSeq
static

Definition at line 41 of file tlm_ble.c.

Referenced by tlm_ble_on_command(), tlm_ble_reset(), tlm_ble_set_state(), and tlm_ble_want_state().

◆ g_dbg_ble_stall

volatile uint8_t g_dbg_ble_stall

Bench test of HANDOVER_FW.md §6 / §16.12 (debugger Live Expression): 1 = the BLE path stops on purpose (CMD writes ignored, TX thread idle).

The app-link failsafe must still fire at 1 s and 3 s.

Definition at line 43 of file tlm_ble.c.

Referenced by tlm_ble_reset().

◆ s_cur

int8_t s_cur = -1
static

Definition at line 46 of file tlm_ble.c.

Referenced by tlm_ble_consume(), tlm_ble_discard(), tlm_ble_peek(), and tlm_ble_reset().

◆ s_curRem

uint16_t s_curRem
static

Definition at line 47 of file tlm_ble.c.

Referenced by tlm_ble_consume(), tlm_ble_discard(), tlm_ble_peek(), and tlm_ble_reset().

◆ s_planTail

uint32_t s_planTail[NRING]
static

Definition at line 48 of file tlm_ble.c.

Referenced by tlm_ble_consume(), and tlm_ble_peek().

◆ s_planCur

int8_t s_planCur
static

Definition at line 49 of file tlm_ble.c.

Referenced by tlm_ble_consume(), and tlm_ble_peek().

◆ s_planRem

uint16_t s_planRem
static

Definition at line 50 of file tlm_ble.c.

Referenced by tlm_ble_consume(), and tlm_ble_peek().

◆ s_planTotal

uint16_t s_planTotal
static

Definition at line 50 of file tlm_ble.c.

Referenced by tlm_ble_consume(), and tlm_ble_peek().

◆ s_planValid

uint8_t s_planValid
static

Definition at line 51 of file tlm_ble.c.

Referenced by tlm_ble_consume(), tlm_ble_discard(), tlm_ble_peek(), and tlm_ble_reset().