|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Network Platform Abstraction Layer for the RA8D2 ESWM block. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_net_pal_mac_t |
| 48-bit MAC address container. More... | |
Typedefs | |
| typedef void(* | ra8_net_pal_event_fn_t) (void *ctx, uint32_t event_mask) |
| Async event callback shape (link change, RX ready, error). | |
Enumerations | |
| enum | ra8_net_pal_limits_t : uint16_t { k_ra8_net_pal_mac_addr_len = 6U , k_ra8_net_pal_mtu = 1500U , k_ra8_net_pal_frame_max = 1518U } |
| maximums / sizes baked into the PAL contract. More... | |
| enum | ra8_net_pal_link_state_t : uint8_t { k_ra8_net_pal_link_down = 0U , k_ra8_net_pal_link_up = 1U } |
| Possible link-up states surfaced to the stack. More... | |
| enum | ra8_net_pal_event_t : uint32_t { k_ra8_net_pal_event_none = 0x00U , k_ra8_net_pal_event_link_up = 0x01U , k_ra8_net_pal_event_link_down = 0x02U , k_ra8_net_pal_event_rx_ready = 0x04U , k_ra8_net_pal_event_tx_done = 0x08U , k_ra8_net_pal_event_error = 0x10U } |
| Bits passed to ra8_net_pal_event_fn_t. More... | |
Functions | |
| ra8_err_t | ra8_net_pal_init (const ra8_net_pal_mac_t *mac) |
| Initialise the network PAL. | |
| ra8_err_t | ra8_net_pal_deinit (void) |
| Tear down the network PAL. | |
| 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) |
| Attach a single event handler for link / RX / TX events. | |
Network Platform Abstraction Layer for the RA8D2 ESWM block.
scaffold for the ethernet PAL. The PAL sits between the Ring-3 ra8_eth_* driver and any higher-level network stack (NetX Duo today, possibly TCPDirect or a custom stack later).
Responsibilities:
The PAL is intentionally stack-agnostic: no NetX Duo types appear in this header, and the same would hold for any future TCPDirect or zero-stack consumer.
Its real consumers today are libs/ra8_nsc/src/ra8_nsc_eth.c (the TrustZone veneer that exposes Ethernet to the Non-Secure world) and the host tests. NetX Duo is NOT one of them: its driver (port/netxduo/src/nx_ether_driver_ra8_eth.c) includes ra8_eth.h and calls ra8_eth_* directly, never this API (#621).
+---------------------—+ ra8_net_pal_send_frame | network stack (NetX) | ra8_net_pal_recv_frame +--------—+---------—+ ra8_net_pal_link_status | v +---------------------—+ | ra8_net_pal (this file) | wraps Ring-3 ra8_eth_* +--------—+---------—+ | v +---------------------—+ | ra8_eth (Ring 3 / HAL) | +---------------------—+
Single-threaded. Init runs from the boot path; send/recv are called from the main loop or a single network task. Frame RX is delivered through ra8_net_pal_recv_frame polling – the IRQ path lives inside ra8_eth and is fanned out via ra8_net_pal_set_event_handler.
The PAL owns a small in-memory ring (k_ra8_net_pal_ring_slots slots, each k_ra8_net_pal_frame_max bytes) the stack writes to with ra8_net_pal_send_frame and drains with ra8_net_pal_recv_frame. On real hardware the ring is backed by the GWCA descriptor engine; in host tests it is a plain contiguous RAM buffer. The stack-facing contract is identical in either case, so NetX Duo's driver talks to the same API.
Definition in file ra8_net_pal.h.
| typedef void(* ra8_net_pal_event_fn_t) (void *ctx, uint32_t event_mask) |
Async event callback shape (link change, RX ready, error).
| [in] | ctx | Caller-supplied context. |
| [in] | event_mask | OR of k_ra8_net_pal_event_* bits. |
Definition at line 139 of file ra8_net_pal.h.
| enum ra8_net_pal_event_t : uint32_t |
Bits passed to ra8_net_pal_event_fn_t.
Definition at line 145 of file ra8_net_pal.h.
| enum ra8_net_pal_limits_t : uint16_t |
maximums / sizes baked into the PAL contract.
MTU is the standard Ethernet maximum payload (1500 bytes) plus the 14-byte header. Frame size includes the FCS placeholder so the descriptor ring can route 1518-byte frames without truncation.
| Enumerator | |
|---|---|
| k_ra8_net_pal_mac_addr_len | 48-bit Ethernet MAC. |
| k_ra8_net_pal_mtu | Standard payload size. |
| k_ra8_net_pal_frame_max | MTU + header + FCS. |
Definition at line 94 of file ra8_net_pal.h.
| enum ra8_net_pal_link_state_t : uint8_t |
Possible link-up states surfaced to the stack.
| Enumerator | |
|---|---|
| k_ra8_net_pal_link_down | Cable unplugged or PHY not up. |
| k_ra8_net_pal_link_up | Link up at any speed/duplex. |
Definition at line 104 of file ra8_net_pal.h.
|
nodiscard |
Tear down the network PAL.
Releases any in-flight TX descriptors, detaches the event handler, and calls ra8_eth_deinit to drop the ESWM MSTP reference.
| k_ra8_ok | PAL released. |
| k_ra8_err_invalid_state | PAL was never initialized. |
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.
| [out] | out_mac | Receives the MAC. |
| k_ra8_ok | MAC copied. |
| k_ra8_err_null_ptr | out_mac was NULL. |
| k_ra8_err_invalid_state | PAL not initialized. |
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 |
Initialise the network PAL.
Powers on the underlying ra8_eth driver via ra8_eth_init, loads the MAC address from the supplied descriptor (NULL keeps the implementation default of all-zeros), and resets the internal state machine to "link down, no event handler".
| [in] | mac | MAC address to programme. May be NULL to keep whatever the underlying ESWM block already has. |
| k_ra8_ok | PAL ready, link state = down. |
| k_ra8_err_hw_init_failed | Underlying ra8_eth_init failed. |
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 updated to the byte count actually written. When no frame is ready the function returns k_ra8_err_no_data so callers can poll without blocking.
| [out] | out_buf | Destination buffer. |
| [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 (poll-friendly). |
| k_ra8_err_null_ptr | out_buf / inout_len NULL. |
| k_ra8_err_invalid_state | PAL not initialized. |
| k_ra8_err_invalid_arg | *inout_len < frame_max capacity. |
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 is 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.
| [in] | frame | Ethernet frame bytes (header + payload, no FCS). |
| [in] | len | Frame length in bytes; non-zero, <= frame_max. |
| k_ra8_ok | Frame queued for TX. |
| k_ra8_err_null_ptr | frame was NULL. |
| k_ra8_err_invalid_arg | len zero or out of range. |
| k_ra8_err_invalid_state | PAL not initialized. |
| k_ra8_err_no_mem | TX ring full; try again later. |
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 |
Attach a single event handler for link / RX / TX events.
Replaces any previously installed handler. The PAL relays ra8_eth ISR events into this callback after translating them into the PAL-level k_ra8_net_pal_event_* bit set.
| [in] | fn | Callback. Pass NULL to detach. |
| [in] | ctx | Context passed to the callback. |
| k_ra8_ok | Handler installed (or detached). |
| k_ra8_err_invalid_state | PAL not initialized. |
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 copy of the MAC and (when ra8_eth gains MAC-write support) the ESWM hardware filter. Called by the stack at any time after ra8_net_pal_init.
| [in] | mac | Non-NULL MAC descriptor. |
| k_ra8_ok | MAC stored. |
| k_ra8_err_null_ptr | mac was NULL. |
| k_ra8_err_invalid_state | ra8_net_pal_init not called yet. |
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.