ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
c6_frame.c File Reference

Hand-decoded esp-hosted payload header for the ESP32-C6 SPI probe. More...

#include <stdint.h>
#include "c6_probe.h"
#include "c6_proto.h"
Include dependency graph for c6_frame.c:

Go to the source code of this file.

Functions

static uint16_t internal_le16 (const uint8_t *buf, uint8_t off_lo)
 Read a little-endian 16-bit field out of a byte buffer.
uint16_t c6_probe_checksum (const uint8_t *buf, uint16_t count)
 Recompute the esp-hosted checksum over a received frame.
void c6_probe_decode_header (const uint8_t *buf, c6_hdr_t *out)
 Unpack the twelve-byte esp-hosted payload header.
c6_frame_kind_t c6_probe_classify (const c6_hdr_t *h)
 Implementation of c6_probe_classify() – filler check first.
void c6_probe_print_header (const c6_hdr_t *h)
 Print the decoded header fields on one console line.
void c6_probe_dump_payload (const uint8_t *buf, uint16_t len)
 Hex-dump the leading payload bytes of a received frame.

Detailed Description

Hand-decoded esp-hosted payload header for the ESP32-C6 SPI probe.

Tag
[Ring 6 / APP] {World: S}

Unpacks and judges struct esp_payload_header (esp-hosted-mcu common/esp_hosted_header.h, pinned commit 949bb30) straight out of the receive buffer, without vendoring any upstream source. Field offsets, endianness and the acceptance rules all live in c6_proto.h next to the upstream file they were read from.

Since
0.1.0

Definition in file c6_frame.c.

Function Documentation

◆ c6_probe_checksum()

uint16_t c6_probe_checksum ( const uint8_t * buf,
uint16_t count )

Recompute the esp-hosted checksum over a received frame.

compute_checksum() in esp-hosted-mcu common/transport/esp_hosted_transport.h is a plain 16-bit sum of every byte from the start of the header through the end of the payload. Both peers zero the checksum field before summing (process_spi_rx_buf in host/drivers/transport/spi/spi_drv.c), so the two checksum bytes are skipped here instead of being cleared, which leaves the receive buffer intact for the hex dump.

Parameters
[in]bufReceive buffer.
[in]countBytes to sum: header offset plus payload length.
Returns
The 16-bit sum, or zero when buf is NULL.
Return values
0buf was NULL, count was zero, or the sum is zero.
Precondition
buf holds at least count bytes.
count is no larger than k_c6_proto_buf_size.
Postcondition
The buffer is unmodified.
Overflow wraps at 16 bits, exactly as upstream does.
Note
Requires buf to be stable for the duration of the call.
Example:
const uint16_t sum = c6_probe_checksum(rx, (uint16_t)(h.offset + h.len));
uint16_t c6_probe_checksum(const uint8_t *buf, uint16_t count)
Recompute the esp-hosted checksum over a received frame.
Definition c6_frame.c:55
See also
c6_probe_decode_header
Since
0.1.0

Definition at line 55 of file c6_frame.c.

References k_c6_hdr_off_csum_hi, k_c6_hdr_off_csum_lo, and k_c6_proto_buf_size.

Referenced by c6_probe_decode_header().

◆ c6_probe_classify()

c6_frame_kind_t c6_probe_classify ( const c6_hdr_t * h)

Implementation of c6_probe_classify() – filler check first.

Judge a decoded header against the upstream receive rules.

Definition at line 95 of file c6_frame.c.

References c6_hdr_t::checksum, c6_hdr_t::computed, c6_hdr_t::if_num, c6_hdr_t::if_type, k_c6_dummy_if_num, k_c6_frame_bad_csum, k_c6_frame_data, k_c6_frame_garbage, k_c6_frame_idle, k_c6_if_max, k_c6_proto_hdr_size, k_c6_proto_payload_max, c6_hdr_t::len, and c6_hdr_t::offset.

Referenced by internal_report_frame().

◆ c6_probe_decode_header()

void c6_probe_decode_header ( const uint8_t * buf,
c6_hdr_t * out )

Unpack the twelve-byte esp-hosted payload header.

Parameters
[in]bufReceive buffer holding a completed transaction.
[out]outDecoded header; ignored when NULL.
Precondition
buf holds at least k_c6_proto_hdr_size bytes.
out is non-NULL for anything to be stored.
Postcondition
Every out field is populated from the wire bytes.
out->computed holds the locally recomputed checksum.
Note
Performs no validation; c6_probe_classify judges the result.
Example:
c6_hdr_t h = {};
void c6_probe_decode_header(const uint8_t *buf, c6_hdr_t *out)
Unpack the twelve-byte esp-hosted payload header.
Definition c6_frame.c:72
Decoded esp-hosted payload header plus the locally recomputed sum.
Definition c6_proto.h:246
See also
c6_probe_classify
Since
0.1.0

Definition at line 72 of file c6_frame.c.

References c6_probe_checksum(), c6_hdr_t::checksum, c6_hdr_t::computed, c6_hdr_t::flags, c6_hdr_t::if_num, c6_hdr_t::if_type, internal_le16(), k_c6_hdr_off_csum_lo, k_c6_hdr_off_flags, k_c6_hdr_off_iface, k_c6_hdr_off_len_lo, k_c6_hdr_off_off_lo, k_c6_hdr_off_pkttype, k_c6_hdr_off_seq_lo, k_c6_hdr_off_throttle, k_c6_mask_nibble, k_c6_mask_throttle, k_c6_proto_hdr_size, k_c6_proto_payload_max, k_c6_shift_nibble, c6_hdr_t::len, c6_hdr_t::offset, c6_hdr_t::pkt_type, c6_hdr_t::seq_num, and c6_hdr_t::throttle.

Referenced by internal_report_frame().

◆ c6_probe_dump_payload()

void c6_probe_dump_payload ( const uint8_t * buf,
uint16_t len )

Hex-dump the leading payload bytes of a received frame.

Parameters
[in]bufReceive buffer.
[in]lenPayload length claimed by the header.
Precondition
The board UART console has been initialised.
buf holds a completed transaction.
Postcondition
At most k_c6_probe_dump_bytes payload bytes were printed.
buf is unmodified.
Note
Not thread-safe.
Example:
void c6_probe_dump_payload(const uint8_t *buf, uint16_t len)
Hex-dump the leading payload bytes of a received frame.
Definition c6_frame.c:142
See also
c6_probe_print_header
Since
0.1.0

Definition at line 142 of file c6_frame.c.

References c6_probe_put_hex(), c6_probe_puts(), k_c6_fmt_hex_byte, k_c6_probe_dump_bytes, and k_c6_proto_hdr_size.

Referenced by internal_report_frame().

◆ c6_probe_print_header()

void c6_probe_print_header ( const c6_hdr_t * h)

Print the decoded header fields on one console line.

Parameters
[in]hDecoded header; ignored when NULL.
Precondition
The board UART console has been initialised.
h is non-NULL for anything to be printed.
Postcondition
Exactly one console line was emitted when h is non-NULL.
h is unmodified.
Note
Not thread-safe.
Example:
void c6_probe_print_header(const c6_hdr_t *h)
Print the decoded header fields on one console line.
Definition c6_frame.c:116
See also
c6_probe_dump_payload
Since
0.1.0

Definition at line 116 of file c6_frame.c.

References c6_probe_put_hex(), c6_probe_put_u32(), c6_probe_puts(), c6_hdr_t::checksum, c6_hdr_t::computed, c6_hdr_t::flags, c6_hdr_t::if_num, c6_hdr_t::if_type, k_c6_fmt_hex_byte, k_c6_fmt_hex_word, c6_hdr_t::len, c6_hdr_t::offset, c6_hdr_t::pkt_type, and c6_hdr_t::seq_num.

Referenced by internal_report_frame().

◆ internal_le16()

uint16_t internal_le16 ( const uint8_t * buf,
uint8_t off_lo )
static

Read a little-endian 16-bit field out of a byte buffer.

Matches le16toh as used throughout esp-hosted-mcu, and is byte-order-correct on any host because it reassembles from bytes rather than aliasing a uint16_t.

Parameters
[in]bufSource buffer.
[in]off_loOffset of the low byte; the high byte follows it.
Returns
The reassembled 16-bit value, or zero when buf is NULL.
Return values
0buf was NULL or the field genuinely reads zero.
Precondition
buf holds at least off_lo + 2 bytes.
off_lo is a header offset from c6_hdr_offset_t.
Postcondition
No buffer byte is modified.
The result is independent of host endianness.
Note
Pure function; safe from any context.
Since
0.1.0

Definition at line 46 of file c6_frame.c.

References k_c6_shift_byte.

Referenced by c6_probe_decode_header().