39#ifndef NX_DISABLE_IPV4
58typedef enum : uint16_t {
78typedef enum : uint8_t {
89typedef enum : uint32_t {
99typedef enum : uint8_t {
113typedef enum : uint16_t {
129typedef enum : uint32_t {
191 if (mac == NX_NULL) {
205 static CHAR s_mutex_name[] = {
'c',
'6',
'_',
'w',
'i',
'r',
'e',
'\0'};
206 if (link == NX_NULL) {
233 ULONG msw = iface->nx_interface_physical_address_msw;
234 ULONG lsw = iface->nx_interface_physical_address_lsw;
263 iface->nx_interface_physical_address_msw = msw;
264 iface->nx_interface_physical_address_lsw = lsw;
284 (void)nx_packet_release(pkt);
288 const UCHAR* p = (
const UCHAR*)pkt->nx_packet_prepend_ptr;
294 _nx_ip_packet_deferred_receive(
s_rx_ip, pkt);
298#ifndef NX_DISABLE_IPV4
300 _nx_arp_packet_deferred_receive(
s_rx_ip, pkt);
305 _nx_rarp_packet_deferred_receive(
s_rx_ip, pkt);
310 (void)nx_packet_release(pkt);
339 if (frame == NX_NULL) {
362 NX_PACKET_POOL* pool =
s_rx_ip->nx_ip_default_packet_pool;
363 if (pool == NX_NULL) {
367 NX_PACKET* pkt = NX_NULL;
368 if (nx_packet_allocate(pool, &pkt, NX_RECEIVE_PACKET, NX_NO_WAIT) != NX_SUCCESS) {
372 if (pkt == NX_NULL) {
383 pkt->nx_packet_append_ptr = pkt->nx_packet_prepend_ptr;
385 (void)nx_packet_release(pkt);
415 bool pumpable =
true;
466 static CHAR s_rx_name[] = {
'c',
'6',
'_',
'n',
'x',
'_',
'r',
'x',
'\0'};
508 case NX_LINK_ARP_SEND:
509 case NX_LINK_ARP_RESPONSE_SEND:
511 case NX_LINK_RARP_SEND:
540 const NX_PACKET* cur = packet;
541 while (cur != NX_NULL) {
542 const uint8_t* seg = (
const uint8_t*)cur->nx_packet_prepend_ptr;
543 uint32_t seg_len = (uint32_t)(cur->nx_packet_append_ptr - cur->nx_packet_prepend_ptr);
544 if ((total + seg_len) > cap) {
547 (void)
memcpy((
void*)(dst + total), (
const void*)seg, (
size_t)seg_len);
549#ifndef NX_DISABLE_PACKET_CHAIN
550 cur = cur->nx_packet_next;
576 const ULONG msw = req->nx_ip_driver_physical_address_msw;
577 const ULONG lsw = req->nx_ip_driver_physical_address_lsw;
614 NX_INTERFACE* iface = req->nx_ip_driver_interface;
616 if (iface == NX_NULL) {
617 req->nx_ip_driver_status = NX_NOT_SUCCESSFUL;
621 req->nx_ip_driver_status = NX_NOT_SUCCESSFUL;
629 iface->nx_interface_address_mapping_needed = NX_TRUE;
632 req->nx_ip_driver_status = NX_SUCCESS;
653 bool blocked =
false;
654 if (pkt == NX_NULL) {
685 NX_PACKET* pkt = req->nx_ip_driver_packet;
687 if (pkt != NX_NULL) {
688 (void)nx_packet_transmit_release(pkt);
691 req->nx_ip_driver_status = NX_NOT_SUCCESSFUL;
695 uint32_t body_len = 0U;
700 (void)nx_packet_transmit_release(pkt);
702 req->nx_ip_driver_status = NX_NOT_SUCCESSFUL;
713 (void)nx_packet_transmit_release(pkt);
716 req->nx_ip_driver_status = NX_SUCCESS;
719 req->nx_ip_driver_status = NX_NOT_SUCCESSFUL;
738 if (req->nx_ip_driver_return_ptr == NX_NULL) {
739 req->nx_ip_driver_status = NX_NOT_SUCCESSFUL;
743 req->nx_ip_driver_status = NX_SUCCESS;
764 req->nx_ip_driver_status = NX_SUCCESS;
765 if (req->nx_ip_driver_interface != NX_NULL) {
766 req->nx_ip_driver_interface->nx_interface_link_up = (link_up != 0U) ? NX_TRUE : NX_FALSE;
772 if (driver_req == NX_NULL) {
775 switch (driver_req->nx_ip_driver_command) {
776 case NX_LINK_INITIALIZE:
782 case NX_LINK_DISABLE:
785 case NX_LINK_PACKET_SEND:
786 case NX_LINK_PACKET_BROADCAST:
787 case NX_LINK_ARP_SEND:
788 case NX_LINK_ARP_RESPONSE_SEND:
789 case NX_LINK_RARP_SEND:
792 case NX_LINK_GET_STATUS:
795 case NX_LINK_UNINITIALIZE:
797 driver_req->nx_ip_driver_status = NX_SUCCESS;
799 case NX_LINK_MULTICAST_JOIN:
800 case NX_LINK_MULTICAST_LEAVE:
801 case NX_LINK_INTERFACE_ATTACH:
802 case NX_LINK_INTERFACE_DETACH:
803 case NX_LINK_SET_PHYSICAL_ADDRESS:
804 driver_req->nx_ip_driver_status = NX_SUCCESS;
807 driver_req->nx_ip_driver_status = NX_NOT_SUCCESSFUL;
static void internal_stamp_iface_mac(NX_INTERFACE *iface, const uint8_t *mac)
Write a six-octet MAC into a NetX interface's msw/lsw words.
struct nx_c6_diag nx_c6_diag_t
nx_c6_const_t
Compile-time sizes and offsets for the NetX Duo <-> C6 bridge.
@ k_nx_c6_rx_align
Prepend slide so the IP header lands aligned.
@ k_nx_c6_mac_len
Length of an Ethernet MAC, in octets.
@ k_nx_c6_mtu
IP MTU advertised on this interface.
@ k_nx_c6_max_frame
Largest 802.3 frame forwarded to the C6.
@ k_nx_c6_hdr_bytes
Ethernet II header length.
@ k_nx_c6_etype_off
Offset of the EtherType field in the header.
@ k_nx_c6_min_frame
Smallest 802.3 frame; runts are zero-padded.
static uint8_t s_local_mac[k_nx_c6_mac_len]
Station MAC stamped on transmitted frames.
void nx_ether_driver_c6_bind(ra8_c6link_t *link)
Bind an open C6 link handle to the driver and arm its mutex.
static void internal_rx_worker_entry(ULONG arg)
RX poll worker entry: pump the link so received frames reach NetX.
static void internal_spawn_rx_worker(NX_IP *ip, NX_INTERFACE *iface)
Spawn the RX poll worker thread once; idempotent on later calls.
static ra8_c6link_t * s_c6_link
Bound C6 link handle.
static void internal_handle_get_status(NX_IP_DRIVER *req)
Handle NX_LINK_GET_STATUS: report the link state NetX asks for.
static bool internal_rx_acceptable(const uint8_t *frame, uint16_t len)
Report whether a received frame is fit to deliver into NetX.
nx_c6_mask_t
Octet mask used when packing and unpacking MAC words.
@ k_nx_c6_byte_mask
Low-octet mask.
void nx_ether_driver_c6(NX_IP_DRIVER *driver_req)
NetX Duo link driver entry point for the ESP32-C6 Wi-Fi station.
static uint8_t s_mac_user_set
Non-zero once _set_mac ran.
static uint8_t s_link_up
NX_LINK_ENABLE mirror.
nx_c6_shift_t
Bit shifts for packing a six-octet MAC into NetX msw/lsw words.
@ k_nx_c6_shift_8
One-octet shift (msw octet 0, lsw octet 4).
@ k_nx_c6_shift_24
Three-octet shift (lsw octet 2).
@ k_nx_c6_shift_16
Two-octet shift (lsw octet 3).
static void internal_handle_send(NX_IP_DRIVER *req)
Handle NX_LINK_PACKET_SEND and its broadcast / ARP / RARP variants.
static uint8_t s_c6_mtx_made
Non-zero once the mutex exists.
static void internal_write_eth_header(const NX_IP_DRIVER *req)
Write the 14-byte Ethernet II header into the staging buffer.
nx_c6_ethertype_t
Ethernet II EtherType values in host byte order.
@ k_nx_c6_ethertype_rarp
RARP frame.
@ k_nx_c6_ethertype_arp
ARP frame.
@ k_nx_c6_ethertype_ipv4
IPv4 frame.
static void internal_handle_init(NX_IP_DRIVER *req)
Handle NX_LINK_INITIALIZE: adopt the MAC and spawn the RX worker.
void nx_ether_driver_c6_rx(void *ctx, const uint8_t *frame, uint16_t len)
Receive callback the application registers with ra8_c6link_open.
static void internal_set_link_state(NX_IP_DRIVER *req, UCHAR link_up)
Apply an ENABLE / DISABLE change to the link mirror and NetX iface.
static TX_MUTEX s_c6_mtx
Wire-serialisation mutex.
nx_c6_mac_idx_t
Octet indices into a six-byte MAC address.
@ k_nx_c6_mac_i3
Fourth MAC octet.
@ k_nx_c6_mac_i1
Second MAC octet.
@ k_nx_c6_mac_i5
Sixth MAC octet.
@ k_nx_c6_mac_i2
Third MAC octet.
@ k_nx_c6_mac_i0
First MAC octet.
@ k_nx_c6_mac_i4
Fifth MAC octet.
static nx_c6_diag_t s_nx_c6_diag
Diagnostic counters for the C6 NetX bridge.
static uint16_t internal_ethertype_for_cmd(UINT cmd)
Map a NetX link-send command to the EtherType its frame carries.
static bool internal_send_blocked(const NX_PACKET *pkt)
Report whether a transmit must be refused before touching the wire.
static NX_INTERFACE * s_rx_iface
Interface the receive path tags frames with.
static UCHAR internal_packet_to_buffer(const NX_PACKET *packet, uint8_t *dst, uint32_t cap, uint32_t *out_len)
Copy a (possibly chained) NX_PACKET body into a linear buffer.
static NX_IP * s_rx_ip
IP the receive path pushes frames into.
static void internal_dispatch_to_netx(NX_PACKET *pkt)
Route a received frame into NetX by EtherType, stripping the header.
static uint8_t s_tx_staging[k_nx_c6_max_frame]
Linear transmit frame buffer.
nx_c6_worker_t
Sizing constants for the RX-poll worker thread.
@ k_nx_c6_poll_transactions
One DATA_READY frame per poll.
@ k_nx_c6_worker_stack_bytes
RX worker stack, in octets.
@ k_nx_c6_worker_priority
RX worker ThreadX priority.
@ k_nx_c6_worker_period_ticks
Sleep between polls, in ticks.
static void internal_unpack_mac(const NX_INTERFACE *iface, uint8_t *mac)
Pull the six-octet station MAC out of a NetX interface descriptor.
void nx_ether_driver_c6_set_mac(const uint8_t mac[6])
Tell the driver the station MAC address to stamp on outgoing frames.
NetX Duo network driver shim that bridges onto the ESP32-C6 link.
static uint8_t s_rx_staging[k_nx_ra8_eth_max_frame]
Contiguous RX staging buffer.
static uint8_t s_rx_thread_stack[k_nx_ra8_eth_worker_stack_bytes]
static uint8_t s_rx_thread_made
static TX_THREAD s_rx_thread
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
The single integration boundary between this firmware and the ESP32-C6.
ra8_err_t ra8_c6link_eth_send(ra8_c6link_t *link, const uint8_t *frame, uint16_t len)
Hand one 802.3 frame to the co-processor for transmission.
ra8_err_t ra8_c6link_poll(ra8_c6link_t *link, uint16_t max_transactions, ra8_c6link_stats_t *stats)
Clock transactions, delivering whatever the co-processor sends.
struct ra8_c6link ra8_c6link_t
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
bool ra8_esp_hosted_port_rx_pending(void)
Report whether the co-processor has queued receive data.
static bool s_open
True between a successful open and its matching close.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
char CHAR
ThreadX-compatible CHAR (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Opaque mutex stand-in for the host build.
Opaque thread stand-in for the host build.
Bench-visible counters for the C6 NetX bridge.
uint32_t tx_total
Frames handed to ra8_c6link_eth_send.
uint32_t poll_total
ra8_c6link_poll calls the worker made.
uint32_t rx_drop
Frames dropped (pre-init, runt, no packet).
uint32_t tx_err
Transmits the facade or link rejected.
uint32_t rx_total
Frames pushed into NetX from the receive path.