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

Bounded console formatters for the esp-hosted RPC round-trip app. More...

#include <stddef.h>
#include <stdint.h>
#include "c6_fwver.h"
#include "esp_hosted_transport.h"
#include "port_esp_hosted_host_os.h"
#include "ra8_board_ek_ra8d2.h"
Include dependency graph for c6_fwver_console.c:

Go to the source code of this file.

Enumerations

enum  c6_fwver_ascii_t : uint8_t {
  k_c6_fwver_ascii_low = 0x20U ,
  k_c6_fwver_ascii_high = 0x7EU ,
  k_c6_fwver_ascii_sub = '.'
}
 Printable-ASCII window used to sanitise co-processor text. More...

Functions

void c6_fwver_puts (const char *text)
 Write a NUL-terminated string to the board console.
void c6_fwver_put_u32 (uint32_t value)
 Implementation of c6_fwver_put_u32() – reversed division loop.
void c6_fwver_put_i32 (int32_t value)
 Implementation of c6_fwver_put_i32() – two's-complement magnitude.
void c6_fwver_put_hex (uint32_t value, uint8_t digits)
 Emit a value as a fixed-width lower-case hexadecimal field.
void c6_fwver_put_text (const uint8_t *text, size_t len)
 Implementation of c6_fwver_put_text() – truncate, then sanitise.
void c6_fwver_print_banner (uint32_t cpuclk_hz, uint32_t pclka_hz)
 Print the banner: identity, clocks and SPI parameters.
void c6_fwver_print_pump (const char *label, const c6_fwver_pump_stats_t *stats)
 Print what one pump did, as one console line.

Detailed Description

Bounded console formatters for the esp-hosted RPC round-trip app.

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

Five tiny serialisers – string, unsigned decimal, signed decimal, hexadecimal and untrusted text – plus the banner and the pump-statistics line. They exist so the application can narrate itself without dragging newlib's printf (and its heap and reentrancy machinery) into a bare-metal image that has no heap at all.

Every loop here is bounded by a constant from c6_fwver.h, which is what satisfies NASA Power of 10 Rule 2. c6_fwver_put_text is the one that matters for more than that: the bytes it prints come off the wire from the co-processor, so it sanitises rather than trusts.

Since
0.1.0

Definition in file c6_fwver_console.c.

Enumeration Type Documentation

◆ c6_fwver_ascii_t

enum c6_fwver_ascii_t : uint8_t

Printable-ASCII window used to sanitise co-processor text.

A protocol field is evidence; evidence that can reprogram a terminal is not evidence. Anything outside this window is replaced.

Invariant
k_c6_fwver_ascii_low is the first printable code point and k_c6_fwver_ascii_high the last, so the test is a range test.
Example:
const bool ok = (b >= k_c6_fwver_ascii_low) && (b <= k_c6_fwver_ascii_high);
@ k_c6_fwver_ascii_low
Space: lowest printable code point.
@ k_c6_fwver_ascii_high
Tilde: highest printable code point.
See also
c6_fwver_put_text
Since
0.1.0
Enumerator
k_c6_fwver_ascii_low 

Space: lowest printable code point.

k_c6_fwver_ascii_high 

Tilde: highest printable code point.

k_c6_fwver_ascii_sub 

Substitute for anything else.

Definition at line 47 of file c6_fwver_console.c.

Function Documentation

◆ c6_fwver_print_banner()

void c6_fwver_print_banner ( uint32_t cpuclk_hz,
uint32_t pclka_hz )

Print the banner: identity, clocks and SPI parameters.

Parameters
[in]cpuclk_hzLive CPUCLK0 rate in hertz.
[in]pclka_hzLive PCLKA rate in hertz, the SCI baud-clock source.
Returns
Nothing.
Precondition
The console is up.
Both rates were read from the CGC rather than assumed.
Postcondition
Three banner lines were emitted.
No application state is modified.
Note
The SPI mode printed is the co-processor's: the C6 image in coprocessor/esp32c6/ is built with CONFIG_ESP_SPI_MODE=3 and the port opens the bus to match.
See also
c6_fwver_link_pump
Since
0.1.0

Definition at line 128 of file c6_fwver_console.c.

References c6_fwver_put_u32(), c6_fwver_puts(), k_c6_fwver_frame_bytes, k_c6_fwver_sck_hz, k_ra8_board_pmod1_sci_channel, and MAX_PAYLOAD_SIZE.

Referenced by main().

◆ c6_fwver_print_pump()

void c6_fwver_print_pump ( const char * label,
const c6_fwver_pump_stats_t * stats )

Print what one pump did, as one console line.

Parameters
[in]labelField name printed before the counters; null prints nothing at all rather than being dereferenced.
[in]statsCounters filled in by c6_fwver_link_pump; null prints nothing.
Returns
Nothing.
Precondition
The console is up.
stats came from a completed pump.
Postcondition
Exactly one line was emitted, or none on a null argument.
No application state is modified.
Note
Every counter is printed, including the zero ones: a zero bad_checksum beside a non-zero transfers is itself the evidence that the link is clean.
See also
c6_fwver_pump_stats
Since
0.1.0

Definition at line 147 of file c6_fwver_console.c.

References c6_fwver_pump_stats::bad_checksum, c6_fwver_pump_stats::bus_error, c6_fwver_put_u32(), c6_fwver_puts(), c6_fwver_pump_stats::frames, c6_fwver_pump_stats::hs_timeouts, c6_fwver_pump_stats::idle, c6_fwver_pump_stats::ifnum_defect, c6_fwver_pump_stats::malformed, c6_fwver_pump_stats::sink_stopped, and c6_fwver_pump_stats::transfers.

Referenced by c6_fwver_phase_caps(), and c6_fwver_phase_request().

◆ c6_fwver_put_hex()

void c6_fwver_put_hex ( uint32_t value,
uint8_t digits )

Emit a value as a fixed-width lower-case hexadecimal field.

Parameters
[in]valueValue to print.
[in]digitsField width, 1..k_c6_fwver_hex_digits; an out-of-range width prints nothing rather than overrunning the output array.
Returns
Nothing.
Precondition
The console is up.
digits is within 1..k_c6_fwver_hex_digits.
Postcondition
Exactly digits characters were emitted, or none on a bad width.
No application state is modified.
Note
The loop is bounded by the range-checked digits (NASA Rule 2).
See also
c6_fwver_put_u32
Since
0.1.0

Definition at line 95 of file c6_fwver_console.c.

References k_c6_fwver_hex_alpha, k_c6_fwver_hex_bits, k_c6_fwver_hex_digits, k_c6_fwver_hex_mask, and ra8_board_uart_console_write().

Referenced by c6_fwver_print_reject(), c6_fwver_priv_consume(), c6_fwver_priv_tlv(), c6_fwver_rpc_print_expectation(), and c6_fwver_rpc_print_response().

◆ c6_fwver_put_i32()

void c6_fwver_put_i32 ( int32_t value)

Implementation of c6_fwver_put_i32() – two's-complement magnitude.

Emit a signed 32-bit value in decimal.

Definition at line 85 of file c6_fwver_console.c.

References c6_fwver_put_u32(), and c6_fwver_puts().

Referenced by c6_fwver_rpc_print_response().

◆ c6_fwver_put_text()

void c6_fwver_put_text ( const uint8_t * text,
size_t len )

Implementation of c6_fwver_put_text() – truncate, then sanitise.

Emit a length-counted byte range as printable text.

Definition at line 112 of file c6_fwver_console.c.

References k_c6_fwver_ascii_high, k_c6_fwver_ascii_low, k_c6_fwver_ascii_sub, k_c6_fwver_text_max, and ra8_board_uart_console_write().

Referenced by c6_fwver_rpc_print_response().

◆ c6_fwver_put_u32()

◆ c6_fwver_puts()

void c6_fwver_puts ( const char * text)

Write a NUL-terminated string to the board console.

Parameters
[in]textString to emit; null is ignored rather than dereferenced and the length is capped at k_c6_fwver_str_max.
Returns
Nothing.
Precondition
ra8_board_uart_console_init has succeeded.
text is NUL-terminated within k_c6_fwver_str_max bytes.
Postcondition
The bytes are queued on the console transmitter.
No application state is modified.
Note
Not thread-safe; only pre-kernel bring-up and the single worker thread call it, and those never overlap.
See also
c6_fwver_put_u32
Since
0.1.0

Definition at line 53 of file c6_fwver_console.c.

References k_c6_fwver_str_max, and ra8_board_uart_console_write().

Referenced by c6_fwver_dispatch(), c6_fwver_heartbeat(), c6_fwver_phase_caps(), c6_fwver_phase_request(), c6_fwver_print_banner(), c6_fwver_print_pump(), c6_fwver_print_reject(), c6_fwver_priv_consume(), c6_fwver_priv_tlv(), c6_fwver_put_i32(), c6_fwver_rpc_consume(), c6_fwver_rpc_print_crosscheck(), c6_fwver_rpc_print_expectation(), c6_fwver_rpc_print_response(), c6_fwver_rpc_report(), c6_fwver_rx_dispatch(), c6_fwver_worker_entry(), main(), and tx_application_define().