Skip to content

Commit f4c35d1

Browse files
authored
Merge pull request #3269 from cesanta/wifi612
add support for NXP Wifi in RW612, in an example
2 parents 1f56776 + 81c166a commit f4c35d1

File tree

371 files changed

+321791
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

371 files changed

+321791
-2
lines changed

mongoose.c

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20196,7 +20196,8 @@ void mg_free(void *ptr) {
2019620196

2019720197
#if (!defined(MG_ENABLE_DRIVER_PICO_W) || !MG_ENABLE_DRIVER_PICO_W) && \
2019820198
(!defined(MG_ENABLE_DRIVER_CYW) || !MG_ENABLE_DRIVER_CYW) && \
20199-
(!defined(MG_ENABLE_DRIVER_CYW_SDIO) || !MG_ENABLE_DRIVER_CYW_SDIO)
20199+
(!defined(MG_ENABLE_DRIVER_CYW_SDIO) || !MG_ENABLE_DRIVER_CYW_SDIO) && \
20200+
(!defined(MG_ENABLE_DRIVER_NXP_WIFI) || !MG_ENABLE_DRIVER_NXP_WIFI)
2020020201

2020120202

2020220203
bool mg_wifi_scan(void) {
@@ -22297,6 +22298,101 @@ struct mg_tcpip_driver mg_tcpip_driver_imxrt = {mg_tcpip_driver_imxrt_init,
2229722298

2229822299
#endif
2229922300

22301+
#ifdef MG_ENABLE_LINES
22302+
#line 1 "src/drivers/nxp_wifi.c"
22303+
#endif
22304+
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_NXP_WIFI) && \
22305+
MG_ENABLE_DRIVER_NXP_WIFI
22306+
22307+
22308+
22309+
bool __attribute__((weak)) netif_init(struct mg_tcpip_if *ifp) {
22310+
(void) ifp;
22311+
MG_ERROR(("Please link wifi/net/port/ contents"));
22312+
return false;
22313+
}
22314+
size_t __attribute__((weak))
22315+
netif_tx(const void *bfr, size_t len, struct mg_tcpip_if *ifp) {
22316+
(void) bfr;
22317+
(void) len;
22318+
netif_init(ifp);
22319+
return 0;
22320+
}
22321+
bool __attribute__((weak)) netif_connect(struct mg_wifi_data *wifi) {
22322+
(void) wifi;
22323+
return netif_init(NULL);
22324+
}
22325+
bool __attribute__((weak))
22326+
netif_poll(struct mg_tcpip_if *ifp, bool s1, mg_tcpip_event_handler_t evcb) {
22327+
(void) ifp;
22328+
(void) s1;
22329+
(void) evcb;
22330+
return false;
22331+
}
22332+
22333+
static struct mg_tcpip_if *s_ifp;
22334+
static uint32_t s_ip, s_mask;
22335+
22336+
static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) {
22337+
struct mg_wifi_data *wifi =
22338+
&((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi;
22339+
if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG &&
22340+
*(uint8_t *) ev_data == MG_TCPIP_STATE_UP) {
22341+
MG_DEBUG(("Access Point started"));
22342+
s_ip = ifp->ip, ifp->ip = wifi->apip;
22343+
s_mask = ifp->mask, ifp->mask = wifi->apmask;
22344+
ifp->enable_dhcp_client = false;
22345+
ifp->enable_dhcp_server = true;
22346+
}
22347+
}
22348+
22349+
static bool nxp_wifi_init(struct mg_tcpip_if *ifp) {
22350+
struct mg_wifi_data *wifi =
22351+
&((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi;
22352+
s_ifp = ifp;
22353+
s_ip = ifp->ip;
22354+
s_mask = ifp->mask;
22355+
ifp->pfn = wifi_cb;
22356+
if (!netif_init(ifp)) return false;
22357+
if (wifi->apmode) {
22358+
return mg_wifi_ap_start(wifi);
22359+
} else if (wifi->ssid != NULL && wifi->pass != NULL) {
22360+
return mg_wifi_connect(wifi);
22361+
}
22362+
return true;
22363+
}
22364+
22365+
bool nxp_wifi_poll(struct mg_tcpip_if *ifp, bool s1) {
22366+
return netif_poll(ifp, s1, mg_tcpip_call);
22367+
}
22368+
22369+
struct mg_tcpip_driver mg_tcpip_driver_nxp_wifi = {nxp_wifi_init, netif_tx,
22370+
NULL, nxp_wifi_poll};
22371+
22372+
bool mg_wifi_connect(struct mg_wifi_data *wifi) {
22373+
s_ifp->ip = s_ip;
22374+
s_ifp->mask = s_mask;
22375+
if (s_ifp->ip == 0) s_ifp->enable_dhcp_client = true;
22376+
s_ifp->enable_dhcp_server = false;
22377+
return netif_connect(wifi);
22378+
}
22379+
22380+
bool __attribute__((weak)) mg_wifi_scan(void) {
22381+
return netif_init(NULL);
22382+
}
22383+
bool __attribute__((weak)) mg_wifi_disconnect(void) {
22384+
return netif_init(NULL);
22385+
}
22386+
bool __attribute__((weak)) mg_wifi_ap_start(struct mg_wifi_data *wifi) {
22387+
(void) wifi;
22388+
return netif_init(NULL);
22389+
}
22390+
bool __attribute__((weak)) mg_wifi_ap_stop(void) {
22391+
return netif_init(NULL);
22392+
}
22393+
22394+
#endif
22395+
2230022396
#ifdef MG_ENABLE_LINES
2230122397
#line 1 "src/drivers/phy.c"
2230222398
#endif

mongoose.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,6 +3158,7 @@ extern struct mg_tcpip_driver mg_tcpip_driver_ppp;
31583158
extern struct mg_tcpip_driver mg_tcpip_driver_pico_w;
31593159
extern struct mg_tcpip_driver mg_tcpip_driver_rw612;
31603160
extern struct mg_tcpip_driver mg_tcpip_driver_cyw;
3161+
extern struct mg_tcpip_driver mg_tcpip_driver_nxp_wifi;
31613162

31623163
// Drivers that require SPI, can use this SPI abstraction
31633164
struct mg_tcpip_spi {
@@ -3276,6 +3277,34 @@ struct mg_tcpip_driver_imxrt_data {
32763277
#endif
32773278

32783279

3280+
#if MG_ENABLE_TCPIP && \
3281+
defined(MG_ENABLE_DRIVER_NXP_WIFI) && MG_ENABLE_DRIVER_NXP_WIFI
3282+
3283+
3284+
struct mg_tcpip_driver_nxp_wifi_data {
3285+
struct mg_wifi_data wifi;
3286+
};
3287+
3288+
3289+
#define MG_TCPIP_DRIVER_INIT(mgr) \
3290+
do { \
3291+
static struct mg_tcpip_driver_nxp_wifi_data driver_data_; \
3292+
static struct mg_tcpip_if mif_; \
3293+
MG_SET_WIFI_CONFIG(&driver_data_); \
3294+
mif_.ip = MG_TCPIP_IP; \
3295+
mif_.mask = MG_TCPIP_MASK; \
3296+
mif_.gw = MG_TCPIP_GW; \
3297+
mif_.driver = &mg_tcpip_driver_nxp_wifi; \
3298+
mif_.driver_data = &driver_data_; \
3299+
mif_.recv_queue.size = 8192; \
3300+
mif_.mac[0] = 2; /* MAC read from OTP at driver init */ \
3301+
mg_tcpip_init(mgr, &mif_); \
3302+
MG_INFO(("Driver: nxp wifi, MAC: %M", mg_print_mac, mif_.mac)); \
3303+
} while (0)
3304+
3305+
#endif
3306+
3307+
32793308

32803309

32813310
struct mg_phy {

src/drivers/nxp_wifi.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_NXP_WIFI) && \
2+
MG_ENABLE_DRIVER_NXP_WIFI
3+
4+
#include "drivers/nxp_wifi.h"
5+
6+
bool __attribute__((weak)) netif_init(struct mg_tcpip_if *ifp) {
7+
(void) ifp;
8+
MG_ERROR(("Please link wifi/port/net contents"));
9+
return false;
10+
}
11+
size_t __attribute__((weak))
12+
netif_tx(const void *bfr, size_t len, struct mg_tcpip_if *ifp) {
13+
(void) bfr;
14+
(void) len;
15+
netif_init(ifp);
16+
return 0;
17+
}
18+
bool __attribute__((weak)) netif_connect(struct mg_wifi_data *wifi) {
19+
(void) wifi;
20+
return netif_init(NULL);
21+
}
22+
bool __attribute__((weak))
23+
netif_poll(struct mg_tcpip_if *ifp, bool s1, mg_tcpip_event_handler_t evcb) {
24+
(void) ifp;
25+
(void) s1;
26+
(void) evcb;
27+
return false;
28+
}
29+
30+
static struct mg_tcpip_if *s_ifp;
31+
static uint32_t s_ip, s_mask;
32+
33+
static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) {
34+
struct mg_wifi_data *wifi =
35+
&((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi;
36+
if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG &&
37+
*(uint8_t *) ev_data == MG_TCPIP_STATE_UP) {
38+
MG_DEBUG(("Access Point started"));
39+
s_ip = ifp->ip, ifp->ip = wifi->apip;
40+
s_mask = ifp->mask, ifp->mask = wifi->apmask;
41+
ifp->enable_dhcp_client = false;
42+
ifp->enable_dhcp_server = true;
43+
}
44+
}
45+
46+
static bool nxp_wifi_init(struct mg_tcpip_if *ifp) {
47+
struct mg_wifi_data *wifi =
48+
&((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi;
49+
s_ifp = ifp;
50+
s_ip = ifp->ip;
51+
s_mask = ifp->mask;
52+
ifp->pfn = wifi_cb;
53+
if (!netif_init(ifp)) return false;
54+
if (wifi->apmode) {
55+
return mg_wifi_ap_start(wifi);
56+
} else if (wifi->ssid != NULL && wifi->pass != NULL) {
57+
return mg_wifi_connect(wifi);
58+
}
59+
return true;
60+
}
61+
62+
bool nxp_wifi_poll(struct mg_tcpip_if *ifp, bool s1) {
63+
return netif_poll(ifp, s1, mg_tcpip_call);
64+
}
65+
66+
struct mg_tcpip_driver mg_tcpip_driver_nxp_wifi = {nxp_wifi_init, netif_tx,
67+
NULL, nxp_wifi_poll};
68+
69+
bool mg_wifi_connect(struct mg_wifi_data *wifi) {
70+
s_ifp->ip = s_ip;
71+
s_ifp->mask = s_mask;
72+
if (s_ifp->ip == 0) s_ifp->enable_dhcp_client = true;
73+
s_ifp->enable_dhcp_server = false;
74+
return netif_connect(wifi);
75+
}
76+
77+
bool __attribute__((weak)) mg_wifi_scan(void) {
78+
return netif_init(NULL);
79+
}
80+
bool __attribute__((weak)) mg_wifi_disconnect(void) {
81+
return netif_init(NULL);
82+
}
83+
bool __attribute__((weak)) mg_wifi_ap_start(struct mg_wifi_data *wifi) {
84+
(void) wifi;
85+
return netif_init(NULL);
86+
}
87+
bool __attribute__((weak)) mg_wifi_ap_stop(void) {
88+
return netif_init(NULL);
89+
}
90+
91+
#endif

src/drivers/nxp_wifi.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#if MG_ENABLE_TCPIP && \
4+
defined(MG_ENABLE_DRIVER_NXP_WIFI) && MG_ENABLE_DRIVER_NXP_WIFI
5+
6+
7+
struct mg_tcpip_driver_nxp_wifi_data {
8+
struct mg_wifi_data wifi;
9+
};
10+
11+
12+
#define MG_TCPIP_DRIVER_INIT(mgr) \
13+
do { \
14+
static struct mg_tcpip_driver_nxp_wifi_data driver_data_; \
15+
static struct mg_tcpip_if mif_; \
16+
MG_SET_WIFI_CONFIG(&driver_data_); \
17+
mif_.ip = MG_TCPIP_IP; \
18+
mif_.mask = MG_TCPIP_MASK; \
19+
mif_.gw = MG_TCPIP_GW; \
20+
mif_.driver = &mg_tcpip_driver_nxp_wifi; \
21+
mif_.driver_data = &driver_data_; \
22+
mif_.recv_queue.size = 8192; \
23+
mif_.mac[0] = 2; /* MAC read from OTP at driver init */ \
24+
mg_tcpip_init(mgr, &mif_); \
25+
MG_INFO(("Driver: nxp wifi, MAC: %M", mg_print_mac, mif_.mac)); \
26+
} while (0)
27+
28+
#endif

src/net_builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extern struct mg_tcpip_driver mg_tcpip_driver_ppp;
9696
extern struct mg_tcpip_driver mg_tcpip_driver_pico_w;
9797
extern struct mg_tcpip_driver mg_tcpip_driver_rw612;
9898
extern struct mg_tcpip_driver mg_tcpip_driver_cyw;
99+
extern struct mg_tcpip_driver mg_tcpip_driver_nxp_wifi;
99100

100101
// Drivers that require SPI, can use this SPI abstraction
101102
struct mg_tcpip_spi {

src/wifi_dummy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#if (!defined(MG_ENABLE_DRIVER_PICO_W) || !MG_ENABLE_DRIVER_PICO_W) && \
44
(!defined(MG_ENABLE_DRIVER_CYW) || !MG_ENABLE_DRIVER_CYW) && \
5-
(!defined(MG_ENABLE_DRIVER_CYW_SDIO) || !MG_ENABLE_DRIVER_CYW_SDIO)
5+
(!defined(MG_ENABLE_DRIVER_CYW_SDIO) || !MG_ENABLE_DRIVER_CYW_SDIO) && \
6+
(!defined(MG_ENABLE_DRIVER_NXP_WIFI) || !MG_ENABLE_DRIVER_NXP_WIFI)
67

78

89
bool mg_wifi_scan(void) {

0 commit comments

Comments
 (0)