44#include "esp_hosted_header.h"
45#include "esp_hosted_interface.h"
46#include "esp_hosted_os_abstraction.h"
47#include "esp_hosted_transport.h"
51#include "transport_drv.h"
70typedef enum : uint16_t {
161static void c6_fwver_tx_frame(uint8_t if_type, uint8_t if_num,
const uint8_t* payload, uint16_t len)
168 for (uint16_t i = 0U; i < len; i++) {
193 const int32_t level =
220 const uint16_t calc = compute_checksum(
s_c6_fwver_rx.bytes, span);
297 const uint16_t contribution =
299 return (contribution != 0U) && ((uint16_t)(calc - stated) == contribution);
337 c6_fwver_puts(
"c6_fwver: ^ explained: the co-processor checksummed this frame with "
338 "if_num=0 and then transmitted a non-zero if_num. A conformant host "
339 "drops it -- upstream's own process_spi_rx_buf() would too.\r\n");
345 if (sink ==
nullptr) {
376 uint16_t payload_len,
377 uint16_t max_transfers,
380 if ((stats ==
nullptr) || ((payload_len != 0U) && (payload ==
nullptr))) {
383 if (max_transfers == 0U) {
397 const uint8_t* payload,
398 uint16_t payload_len,
399 uint16_t max_transfers,
409 bool tx_pending = (payload_len != 0U);
410 struct hosted_transport_context_t ctx = {};
412 uint16_t consecutive_timeouts = 0U;
414 for (uint16_t i = 0U; i < max_transfers; i++) {
417 consecutive_timeouts++;
423 consecutive_timeouts = 0U;
434 if ((int32_t)
g_h.funcs->_h_do_bus_transfer(&ctx) != (int32_t)
RET_OK) {
Shared contract for the esp-hosted RPC round-trip application.
@ k_c6_fwver_dma_align
Transaction-buffer alignment, in bytes.
bool(* c6_fwver_sink_t)(uint8_t if_type, uint8_t if_num, const uint8_t *payload, uint16_t len)
Receiver for one well-formed frame the co-processor sent.
void c6_fwver_put_hex(uint32_t value, uint8_t digits)
Emit a value as a fixed-width lower-case hexadecimal field.
@ k_c6_fwver_gap_ms
Settling gap between consecutive transactions.
@ k_c6_fwver_hs_poll_ms
Sampling period while waiting for HANDSHAKE.
@ k_c6_fwver_hs_giveup
Consecutive HANDSHAKE timeouts after which the pump stops.
@ k_c6_fwver_frame_bytes
Bytes clocked in one full-duplex transaction.
@ k_c6_fwver_hs_wait_ms
Milliseconds to wait for HANDSHAKE before abandoning a transaction.
@ k_c6_fwver_tx_max
Bound on any payload this application transmits: the packed RPC request and its TLV envelope are two ...
union c6_fwver_frame c6_fwver_frame_t
struct c6_fwver_pump_stats c6_fwver_pump_stats_t
@ k_c6_fwver_hex_word
Hex digits printed for a 16-bit field.
@ k_c6_fwver_hex_byte
Hex digits printed for a byte-wide field.
void c6_fwver_put_u32(uint32_t value)
Emit an unsigned 32-bit value in decimal.
void c6_fwver_puts(const char *text)
Write a NUL-terminated string to the board console.
ra8_err_t c6_fwver_link_pump(uint8_t if_type, uint8_t if_num, const uint8_t *payload, uint16_t payload_len, uint16_t max_transfers, c6_fwver_sink_t sink, c6_fwver_pump_stats_t *stats)
Clock full-duplex transactions until the sink is satisfied.
static void c6_fwver_tx_clear(void)
Zero the whole transmit frame.
static ra8_err_t c6_fwver_pump_check(const uint8_t *payload, uint16_t payload_len, uint16_t max_transfers, const c6_fwver_pump_stats_t *stats)
Reject a pump request whose arguments cannot be honoured.
static uint16_t c6_fwver_rx_checksum(uint16_t span)
Recompute the received frame's checksum over header plus payload.
static c6_fwver_frame_t s_c6_fwver_tx
Transmit buffer for the frame the pump is currently clocking.
static bool c6_fwver_rx_dispatch(c6_fwver_sink_t sink, c6_fwver_pump_stats_t *stats)
Classify the received frame and deliver it if it is real.
static c6_fwver_frame_t s_c6_fwver_rx
Receive buffer the co-processor's frame lands in.
static bool c6_fwver_ifnum_defect(uint16_t calc, uint16_t stated)
Decide whether a checksum failure is the known if_num defect.
static void c6_fwver_tx_filler(void)
Stamp the transmit frame as the host's idle filler.
static bool c6_fwver_wait_handshake(void)
Wait, bounded, for the co-processor to arm HANDSHAKE.
static void c6_fwver_print_reject(const char *why, uint16_t calc)
Print every header field of a frame the pump is about to drop.
static void c6_fwver_tx_frame(uint8_t if_type, uint8_t if_num, const uint8_t *payload, uint16_t len)
Wrap a payload in a payload header, checksum included.
c6_fwver_proto_t
Protocol constants the pump judges a received frame against.
@ k_c6_fwver_max_payload
Largest payload a valid data frame may advertise.
@ k_c6_fwver_nibble_mask
Mask applied before a write to a four-bit header field.
@ k_c6_fwver_hdr_bytes
Payload-header size; twelve bytes on this ABI.
@ k_c6_fwver_ifnum_shift
Bit position of if_num within the header's first byte.
esp-hosted port header: transport selection, side-band pin map, link polarity.
#define H_GPIO_HANDSHAKE_Pin
Pin index of the HANDSHAKE input, or -1 when it is not wired.
#define H_GPIO_HANDSHAKE_Port
Opaque port handle of the HANDSHAKE input.
#define H_HS_VAL_ACTIVE
Level read back on HANDSHAKE when it is asserted.
esp-hosted port header: RTOS handle types, return codes and budgets.
#define MAX_PAYLOAD_SIZE
Largest payload one transport frame can carry, in bytes.
#define RET_OK
Operation completed.
@ k_ra8_err_spi_error
SPI transfer failed (bus fault, mode fault, overrun, ...).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
struct hosted_config_t g_h
The handle the vendored core dereferences to reach the vtable.
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
bool ra8_esp_hosted_port_is_ready(void)
Report whether the port is currently initialised.
uint16_t malformed
Frames whose offset or length could not be believed.
uint16_t idle
Filler frames the co-processor returned (len zero).
bool bus_error
A bus transfer did not return RET_OK.
uint16_t transfers
Full-duplex transactions clocked.
bool sink_stopped
The sink asked the pump to stop early.
uint16_t bad_checksum
Frames whose recomputed checksum disagreed.
uint16_t frames
Well-formed payload frames handed to the sink.
uint16_t ifnum_defect
Bad-checksum frames explained by the co-processor's if_num accounting; see the app README.
uint16_t hs_timeouts
Transactions abandoned waiting for HANDSHAKE.