ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
nx_ether_driver_ra8_eth.c File Reference

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"
Include dependency graph for nx_ether_driver_ra8_eth.c:

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...

Enumerations

enum  nx_ra8_eth_constants_t : uint16_t {
  k_nx_ra8_eth_max_frame = 1514U ,
  k_nx_ra8_eth_min_frame = 60U ,
  k_nx_ra8_eth_mac_len = 6U ,
  k_nx_ra8_eth_phys_addr_len = 6U ,
  k_nx_ra8_eth_mtu = 128U ,
  k_nx_ra8_eth_phys_msw_shift = 8U
}
 Compile-time constants for the NetX Duo <-> ra8_eth bridge. More...
enum  nx_ra8_eth_mac_byte_idx_t : uint8_t {
  k_nx_ra8_eth_mac_byte_0 = 0U ,
  k_nx_ra8_eth_mac_byte_1 = 1U ,
  k_nx_ra8_eth_mac_byte_2 = 2U ,
  k_nx_ra8_eth_mac_byte_3 = 3U ,
  k_nx_ra8_eth_mac_byte_4 = 4U ,
  k_nx_ra8_eth_mac_byte_5 = 5U
}
 Indices into the local 6-byte MAC array. More...
enum  nx_ra8_eth_mac_word_shift_t : uint8_t {
  k_nx_ra8_eth_msw_shift_byte0 = 8U ,
  k_nx_ra8_eth_lsw_shift_byte2 = 24U ,
  k_nx_ra8_eth_lsw_shift_byte3 = 16U ,
  k_nx_ra8_eth_lsw_shift_byte4 = 8U ,
  k_nx_ra8_eth_lsw_shift_byte5 = 0U
}
 Bit shifts that pack the 6 MAC bytes into NetX's msw/lsw words. More...
enum  nx_ra8_eth_byte_mask_t : uint8_t { k_nx_ra8_eth_byte_mask = 0xFFU }
 Low-octet mask used when extracting bytes from packed words. More...
enum  nx_ra8_eth_hdr_offset_t : uint8_t {
  k_nx_ra8_eth_hdr_src_mac_byte1 = 7U ,
  k_nx_ra8_eth_hdr_src_mac_byte3 = 9U ,
  k_nx_ra8_eth_hdr_src_mac_byte4 = 10U ,
  k_nx_ra8_eth_hdr_src_mac_byte5 = 11U ,
  k_nx_ra8_eth_hdr_ethertype_hi = 12U ,
  k_nx_ra8_eth_hdr_ethertype_lo = 13U
}
 Byte offsets of the fields in the 14-byte Ethernet header that internal_handle_send stages into s_tx_staging[]. More...
enum  nx_ra8_eth_worker_t : uint32_t {
  k_nx_ra8_eth_worker_stack_bytes = 4096U ,
  k_nx_ra8_eth_worker_priority = 4U ,
  k_nx_ra8_eth_worker_period_ticks = 1U
}
 Sizing constants for the RX-poll worker thread. More...
enum  nx_ra8_eth_ethertype_t : uint16_t {
  k_nx_ra8_eth_ethertype_ipv4 = 0x0800U ,
  k_nx_ra8_eth_ethertype_arp = 0x0806U ,
  k_nx_ra8_eth_ethertype_rarp = 0x8035U ,
  k_nx_ra8_eth_ethertype_ipv6 = 0x86DDU
}
 Ethernet II EtherType constants in host byte order. More...
enum  nx_ra8_eth_hdr_t : uint16_t {
  k_nx_ra8_eth_hdr_bytes = 14U ,
  k_nx_ra8_eth_etype_off = 12U
}

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

Detailed Description

NetX Duo network driver bridging onto the RA8 ra8_eth frame API.

Tag
[Ring 4 / PORT] {World: NS}

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:

  • s_ra8_eth_open – whether ra8_eth_open has been called.
  • s_link_up – whether NX_LINK_ENABLE was the most recent enable / disable command.
  • s_attached_ip – the NX_IP pointer captured on NX_LINK_INTERFACE_ATTACH, used by the deferred-RX path so it can hand the received packet to the right stack.

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.

Enumeration Type Documentation

◆ nx_ra8_eth_byte_mask_t

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.

◆ nx_ra8_eth_constants_t

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.

Enumerator
k_nx_ra8_eth_max_frame 

Largest 802.3 frame we forward.

k_nx_ra8_eth_min_frame 

Smallest 802.3 frame.

k_nx_ra8_eth_mac_len 

Length of an Ethernet MAC.

k_nx_ra8_eth_phys_addr_len 

Reported to NX_LINK_FACTORY_*.

k_nx_ra8_eth_mtu 

Capped MTU.

The EK-RA8D2 ESWM silently corrupts any single transmitted frame as it approaches ~512 B (a per-FRAME egress defect – confirmed: splitting into multiple descriptors does NOT help, only separate IP packets do). Cap the payload so every frame stays small; IP fragments larger packets and TCP clamps its MSS. RX is unaffected. Silicon-level limitation, not a driver bug – see issue #21 (accepted; needs a logic analyzer to pursue further).

k_nx_ra8_eth_phys_msw_shift 

Bytes-per-byte shift for MAC msw.

Definition at line 60 of file nx_ether_driver_ra8_eth.c.

◆ nx_ra8_eth_ethertype_t

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.

◆ nx_ra8_eth_hdr_offset_t

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.

Enumerator
k_nx_ra8_eth_hdr_src_mac_byte1 

Source MAC octet 1.

k_nx_ra8_eth_hdr_src_mac_byte3 

Source MAC octet 3.

k_nx_ra8_eth_hdr_src_mac_byte4 

Source MAC octet 4.

k_nx_ra8_eth_hdr_src_mac_byte5 

Source MAC octet 5.

k_nx_ra8_eth_hdr_ethertype_hi 

EtherType high octet.

k_nx_ra8_eth_hdr_ethertype_lo 

EtherType low octet.

Definition at line 131 of file nx_ether_driver_ra8_eth.c.

◆ nx_ra8_eth_hdr_t

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.

◆ nx_ra8_eth_mac_byte_idx_t

enum nx_ra8_eth_mac_byte_idx_t : uint8_t

Indices into the local 6-byte MAC array.

Enumerator
k_nx_ra8_eth_mac_byte_0 

Nx RA8 Ethernet MAC byte 0.

k_nx_ra8_eth_mac_byte_1 

Nx RA8 Ethernet MAC byte 1.

k_nx_ra8_eth_mac_byte_2 

Nx RA8 Ethernet MAC byte 2.

k_nx_ra8_eth_mac_byte_3 

Nx RA8 Ethernet MAC byte 3.

k_nx_ra8_eth_mac_byte_4 

Nx RA8 Ethernet MAC byte 4.

k_nx_ra8_eth_mac_byte_5 

Nx RA8 Ethernet MAC byte 5.

Definition at line 86 of file nx_ether_driver_ra8_eth.c.

◆ nx_ra8_eth_mac_word_shift_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.

Enumerator
k_nx_ra8_eth_msw_shift_byte0 

Nx RA8 Ethernet msw shift byte0.

k_nx_ra8_eth_lsw_shift_byte2 

Nx RA8 Ethernet lsw shift byte2.

k_nx_ra8_eth_lsw_shift_byte3 

Nx RA8 Ethernet lsw shift byte3.

k_nx_ra8_eth_lsw_shift_byte4 

Nx RA8 Ethernet lsw shift byte4.

k_nx_ra8_eth_lsw_shift_byte5 

Nx RA8 Ethernet lsw shift byte5.

Definition at line 105 of file nx_ether_driver_ra8_eth.c.

◆ nx_ra8_eth_worker_t

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.

Since
0.1.0
Enumerator
k_nx_ra8_eth_worker_stack_bytes 

Nx RA8 Ethernet worker stack bytes.

k_nx_ra8_eth_worker_priority 

Nx RA8 Ethernet worker priority.

k_nx_ra8_eth_worker_period_ticks 

Nx RA8 Ethernet worker period ticks.

Definition at line 293 of file nx_ether_driver_ra8_eth.c.

Function Documentation

◆ internal_dispatch_to_netx()

void internal_dispatch_to_netx ( NX_PACKET * pkt)
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.

Parameters
[in,out]pktNX_PACKET containing the raw ethernet frame.
Precondition
pkt is non-NULL and pkt->nx_packet_length >= 14.
s_rx_ip and s_rx_iface have been populated.
Postcondition
Header is stripped and the packet is owned by NetX.
Unknown ethertypes release the packet rather than leaking.
Note
Not thread-safe; only the RX worker calls this.
Since
0.1.0

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().

◆ internal_ethertype_for_cmd()

uint16_t internal_ethertype_for_cmd ( UINT cmd)
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.

Parameters
[in]cmdNetX driver command code.
Returns
ethertype in host byte order.
Return values
0x0806cmd was NX_LINK_ARP_SEND or NX_LINK_ARP_RESPONSE_SEND.
0x8035cmd was NX_LINK_RARP_SEND.
0x0800default (IPv4 – PACKET_SEND, PACKET_BROADCAST).
Precondition
Module state is consistent.
Caller validated cmd came from NetX's dispatch.
Postcondition
Returns 0x0806/0x8035/0x0800.
No side effects.
Note
Not thread-safe; pure.
Since
0.1.0

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().

◆ internal_handle_deferred_rx()

void internal_handle_deferred_rx ( NX_IP_DRIVER * req)
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.

Parameters
[in,out]reqNetX driver request.
Since
0.1.0
Precondition
Module has been initialized.
Caller has validated arguments.
Postcondition
Side effects bounded to documented state.
State reflects operation result.
Note
Not thread-safe unless documented otherwise.

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().

◆ internal_handle_get_status()

void internal_handle_get_status ( NX_IP_DRIVER * req)
static

◆ internal_handle_init()

◆ internal_handle_send()

void internal_handle_send ( NX_IP_DRIVER * req)
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.

Parameters
[in,out]reqNetX driver request.
Precondition
s_ra8_eth_open != 0U and s_link_up != 0U.
req->nx_ip_driver_packet and its chain are valid.
Postcondition
nx_packet_transmit_release is always called on the packet.
req->nx_ip_driver_status is NX_SUCCESS / NX_NOT_SUCCESSFUL.
Note
Not thread-safe; only the NetX IP thread calls this.
Since
0.1.0

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().

◆ internal_handle_uninit()

void internal_handle_uninit ( NX_IP_DRIVER * req)
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().

◆ internal_packet_to_buffer()

UCHAR internal_packet_to_buffer ( const NX_PACKET * packet,
uint8_t * dst,
uint32_t cap,
uint32_t * out_len )
static

Definition at line 532 of file nx_ether_driver_ra8_eth.c.

References memcpy().

Referenced by internal_handle_send().

◆ internal_rx_drain()

void internal_rx_drain ( void )
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.

Precondition
s_rx_ip != NX_NULL.
s_ra8_eth_open == 1U.
Postcondition
Pending RX frames have been dispatched into NetX (drops on alloc fail).
g_nx_ether_diag.rx_total reflects successful pushes.
Note
Not thread-safe; only the RX worker calls this.
Since
0.1.0

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().

◆ internal_rx_worker_entry()

void internal_rx_worker_entry ( ULONG arg)
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.

Parameters
[in]argUnused.
Precondition
s_rx_ip and s_rx_iface have been populated.
ra8_eth_open has returned k_ra8_ok.
Postcondition
Loops forever; never returns.
g_nx_ether_diag.rx_total reflects every successful push to NetX.
Note
Runs at priority k_nx_ra8_eth_worker_priority.
Since
0.1.0

Loops forever, draining the GWCA RX ring on every tick.

Parameters
[in]argUnused.
Precondition
Driver state has been initialised.
s_rx_ip / s_rx_iface populated by internal_spawn_rx_worker.
Postcondition
Drains pending RX into NetX whenever the driver is open.
Never returns.
Note
Owns no shared state; safe to run alongside the IP thread.
Since
0.1.0

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.

◆ internal_set_link_state()

void internal_set_link_state ( NX_IP_DRIVER * driver_req,
UCHAR link_up )
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.

Parameters
[in,out]driver_reqNetX driver request; non-NULL.
[in]link_up1U to bring the link up, 0U to bring it down.
Precondition
driver_req != NULL.
link_up is either 0U (disable) or 1U (enable).
Postcondition
s_link_up == link_up and request status is NX_SUCCESS.
If driver_req->nx_ip_driver_interface != NULL, the NetX interface link state mirrors link_up.
Note
Serialised on the NetX IP thread; not safe to call from ISRs.
Since
0.1.0

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().

◆ internal_spawn_rx_worker()

void internal_spawn_rx_worker ( NX_IP * ip,
NX_INTERFACE * iface )
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.

Parameters
[in]ipNetX IP control block the worker pushes frames into.
[in]ifaceNetX interface struct the worker tags frames with.
Precondition
ip and iface are non-NULL.
ra8_eth_open succeeded (s_ra8_eth_open == 1U).
Postcondition
On first call, s_rx_thread is running.
On later calls, no-op.
Note
Not thread-safe; the dispatch funnel serialises callers.
Since
0.1.0

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().

◆ internal_unpack_mac()

◆ nx_ether_driver_ra8_eth()

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):

  1. Walk the chained NX_PACKET (if any) and copy the payload into a contiguous staging buffer (1514 bytes max).
  2. Call ra8_eth_write with the staging buffer.
  3. Always release the packet via nx_packet_transmit_release so the NetX pool does not leak.

Frame RX path (NX_LINK_DEFERRED_PROCESSING):

  1. Loop calling ra8_eth_read until it returns k_ra8_err_no_data.
  2. For each frame, allocate an NX_PACKET from the IP's default packet pool, copy the bytes in, and pass it to _nx_ip_packet_receive (NetX consumes the packet).
Parameters
[in,out]driver_reqNetX 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.
Precondition
driver_req != NULL.
PHY pins routed and ra8_eth_init reachable.
Postcondition
On success driver_req->nx_ip_driver_status == NX_SUCCESS.
On failure driver_req->nx_ip_driver_status == NX_NOT_SUCCESSFUL.
Note
Polled implementation. Must run from a ThreadX context (the NetX Duo IP thread). Not safe to call from an ISR.
Since
0.1.0

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().

◆ nx_ether_driver_ra8_eth_set_mac()

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.

Parameters
[in]mac6-byte unicast MAC in network byte order.
Precondition
mac != nullptr.
Called from a single-threaded init context (before nx_ip_create).
Postcondition
The driver's static cache holds mac and will use it during its next INITIALIZE callback.
Subsequent INITIALIZE callbacks ignore the (zero) interface physical_address fields and program the RMAC from the cache.
Note
Not thread-safe; call once during app setup.
Since
0.1.0

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().

Variable Documentation

◆ g_nx_ether_diag

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.

Note
Not safe to mutate outside the NetX IP thread.
Warning
Not part of the public ABI – bench/debug only.
Since
0.1.0

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().

◆ s_link_up

UCHAR s_link_up
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.

Since
0.1.0

Definition at line 194 of file nx_ether_driver_ra8_eth.c.

◆ s_local_mac

uint8_t s_local_mac[k_nx_ra8_eth_mac_len]
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.

Since
0.1.0

Definition at line 208 of file nx_ether_driver_ra8_eth.c.

◆ s_local_mac_user_set

uint8_t s_local_mac_user_set
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.

Note
Module-private; not exported.
Since
0.1.0

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().

◆ s_ra8_eth_open

UCHAR s_ra8_eth_open
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.

Since
0.1.0

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().

◆ s_rx_iface

NX_INTERFACE* s_rx_iface = NX_NULL
static

Definition at line 302 of file nx_ether_driver_ra8_eth.c.

◆ s_rx_ip

NX_IP* s_rx_ip = NX_NULL
static

Definition at line 301 of file nx_ether_driver_ra8_eth.c.

◆ s_rx_staging

uint8_t s_rx_staging[k_nx_ra8_eth_max_frame]
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.

Since
0.1.0

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().

◆ s_rx_thread

TX_THREAD s_rx_thread
static

◆ s_rx_thread_made

uint8_t s_rx_thread_made = 0U
static

◆ s_rx_thread_stack

uint8_t s_rx_thread_stack[k_nx_ra8_eth_worker_stack_bytes]
static

◆ s_tx_staging

uint8_t s_tx_staging[k_nx_ra8_eth_max_frame]
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).

Note
Only safe to access from the NetX IP thread.
Since
0.1.0

Definition at line 155 of file nx_ether_driver_ra8_eth.c.