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

examples/ek_ra8d2/hw_pending/manual/usb_msc_sdcard/src/usb_msc_sdcard_console.c More...

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

Go to the source code of this file.

Functions

static uint8_t sdmsc_nibble_to_hex (uint32_t nibble)
 Format one nibble (0..15) into an uppercase hex character.
static uint32_t sdmsc_str_len (const char *text)
 Bounded ASCII string length (cap k_sdmsc_print_cap).
static ra8_err_t sdmsc_sci_write (const uint8_t *data, uint32_t len)
 Push a literal block over the J-Link OB CDC console polled.
ra8_err_t sdmsc_print (const char *text)
 Print a NUL-terminated ASCII string over the SCI8 console.
ra8_err_t sdmsc_print_dec (uint32_t value)
 Implementation of sdmsc_print_dec() – digit-reversal scratch.
ra8_err_t sdmsc_print_hex (uint32_t value, uint8_t digits)
 Implementation of sdmsc_print_hex() – width clamped to 8.
ra8_err_t sdmsc_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_pending/manual/usb_msc_sdcard/src/usb_msc_sdcard_console.c

SCI8 (J-Link OB CDC) console formatters for the live-SD MSC device

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 sdmsc_print* entry points are declared in usb_msc_sdcard_steps.h and consumed by both main.c and the device-worker sibling.

Author
Brighton Sikarskie
Date
2026-07-08
Since
0.1.0

Definition in file usb_msc_sdcard_console.c.

Function Documentation

◆ sdmsc_nibble_to_hex()

uint8_t sdmsc_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 54 of file usb_msc_sdcard_console.c.

References k_sdmsc_hex_digit_split.

Referenced by sdmsc_print_hex().

◆ sdmsc_print()

ra8_err_t sdmsc_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_sdmsc_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 117 of file usb_msc_sdcard_console.c.

References sdmsc_sci_write(), and sdmsc_str_len().

Referenced by sdmsc_print_card_banner(), sdmsc_print_fail(), and sdmsc_print_ready().

◆ sdmsc_print_dec()

ra8_err_t sdmsc_print_dec ( uint32_t value)
nodiscard

Implementation of sdmsc_print_dec() – digit-reversal scratch.

Print a uint32_t as ASCII decimal over the SCI8 console.

Definition at line 123 of file usb_msc_sdcard_console.c.

References k_sdmsc_dec_chars_u32, k_sdmsc_dec_radix, and sdmsc_sci_write().

Referenced by sdmsc_print_card_banner(), and sdmsc_print_ready().

◆ sdmsc_print_fail()

ra8_err_t sdmsc_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 162 of file usb_msc_sdcard_console.c.

References k_ra8_ok, k_sdmsc_hex_chars_u32, sdmsc_print(), and sdmsc_print_hex().

Referenced by sdmsc_card_up(), and sdmsc_device_worker().

◆ sdmsc_print_hex()

ra8_err_t sdmsc_print_hex ( uint32_t value,
uint8_t digits )
nodiscard

Implementation of sdmsc_print_hex() – width clamped to 8.

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

Definition at line 148 of file usb_msc_sdcard_console.c.

References k_sdmsc_hex_chars_u32, k_sdmsc_nibble_bits, k_sdmsc_nibble_mask, sdmsc_nibble_to_hex(), and sdmsc_sci_write().

Referenced by sdmsc_print_fail().

◆ sdmsc_sci_write()

ra8_err_t sdmsc_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 112 of file usb_msc_sdcard_console.c.

References ra8_board_uart_console_write().

Referenced by sdmsc_print(), sdmsc_print_dec(), and sdmsc_print_hex().

◆ sdmsc_str_len()

uint32_t sdmsc_str_len ( const char * text)
static

Bounded ASCII string length (cap k_sdmsc_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_sdmsc_print_cap.
Note
Bounded scan.
Since
0.1.0

Definition at line 80 of file usb_msc_sdcard_console.c.

References k_sdmsc_print_cap.

Referenced by sdmsc_print().