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

Bounded console formatters for the ra8_c6link bring-up application. More...

#include <stddef.h>
#include <stdint.h>
#include "c6_wifi.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_c6link.h"
Include dependency graph for c6_wifi_console.c:

Go to the source code of this file.

Enumerations

enum  c6_wifi_ascii_t : uint8_t {
  k_c6_wifi_ascii_low = 0x20U ,
  k_c6_wifi_ascii_high = 0x7EU ,
  k_c6_wifi_ascii_sub = '.'
}
 Printable-ASCII window used to sanitise co-processor text. More...

Functions

void c6_wifi_puts (const char *text)
 Write a NUL-terminated string to the board console.
void c6_wifi_put_u32 (uint32_t value)
 Implementation of c6_wifi_put_u32() – reversed division loop.
void c6_wifi_put_i32 (int32_t value)
 Implementation of c6_wifi_put_i32() – two's-complement magnitude.
void c6_wifi_put_hex (uint32_t value, uint8_t digits)
 Emit a value as a fixed-width lower-case hexadecimal field.
void c6_wifi_put_text (const char *text, size_t len)
 Implementation of c6_wifi_put_text() – truncate, then sanitise.
void c6_wifi_put_mac (const ra8_c6link_mac_t *mac)
 Emit an IEEE 802 address as six colon-separated hexadecimal octets.
void c6_wifi_print_banner (uint32_t cpuclk_hz, uint32_t pclka_hz)
 Print the banner: identity, clocks and link parameters.
void c6_wifi_print_stats (const char *label, const ra8_c6link_stats_t *stats)
 Print what one facade poll did, as one console line.

Detailed Description

Bounded console formatters for the ra8_c6link bring-up application.

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

Six tiny serialisers – string, unsigned decimal, signed decimal, hexadecimal, untrusted text and MAC address – plus the banner and the poll-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_wifi.h, which is what satisfies NASA Power of 10 Rule 2. c6_wifi_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_wifi_console.c.

Enumeration Type Documentation

◆ c6_wifi_ascii_t

enum c6_wifi_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_wifi_ascii_low is the first printable code point and k_c6_wifi_ascii_high the last, so the test is a range test.
Example:
const bool ok = (b >= k_c6_wifi_ascii_low) && (b <= k_c6_wifi_ascii_high);
@ k_c6_wifi_ascii_high
Tilde: highest printable code point.
@ k_c6_wifi_ascii_low
Space: lowest printable code point.
See also
c6_wifi_put_text
Since
0.1.0
Enumerator
k_c6_wifi_ascii_low 

Space: lowest printable code point.

k_c6_wifi_ascii_high 

Tilde: highest printable code point.

k_c6_wifi_ascii_sub 

Substitute for anything else.

Definition at line 46 of file c6_wifi_console.c.

Function Documentation

◆ c6_wifi_print_banner()

void c6_wifi_print_banner ( uint32_t cpuclk_hz,
uint32_t pclka_hz )

Print the banner: identity, clocks and link 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 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_wifi_print_stats
Since
0.1.0

Definition at line 140 of file c6_wifi_console.c.

References c6_wifi_put_u32(), c6_wifi_puts(), k_c6_wifi_sck_hz, k_ra8_board_pmod1_sci_channel, k_ra8_c6link_frame_bytes, and k_ra8_c6link_max_payload.

Referenced by main().

◆ c6_wifi_print_stats()

void c6_wifi_print_stats ( const char * label,
const ra8_c6link_stats_t * stats )

Print what one facade poll 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 ra8_c6link_poll; null prints nothing.
Returns
Nothing.
Precondition
The console is up.
stats came from a completed poll.
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
ra8_c6link_stats
Since
0.1.0

Definition at line 159 of file c6_wifi_console.c.

References ra8_c6link_stats::bad_checksum, c6_wifi_put_u32(), c6_wifi_puts(), ra8_c6link_stats::data, ra8_c6link_stats::eth_in, ra8_c6link_stats::events, ra8_c6link_stats::hs_timeouts, ra8_c6link_stats::idle, ra8_c6link_stats::malformed, ra8_c6link_stats::rpc_in, ra8_c6link_stats::transfers, ra8_c6link_stats::undecodable, and ra8_c6link_stats::unrouted.

Referenced by c6_wifi_phase_station().

◆ c6_wifi_put_hex()

void c6_wifi_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_wifi_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_wifi_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_wifi_put_u32
Since
0.1.0

Definition at line 94 of file c6_wifi_console.c.

References k_c6_wifi_hex_alpha, k_c6_wifi_hex_bits, k_c6_wifi_hex_digits, k_c6_wifi_hex_mask, and ra8_board_uart_console_write().

Referenced by c6_wifi_phase_identity(), and c6_wifi_put_mac().

◆ c6_wifi_put_i32()

void c6_wifi_put_i32 ( int32_t value)

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

Emit a signed 32-bit value in decimal.

Definition at line 84 of file c6_wifi_console.c.

References c6_wifi_put_u32(), and c6_wifi_puts().

Referenced by c6_wifi_on_event(), and c6_wifi_report_fault().

◆ c6_wifi_put_mac()

void c6_wifi_put_mac ( const ra8_c6link_mac_t * mac)

Emit an IEEE 802 address as six colon-separated hexadecimal octets.

Parameters
[in]macAddress to print; null prints nothing.
Returns
Nothing.
Precondition
The console is up.
mac was filled by ra8_c6link_wifi_mac or is the zero address.
Postcondition
Seventeen characters were emitted, or none on a null argument.
No application state is modified.
Note
The loop is bounded by k_ra8_c6link_mac_bytes (NASA Rule 2).
See also
ra8_c6link_wifi_mac
Since
0.1.0

Definition at line 127 of file c6_wifi_console.c.

References c6_wifi_put_hex(), c6_wifi_puts(), k_c6_wifi_hex_byte, k_ra8_c6link_mac_bytes, and ra8_c6link_mac::octet.

Referenced by c6_wifi_phase_station().

◆ c6_wifi_put_text()

void c6_wifi_put_text ( const char * text,
size_t len )

Implementation of c6_wifi_put_text() – truncate, then sanitise.

Emit a NUL-terminated co-processor string as printable text.

Definition at line 111 of file c6_wifi_console.c.

References k_c6_wifi_ascii_high, k_c6_wifi_ascii_low, k_c6_wifi_ascii_sub, k_c6_wifi_text_max, and ra8_board_uart_console_write().

Referenced by c6_wifi_on_event(), and c6_wifi_phase_identity().

◆ c6_wifi_put_u32()

void c6_wifi_put_u32 ( uint32_t value)

◆ c6_wifi_puts()

void c6_wifi_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_wifi_str_max.
Returns
Nothing.
Precondition
ra8_board_uart_console_init has succeeded.
text is NUL-terminated within k_c6_wifi_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_wifi_put_u32
Since
0.1.0

Definition at line 52 of file c6_wifi_console.c.

References k_c6_wifi_str_max, and ra8_board_uart_console_write().

Referenced by c6_wifi_heartbeat(), c6_wifi_on_event(), c6_wifi_phase_identity(), c6_wifi_phase_ready(), c6_wifi_phase_station(), c6_wifi_print_banner(), c6_wifi_print_stats(), c6_wifi_put_i32(), c6_wifi_put_mac(), c6_wifi_report_fault(), c6_wifi_worker_entry(), main(), and tx_application_define().