ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
c6_fwver_console.c
Go to the documentation of this file.
1
24
25#include <stddef.h>
26#include <stdint.h>
27
28#include "c6_fwver.h"
29#include "esp_hosted_transport.h"
31#include "ra8_board_ek_ra8d2.h"
32
52
53void c6_fwver_puts(const char* text)
54{
55 if (text == nullptr) {
56 return;
57 }
58 uint32_t len = 0U;
59 while ((len < (uint32_t)k_c6_fwver_str_max) && (text[len] != '\0')) {
60 len++;
61 }
62 (void)ra8_board_uart_console_write((const uint8_t*)text, (size_t)len);
63}
64
66void c6_fwver_put_u32(uint32_t value)
67{
68 uint8_t digits[k_c6_fwver_dec_digits] = {};
69 uint32_t count = 0U;
70 uint32_t rest = value;
71 do {
72 digits[count] = (uint8_t)('0' + (uint8_t)(rest % (uint32_t)k_c6_fwver_dec_radix));
73 rest = rest / (uint32_t)k_c6_fwver_dec_radix;
74 count++;
75 } while ((rest != 0U) && (count < (uint32_t)k_c6_fwver_dec_digits));
76
77 uint8_t out[k_c6_fwver_dec_digits] = {};
78 for (uint32_t i = 0U; i < count; i++) {
79 out[i] = digits[count - 1U - i];
80 }
81 (void)ra8_board_uart_console_write(out, (size_t)count);
82}
83
85void c6_fwver_put_i32(int32_t value)
86{
87 uint32_t magnitude = (uint32_t)value;
88 if (value < 0) {
89 c6_fwver_puts("-");
90 magnitude = ~(uint32_t)value + 1U;
91 }
92 c6_fwver_put_u32(magnitude);
93}
94
95void c6_fwver_put_hex(uint32_t value, uint8_t digits)
96{
97 if ((digits == 0U) || (digits > (uint8_t)k_c6_fwver_hex_digits)) {
98 return;
99 }
100 uint8_t out[k_c6_fwver_hex_digits] = {};
101 for (uint8_t i = 0U; i < digits; i++) {
102 const uint8_t shift = (uint8_t)((digits - 1U - i) * (uint8_t)k_c6_fwver_hex_bits);
103 const uint8_t nibble = (uint8_t)((value >> shift) & (uint32_t)k_c6_fwver_hex_mask);
104 out[i] = (nibble < (uint8_t)k_c6_fwver_hex_alpha)
105 ? (uint8_t)('0' + nibble)
106 : (uint8_t)('a' + (uint8_t)(nibble - (uint8_t)k_c6_fwver_hex_alpha));
107 }
108 (void)ra8_board_uart_console_write(out, (size_t)digits);
109}
110
112void c6_fwver_put_text(const uint8_t* text, size_t len)
113{
114 if ((text == nullptr) || (len == 0U)) {
115 return;
116 }
117 const size_t take = (len < (size_t)k_c6_fwver_text_max) ? len : (size_t)k_c6_fwver_text_max;
118 uint8_t out[k_c6_fwver_text_max] = {};
119 for (size_t i = 0U; i < take; i++) {
120 const uint8_t byte = text[i];
121 const bool printable =
122 (byte >= (uint8_t)k_c6_fwver_ascii_low) && (byte <= (uint8_t)k_c6_fwver_ascii_high);
123 out[i] = printable ? byte : (uint8_t)k_c6_fwver_ascii_sub;
124 }
125 (void)ra8_board_uart_console_write(out, take);
126}
127
128void c6_fwver_print_banner(uint32_t cpuclk_hz, uint32_t pclka_hz)
129{
130 c6_fwver_puts("c6_fwver: EK-RA8D2 <-> ESP32-C6 esp-hosted RPC round-trip\r\n");
131 c6_fwver_puts("c6_fwver: cpuclk0_hz=");
132 c6_fwver_put_u32(cpuclk_hz);
133 c6_fwver_puts(" pclka_hz=");
134 c6_fwver_put_u32(pclka_hz);
135 c6_fwver_puts("\r\n");
136 c6_fwver_puts("c6_fwver: spi sci=");
138 c6_fwver_puts(" sck_hz=");
140 c6_fwver_puts(" frame_bytes=");
142 c6_fwver_puts(" max_payload=");
144 c6_fwver_puts("\r\n");
145}
146
147void c6_fwver_print_pump(const char* label, const c6_fwver_pump_stats_t* stats)
148{
149 if ((label == nullptr) || (stats == nullptr)) {
150 return;
151 }
152 c6_fwver_puts("c6_fwver: pump ");
153 c6_fwver_puts(label);
154 c6_fwver_puts(" xfers=");
155 c6_fwver_put_u32((uint32_t)stats->transfers);
156 c6_fwver_puts(" frames=");
157 c6_fwver_put_u32((uint32_t)stats->frames);
158 c6_fwver_puts(" idle=");
159 c6_fwver_put_u32((uint32_t)stats->idle);
160 c6_fwver_puts(" badcsum=");
161 c6_fwver_put_u32((uint32_t)stats->bad_checksum);
162 c6_fwver_puts(" malformed=");
163 c6_fwver_put_u32((uint32_t)stats->malformed);
164 c6_fwver_puts(" hs_timeouts=");
165 c6_fwver_put_u32((uint32_t)stats->hs_timeouts);
166 c6_fwver_puts(" ifnum_defect=");
167 c6_fwver_put_u32((uint32_t)stats->ifnum_defect);
168 c6_fwver_puts(stats->bus_error ? " bus_error=y" : " bus_error=n");
169 c6_fwver_puts(stats->sink_stopped ? " stopped=sink" : " stopped=budget");
170 c6_fwver_puts("\r\n");
171}
Shared contract for the esp-hosted RPC round-trip application.
@ k_c6_fwver_sck_hz
SPI bit rate; the rate the port ran at on silicon in the c6_hosted_init bring-up.
Definition c6_fwver.h:72
@ k_c6_fwver_frame_bytes
Bytes clocked in one full-duplex transaction.
Definition c6_fwver.h:139
struct c6_fwver_pump_stats c6_fwver_pump_stats_t
@ k_c6_fwver_hex_alpha
First nibble value spelled with a letter.
Definition c6_fwver.h:110
@ k_c6_fwver_str_max
Longest string the console helper emits.
Definition c6_fwver.h:104
@ k_c6_fwver_dec_digits
Digits in the widest 32-bit decimal value.
Definition c6_fwver.h:106
@ k_c6_fwver_dec_radix
Decimal radix.
Definition c6_fwver.h:105
@ k_c6_fwver_hex_mask
Nibble mask.
Definition c6_fwver.h:109
@ k_c6_fwver_hex_digits
Digits in the widest 32-bit hex value.
Definition c6_fwver.h:107
@ k_c6_fwver_text_max
Longest co-processor-supplied string echoed to the console; anything longer is truncated rather than ...
Definition c6_fwver.h:113
@ k_c6_fwver_hex_bits
Bits per hexadecimal digit.
Definition c6_fwver.h:108
void c6_fwver_print_banner(uint32_t cpuclk_hz, uint32_t pclka_hz)
Print the banner: identity, clocks and SPI parameters.
void c6_fwver_put_i32(int32_t value)
Implementation of c6_fwver_put_i32() – two's-complement magnitude.
void c6_fwver_print_pump(const char *label, const c6_fwver_pump_stats_t *stats)
Print what one pump did, as one console line.
void c6_fwver_put_hex(uint32_t value, uint8_t digits)
Emit a value as a fixed-width lower-case hexadecimal field.
c6_fwver_ascii_t
Printable-ASCII window used to sanitise co-processor text.
@ k_c6_fwver_ascii_low
Space: lowest printable code point.
@ k_c6_fwver_ascii_sub
Substitute for anything else.
@ k_c6_fwver_ascii_high
Tilde: highest printable code point.
void c6_fwver_put_text(const uint8_t *text, size_t len)
Implementation of c6_fwver_put_text() – truncate, then sanitise.
void c6_fwver_put_u32(uint32_t value)
Implementation of c6_fwver_put_u32() – reversed division loop.
void c6_fwver_puts(const char *text)
Write a NUL-terminated string to the board console.
esp-hosted port header: RTOS handle types, return codes and budgets.
#define MAX_PAYLOAD_SIZE
Largest payload one transport frame can carry, in bytes.
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
@ k_ra8_board_pmod1_sci_channel
Pmod1 (J26) Simple-SPI is SCI2.
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.
uint16_t malformed
Frames whose offset or length could not be believed.
Definition c6_fwver.h:214
uint16_t idle
Filler frames the co-processor returned (len zero).
Definition c6_fwver.h:212
bool bus_error
A bus transfer did not return RET_OK.
Definition c6_fwver.h:218
uint16_t transfers
Full-duplex transactions clocked.
Definition c6_fwver.h:210
bool sink_stopped
The sink asked the pump to stop early.
Definition c6_fwver.h:219
uint16_t bad_checksum
Frames whose recomputed checksum disagreed.
Definition c6_fwver.h:213
uint16_t frames
Well-formed payload frames handed to the sink.
Definition c6_fwver.h:211
uint16_t ifnum_defect
Bad-checksum frames explained by the co-processor's if_num accounting; see the app README.
Definition c6_fwver.h:216
uint16_t hs_timeouts
Transactions abandoned waiting for HANDSHAKE.
Definition c6_fwver.h:215