![]() |
ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
|
Byte-stream link over USB CDC: protocol v2 frames in both directions (A5 5A | TYPE | LEN | PAYLOAD | CRC16).
More...
#include <stdint.h>#include <stddef.h>Go to the source code of this file.
Macros | |
| #define | USBL_RX_SIZE 1024u |
| #define | USBL_TX_SIZE 4096u |
| per producer | |
| #define | USBL_CMD_MAX 32u |
| #define | USBL_OPEN_MS 3000u |
| without DTR, the link stays open this long after a command | |
Enumerations | |
| enum | { USBL_SRC_LOG = 0 , USBL_SRC_APP = 1 , USBL_SRC_TLM = 2 , USBL_SRC_COUNT } |
| producers of the TX rings More... | |
Functions | |
| void | usbl_reset (void) |
| void | usbl_rx_isr (const uint8_t *p, uint32_t n) |
| bytes that do not fit are dropped | |
| void | usbl_set_configured (uint8_t on) |
| host state: configured by a host, DTR set (any context, single writer each) | |
| void | usbl_set_dtr (uint8_t on) |
| uint8_t | usbl_host (void) |
| a USB host has configured the device (cable to a PC): ARM is refused | |
| uint8_t | usbl_open (uint32_t now_ms) |
| a program has the port open: host and (DTR or a command in the last USBL_OPEN_MS) | |
| uint32_t | usbl_poll (uint8_t *cmd, uint32_t cap, uint32_t now_ms) |
| next CMD frame payload; returns its length (>= 2), 0 if none. | |
| uint32_t | usbl_rx_errors (void) |
| frames with a bad CRC | |
| uint32_t | usbl_tx_free_src (uint8_t src) |
| int | usbl_send_src (uint8_t src, uint8_t type, const void *payload, uint8_t len) |
| a whole v2 frame built from type and payload; 0 = queued whole | |
| int | usbl_put_frame (uint8_t src, const uint8_t *frame, uint32_t n) |
| a frame already encoded; 0 = queued whole | |
| static uint32_t | usbl_tx_free (void) |
| the LogTask's ring (log answers) | |
| static int | usbl_send (uint8_t type, const void *payload, uint8_t len) |
| uint32_t | usbl_tx_dropped (uint8_t src) |
| frames that did not fit | |
| uint32_t | usbl_tx_peek (uint8_t *buf, uint32_t cap) |
| void | usbl_tx_consume (uint32_t n) |
| void | usbl_tx_flush (void) |
| nobody listening: empties every ring | |
Byte-stream link over USB CDC: protocol v2 frames in both directions (A5 5A | TYPE | LEN | PAYLOAD | CRC16).
The USB link is a ground link: telemetry, parameters, calibrations and the flight log. It never flies the drone (ADR 0009): the AppTask refuses the flight commands that arrive this way, and the flight core refuses ARM, TAKEOFF and MOTOR_TEST while a USB host is connected.
A5 5A, checks the CRC and returns the payload of every CMD frame (type 0x20: op, seq, args, the same bytes as a BLE CMD write).Transport-agnostic and host-testable: the same code would carry a UART.
Definition in file usb_link.h.
| #define USBL_RX_SIZE 1024u |
Definition at line 31 of file usb_link.h.
| #define USBL_TX_SIZE 4096u |
per producer
Definition at line 32 of file usb_link.h.
| #define USBL_CMD_MAX 32u |
Definition at line 33 of file usb_link.h.
| #define USBL_OPEN_MS 3000u |
without DTR, the link stays open this long after a command
Definition at line 34 of file usb_link.h.
| anonymous enum |
producers of the TX rings
| Enumerator | |
|---|---|
| USBL_SRC_LOG | |
| USBL_SRC_APP | |
| USBL_SRC_TLM | |
| USBL_SRC_COUNT | |
Definition at line 37 of file usb_link.h.
| void usbl_reset | ( | void | ) |
Definition at line 35 of file usb_link.c.
References s_cfgd, s_cmd_ms, s_cur, s_cur_left, s_dtr, s_err, s_ever, s_na, s_rx_h, s_rx_t, and s_tx.
Referenced by log_task_init().
| void usbl_rx_isr | ( | const uint8_t * | p, |
| uint32_t | n | ||
| ) |
bytes that do not fit are dropped
Definition at line 57 of file usb_link.c.
References n, s_rx, s_rx_h, s_rx_t, SPSC_BARRIER, and USBL_RX_SIZE.
Referenced by itf_receive().
| void usbl_set_configured | ( | uint8_t | on | ) |
host state: configured by a host, DTR set (any context, single writer each)
Definition at line 45 of file usb_link.c.
References on, s_cfgd, and s_dtr.
Referenced by usb_cdc_pump().
| void usbl_set_dtr | ( | uint8_t | on | ) |
Definition at line 46 of file usb_link.c.
Referenced by itf_control().
| uint8_t usbl_host | ( | void | ) |
a USB host has configured the device (cable to a PC): ARM is refused
Definition at line 47 of file usb_link.c.
References s_cfgd.
Referenced by app_start(), and build_checks().
| uint8_t usbl_open | ( | uint32_t | now_ms | ) |
a program has the port open: host and (DTR or a command in the last USBL_OPEN_MS)
Definition at line 49 of file usb_link.c.
References s_cfgd, s_cmd_ms, s_dtr, s_ever, and USBL_OPEN_MS.
Referenced by app_step(), LogTask(), and tx_frame().
| uint32_t usbl_poll | ( | uint8_t * | cmd, |
| uint32_t | cap, | ||
| uint32_t | now_ms | ||
| ) |
next CMD frame payload; returns its length (>= 2), 0 if none.
Records the arrival time.
Definition at line 105 of file usb_link.c.
References b, cap, cmd(), frame_ready(), n, PV2_FT_CMD, rx_byte(), s_acc, s_cmd_ms, s_ever, and s_na.
Referenced by log_task_step().
| uint32_t usbl_rx_errors | ( | void | ) |
| uint32_t usbl_tx_free_src | ( | uint8_t | src | ) |
Definition at line 134 of file usb_link.c.
References ring_t::h, s_tx, ring_t::t, USBL_SRC_COUNT, and USBL_TX_SIZE.
Referenced by list_pace(), usbl_put_frame(), and usbl_tx_free().
| int usbl_send_src | ( | uint8_t | src, |
| uint8_t | type, | ||
| const void * | payload, | ||
| uint8_t | len | ||
| ) |
a whole v2 frame built from type and payload; 0 = queued whole
Definition at line 154 of file usb_link.c.
References n, pv2_frame(), and usbl_put_frame().
Referenced by usbl_send().
| int usbl_put_frame | ( | uint8_t | src, |
| const uint8_t * | frame, | ||
| uint32_t | n | ||
| ) |
a frame already encoded; 0 = queued whole
Definition at line 142 of file usb_link.c.
References ring_t::b, ring_t::dropped, ring_t::h, n, s_tx, SPSC_BARRIER, USBL_SRC_COUNT, usbl_tx_free_src(), and USBL_TX_SIZE.
Referenced by tx(), tx_frame(), and usbl_send_src().
|
inlinestatic |
the LogTask's ring (log answers)
Definition at line 65 of file usb_link.h.
References USBL_SRC_LOG, and usbl_tx_free_src().
Referenced by port_room(), and port_room_ack().
|
inlinestatic |
Definition at line 66 of file usb_link.h.
References usbl_send_src(), and USBL_SRC_LOG.
Referenced by cmd_list(), and port_send().
| uint32_t usbl_tx_dropped | ( | uint8_t | src | ) |
frames that did not fit
Definition at line 140 of file usb_link.c.
References ring_t::dropped, s_tx, and USBL_SRC_COUNT.
| uint32_t usbl_tx_peek | ( | uint8_t * | buf, |
| uint32_t | cap | ||
| ) |
Definition at line 174 of file usb_link.c.
References ring_t::b, cap, choose(), n, s_cur, s_cur_left, s_tx, ring_t::t, and USBL_TX_SIZE.
Referenced by usb_cdc_pump().
| void usbl_tx_consume | ( | uint32_t | n | ) |
Definition at line 185 of file usb_link.c.
References n, s_cur, s_cur_left, s_tx, and ring_t::t.
Referenced by usb_cdc_pump().
| void usbl_tx_flush | ( | void | ) |
nobody listening: empties every ring
Definition at line 192 of file usb_link.c.
References s_cur_left, s_tx, and USBL_SRC_COUNT.
Referenced by usb_cdc_pump().