ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
c6_hosted_console.c
Go to the documentation of this file.
1
24
25#include <stddef.h>
26#include <stdint.h>
27
28#include "c6_hosted.h"
29#include "ra8_board_ek_ra8d2.h"
30#include "ra8_esp_hosted_pins.h"
31
32void c6_hosted_puts(const char* text)
33{
34 if (text == nullptr) {
35 return;
36 }
37 uint32_t len = 0U;
38 while ((len < (uint32_t)k_c6_hosted_str_max) && (text[len] != '\0')) {
39 len++;
40 }
41 (void)ra8_board_uart_console_write((const uint8_t*)text, (size_t)len);
42}
43
45void c6_hosted_put_u32(uint32_t value)
46{
47 uint8_t digits[k_c6_hosted_dec_digits] = {};
48 uint32_t count = 0U;
49 uint32_t rest = value;
50 do {
51 digits[count] = (uint8_t)('0' + (uint8_t)(rest % (uint32_t)k_c6_hosted_dec_radix));
52 rest = rest / (uint32_t)k_c6_hosted_dec_radix;
53 count++;
54 } while ((rest != 0U) && (count < (uint32_t)k_c6_hosted_dec_digits));
55
56 uint8_t out[k_c6_hosted_dec_digits] = {};
57 for (uint32_t i = 0U; i < count; i++) {
58 out[i] = digits[count - 1U - i];
59 }
60 (void)ra8_board_uart_console_write(out, (size_t)count);
61}
62
64void c6_hosted_put_i32(int32_t value)
65{
66 uint32_t magnitude = (uint32_t)value;
67 if (value < 0) {
68 c6_hosted_puts("-");
69 magnitude = ~(uint32_t)value + 1U;
70 }
71 c6_hosted_put_u32(magnitude);
72}
73
74void c6_hosted_put_hex(uint32_t value, uint8_t digits)
75{
76 if ((digits == 0U) || (digits > (uint8_t)k_c6_hosted_hex_digits)) {
77 return;
78 }
79 uint8_t out[k_c6_hosted_hex_digits] = {};
80 for (uint8_t i = 0U; i < digits; i++) {
81 const uint8_t shift = (uint8_t)((digits - 1U - i) * (uint8_t)k_c6_hosted_hex_bits);
82 const uint8_t nibble = (uint8_t)((value >> shift) & (uint32_t)k_c6_hosted_hex_mask);
83 out[i] = (nibble < (uint8_t)k_c6_hosted_hex_alpha)
84 ? (uint8_t)('0' + nibble)
85 : (uint8_t)('a' + (uint8_t)(nibble - (uint8_t)k_c6_hosted_hex_alpha));
86 }
87 (void)ra8_board_uart_console_write(out, (size_t)digits);
88}
89
90void c6_hosted_print_gpio(const char* label, const void* gpio_port, int32_t gpio_pin)
91{
92 c6_hosted_puts(label);
93 if (gpio_pin < 0) {
94 c6_hosted_puts("=unwired");
95 return;
96 }
97 c6_hosted_puts("=port");
98 c6_hosted_put_u32((uint32_t)(uintptr_t)gpio_port);
99 c6_hosted_puts(".pin");
100 c6_hosted_put_i32(gpio_pin);
101}
102
105{
106 const bool wired = ((uint16_t)pin != (uint16_t)k_ra8_pin_none);
108 (const void*)(uintptr_t)RA8_PIN_PORT(pin),
109 wired ? (int32_t)RA8_PIN_PIN(pin) : -1);
110}
Shared contract for the esp-hosted port bring-up application.
@ k_c6_hosted_hex_alpha
First nibble value spelled with a letter.
Definition c6_hosted.h:94
@ k_c6_hosted_str_max
Longest string the console helper emits.
Definition c6_hosted.h:88
@ k_c6_hosted_dec_digits
Digits in the widest 32-bit decimal value.
Definition c6_hosted.h:90
@ k_c6_hosted_hex_bits
Bits per hexadecimal digit.
Definition c6_hosted.h:92
@ k_c6_hosted_hex_digits
Digits in the widest 32-bit hex value.
Definition c6_hosted.h:91
@ k_c6_hosted_hex_mask
Nibble mask.
Definition c6_hosted.h:93
@ k_c6_hosted_dec_radix
Decimal radix.
Definition c6_hosted.h:89
void c6_hosted_puts(const char *text)
Write a NUL-terminated string to the board console.
void c6_hosted_put_i32(int32_t value)
Implementation of c6_hosted_put_i32() – two's-complement magnitude.
void c6_hosted_put_u32(uint32_t value)
Implementation of c6_hosted_put_u32() – reversed division loop.
void c6_hosted_put_hex(uint32_t value, uint8_t digits)
Emit a value as a fixed-width lower-case hexadecimal field.
void c6_hosted_print_pin(const char *label, ra8_esp_hosted_pin_t pin)
Implementation of c6_hosted_print_pin() – unpacks, then delegates.
void c6_hosted_print_gpio(const char *label, const void *gpio_port, int32_t gpio_pin)
Print an H_GPIO_*_Port / H_GPIO_*_Pin pair as one field.
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_board_eth_pin_t pin
Pin.
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.
THE single point of change for the RA8 <-> ESP32-C6 harness map.
ra8_esp_hosted_pin_t
RA8-side pin assignment for every esp-hosted link signal.
@ k_ra8_pin_none
Sentinel: no pin selected.
#define RA8_PIN_PORT(p)
Extract the port index from a packed ra8_port_pin_t.
#define RA8_PIN_PIN(p)
Extract the pin index from a packed ra8_port_pin_t.