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

BLE telemetry, transport-independent part (phase 2 + protocol v2). More...

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

Go to the source code of this file.

Macros

#define TLM_BLE_RING_SIZE   2048u
 per queue, power of 2

 
#define TLM_BLE_MTU_DEFAULT   23u
 ATT_MTU before any exchange

 
#define TLM_BLE_CMD_SEND_INIT   0x01u
 [0x01] resend INIT now

 
#define TLM_BLE_CMD_STATE_DECIM   0x02u
 [0x02, N] STATE every N acc updates
 

Enumerations

enum  tlm_ble_state_t { TLM_BLE_OFF = 0 , TLM_BLE_READY = 1 , TLM_BLE_CONNECTED = 2 , TLM_BLE_STREAMING = 3 }
 

Functions

void tlm_ble_reset (void)
 
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)
 
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)
 
uint16_t tlm_ble_queued (void)
 
void tlm_ble_set_state (tlm_ble_state_t s)
 
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

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).
 

Detailed Description

BLE telemetry, transport-independent part (phase 2 + protocol v2).

The BLE link carries the same frames as the UART (A5 5A | TYPE | LEN | PAYLOAD | CRC16), as a byte stream: frames are queued here and sent as notifications of up to (ATT_MTU - 3) bytes, regardless of the frame boundaries. The receiver concatenates the notifications and re-synchronises on A5 5A + CRC. Any MTU works (23 .. 247), no fragmentation protocol.

Two queues, each with ONE producer (lock-free single-producer single-consumer rings, whole frames only): HI AppTask protocol v2 frames: ACK, EVENT, CALIB, PARAM, FLIGHT, CHECKS, NAV, MOTORS, SYSTEM, CAPS, and INIT on subscribe LO TelemetryTask STATE (decimated), STATUS, INIT (~1 Hz) The BLE TX thread is the single consumer of both. It switches queue only at a frame boundary (a frame split over notifications is completed first), and always prefers HI.

TX priority when the link is short (HANDOVER_FW.md §2.3): every frame type may only fill its queue up to a level, so the low-priority frames are the first to be refused: ACK = EVENT = CAPS (100 %) > CALIB = PARAM = INIT (85 %) > FLIGHT = CHECKS (70 %)

‍POWER = NAV (55 %) > MOTORS = SYSTEM (45 %); LO: STATUS 85 % > STATE 50 %.

Refused frames are counted in STATUS.ble_drop.

On notification enable (CCCD) the AppTask sends CAPS, INIT, CHECKS in this order, then calls tlm_ble_open_streams(): until then the LO queue accepts nothing, so STATE/STATUS never precede CAPS.

Host-testable: no HAL, no STM32_WPAN, no RTOS here.

Definition in file tlm_ble.h.

Macro Definition Documentation

◆ TLM_BLE_RING_SIZE

#define TLM_BLE_RING_SIZE   2048u

per queue, power of 2

Definition at line 42 of file tlm_ble.h.

◆ TLM_BLE_MTU_DEFAULT

#define TLM_BLE_MTU_DEFAULT   23u

ATT_MTU before any exchange

Definition at line 43 of file tlm_ble.h.

◆ TLM_BLE_CMD_SEND_INIT

#define TLM_BLE_CMD_SEND_INIT   0x01u

[0x01] resend INIT now

Definition at line 52 of file tlm_ble.h.

◆ TLM_BLE_CMD_STATE_DECIM

#define TLM_BLE_CMD_STATE_DECIM   0x02u

[0x02, N] STATE every N acc updates

Definition at line 53 of file tlm_ble.h.

Enumeration Type Documentation

◆ tlm_ble_state_t

Enumerator
TLM_BLE_OFF 

BLE not compiled in or stack not started

TLM_BLE_READY 

service registered, advertising

TLM_BLE_CONNECTED 

central connected, notifications not enabled

TLM_BLE_STREAMING 

Definition at line 44 of file tlm_ble.h.

Function Documentation

◆ tlm_ble_reset()

◆ 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:

◆ 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_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_set_state()

void tlm_ble_set_state ( tlm_ble_state_t  s)

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

◆ g_dbg_ble_stall

volatile uint8_t g_dbg_ble_stall
extern

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().