ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
wifi_hal_ip.c
Go to the documentation of this file.
1
25
26#include <stdint.h>
27
28#include "nx_api.h"
29#include "nx_ether_driver_c6.h"
30#include "nxd_dhcp_client.h"
31#include "ra8_c6link.h"
32#include "ra8_err.h"
33#include "ra8_wifi.h"
34#include "tx_api.h"
35#include "wifi_hal_join.h"
36
60
62static NX_PACKET_POOL s_pool;
64alignas(4) static uint8_t s_pool_mem[k_wifi_hal_pool_bytes];
66static NX_IP s_ip;
68alignas(8) static uint8_t s_ip_stack[k_wifi_hal_ip_stack];
70alignas(4) static uint8_t s_arp_cache[k_wifi_hal_arp_bytes];
72static NX_DHCP s_dhcp;
74static CHAR s_pool_name[] = "wifi_hal_pool";
76static CHAR s_ip_name[] = "wifi_hal_ip";
78static CHAR s_dhcp_name[] = "wifi_hal_dhcp";
79
80/* Create the packet pool + IP instance and enable the protocols DHCP needs. */
82{
83 UINT s = nx_packet_pool_create(&s_pool,
86 (VOID*)s_pool_mem,
87 (ULONG)sizeof(s_pool_mem));
88 if (s != NX_SUCCESS) {
89 return s;
90 }
91 s = nx_ip_create(&s_ip,
93 IP_ADDRESS(0, 0, 0, 0),
94 IP_ADDRESS(0, 0, 0, 0),
95 &s_pool,
97 (VOID*)s_ip_stack,
98 (ULONG)sizeof(s_ip_stack),
100 if (s != NX_SUCCESS) {
101 return s;
102 }
103 s = nx_arp_enable(&s_ip, (VOID*)s_arp_cache, (ULONG)sizeof(s_arp_cache));
104 if (s != NX_SUCCESS) {
105 return s;
106 }
107 s = nx_udp_enable(&s_ip);
108 if (s != NX_SUCCESS) {
109 return s;
110 }
111 return nx_icmp_enable(&s_ip);
112}
113
114/* Run the DHCP client to a bound lease, then read the lease into out. */
116{
117 UINT s = nx_dhcp_create(&s_dhcp, &s_ip, s_dhcp_name);
118 if (s != NX_SUCCESS) {
119 return s;
120 }
121 s = nx_dhcp_start(&s_dhcp);
122 if (s != NX_SUCCESS) {
123 return s;
124 }
125 ULONG actual = 0U;
126 s = nx_ip_status_check(&s_ip,
127 (ULONG)NX_IP_ADDRESS_RESOLVED,
128 &actual,
130 if (s != NX_SUCCESS) {
131 return s;
132 }
133 ULONG ip = 0U;
134 ULONG mask = 0U;
135 ULONG gw = 0U;
136 ULONG server = 0U;
137 (void)nx_ip_address_get(&s_ip, &ip, &mask);
138 (void)nx_ip_gateway_address_get(&s_ip, &gw);
139 (void)nx_dhcp_server_address_get(&s_dhcp, &server);
140 out->ip = (uint32_t)ip;
141 out->mask = (uint32_t)mask;
142 out->gateway = (uint32_t)gw;
143 out->dhcp_server = (uint32_t)server;
144 return NX_SUCCESS;
145}
146
148{
149 if ((ip_ctx == nullptr) || (mac == nullptr) || (out == nullptr)) {
150 return k_ra8_err_null_ptr;
151 }
152 *out = (ra8_wifi_lease_t){};
153 ra8_c6link_t* link = (ra8_c6link_t*)ip_ctx;
154
157 nx_system_initialize();
158
159 if (priv_net_create_ip() != NX_SUCCESS) {
161 }
162 if (priv_net_dhcp(out) != NX_SUCCESS) {
163 *out = (ra8_wifi_lease_t){};
164 return k_ra8_err_timeout;
165 }
166 out->bound = (out->ip != 0U);
167 return k_ra8_ok;
168}
static CHAR s_dhcp_name[]
Definition c6_cam_net.c:39
static uint8_t s_pool_mem[k_c6_cam_net_pool_bytes]
Definition c6_cam_net.c:31
static CHAR s_pool_name[]
Definition c6_cam_net.c:37
static NX_DHCP s_dhcp
Definition c6_cam_net.c:35
static CHAR s_ip_name[]
Definition c6_cam_net.c:38
static ULONG s_ip_stack[k_demo_ip_stack/sizeof(ULONG)]
Definition main.c:232
static NX_IP s_ip
Definition main.c:229
static ULONG s_arp_cache[k_demo_arp_cache/sizeof(ULONG)]
Definition main.c:233
NetX Duo network driver shim that bridges onto the ESP32-C6 link.
void nx_ether_driver_c6_bind(ra8_c6link_t *link)
Bind an open C6 link handle to the driver and arm its mutex.
void nx_ether_driver_c6(NX_IP_DRIVER *driver_req)
NetX Duo link driver entry point for the ESP32-C6 Wi-Fi station.
void nx_ether_driver_c6_set_mac(const uint8_t mac[6])
Tell the driver the station MAC address to stamp on outgoing frames.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
@ k_ra8_err_timeout
Operation exceeded its time budget.
Definition ra8_err.h:188
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
static ra8_esp_hosted_pool_state_t s_pool
Singleton state of the memory and queue half.
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).
A small, uniform Wi-Fi facade: init, connect, get an IP, disconnect.
struct ra8_wifi_mac ra8_wifi_mac_t
struct ra8_wifi_lease ra8_wifi_lease_t
uint32_t dhcp_server
Address of the DHCP server that answered.
Definition ra8_wifi.h:237
uint32_t gateway
Default gateway from the lease.
Definition ra8_wifi.h:236
uint32_t mask
Subnet mask from the lease.
Definition ra8_wifi.h:235
bool bound
A usable lease is held.
Definition ra8_wifi.h:238
uint32_t ip
Leased station address, or zero if unbound.
Definition ra8_wifi.h:234
uint8_t octet[k_ra8_wifi_mac_bytes]
Address octets, first on the wire first.
Definition ra8_wifi.h:210
static UINT priv_net_dhcp(ra8_wifi_lease_t *out)
ra8_err_t wifi_hal_ip_bind(void *ip_ctx, const ra8_wifi_mac_t *mac, ra8_wifi_lease_t *out)
The application's IP provider: a NetX Duo DHCP client to a lease.
wifi_hal_net_size_t
Static sizing for the NetX Duo objects this application owns.
Definition wifi_hal_ip.c:53
@ k_wifi_hal_ip_prio
NetX IP helper-thread priority.
Definition wifi_hal_ip.c:58
@ k_wifi_hal_ip_stack
NetX IP helper-thread stack, in octets.
Definition wifi_hal_ip.c:56
@ k_wifi_hal_pkt_payload
Per-packet payload, in octets.
Definition wifi_hal_ip.c:54
@ k_wifi_hal_pool_bytes
Packet-pool backing store, in octets.
Definition wifi_hal_ip.c:55
@ k_wifi_hal_arp_bytes
ARP cache backing store, in octets.
Definition wifi_hal_ip.c:57
static UINT priv_net_create_ip(void)
Definition wifi_hal_ip.c:81
Constants, console formatters and the DHCP provider for the HAL join.
@ k_wifi_hal_dhcp_wait_ms
DHCP lease wait budget, ticks.