ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
wifi_hal_console.c
Go to the documentation of this file.
1
20
21#include <stddef.h>
22#include <stdint.h>
23
24#include "ra8_board_ek_ra8d2.h"
25#include "ra8_c6link.h"
26#include "ra8_wifi.h"
27#include "wifi_hal_join.h"
28
29void wifi_hal_puts(const char* text)
30{
31 if (text == nullptr) {
32 return;
33 }
34 uint32_t len = 0U;
35 while ((len < (uint32_t)k_wifi_hal_str_max) && (text[len] != '\0')) {
36 len++;
37 }
38 (void)ra8_board_uart_console_write((const uint8_t*)text, (size_t)len);
39}
40
42void wifi_hal_put_u32(uint32_t value)
43{
44 uint8_t digits[k_wifi_hal_dec_digits] = {};
45 uint32_t count = 0U;
46 uint32_t rest = value;
47 do {
48 digits[count] = (uint8_t)('0' + (uint8_t)(rest % (uint32_t)k_wifi_hal_dec_radix));
49 rest = rest / (uint32_t)k_wifi_hal_dec_radix;
50 count++;
51 } while ((rest != 0U) && (count < (uint32_t)k_wifi_hal_dec_digits));
52
53 uint8_t out[k_wifi_hal_dec_digits] = {};
54 for (uint32_t i = 0U; i < count; i++) {
55 out[i] = digits[count - 1U - i];
56 }
57 (void)ra8_board_uart_console_write(out, (size_t)count);
58}
59
60void wifi_hal_put_hex(uint32_t value, uint8_t digits)
61{
62 if ((digits == 0U) || (digits > (uint8_t)k_wifi_hal_hex_digits)) {
63 return;
64 }
65 uint8_t out[k_wifi_hal_hex_digits] = {};
66 for (uint8_t i = 0U; i < digits; i++) {
67 const uint8_t shift = (uint8_t)((digits - 1U - i) * (uint8_t)k_wifi_hal_hex_bits);
68 const uint8_t nibble = (uint8_t)((value >> shift) & (uint32_t)k_wifi_hal_hex_mask);
69 out[i] = (nibble < (uint8_t)k_wifi_hal_hex_alpha)
70 ? (uint8_t)('0' + nibble)
71 : (uint8_t)('a' + (uint8_t)(nibble - (uint8_t)k_wifi_hal_hex_alpha));
72 }
73 (void)ra8_board_uart_console_write(out, (size_t)digits);
74}
75
77void wifi_hal_put_ip(uint32_t ip)
78{
79 const uint8_t shifts[k_wifi_hal_ip_octets] = {
80 (uint8_t)k_wifi_hal_ip_shift_0,
81 (uint8_t)k_wifi_hal_ip_shift_1,
82 (uint8_t)k_wifi_hal_ip_shift_2,
83 (uint8_t)k_wifi_hal_ip_shift_3,
84 };
85 for (uint8_t i = 0U; i < (uint8_t)k_wifi_hal_ip_octets; i++) {
86 if (i != 0U) {
87 wifi_hal_puts(".");
88 }
89 wifi_hal_put_u32((ip >> shifts[i]) & (uint32_t)k_wifi_hal_ip_mask);
90 }
91}
92
94{
95 if (mac == nullptr) {
96 return;
97 }
98 for (uint8_t i = 0U; i < (uint8_t)k_ra8_wifi_mac_bytes; i++) {
99 if (i != 0U) {
100 wifi_hal_puts(":");
101 }
102 wifi_hal_put_hex((uint32_t)mac->octet[i], (uint8_t)k_wifi_hal_hex_byte);
103 }
104}
105
106void wifi_hal_print_banner(uint32_t cpuclk_hz, uint32_t pclka_hz)
107{
108 wifi_hal_puts("wifi_hal: EK-RA8D2 <-> ESP32-C6 Wi-Fi join + DHCP via ra8_wifi\r\n");
109 wifi_hal_puts("wifi_hal: cpuclk0_hz=");
110 wifi_hal_put_u32(cpuclk_hz);
111 wifi_hal_puts(" pclka_hz=");
112 wifi_hal_put_u32(pclka_hz);
113 wifi_hal_puts("\r\n");
114 wifi_hal_puts("wifi_hal: spi sci=");
116 wifi_hal_puts(" sck_hz=");
118 wifi_hal_puts(" frame_bytes=");
120 wifi_hal_puts("\r\n");
121}
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.
A small, uniform Wi-Fi facade: init, connect, get an IP, disconnect.
@ k_ra8_wifi_mac_bytes
Octets in an IEEE 802 address.
Definition ra8_wifi.h:91
struct ra8_wifi_mac ra8_wifi_mac_t
uint8_t octet[k_ra8_wifi_mac_bytes]
Address octets, first on the wire first.
Definition ra8_wifi.h:210
void wifi_hal_put_ip(uint32_t ip)
Implementation of wifi_hal_put_ip() – four octets, dot-separated.
void wifi_hal_puts(const char *text)
Write a NUL-terminated string to the console, bounded.
void wifi_hal_print_banner(uint32_t cpuclk_hz, uint32_t pclka_hz)
Print the start-up banner naming the clocks and the link geometry.
void wifi_hal_put_mac(const ra8_wifi_mac_t *mac)
Write a station MAC as colon-separated hex octets.
void wifi_hal_put_u32(uint32_t value)
Implementation of wifi_hal_put_u32() – reversed division loop.
void wifi_hal_put_hex(uint32_t value, uint8_t digits)
Write the low digits nibbles of a value in hexadecimal.
Constants, console formatters and the DHCP provider for the HAL join.
@ k_wifi_hal_ip_shift_1
Shift for the second octet.
@ k_wifi_hal_ip_shift_0
Shift for the first (highest) octet.
@ k_wifi_hal_ip_shift_3
Shift for the fourth (lowest) octet.
@ k_wifi_hal_ip_shift_2
Shift for the third octet.
@ k_wifi_hal_hex_byte
Hex digits printed for a byte-wide field.
@ k_wifi_hal_dec_digits
Digits in the widest 32-bit decimal value.
@ k_wifi_hal_ip_mask
Single-octet mask for IPv4 formatting.
@ k_wifi_hal_hex_bits
Bits per hexadecimal digit.
@ k_wifi_hal_hex_digits
Digits in the widest 32-bit hex value.
@ k_wifi_hal_hex_alpha
First nibble value spelled with a letter.
@ k_wifi_hal_dec_radix
Decimal radix.
@ k_wifi_hal_hex_mask
Nibble mask.
@ k_wifi_hal_ip_octets
Octets in an IPv4 address.
@ k_wifi_hal_str_max
Longest string the console helper emits.
@ k_wifi_hal_sck_hz
SPI bit rate; the rate silicon ran at.