ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
c6_join_console.c
Go to the documentation of this file.
1
19
20#include <stddef.h>
21#include <stdint.h>
22
23#include "c6_join.h"
24#include "ra8_board_ek_ra8d2.h"
25#include "ra8_c6link.h"
26
27void c6_join_puts(const char* text)
28{
29 if (text == nullptr) {
30 return;
31 }
32 uint32_t len = 0U;
33 while ((len < (uint32_t)k_c6_join_str_max) && (text[len] != '\0')) {
34 len++;
35 }
36 (void)ra8_board_uart_console_write((const uint8_t*)text, (size_t)len);
37}
38
40void c6_join_put_u32(uint32_t value)
41{
42 uint8_t digits[k_c6_join_dec_digits] = {};
43 uint32_t count = 0U;
44 uint32_t rest = value;
45 do {
46 digits[count] = (uint8_t)('0' + (uint8_t)(rest % (uint32_t)k_c6_join_dec_radix));
47 rest = rest / (uint32_t)k_c6_join_dec_radix;
48 count++;
49 } while ((rest != 0U) && (count < (uint32_t)k_c6_join_dec_digits));
50
51 uint8_t out[k_c6_join_dec_digits] = {};
52 for (uint32_t i = 0U; i < count; i++) {
53 out[i] = digits[count - 1U - i];
54 }
55 (void)ra8_board_uart_console_write(out, (size_t)count);
56}
57
58void c6_join_put_hex(uint32_t value, uint8_t digits)
59{
60 if ((digits == 0U) || (digits > (uint8_t)k_c6_join_hex_digits)) {
61 return;
62 }
63 uint8_t out[k_c6_join_hex_digits] = {};
64 for (uint8_t i = 0U; i < digits; i++) {
65 const uint8_t shift = (uint8_t)((digits - 1U - i) * (uint8_t)k_c6_join_hex_bits);
66 const uint8_t nibble = (uint8_t)((value >> shift) & (uint32_t)k_c6_join_hex_mask);
67 out[i] = (nibble < (uint8_t)k_c6_join_hex_alpha)
68 ? (uint8_t)('0' + nibble)
69 : (uint8_t)('a' + (uint8_t)(nibble - (uint8_t)k_c6_join_hex_alpha));
70 }
71 (void)ra8_board_uart_console_write(out, (size_t)digits);
72}
73
75void c6_join_put_ip(uint32_t ip)
76{
77 const uint8_t shifts[k_c6_join_ip_octets] = {
78 (uint8_t)k_c6_join_ip_shift_0,
79 (uint8_t)k_c6_join_ip_shift_1,
80 (uint8_t)k_c6_join_ip_shift_2,
81 (uint8_t)k_c6_join_ip_shift_3,
82 };
83 for (uint8_t i = 0U; i < (uint8_t)k_c6_join_ip_octets; i++) {
84 if (i != 0U) {
85 c6_join_puts(".");
86 }
87 c6_join_put_u32((ip >> shifts[i]) & (uint32_t)k_c6_join_ip_mask);
88 }
89}
90
92{
93 if (mac == nullptr) {
94 return;
95 }
96 for (uint8_t i = 0U; i < (uint8_t)k_ra8_c6link_mac_bytes; i++) {
97 if (i != 0U) {
98 c6_join_puts(":");
99 }
100 c6_join_put_hex((uint32_t)mac->octet[i], (uint8_t)k_c6_join_hex_byte);
101 }
102}
103
104void c6_join_print_banner(uint32_t cpuclk_hz, uint32_t pclka_hz)
105{
106 c6_join_puts("c6_join: EK-RA8D2 <-> ESP32-C6 Wi-Fi join + DHCP + reachability\r\n");
107 c6_join_puts("c6_join: cpuclk0_hz=");
108 c6_join_put_u32(cpuclk_hz);
109 c6_join_puts(" pclka_hz=");
110 c6_join_put_u32(pclka_hz);
111 c6_join_puts("\r\n");
112 c6_join_puts("c6_join: spi sci=");
114 c6_join_puts(" sck_hz=");
116 c6_join_puts(" frame_bytes=");
118 c6_join_puts(" max_payload=");
120 c6_join_puts("\r\n");
121}
Shared contract for the C6 Wi-Fi join + DHCP + reachability app.
@ k_c6_join_ip_shift_1
Shift for the second octet.
Definition c6_join.h:142
@ k_c6_join_ip_shift_2
Shift for the third octet.
Definition c6_join.h:143
@ k_c6_join_ip_shift_0
Shift for the first (highest) octet.
Definition c6_join.h:141
@ k_c6_join_ip_shift_3
Shift for the fourth (lowest) octet.
Definition c6_join.h:144
@ k_c6_join_sck_hz
SPI bit rate; the rate silicon ran at.
Definition c6_join.h:62
@ k_c6_join_str_max
Longest string the console helper emits.
Definition c6_join.h:115
@ k_c6_join_hex_byte
Hex digits printed for a byte-wide field.
Definition c6_join.h:122
@ k_c6_join_hex_bits
Bits per hexadecimal digit.
Definition c6_join.h:119
@ k_c6_join_dec_digits
Digits in the widest 32-bit decimal value.
Definition c6_join.h:117
@ k_c6_join_ip_mask
Single-octet mask for IPv4 formatting.
Definition c6_join.h:124
@ k_c6_join_hex_mask
Nibble mask.
Definition c6_join.h:120
@ k_c6_join_dec_radix
Decimal radix.
Definition c6_join.h:116
@ k_c6_join_ip_octets
Octets in an IPv4 address.
Definition c6_join.h:123
@ k_c6_join_hex_digits
Digits in the widest 32-bit hex value.
Definition c6_join.h:118
@ k_c6_join_hex_alpha
First nibble value spelled with a letter.
Definition c6_join.h:121
void c6_join_print_banner(uint32_t cpuclk_hz, uint32_t pclka_hz)
Print the banner: identity, clocks and link parameters.
void c6_join_put_hex(uint32_t value, uint8_t digits)
Emit a value as a fixed-width lower-case hexadecimal field.
void c6_join_put_ip(uint32_t ip)
Implementation of c6_join_put_ip() – four octets, dot-separated.
void c6_join_put_u32(uint32_t value)
Implementation of c6_join_put_u32() – reversed division loop.
void c6_join_put_mac(const ra8_c6link_mac_t *mac)
Emit an IEEE 802 address as six colon-separated hexadecimal octets.
void c6_join_puts(const char *text)
Write a NUL-terminated string to the board console.
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.