ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_eth.h
Go to the documentation of this file.
1
38
39#pragma once
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45#include <stdint.h>
46
47#include "ra8_err.h"
48
53typedef void (*ra8_eth_event_fn_t)(void* ctx, uint32_t status_mask);
54
59[[nodiscard]] ra8_err_t ra8_eth_init(void);
60
65[[nodiscard]] ra8_err_t ra8_eth_deinit(void);
66
71[[nodiscard]] ra8_err_t ra8_eth_get_status(uint32_t* out_mask);
72
77[[nodiscard]] ra8_err_t ra8_eth_clear_status(uint32_t mask);
78
99
111void ra8_eth_dispatch(void);
112
117[[nodiscard]] ra8_err_t ra8_eth_enter_stop(void);
118
123[[nodiscard]] ra8_err_t ra8_eth_exit_stop(void);
124
142
191
192/* -----------------------------------------------------------------------
193 * Frame-level NIC API (FSP r_ether shape).
194 * -------------------------------------------------------------------- */
195
216
228typedef struct {
229 uint8_t mac_address[6];
230 uint8_t channel;
233 uint16_t buffer_size;
235
244typedef struct {
245 uint8_t link_up;
246 uint16_t speed_mbps;
247 uint8_t full_duplex;
248 uint16_t bmsr;
250
260typedef struct {
261 uint32_t tx_ok;
262 uint32_t rx_ok;
263 uint32_t tx_err;
264 uint32_t rx_err;
266
312[[nodiscard]] ra8_err_t ra8_eth_open(const ra8_eth_cfg_t* cfg);
313
330[[nodiscard]] ra8_err_t ra8_eth_close(void);
331
362[[nodiscard]] ra8_err_t ra8_eth_write(const uint8_t* buf, uint32_t len);
363
395[[nodiscard]] ra8_err_t ra8_eth_read(uint8_t* buf, uint32_t max_len, uint32_t* got_len);
396
421[[nodiscard]] ra8_err_t ra8_eth_link_status(ra8_eth_link_t* out_status);
422
442[[nodiscard]] ra8_err_t ra8_eth_get_stats(ra8_eth_stats_t* out_stats);
443
444#ifdef UNIT_TEST
466[[nodiscard]] ra8_err_t ra8_eth_test_inject_rx(const uint8_t* payload, uint32_t len);
467#endif /* UNIT_TEST */
468
469#ifdef __cplusplus
470}
471#endif
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
void(* ra8_eth_event_fn_t)(void *ctx, uint32_t status_mask)
Ethernet switch event callback.
Definition ra8_eth.h:53
ra8_err_t ra8_eth_enter_stop(void)
Put the ethernet switch into MSTP-gated stop.
Definition ra8_eth.c:553
ra8_err_t ra8_eth_get_status(uint32_t *out_mask)
Read the ESWM_STS status register.
Definition ra8_eth.c:515
ra8_err_t ra8_eth_close(void)
Close the NIC: gate clocks and idle the descriptor rings.
Definition ra8_eth.c:799
ra8_eth_mii_port_t
ESWM media-interface port selector (m = 0, 1).
Definition ra8_eth.h:137
@ k_ra8_eth_mii_port_0
ESWM media port 0 (RMAC0 / ETHA0).
Definition ra8_eth.h:138
@ k_ra8_eth_mii_port_1
ESWM media port 1 (RMAC1 / ETHA1).
Definition ra8_eth.h:139
@ k_ra8_eth_mii_port_count
Number of media-interface ports.
Definition ra8_eth.h:140
ra8_err_t ra8_eth_get_stats(ra8_eth_stats_t *out_stats)
Read the NIC software counters.
Definition ra8_eth.c:869
ra8_err_t ra8_eth_exit_stop(void)
Exit MSTP-gated stop.
Definition ra8_eth.c:560
void ra8_eth_dispatch(void)
Dispatch an ESWM event – snapshot + fire callback.
Definition ra8_eth.c:539
ra8_err_t ra8_eth_write(const uint8_t *buf, uint32_t len)
Transmit a frame through the GWCA TX queue.
Definition ra8_eth.c:825
ra8_err_t ra8_eth_link_status(ra8_eth_link_t *out_status)
Query the PHY link state via MIIM (RMAC MDIO Clause-22).
ra8_eth_limits_t
Compile-time NIC ring sizing constants.
Definition ra8_eth.h:207
@ k_ra8_eth_buf_size
Per-descriptor buffer size in bytes.
Definition ra8_eth.h:210
@ k_ra8_eth_max_frame
Maximum 802.3 untagged frame.
Definition ra8_eth.h:214
@ k_ra8_eth_num_rx_desc
Number of RX descriptors in the ring.
Definition ra8_eth.h:209
@ k_ra8_eth_desc_align
Descriptor / buffer alignment in bytes.
Definition ra8_eth.h:212
@ k_ra8_eth_mac_len
Length of an Ethernet MAC address.
Definition ra8_eth.h:211
@ k_ra8_eth_num_tx_desc
Number of TX descriptors in the ring.
Definition ra8_eth.h:208
@ k_ra8_eth_min_frame
Minimum 802.3 frame (excl.
Definition ra8_eth.h:213
ra8_err_t ra8_eth_open(const ra8_eth_cfg_t *cfg)
Open the NIC: bring up the controller stack and the descriptor rings.
Definition ra8_eth.c:756
void ra8_eth_attach_handler(ra8_eth_event_fn_t fn, void *ctx)
Replace the shared Ethernet event callback.
Definition ra8_eth.c:532
ra8_err_t ra8_eth_deinit(void)
Tear down the ESWM block.
Definition ra8_eth.c:504
ra8_err_t ra8_eth_rgmii_select(ra8_eth_mii_port_t port)
Select RGMII on a port's ESWM media-interface mux and enable it.
ra8_err_t ra8_eth_init(void)
Initialise the ESWM block (MSTP enable + reset regs).
Definition ra8_eth.c:486
ra8_err_t ra8_eth_read(uint8_t *buf, uint32_t max_len, uint32_t *got_len)
Pop the next received frame from the RX descriptor ring.
Definition ra8_eth.c:845
ra8_err_t ra8_eth_clear_status(uint32_t mask)
Clear bits in ESWM_STS via ESWM_ICLR.
Definition ra8_eth.c:523
Per-channel NIC configuration.
Definition ra8_eth.h:228
uint16_t buffer_size
Buffer size per descriptor.
Definition ra8_eth.h:233
uint8_t mac_address[6]
Local MAC address (octets 0..5).
Definition ra8_eth.h:229
uint8_t channel
Logical channel index (0..1).
Definition ra8_eth.h:230
uint16_t num_tx_descriptors
Active TX descriptors (<=8, 0=def).
Definition ra8_eth.h:231
uint16_t num_rx_descriptors
Active RX descriptors (<=8, 0=def).
Definition ra8_eth.h:232
NIC software counters.
Definition ra8_eth.h:260
uint32_t rx_ok
Frames successfully received.
Definition ra8_eth.h:262
uint32_t tx_ok
Frames successfully enqueued.
Definition ra8_eth.h:261
uint32_t rx_err
RX failures (no data, etc.).
Definition ra8_eth.h:264
uint32_t tx_err
TX failures (ring full, etc.).
Definition ra8_eth.h:263