|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Network PAL implementation – ra8_eth wrapper. More...
#include "ra8_net_pal.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_eth.h"#include "ra8_log.h"Go to the source code of this file.
Data Structures | |
| struct | ra8_net_pal_slot_t |
| One ring slot holding a single frame plus its byte length. More... | |
| struct | ra8_net_pal_state_t |
| Singleton PAL state. More... | |
Enumerations | |
| enum | ra8_net_pal_ring_dim_t : uint16_t { k_ra8_net_pal_ring_slots = 4U } |
Functions | |
| static void | internal_copy_bytes (uint8_t *dst, const uint8_t *src, uint16_t len) |
| Copy len bytes byte-by-byte (string.h-free implementation). | |
| static void | internal_zero_bytes (uint8_t *dst, uint16_t len) |
| Zero len bytes (project-local replacement for memset). | |
| static void | internal_ring_reset (void) |
| Reset the software ring to empty. | |
| static uint32_t | internal_translate_event (uint32_t eth_mask) |
| Translate ra8_eth status bits into PAL event bits. | |
| static void | internal_eth_event (void *ctx, uint32_t status_mask) |
| ra8_eth event handler – translate + forward to the PAL callback. | |
| ra8_err_t | ra8_net_pal_init (const ra8_net_pal_mac_t *mac) |
| Bring up the network PAL singleton. | |
| ra8_err_t | ra8_net_pal_deinit (void) |
| Tear down the network PAL singleton. | |
| ra8_err_t | ra8_net_pal_set_mac_addr (const ra8_net_pal_mac_t *mac) |
| Programme the PAL MAC address. | |
| ra8_err_t | ra8_net_pal_get_mac_addr (ra8_net_pal_mac_t *out_mac) |
| Read the currently programmed MAC address. | |
| ra8_err_t | ra8_net_pal_send_frame (const uint8_t *frame, uint16_t len) |
| Hand a complete ethernet frame to the MAC for transmit. | |
| ra8_err_t | ra8_net_pal_recv_frame (uint8_t *out_buf, uint16_t *inout_len) |
| Pull the next received ethernet frame, if any, into a buffer. | |
| ra8_err_t | ra8_net_pal_link_status (ra8_net_pal_link_state_t *out_state) |
| Read the current link state. | |
| ra8_err_t | ra8_net_pal_set_event_handler (ra8_net_pal_event_fn_t fn, void *ctx) |
| Install a single event handler for link / RX / TX events. | |
Variables | |
| static const char * | s_tag = "NETPAL" |
| static ra8_net_pal_state_t | s_state = {} |
Network PAL implementation – ra8_eth wrapper.
PAL over the Ring-3 ra8_eth driver. The PAL owns a small in-memory TX/RX ring the stack drains with the send/recv primitives. On real hardware the ring would be backed by the GWCA descriptor engine; today the ring is a contiguous RAM buffer large enough for Ethernet loopback tests.
Definition in file ra8_net_pal.c.
| enum ra8_net_pal_ring_dim_t : uint16_t |
| Enumerator | |
|---|---|
| k_ra8_net_pal_ring_slots | Number of in-flight frames. |
Definition at line 91 of file ra8_net_pal.c.
|
static |
Copy len bytes byte-by-byte (string.h-free implementation).
The codebase avoids string.h to dodge clang-tidy's insecureAPI.DeprecatedOrUnsafeBufferHandling check; this loop is the project-local replacement for memcpy on small fixed buffers like the 6-byte MAC.
| [out] | dst | Destination buffer; must hold at least len bytes. |
| [in] | src | Source buffer; must hold at least len bytes. |
| [in] | len | Number of bytes to copy. |
Definition at line 51 of file ra8_net_pal.c.
Referenced by ra8_net_pal_get_mac_addr(), ra8_net_pal_init(), ra8_net_pal_recv_frame(), ra8_net_pal_send_frame(), and ra8_net_pal_set_mac_addr().
|
static |
ra8_eth event handler – translate + forward to the PAL callback.
Installed via ra8_eth_attach_handler during ra8_net_pal_init. Drops events while the PAL is uninitialized, then translates the raw status mask via internal_translate_event and forwards non-zero results to the stack-installed callback.
| [in] | ctx | Opaque context (unused – PAL is a singleton). |
| [in] | status_mask | Raw ra8_eth status bits. |
Definition at line 212 of file ra8_net_pal.c.
References internal_translate_event(), k_ra8_net_pal_event_none, and s_state.
Referenced by ra8_net_pal_init().
|
static |
Reset the software ring to empty.
Clears the head/tail/count cursors and zeroes every slot's len field so a subsequent ra8_net_pal_send_frame starts at slot 0.
Definition at line 149 of file ra8_net_pal.c.
References k_ra8_net_pal_ring_slots, and s_state.
Referenced by ra8_net_pal_deinit(), and ra8_net_pal_init().
|
static |
Translate ra8_eth status bits into PAL event bits.
Today the mapping is "any non-zero ra8_eth status bit becomes an error event"; future waves will fan the bits out into the link/RX/TX event taxonomy.
| [in] | eth_mask | Raw status mask published by ra8_eth. |
| k_ra8_net_pal_event_none | eth_mask was zero. |
| k_ra8_net_pal_event_error | eth_mask had any bit set. |
Definition at line 182 of file ra8_net_pal.c.
References k_ra8_net_pal_event_error, and k_ra8_net_pal_event_none.
Referenced by internal_eth_event().
|
static |
Zero len bytes (project-local replacement for memset).
Same rationale as internal_copy_bytes – string.h is excluded by clang-tidy policy, so a hand-rolled loop fills small buffers.
| [out] | dst | Destination buffer; must hold at least len bytes. |
| [in] | len | Number of bytes to clear. |
Definition at line 77 of file ra8_net_pal.c.
Referenced by ra8_net_pal_init().
|
nodiscard |
Tear down the network PAL singleton.
Tear down the network PAL.
Detaches the ra8_eth handler, releases the underlying driver, clears the event callback, marks the link as down, and resets the in-memory ring.
| k_ra8_ok | Released cleanly. |
| k_ra8_err_invalid_state | PAL was never initialized. |
Definition at line 302 of file ra8_net_pal.c.
References internal_ring_reset(), k_ra8_err_invalid_state, k_ra8_net_pal_link_down, ra8_eth_attach_handler(), ra8_eth_deinit(), and s_state.
|
nodiscard |
Read the currently programmed MAC address.
Copies s_state.mac into the caller buffer.
| [out] | out_mac | Receives the MAC descriptor. |
| k_ra8_ok | MAC copied. |
| k_ra8_err_null_ptr | out_mac was NULL. |
| k_ra8_err_invalid_state | PAL not initialized. |
Definition at line 369 of file ra8_net_pal.c.
References ra8_net_pal_mac_t::bytes, internal_copy_bytes(), k_ra8_err_invalid_state, k_ra8_net_pal_mac_addr_len, k_ra8_ok, RA8_CHECK_NULL_PTR, s_state, and s_tag.
|
nodiscard |
Bring up the network PAL singleton.
Initialise the network PAL.
Powers up the underlying ra8_eth driver, programmes the supplied MAC (or leaves it zero), resets the in-memory ring, and installs the internal ra8_eth event handler so the stack callback can fire.
| [in] | mac | MAC descriptor to programme; may be NULL to keep the all-zero default. |
| k_ra8_ok | PAL ready, link state = down. |
| k_ra8_err_hw_init_failed | ra8_eth_init failed. |
Definition at line 256 of file ra8_net_pal.c.
References ra8_net_pal_mac_t::bytes, internal_copy_bytes(), internal_eth_event(), internal_ring_reset(), internal_zero_bytes(), k_ra8_err_hw_init_failed, k_ra8_net_pal_link_down, k_ra8_net_pal_mac_addr_len, k_ra8_ok, ra8_eth_attach_handler(), ra8_eth_init(), ra8_log_error_val, ra8_log_info, s_state, and s_tag.
|
nodiscard |
Read the current link state.
| [out] | out_state | Receives link up/down. |
| k_ra8_ok | Link state copied. |
| k_ra8_err_null_ptr | out_state was NULL. |
| k_ra8_err_invalid_state | PAL not initialized. |
Definition at line 485 of file ra8_net_pal.c.
References k_ra8_err_invalid_state, k_ra8_ok, RA8_CHECK_NULL_PTR, s_state, and s_tag.
|
nodiscard |
Pull the next received ethernet frame, if any, into a buffer.
If a frame is available it is copied into out_buf and *inout_len is set to the byte count actually written. When no frame is queued the function returns k_ra8_err_no_data so callers can poll without blocking.
| [out] | out_buf | Destination buffer, sized at least k_ra8_net_pal_frame_max bytes. |
| [in,out] | inout_len | On entry: capacity of out_buf. On exit: bytes written. |
| k_ra8_ok | Frame copied. |
| k_ra8_err_no_data | No frame ready. |
| k_ra8_err_null_ptr | out_buf or inout_len NULL. |
| k_ra8_err_invalid_state | PAL not initialized. |
| k_ra8_err_invalid_arg | *inout_len < k_ra8_net_pal_frame_max. |
Definition at line 462 of file ra8_net_pal.c.
References ra8_net_pal_slot_t::data, internal_copy_bytes(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_err_no_data, k_ra8_net_pal_frame_max, k_ra8_net_pal_ring_slots, k_ra8_ok, ra8_net_pal_slot_t::len, RA8_CHECK_NULL_PTR, s_state, and s_tag.
Referenced by ra8_nsc_eth_recv().
|
nodiscard |
Hand a complete ethernet frame to the MAC for transmit.
Copies frame[0..len-1] into the next free TX ring slot. On real hardware the slot would be a GWCA descriptor; in the host build it is a plain RAM buffer the PAL also exposes through ra8_net_pal_recv_frame for loopback tests. Fires the k_ra8_net_pal_event_tx_done event after enqueue when an event handler is installed.
| [in] | frame | Ethernet frame bytes (header + payload, no FCS). |
| [in] | len | Frame length in bytes; non-zero, <= frame_max. |
| k_ra8_ok | Frame queued. |
| k_ra8_err_null_ptr | frame was NULL. |
| k_ra8_err_invalid_arg | len zero or above k_ra8_net_pal_frame_max. |
| k_ra8_err_invalid_state | PAL not initialized. |
| k_ra8_err_no_mem | TX ring is full; retry after drain. |
Definition at line 409 of file ra8_net_pal.c.
References ra8_net_pal_slot_t::data, internal_copy_bytes(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_err_no_mem, k_ra8_net_pal_event_tx_done, k_ra8_net_pal_frame_max, k_ra8_net_pal_ring_slots, k_ra8_ok, ra8_net_pal_slot_t::len, RA8_CHECK_NULL_PTR, s_state, and s_tag.
Referenced by ra8_nsc_eth_send().
|
nodiscard |
Install a single event handler for link / RX / TX events.
Attach a single event handler for link / RX / TX events.
Replaces any previously installed callback. Pass fn == nullptr to detach. The callback fires from ra8_eth ISR/task context via internal_eth_event and from the send/recv hot path.
| [in] | fn | Event callback, or NULL to detach. |
| [in] | ctx | Opaque context handed back to fn. |
| k_ra8_ok | Handler installed/cleared. |
| k_ra8_err_invalid_state | PAL not initialized. |
Definition at line 518 of file ra8_net_pal.c.
References k_ra8_err_invalid_state, k_ra8_ok, and s_state.
|
nodiscard |
Programme the PAL MAC address.
Updates the in-memory MAC. When ra8_eth gains MAC-write support the same call will also update the ESWM hardware filter.
| [in] | mac | Non-NULL MAC descriptor. |
| k_ra8_ok | MAC stored. |
| k_ra8_err_null_ptr | mac was NULL. |
| k_ra8_err_invalid_state | PAL not initialized. |
Definition at line 339 of file ra8_net_pal.c.
References ra8_net_pal_mac_t::bytes, internal_copy_bytes(), k_ra8_err_invalid_state, k_ra8_net_pal_mac_addr_len, k_ra8_ok, RA8_CHECK_NULL_PTR, s_state, and s_tag.
|
static |
Definition at line 125 of file ra8_net_pal.c.
|
static |
Definition at line 84 of file ra8_net_pal.c.