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

examples/ek_ra8d2/hw_validated/hil/usb_selftest_microsd/src/usb_selftest_microsd_console.c More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_err.h"
#include "usb_selftest_microsd_steps.h"
Include dependency graph for usb_selftest_microsd_console.c:

Go to the source code of this file.

Functions

static uint8_t microsd_nibble_to_hex (uint32_t nibble)
 Format one nibble (0..15) into an uppercase hex character.
static uint32_t microsd_str_len (const char *text)
 Bounded ASCII string length (cap k_microsd_print_cap).
static ra8_err_t microsd_sci_write (const uint8_t *data, uint32_t len)
 Push a literal block over the J-Link OB CDC console polled.
ra8_err_t microsd_print (const char *text)
 Print a NUL-terminated ASCII string over the SCI8 console.
ra8_err_t microsd_print_dec (uint32_t value)
 Implementation of microsd_print_dec() – digit-reversal scratch.
ra8_err_t microsd_print_hex (uint32_t value, uint8_t digits)
 Implementation of microsd_print_hex() – width clamped to 8.
ra8_err_t microsd_print_fail (const char *what, ra8_err_t err)
 Print "FAIL <what> err=0xNNNNNNNN" on its own console line.

Detailed Description

examples/ek_ra8d2/hw_validated/hil/usb_selftest_microsd/src/usb_selftest_microsd_console.c

SCI8 (J-Link OB CDC) console formatters for the USB-microSD self-test

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

Split out of main.c to keep every translation unit under the line-count cap. Holds the bounded string/hex/decimal text formatters that stream verdicts over SCI8 at 115200 to the J-Link OB CDC bridge. The internal nibble/length/byte-write helpers stay file-static here; the public microsd_print* entry points are declared in usb_selftest_microsd_steps.h and consumed by both main.c and the host/device worker sibling.

Author
Brighton Sikarskie
Date
2026-06-13
Since
0.1.0

Definition in file usb_selftest_microsd_console.c.

Function Documentation

◆ microsd_nibble_to_hex()

uint8_t microsd_nibble_to_hex ( uint32_t nibble)
static

Format one nibble (0..15) into an uppercase hex character.

Standard '0'-'9' then 'A'-'F' mapping.

Parameters
[in]nibble4-bit value.
Returns
ASCII '0'..'9' or 'A'..'F'.
Return values
'0'For a zero nibble.
Precondition
Caller has masked the value to 4 bits.
None beyond the mask contract.
Postcondition
Returned byte is printable hex.
No state changes.
Note
Pure function.
Since
0.1.0

Definition at line 56 of file usb_selftest_microsd_console.c.

References k_microsd_hex_digit_split.

Referenced by microsd_print_hex().

◆ microsd_print()

ra8_err_t microsd_print ( const char * text)
nodiscard

Print a NUL-terminated ASCII string over the SCI8 console.

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_microsd_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 119 of file usb_selftest_microsd_console.c.

References microsd_sci_write(), and microsd_str_len().

Referenced by microsd_host_enumerate(), microsd_host_pass(), microsd_print_fail(), and microsd_print_lun_ok().

◆ microsd_print_dec()

ra8_err_t microsd_print_dec ( uint32_t value)
nodiscard

Implementation of microsd_print_dec() – digit-reversal scratch.

Print a uint32_t as ASCII decimal over the SCI8 console.

Definition at line 125 of file usb_selftest_microsd_console.c.

References k_microsd_dec_chars_u32, k_microsd_dec_radix, and microsd_sci_write().

Referenced by microsd_host_enumerate(), and microsd_print_lun_ok().

◆ microsd_print_fail()

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

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

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 164 of file usb_selftest_microsd_console.c.

References k_microsd_hex_chars_u32, k_ra8_ok, microsd_print(), and microsd_print_hex().

Referenced by microsd_host_enumerate(), microsd_host_pass(), and microsd_verify_one().

◆ microsd_print_hex()

ra8_err_t microsd_print_hex ( uint32_t value,
uint8_t digits )
nodiscard

Implementation of microsd_print_hex() – width clamped to 8.

Print a value as fixed-width uppercase hex over the SCI8 console.

Definition at line 150 of file usb_selftest_microsd_console.c.

References k_microsd_hex_chars_u32, k_microsd_nibble_bits, k_microsd_nibble_mask, microsd_nibble_to_hex(), and microsd_sci_write().

Referenced by microsd_host_enumerate(), and microsd_print_fail().

◆ microsd_sci_write()

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

Push a literal block over the J-Link OB CDC console polled.

Thin wrapper fixing the console channel onto the EK-RA8D2 BSP SCI8 console transport.

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; the BSP console init already ran.
len excludes any NUL terminator.
Postcondition
Bytes are in the SCI8 TX FIFO.
No other state changes.
Note
Blocking polled TX.
Since
0.1.0

Definition at line 114 of file usb_selftest_microsd_console.c.

References ra8_board_uart_console_write().

Referenced by microsd_print(), microsd_print_dec(), and microsd_print_hex().

◆ microsd_str_len()

uint32_t microsd_str_len ( const char * text)
static

Bounded ASCII string length (cap k_microsd_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 length.
Postcondition
No state changes.
Return value never exceeds k_microsd_print_cap.
Note
Bounded scan.
Since
0.1.0

Definition at line 82 of file usb_selftest_microsd_console.c.

References k_microsd_print_cap.

Referenced by microsd_print().