|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
NetX Duo network driver bridging onto the RA8 ra8_eth frame API. More...
#include "nx_ether_driver_ra8_eth.h"#include <stdint.h>#include <string.h>#include "nx_api.h"#include "nx_arp.h"#include "nx_ip.h"#include "ra8_attributes.h"#include "ra8_err.h"#include "ra8_eth.h"#include "tx_api.h"#include "nx_rarp.h"Go to the source code of this file.
Data Structures | |
| struct | nx_ether_diag_t |
| Bench-readable diagnostic counters for the NetX link driver. More... | |
Functions | |
| void | nx_ether_driver_ra8_eth_set_mac (const uint8_t mac[6]) |
| Install the local MAC address used by the driver at NX_LINK_INITIALIZE. | |
| static void | internal_rx_worker_entry (ULONG arg) |
| RX-poll worker entry. | |
| static void | internal_spawn_rx_worker (NX_IP *ip, NX_INTERFACE *iface) |
| Spawn the RX-poll worker thread once, idempotent. | |
| static void | internal_dispatch_to_netx (NX_PACKET *pkt) |
| Dispatch a received frame into NetX by ethertype. | |
| static void | internal_rx_drain (void) |
| Drain the GWCA RX ring and push every frame into NetX. | |
| static void | internal_unpack_mac (const NX_INTERFACE *iface, uint8_t *mac) |
| static UCHAR | internal_packet_to_buffer (const NX_PACKET *packet, uint8_t *dst, uint32_t cap, uint32_t *out_len) |
| static void | internal_handle_init (NX_IP_DRIVER *req) |
| static void | internal_handle_uninit (NX_IP_DRIVER *req) |
| static uint16_t | internal_ethertype_for_cmd (UINT cmd) |
| Pick the ethernet ethertype for a NetX driver SEND command. | |
| static void | internal_handle_send (NX_IP_DRIVER *req) |
| Handle NX_LINK_PACKET_SEND / ARP_SEND / ARP_RESPONSE_SEND / RARP_SEND. | |
| static void | internal_handle_deferred_rx (NX_IP_DRIVER *req) |
| Handle NX_LINK_DEFERRED_PROCESSING: drain RX into NetX. | |
| static void | internal_handle_get_status (NX_IP_DRIVER *req) |
| static void | internal_set_link_state (NX_IP_DRIVER *driver_req, UCHAR link_up) |
| Apply an ENABLE/DISABLE state change to the link mirror and NetX iface. | |
| void | nx_ether_driver_ra8_eth (NX_IP_DRIVER *driver_req) |
| NetX Duo network-driver entry point bridging onto ra8_eth_*. | |
Variables | |
| static uint8_t | s_tx_staging [k_nx_ra8_eth_max_frame] |
| Contiguous TX staging buffer. | |
| static uint8_t | s_rx_staging [k_nx_ra8_eth_max_frame] |
| Contiguous RX staging buffer. | |
| static UCHAR | s_ra8_eth_open |
| Latched flag: has ra8_eth_open been called for this interface? | |
| static UCHAR | s_link_up |
| Latched flag: has NX_LINK_ENABLE been the most recent transition? | |
| static uint8_t | s_local_mac [k_nx_ra8_eth_mac_len] |
| Cached local MAC address captured at INITIALIZE time. | |
| static uint8_t | s_local_mac_user_set |
| Flag indicating whether the app supplied a MAC via the pre-init seam. | |
| volatile nx_ether_diag_t | g_nx_ether_diag = {} |
| Diagnostic counters readable via JLink. | |
| static TX_THREAD | s_rx_thread |
| static uint8_t | s_rx_thread_stack [k_nx_ra8_eth_worker_stack_bytes] |
| static NX_IP * | s_rx_ip = NX_NULL |
| static NX_INTERFACE * | s_rx_iface = NX_NULL |
| static uint8_t | s_rx_thread_made = 0U |
NetX Duo network driver bridging onto the RA8 ra8_eth frame API.
Implements nx_ether_driver_ra8_eth – the single entry point passed to nx_ip_create() – by dispatching on driver_req->nx_ip_driver_command into the matching ra8_eth_* polled frame primitive.
The shim is intentionally thin: every NetX Duo I/O request maps 1:1 onto one ra8_eth_open / ra8_eth_close / ra8_eth_write / ra8_eth_read / ra8_eth_link_status call. The driver holds three pieces of state of its own:
NetX serialises driver invocations on the IP thread, so no additional locking is required around these statics.
Definition in file nx_ether_driver_ra8_eth.c.
| enum nx_ra8_eth_byte_mask_t : uint8_t |
Low-octet mask used when extracting bytes from packed words.
| Enumerator | |
|---|---|
| k_nx_ra8_eth_byte_mask | Keep the least-significant octet. |
Definition at line 117 of file nx_ether_driver_ra8_eth.c.
| enum nx_ra8_eth_constants_t : uint16_t |
Compile-time constants for the NetX Duo <-> ra8_eth bridge.
The staging buffer covers the largest untagged 802.3 frame we ever push to ra8_eth_write (1514 bytes payload, no FCS). The minimum frame length matches ra8_eth's own k_ra8_eth_min_frame.
Definition at line 60 of file nx_ether_driver_ra8_eth.c.
| enum nx_ra8_eth_ethertype_t : uint16_t |
Ethernet II EtherType constants in host byte order.
NetX dispatch keys; matched against the 16-bit ethertype field at frame offset 12.
| Enumerator | |
|---|---|
| k_nx_ra8_eth_ethertype_ipv4 | IPv4 frame. |
| k_nx_ra8_eth_ethertype_arp | ARP frame. |
| k_nx_ra8_eth_ethertype_rarp | RARP frame. |
| k_nx_ra8_eth_ethertype_ipv6 | IPv6 frame. |
Definition at line 371 of file nx_ether_driver_ra8_eth.c.
| enum nx_ra8_eth_hdr_offset_t : uint8_t |
Byte offsets of the fields in the 14-byte Ethernet header that internal_handle_send stages into s_tx_staging[].
The destination MAC occupies octets 0-5, the source MAC octets 6-11, and the EtherType octets 12-13. Indices that fall outside the ignored small-integer set are named here.
Definition at line 131 of file nx_ether_driver_ra8_eth.c.
| enum nx_ra8_eth_hdr_t : uint16_t |
| Enumerator | |
|---|---|
| k_nx_ra8_eth_hdr_bytes | Nx RA8 Ethernet hdr bytes. |
| k_nx_ra8_eth_etype_off | Nx RA8 Ethernet etype off. |
Definition at line 378 of file nx_ether_driver_ra8_eth.c.
| enum nx_ra8_eth_mac_byte_idx_t : uint8_t |
Indices into the local 6-byte MAC array.
Definition at line 86 of file nx_ether_driver_ra8_eth.c.
| enum nx_ra8_eth_mac_word_shift_t : uint8_t |
Bit shifts that pack the 6 MAC bytes into NetX's msw/lsw words.
NetX reports the local MAC as two 32-bit words: the MSW holds octets 0-1 (with octet 0 in bits 8-15), the LSW holds octets 2-5 (with octet 2 in bits 24-31). These named shifts replace the magic numbers the casts would otherwise contain.
Definition at line 105 of file nx_ether_driver_ra8_eth.c.
| enum nx_ra8_eth_worker_t : uint32_t |
Sizing constants for the RX-poll worker thread.
Without an IRQ from the GWCA RX path, NetX is never notified that frames have arrived. A dedicated ThreadX worker polls ra8_eth_read at a short cadence and pushes packets into NetX via _nx_ip_packet_deferred_receive. 2 ms cadence balances latency against CPU load on the M85; tighter polls saturate the NetX packet pool, looser ones add visible RTT to ICMP echo.
Definition at line 293 of file nx_ether_driver_ra8_eth.c.
|
static |
Dispatch a received frame into NetX by ethertype.
Mirrors the NetX reference driver's RX path: read the ethertype, strip the 14-byte ethernet header, then hand the IP payload to the matching *_packet_deferred_receive. Calling _nx_ip_packet_deferred_receive directly routes everything to the IP path and ARP frames get silently dropped, so the chip never answers who-has requests.
| [in,out] | pkt | NX_PACKET containing the raw ethernet frame. |
Definition at line 403 of file nx_ether_driver_ra8_eth.c.
References k_nx_ra8_eth_ethertype_arp, k_nx_ra8_eth_ethertype_ipv4, k_nx_ra8_eth_ethertype_rarp, k_nx_ra8_eth_etype_off, k_nx_ra8_eth_hdr_bytes, RA8_INTERNAL, and s_rx_ip.
Referenced by internal_handle_deferred_rx(), and internal_rx_drain().
|
static |
Pick the ethernet ethertype for a NetX driver SEND command.
NetX hands us the L3 payload (ARP body, IP packet) without an ethernet header; the driver builds the header. The command kind implicitly tells us which ethertype goes on the wire.
| [in] | cmd | NetX driver command code. |
| 0x0806 | cmd was NX_LINK_ARP_SEND or NX_LINK_ARP_RESPONSE_SEND. |
| 0x8035 | cmd was NX_LINK_RARP_SEND. |
| 0x0800 | default (IPv4 – PACKET_SEND, PACKET_BROADCAST). |
Definition at line 647 of file nx_ether_driver_ra8_eth.c.
References k_nx_ra8_eth_ethertype_arp, k_nx_ra8_eth_ethertype_ipv4, k_nx_ra8_eth_ethertype_rarp, and RA8_INTERNAL.
Referenced by internal_handle_send().
|
static |
Handle NX_LINK_DEFERRED_PROCESSING: drain RX into NetX.
Loops calling ra8_eth_read until the descriptor ring is empty. For each frame we allocate a new NX_PACKET, copy the bytes in, and hand the packet to _nx_ip_packet_receive (NetX consumes and eventually releases it). Allocation failures are tolerated – the frame is dropped and the rx_err counter (in ra8_eth_stats) captures the loss.
| [in,out] | req | NetX driver request. |
Definition at line 764 of file nx_ether_driver_ra8_eth.c.
References internal_dispatch_to_netx(), k_ra8_ok, ra8_eth_read(), RA8_INTERNAL, s_ra8_eth_open, and s_rx_staging.
Referenced by nx_ether_driver_ra8_eth().
|
static |
Definition at line 807 of file nx_ether_driver_ra8_eth.c.
References k_ra8_ok, ra8_eth_link_t::link_up, ra8_eth_link_status(), RA8_INTERNAL, and s_ra8_eth_open.
Referenced by nx_ether_driver_ra8_eth().
|
static |
Definition at line 556 of file nx_ether_driver_ra8_eth.c.
References g_nx_ether_diag, internal_spawn_rx_worker(), internal_unpack_mac(), k_nx_ra8_eth_lsw_shift_byte2, k_nx_ra8_eth_lsw_shift_byte3, k_nx_ra8_eth_mac_byte_0, k_nx_ra8_eth_mac_byte_1, k_nx_ra8_eth_mac_byte_2, k_nx_ra8_eth_mac_byte_3, k_nx_ra8_eth_mac_byte_4, k_nx_ra8_eth_mac_byte_5, k_nx_ra8_eth_mac_len, k_nx_ra8_eth_msw_shift_byte0, k_nx_ra8_eth_mtu, k_ra8_ok, ra8_eth_cfg_t::mac_address, memcpy(), ra8_eth_open(), RA8_INTERNAL, s_local_mac, s_local_mac_user_set, and s_ra8_eth_open.
Referenced by nx_ether_driver_ra8_eth().
|
static |
Handle NX_LINK_PACKET_SEND / ARP_SEND / ARP_RESPONSE_SEND / RARP_SEND.
Constructs the 14-byte ethernet header from req->nx_ip_driver_physical_address_msw/lsw (destination MAC NetX resolved via ARP for IP, or the broadcast address for ARP-request etc.) plus s_local_mac and an ethertype derived from req->nx_ip_driver_command. The packet's prepend_ptr-to-append_ptr range is then linearised after the header and fed to ra8_eth_write.
| [in,out] | req | NetX driver request. |
Definition at line 681 of file nx_ether_driver_ra8_eth.c.
References internal_ethertype_for_cmd(), internal_packet_to_buffer(), k_nx_ra8_eth_byte_mask, k_nx_ra8_eth_hdr_bytes, k_nx_ra8_eth_hdr_ethertype_hi, k_nx_ra8_eth_hdr_ethertype_lo, k_nx_ra8_eth_hdr_src_mac_byte1, k_nx_ra8_eth_hdr_src_mac_byte3, k_nx_ra8_eth_hdr_src_mac_byte4, k_nx_ra8_eth_hdr_src_mac_byte5, k_nx_ra8_eth_lsw_shift_byte2, k_nx_ra8_eth_lsw_shift_byte3, k_nx_ra8_eth_lsw_shift_byte4, k_nx_ra8_eth_mac_byte_0, k_nx_ra8_eth_mac_byte_1, k_nx_ra8_eth_mac_byte_2, k_nx_ra8_eth_mac_byte_3, k_nx_ra8_eth_mac_byte_4, k_nx_ra8_eth_mac_byte_5, k_nx_ra8_eth_min_frame, k_nx_ra8_eth_msw_shift_byte0, k_ra8_ok, memset(), ra8_eth_write(), RA8_INTERNAL, s_link_up, s_local_mac, s_ra8_eth_open, and s_tx_staging.
Referenced by nx_ether_driver_ra8_eth().
|
static |
Definition at line 617 of file nx_ether_driver_ra8_eth.c.
References ra8_eth_close(), RA8_INTERNAL, s_link_up, and s_ra8_eth_open.
Referenced by nx_ether_driver_ra8_eth().
|
static |
Definition at line 532 of file nx_ether_driver_ra8_eth.c.
References memcpy().
Referenced by internal_handle_send().
|
static |
Drain the GWCA RX ring and push every frame into NetX.
One pass of the inner loop – factored out so the worker entry stays simple and the function-size gate stays happy.
Definition at line 445 of file nx_ether_driver_ra8_eth.c.
References g_nx_ether_diag, internal_dispatch_to_netx(), k_ra8_ok, ra8_eth_read(), RA8_INTERNAL, s_rx_iface, s_rx_ip, and s_rx_staging.
Referenced by internal_rx_worker_entry().
|
static |
RX-poll worker entry.
Drains the GWCA RX descriptor ring forever, pushing each frame into NetX via _nx_ip_packet_deferred_receive. Sleeps one ThreadX tick between drains so it does not starve other NetX work.
| [in] | arg | Unused. |
Loops forever, draining the GWCA RX ring on every tick.
| [in] | arg | Unused. |
Definition at line 500 of file nx_ether_driver_ra8_eth.c.
References internal_rx_drain(), k_nx_ra8_eth_worker_period_ticks, RA8_INTERNAL, s_ra8_eth_open, s_rx_ip, and tx_thread_sleep.
|
static |
Apply an ENABLE/DISABLE state change to the link mirror and NetX iface.
Sets the driver's s_link_up cache to link_up, marks the request successful, and – when NetX provided an interface pointer – toggles nx_interface_link_up to keep NetX's IP layer in sync with the driver's view.
| [in,out] | driver_req | NetX driver request; non-NULL. |
| [in] | link_up | 1U to bring the link up, 0U to bring it down. |
Definition at line 851 of file nx_ether_driver_ra8_eth.c.
References RA8_INTERNAL, and s_link_up.
Referenced by nx_ether_driver_ra8_eth().
|
static |
Spawn the RX-poll worker thread once, idempotent.
The driver has no RX IRQ; this worker is the only path from the GWCA descriptor ring into NetX. Called from INITIALIZE.
| [in] | ip | NetX IP control block the worker pushes frames into. |
| [in] | iface | NetX interface struct the worker tags frames with. |
Definition at line 341 of file nx_ether_driver_ra8_eth.c.
References internal_rx_worker_entry(), k_nx_ra8_eth_worker_priority, k_nx_ra8_eth_worker_stack_bytes, RA8_INTERNAL, s_rx_iface, s_rx_ip, s_rx_thread, s_rx_thread_made, s_rx_thread_stack, s_thread_name, TX_AUTO_START, TX_NO_TIME_SLICE, TX_SUCCESS, and tx_thread_create.
Referenced by internal_handle_init().
|
static |
Definition at line 514 of file nx_ether_driver_ra8_eth.c.
References k_nx_ra8_eth_byte_mask, k_nx_ra8_eth_lsw_shift_byte2, k_nx_ra8_eth_lsw_shift_byte3, k_nx_ra8_eth_lsw_shift_byte4, k_nx_ra8_eth_mac_byte_0, k_nx_ra8_eth_mac_byte_1, k_nx_ra8_eth_mac_byte_2, k_nx_ra8_eth_mac_byte_3, k_nx_ra8_eth_mac_byte_4, k_nx_ra8_eth_mac_byte_5, k_nx_ra8_eth_msw_shift_byte0, and RA8_INTERNAL.
Referenced by internal_handle_init().
| void nx_ether_driver_ra8_eth | ( | NX_IP_DRIVER * | driver_req | ) |
NetX Duo network-driver entry point bridging onto ra8_eth_*.
Pass this function as the ip_link_driver argument to nx_ip_create(). NetX Duo invokes it once per driver-level request, indicating the request kind in nx_ip_driver->nx_ip_driver_command and reporting completion via nx_ip_driver->nx_ip_driver_status (set to NX_SUCCESS on success or NX_NOT_SUCCESSFUL on any underlying ESWM failure).
Frame TX path (NX_LINK_PACKET_SEND and friends):
Frame RX path (NX_LINK_DEFERRED_PROCESSING):
| [in,out] | driver_req | NetX Duo driver request structure. The driver reads nx_ip_driver_command, nx_ip_driver_packet, nx_ip_driver_interface, and writes nx_ip_driver_status. |
Definition at line 861 of file nx_ether_driver_ra8_eth.c.
References g_nx_ether_diag, internal_handle_deferred_rx(), internal_handle_get_status(), internal_handle_init(), internal_handle_send(), internal_handle_uninit(), and internal_set_link_state().
Referenced by demo_netx_bring_up(), demo_netx_create_ip(), and internal_demo_netx_bring_up().
| void nx_ether_driver_ra8_eth_set_mac | ( | const uint8_t | mac[6] | ) |
Install the local MAC address used by the driver at NX_LINK_INITIALIZE.
nx_ip_create calls the driver's INITIALIZE callback synchronously during IP-thread spin-up, BEFORE the app can call nx_ip_interface_physical_address_set. The interface's physical_address_msw / _lsw fields read zero at that point, so the driver has no MAC to program into the RMAC's MRMAC0/MRMAC1 registers and RX silently filters every frame. Apps must call this function BEFORE nx_ip_create so the driver has the MAC at hand when INITIALIZE fires.
| [in] | mac | 6-byte unicast MAC in network byte order. |
Definition at line 224 of file nx_ether_driver_ra8_eth.c.
References k_nx_ra8_eth_mac_len, s_local_mac, and s_local_mac_user_set.
Referenced by demo_netx_bring_up(), and demo_netx_create_ip().
| volatile nx_ether_diag_t g_nx_ether_diag = {} |
Diagnostic counters readable via JLink.
Symbol export is module-private (no header declaration); the symbol lives in .bss so JLink memprobe can address it via nm.
Definition at line 278 of file nx_ether_driver_ra8_eth.c.
Referenced by internal_handle_init(), internal_rx_drain(), and nx_ether_driver_ra8_eth().
|
static |
Latched flag: has NX_LINK_ENABLE been the most recent transition?
NetX uses NX_LINK_ENABLE / NX_LINK_DISABLE as a software gate independent of PHY link state; we honour it by refusing to transmit (and by skipping the RX drain) when the flag is clear.
Definition at line 194 of file nx_ether_driver_ra8_eth.c.
|
static |
Cached local MAC address captured at INITIALIZE time.
NetX exposes the MAC through the interface's nx_interface_physical_address_msw / ..._lsw fields. We pack them back into a 6-byte array so the packed form can be handed to ra8_eth_open.
Definition at line 208 of file nx_ether_driver_ra8_eth.c.
|
static |
Flag indicating whether the app supplied a MAC via the pre-init seam.
Set to 1 once nx_ether_driver_ra8_eth_set_mac runs. The NX_LINK_INITIALIZE handler prefers s_local_mac over the (empty) interface struct when this flag is 1.
Definition at line 221 of file nx_ether_driver_ra8_eth.c.
Referenced by internal_handle_init(), and nx_ether_driver_ra8_eth_set_mac().
|
static |
Latched flag: has ra8_eth_open been called for this interface?
Driven by NX_LINK_INITIALIZE (true) and NX_LINK_UNINITIALIZE (false). The TX / RX command paths refuse to operate when this flag is clear – mirrors how NetX's reference Ethernet driver gates IO.
Definition at line 181 of file nx_ether_driver_ra8_eth.c.
Referenced by internal_handle_deferred_rx(), internal_handle_get_status(), internal_handle_init(), internal_handle_send(), internal_handle_uninit(), and internal_rx_worker_entry().
|
static |
Definition at line 302 of file nx_ether_driver_ra8_eth.c.
|
static |
Definition at line 301 of file nx_ether_driver_ra8_eth.c.
|
static |
Contiguous RX staging buffer.
ra8_eth_read returns frames into a flat buffer; we hold the scratch space here and then copy into a freshly-allocated NX_PACKET for the stack to consume.
Definition at line 168 of file nx_ether_driver_ra8_eth.c.
Referenced by internal_handle_deferred_rx(), internal_rx_drain(), and nx_ether_driver_c6_rx().
|
static |
Definition at line 299 of file nx_ether_driver_ra8_eth.c.
Referenced by internal_spawn_rx_worker(), and internal_spawn_rx_worker().
|
static |
Definition at line 303 of file nx_ether_driver_ra8_eth.c.
Referenced by internal_spawn_rx_worker(), and internal_spawn_rx_worker().
|
static |
Definition at line 300 of file nx_ether_driver_ra8_eth.c.
Referenced by internal_spawn_rx_worker(), and internal_spawn_rx_worker().
|
static |
Contiguous TX staging buffer.
NetX packets may be chained across multiple NX_PACKET blocks; ra8_eth_write wants a single linear buffer. We copy each outgoing chain into s_tx_staging before handing it to the HAL. The buffer is sized to the largest untagged frame we ever forward (1514 bytes) and is statically allocated (NASA Power-of-10 Rule 3).
Definition at line 155 of file nx_ether_driver_ra8_eth.c.