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

SCI8 / J-Link OB CDC console + text formatters (see header). More...

#include "usb_selftest_console.h"
#include <stdint.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_err.h"
#include "usb_selftest_common.h"
Include dependency graph for usb_selftest_console.c:

Go to the source code of this file.

Functions

static uint8_t selftest_nibble_to_hex (uint32_t nibble)
static uint32_t selftest_str_len (const char *text)
 Bounded ASCII string length (cap k_selftest_print_cap).
static ra8_err_t selftest_sci_write (const uint8_t *data, uint32_t len)
 Push a literal block over SCI8 polled.
ra8_err_t selftest_print (const char *text)
 Print a NUL-terminated ASCII string over the console.
ra8_err_t selftest_print_dec (uint32_t value)
 Print a uint32_t as ASCII decimal.
ra8_err_t selftest_print_hex (uint32_t value, uint8_t digits)
 Print a value as fixed-width uppercase hex.
ra8_err_t selftest_print_fail (const char *what, ra8_err_t err)
 Print "FAIL <what> err=0xNNNNNNNN" on its own line.

Detailed Description

SCI8 / J-Link OB CDC console + text formatters (see header).

The shared console for the soak self-test: a thin wrapper over polled SCI8 writes plus minimal heap-free decimal / hex / fail-line formatters. Split out of main.c so every TU prints through one path.

Since
0.1.0

Definition in file usb_selftest_console.c.

Function Documentation

◆ selftest_nibble_to_hex()

uint8_t selftest_nibble_to_hex ( uint32_t nibble)
static

Definition at line 23 of file usb_selftest_console.c.

References k_selftest_hex_digit_split.

Referenced by selftest_print_hex().

◆ selftest_print()

ra8_err_t selftest_print ( const char * text)
nodiscard

Print a NUL-terminated ASCII string over the console.

Length-bounded by selftest_str_len.

Parameters
[in]textString to print (CR/LF included by the caller).
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran; text is non-NULL.
text is NUL-terminated within k_selftest_print_cap bytes.
Postcondition
The string bytes are in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 103 of file usb_selftest_console.c.

References selftest_sci_write(), selftest_sci_write(), selftest_str_len(), and selftest_str_len().

Referenced by selftest_print_fail().

◆ selftest_print_dec()

ra8_err_t selftest_print_dec ( uint32_t value)
nodiscard

Print a uint32_t as ASCII decimal.

Print an unsigned 32-bit value in decimal.

Digit-reversal into a bounded scratch buffer.

Parameters
[in]valueValue to print.
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran.
None beyond console readiness.
Postcondition
One ASCII decimal token is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 126 of file usb_selftest_console.c.

References k_selftest_dec_chars_u32, k_selftest_dec_radix, selftest_sci_write(), and selftest_sci_write().

◆ selftest_print_fail()

ra8_err_t selftest_print_fail ( const char * what,
ra8_err_t err )
nodiscard

Print "FAIL <what> err=0xNNNNNNNN" on its own line.

Print a "FAIL <what> err=0x..." diagnostic line.

One-line diagnostic; print errors inside are not recoverable anyway, so the first failing chunk's code is returned.

Parameters
[in]whatShort description of the failed step.
[in]errError code returned by the step.
Returns
ra8_err_t propagated from the SCI helpers.
Return values
k_ra8_okThe diagnostic line is queued.
Precondition
SCI8 init already ran.
what is NUL-terminated within the print cap.
Postcondition
One diagnostic line is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 203 of file usb_selftest_console.c.

References k_ra8_ok, k_selftest_hex_chars_u32, selftest_print(), and selftest_print_hex().

◆ selftest_print_hex()

ra8_err_t selftest_print_hex ( uint32_t value,
uint8_t digits )
nodiscard

Print a value as fixed-width uppercase hex.

Print the low digits hex nibbles of value (upper-case).

Width is clamped to 8 hex digits.

Parameters
[in]valueValue to print.
[in]digitsHex digit count (4 for u16, 8 for u32).
Returns
ra8_err_t propagated from the SCI helper.
Return values
k_ra8_okAll bytes queued.
Precondition
SCI8 init already ran.
digits is at most k_selftest_hex_chars_u32.
Postcondition
One fixed-width hex token is in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 169 of file usb_selftest_console.c.

References k_selftest_hex_chars_u32, k_selftest_nibble_bits, k_selftest_nibble_mask, selftest_nibble_to_hex(), selftest_nibble_to_hex(), selftest_sci_write(), and selftest_sci_write().

Referenced by selftest_print_fail().

◆ selftest_sci_write()

ra8_err_t selftest_sci_write ( const uint8_t * data,
uint32_t len )
staticnodiscard

Push a literal block over SCI8 polled.

Thin wrapper fixing the console channel.

Parameters
[in]dataBuffer to send.
[in]lenByte count.
Returns
ra8_err_t passthrough from ra8_board_uart_console_write.
Return values
k_ra8_okAll bytes queued.
Precondition
data is non-NULL; SCI8 init already ran.
len excludes any NUL terminator.
Postcondition
Bytes have been pushed out the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 80 of file usb_selftest_console.c.

References ra8_board_uart_console_write().

Referenced by selftest_print(), selftest_print_dec(), and selftest_print_hex().

◆ selftest_str_len()

uint32_t selftest_str_len ( const char * text)
static

Bounded ASCII string length (cap k_selftest_print_cap).

Linear scan with a hard upper bound.

Parameters
[in]textNUL-terminated string.
Returns
Number of bytes before the NUL, capped.
Return values
0For an empty string.
Precondition
text is non-NULL.
text points to readable storage of at least the returned length.
Postcondition
No state changes.
Return value never exceeds k_selftest_print_cap.
Note
Bounded scan – never walks past the cap on a missing NUL.
Since
0.1.0

Definition at line 49 of file usb_selftest_console.c.

References k_selftest_print_cap.

Referenced by selftest_print().