9#ifndef APP_BLE_STATE_DECIM_DEFAULT
11#define APP_BLE_STATE_DECIM_DEFAULT APP_BLE_STATE_DECIM
15#define TLM_BARRIER() __asm volatile ("dmb" ::: "memory")
17#define TLM_BARRIER() __sync_synchronize()
20#define RING_MASK (TLM_BLE_RING_SIZE - 1u)
21#if (TLM_BLE_RING_SIZE & RING_MASK) != 0
22#error "TLM_BLE_RING_SIZE must be a power of 2"
55 for (
int i = 0; i <
NRING; ++i)
s_r[i].head =
s_r[i].tail = 0u;
83static int push(
ring_t *r,
const uint8_t *frame, uint16_t len)
85 if (len < 6u || frame[0] != 0xA5u || frame[1] != 0x5Au || frame[3] + 6u != len) {
s_dropped++;
return -1; }
86 const uint32_t head = r->
head;
87 const uint32_t
used = head - r->
tail;
91 memcpy(&r->
buf[
pos], frame, first);
92 memcpy(&r->
buf[0], frame + first, len - first);
121 if (d == 0u || d <
n)
return 0;
145static uint32_t
avail(
int i,
const uint32_t *t) {
return s_r[i].
head - t[i]; }
163 rem = (uint16_t)(
s_r[cur].buf[(t[cur] + 3u) &
RING_MASK] + 6u);
166 uint16_t take = (uint16_t)(max -
n);
167 if (take > rem) take = rem;
170 memcpy(dst +
n, &r->
buf[
pos], first);
171 memcpy(dst +
n + first, &r->
buf[0], take - first);
172 t[cur] += take;
n = (uint16_t)(
n + take); rem = (uint16_t)(rem - take);
173 if (rem == 0u) cur = -1;
221 if (!data || len == 0u)
return;
Phase-1 configuration: P-NUCLEO-WB55 (NUCLEO-WB55RG) + X-NUCLEO-IKS4A1 in Mode 3 (LSM6DSV16X is the s...
ACwing Pilot app protocol v2: identifiers and frame layouts.
#define PV2_FT_LOG_ENTRY
answer to LOG_LIST, one per log
#define PV2_FT_LOG_DATA
answer to LOG_READ
uint8_t buf[TLM_BLE_RING_SIZE]
void tlm_ble_set_state(tlm_ble_state_t st)
static volatile uint32_t s_dropped
int tlm_ble_push(const uint8_t *frame, uint16_t len)
Queue a whole frame or nothing.
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) wi...
static uint32_t level_pct(uint8_t type)
int tlm_ble_want_state(uint16_t seq)
1 if a STATE frame with this sequence number must go over BLE (decimation)
static uint16_t s_planRem
static uint32_t s_planTail[NRING]
static volatile uint8_t s_decim
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 purpos...
void tlm_ble_consume(uint16_t n)
static uint16_t s_lastSeq
void tlm_ble_on_command(const uint8_t *data, uint16_t len)
legacy 0x01/0x02
static int push(ring_t *r, const uint8_t *frame, uint16_t len)
uint16_t tlm_ble_hi_free(void)
bytes free in HI
static uint16_t s_planTotal
int tlm_ble_take_subscribe(void)
1 once after a client enabled notifications (AppTask: CAPS, INIT, CHECKS)
uint16_t tlm_ble_mtu(void)
int tlm_ble_push_hi(const uint8_t *frame, uint16_t len)
HI: AppTask
static volatile uint8_t s_state
uint8_t tlm_ble_state_decim(void)
uint16_t tlm_ble_chunk_max(void)
ATT_MTU - 3.
uint32_t tlm_ble_dropped(void)
void tlm_ble_discard(void)
drop everything queued (consumer side)
uint16_t tlm_ble_queued(void)
tlm_ble_state_t tlm_ble_state(void)
void tlm_ble_set_mtu(uint16_t att_mtu)
void tlm_ble_set_error(uint8_t ble_status)
last non-recoverable stack error
static volatile uint8_t s_err
static volatile uint8_t s_initReq
void tlm_ble_open_streams(void)
uint8_t tlm_ble_error(void)
static volatile uint8_t s_subReq
static uint32_t avail(int i, const uint32_t *t)
#define APP_BLE_STATE_DECIM_DEFAULT
static uint8_t s_planValid
static volatile uint8_t s_open
int tlm_ble_take_init_request(void)
1 once after the legacy [0x01] command: send INIT now (TelemetryTask)
static volatile uint16_t s_mtu
BLE telemetry, transport-independent part (phase 2 + protocol v2).
#define TLM_BLE_CMD_STATE_DECIM
[0x02, N] STATE every N acc updates
@ TLM_BLE_OFF
BLE not compiled in or stack not started
@ TLM_BLE_CONNECTED
central connected, notifications not enabled
#define TLM_BLE_MTU_DEFAULT
ATT_MTU before any exchange
#define TLM_BLE_RING_SIZE
per queue, power of 2
#define TLM_BLE_CMD_SEND_INIT
[0x01] resend INIT now
static USBD_StatusTypeDef st(HAL_StatusTypeDef h)