ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
usb_selftest_wlun_console.c
Go to the documentation of this file.
1
24
25#include <stdint.h>
26
27#include "ra8_board_ek_ra8d2.h"
28#include "ra8_err.h"
30
31#ifndef RA8_OFF_TARGET
32
33/* -------------------------------------------------------------------------- */
34/* Shared per-(LUN,LBA) pattern */
35/* -------------------------------------------------------------------------- */
36
37void wlun_pattern_fill(uint32_t lun, uint32_t lba, UCHAR* out)
38{
39 for (uint32_t i = 0U; i < (uint32_t)k_wlun_block_size; i++) {
40 const uint32_t v = (lun * (uint32_t)k_wlun_pat_lun_mul) + (lba * (uint32_t)k_wlun_pat_lba_mul) +
41 i + (uint32_t)k_wlun_pat_bias;
42 out[i] = (UCHAR)(v & (uint32_t)k_wlun_byte_mask);
43 }
44}
45
46/* -------------------------------------------------------------------------- */
47/* Console helpers (SCI8 -> J-Link OB CDC) */
48/* -------------------------------------------------------------------------- */
49
50uint8_t wlun_nibble_to_hex(uint32_t nibble)
51{
52 if (nibble < k_wlun_hex_digit_split) {
53 return (uint8_t)((uint8_t)'0' + (uint8_t)nibble);
54 }
55 return (uint8_t)((uint8_t)'A' + (uint8_t)nibble - (uint8_t)k_wlun_hex_digit_split);
56}
57
58uint32_t wlun_str_len(const char* text)
59{
60 uint32_t len = 0U;
61 while (len < (uint32_t)k_wlun_print_cap) {
62 if (text[len] == '\0') {
63 break;
64 }
65 len++;
66 }
67 return len;
68}
69
70[[nodiscard]] ra8_err_t wlun_sci_write(const uint8_t* data, uint32_t len)
71{
72 return ra8_board_uart_console_write(data, (size_t)len);
73}
74
75[[nodiscard]] ra8_err_t wlun_print(const char* text)
76{
77 return wlun_sci_write((const uint8_t*)text, wlun_str_len(text));
78}
79
80[[nodiscard]] ra8_err_t wlun_print_dec(uint32_t value)
81{
82 uint8_t scratch[k_wlun_dec_chars_u32] = {};
83 uint8_t out[k_wlun_dec_chars_u32] = {};
84 uint8_t count = 0U;
85 uint32_t v = value;
86 if (v == 0U) {
87 out[0] = (uint8_t)'0';
88 return wlun_sci_write(out, 1U);
89 }
90 while (v != 0U) {
91 if (count >= (uint8_t)k_wlun_dec_chars_u32) {
92 break;
93 }
94 scratch[count] = (uint8_t)((uint8_t)'0' + (uint8_t)(v % k_wlun_dec_radix));
95 v = v / k_wlun_dec_radix;
96 count++;
97 }
98 for (uint8_t i = 0U; i < count; i++) {
99 out[i] = scratch[count - 1U - i];
100 }
101 return wlun_sci_write(out, (uint32_t)count);
102}
103
104[[nodiscard]] ra8_err_t wlun_print_hex(uint32_t value, uint8_t digits)
105{
106 uint8_t out[k_wlun_hex_chars_u32] = {};
107 uint8_t width = digits;
108 if (width > (uint8_t)k_wlun_hex_chars_u32) {
109 width = (uint8_t)k_wlun_hex_chars_u32;
110 }
111 for (uint8_t i = 0U; i < width; i++) {
112 const uint8_t shift = (uint8_t)((width - 1U - i) * k_wlun_nibble_bits);
113 out[i] = wlun_nibble_to_hex((value >> shift) & k_wlun_nibble_mask);
114 }
115 return wlun_sci_write(out, (uint32_t)width);
116}
117
118[[nodiscard]] ra8_err_t wlun_print_fail(const char* what, ra8_err_t err)
119{
120 ra8_err_t e = wlun_print("ra8d2 wlun: FAIL ");
121 if (e != k_ra8_ok) {
122 return e;
123 }
124 e = wlun_print(what);
125 if (e != k_ra8_ok) {
126 return e;
127 }
128 e = wlun_print(" err=0x");
129 if (e != k_ra8_ok) {
130 return e;
131 }
132 e = wlun_print_hex((uint32_t)err, (uint8_t)k_wlun_hex_chars_u32);
133 if (e != k_ra8_ok) {
134 return e;
135 }
136 return wlun_print("\r\n");
137}
138
139#endif /* !RA8_OFF_TARGET */
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
void wlun_pattern_fill(uint32_t lun, uint32_t lba, UCHAR *out)
Fill one 512-byte sector with this LUN/LBA's deterministic bytes.
ra8_err_t wlun_print_hex(uint32_t value, uint8_t digits)
Print a value as fixed-width uppercase hex.
ra8_err_t wlun_print(const char *text)
Print a NUL-terminated ASCII string over the console.
uint8_t wlun_nibble_to_hex(uint32_t nibble)
Format one nibble (0..15) into an uppercase hex character.
ra8_err_t wlun_print_fail(const char *what, ra8_err_t err)
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
ra8_err_t wlun_print_dec(uint32_t value)
Print a uint32_t as ASCII decimal.
uint32_t wlun_str_len(const char *text)
Bounded ASCII string length (cap k_wlun_print_cap).
ra8_err_t wlun_sci_write(const uint8_t *data, uint32_t len)
Push a literal block over SCI8 polled.
examples/ek_ra8d2/hil_needs_revalidation/usb_selftest_wlun/inc/usb_selftest_wlun_steps....
@ k_wlun_pat_lba_mul
Per-LBA pattern multiplier.
@ k_wlun_pat_bias
Pattern constant bias.
@ k_wlun_block_size
SCSI logical block size.
@ k_wlun_pat_lun_mul
Per-LUN pattern multiplier.
@ k_wlun_byte_mask
Byte mask.
@ k_wlun_hex_digit_split
Threshold between '0-9'/'A-F'.
@ k_wlun_dec_chars_u32
Max digits for a 32-bit count.
@ k_wlun_nibble_bits
Bits per hex nibble.
@ k_wlun_hex_chars_u32
32-bit value -> "ABCDEF01".
@ k_wlun_print_cap
Bound for console-string scans.
@ k_wlun_nibble_mask
4-bit nibble mask.
@ k_wlun_dec_radix
Base for decimal conversion.