![]() |
ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
|
USB byte-stream link (see usb_link.h). More...
#include "usb_link.h"#include "proto_v2.h"#include "telemetry.h"#include "spsc.h"#include <string.h>Go to the source code of this file.
Data Structures | |
| struct | ring_t |
Functions | |
| void | usbl_reset (void) |
| 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) |
| a program has the port open: host and (DTR or a command in the last USBL_OPEN_MS) | |
| void | usbl_rx_isr (const uint8_t *p, uint32_t n) |
| bytes that do not fit are dropped | |
| static int | rx_byte (uint8_t *b) |
| uint32_t | usbl_rx_errors (void) |
| frames with a bad CRC | |
| static void | resync (void) |
| static int | frame_ready (void) |
| uint32_t | usbl_poll (uint8_t *cmd, uint32_t cap, uint32_t now) |
| next CMD frame payload; returns its length (>= 2), 0 if none. | |
| uint32_t | usbl_tx_free_src (uint8_t src) |
| uint32_t | usbl_tx_dropped (uint8_t src) |
| frames that did not fit | |
| int | usbl_put_frame (uint8_t src, const uint8_t *f, uint32_t n) |
| a frame already encoded; 0 = queued whole | |
| 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 | |
| static void | choose (void) |
| 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 | |
Variables | |
| static uint8_t | s_rx [USBL_RX_SIZE] |
| static volatile uint32_t | s_rx_h |
| static volatile uint32_t | s_rx_t |
| static ring_t | s_tx [USBL_SRC_COUNT] |
| static uint8_t | s_cur |
| static uint32_t | s_cur_left |
| static volatile uint8_t | s_cfgd |
| static volatile uint8_t | s_dtr |
| static volatile uint8_t | s_ever |
| static volatile uint32_t | s_cmd_ms |
| static uint8_t | s_acc [4+255+2] |
| static uint32_t | s_na |
| static uint32_t | s_err |
USB byte-stream link (see usb_link.h).
Definition in file usb_link.c.
| 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_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 | ) |
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().
| 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().
|
static |
Definition at line 70 of file usb_link.c.
References b, s_rx, s_rx_h, s_rx_t, SPSC_BARRIER, and USBL_RX_SIZE.
Referenced by usbl_poll().
| uint32_t usbl_rx_errors | ( | void | ) |
|
static |
Definition at line 83 of file usb_link.c.
Referenced by frame_ready().
|
static |
Definition at line 95 of file usb_link.c.
References resync(), s_acc, s_err, s_na, and tlm_crc16().
Referenced by usbl_poll().
| 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_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().
| 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.
| int usbl_put_frame | ( | uint8_t | src, |
| const uint8_t * | f, | ||
| 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().
| 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().
|
static |
Definition at line 164 of file usb_link.c.
References ring_t::h, n, s_cur, s_cur_left, s_tx, SPSC_BARRIER, ring_t::t, and USBL_SRC_COUNT.
Referenced by usbl_tx_peek().
| 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().
|
static |
Definition at line 11 of file usb_link.c.
Referenced by rx_byte(), and usbl_rx_isr().
|
static |
Definition at line 12 of file usb_link.c.
Referenced by rx_byte(), usbl_reset(), and usbl_rx_isr().
|
static |
Definition at line 12 of file usb_link.c.
Referenced by rx_byte(), usbl_reset(), and usbl_rx_isr().
|
static |
Definition at line 19 of file usb_link.c.
Referenced by choose(), usbl_put_frame(), usbl_reset(), usbl_tx_consume(), usbl_tx_dropped(), usbl_tx_flush(), usbl_tx_free_src(), and usbl_tx_peek().
|
static |
Definition at line 23 of file usb_link.c.
Referenced by choose(), usbl_reset(), usbl_tx_consume(), and usbl_tx_peek().
|
static |
Definition at line 24 of file usb_link.c.
Referenced by choose(), usbl_reset(), usbl_tx_consume(), usbl_tx_flush(), and usbl_tx_peek().
|
static |
Definition at line 27 of file usb_link.c.
Referenced by usbl_host(), usbl_open(), usbl_reset(), and usbl_set_configured().
|
static |
Definition at line 27 of file usb_link.c.
Referenced by usbl_open(), usbl_reset(), usbl_set_configured(), and usbl_set_dtr().
|
static |
Definition at line 27 of file usb_link.c.
Referenced by usbl_open(), usbl_poll(), and usbl_reset().
|
static |
Definition at line 28 of file usb_link.c.
Referenced by usbl_open(), usbl_poll(), and usbl_reset().
|
static |
Definition at line 31 of file usb_link.c.
Referenced by frame_ready(), resync(), and usbl_poll().
|
static |
Definition at line 32 of file usb_link.c.
Referenced by frame_ready(), resync(), usbl_poll(), and usbl_reset().
|
static |
Definition at line 33 of file usb_link.c.
Referenced by frame_ready(), usbl_reset(), and usbl_rx_errors().