mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-08 16:11:18 +00:00
add support for NXP Wifi in RW612, in an example
This commit is contained in:
1 parent
1f56776050
commit
81c166ad74
371 files changed
+321791
-2
No files matched your search
@@ -0,0 +1,91 @@
|
||||
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_NXP_WIFI) && \
|
||||
MG_ENABLE_DRIVER_NXP_WIFI
|
||||
|
||||
#include "drivers/nxp_wifi.h"
|
||||
|
||||
bool __attribute__((weak)) netif_init(struct mg_tcpip_if *ifp) {
|
||||
(void) ifp;
|
||||
MG_ERROR(("Please link wifi/port/net contents"));
|
||||
return false;
|
||||
}
|
||||
size_t __attribute__((weak))
|
||||
netif_tx(const void *bfr, size_t len, struct mg_tcpip_if *ifp) {
|
||||
(void) bfr;
|
||||
(void) len;
|
||||
netif_init(ifp);
|
||||
return 0;
|
||||
}
|
||||
bool __attribute__((weak)) netif_connect(struct mg_wifi_data *wifi) {
|
||||
(void) wifi;
|
||||
return netif_init(NULL);
|
||||
}
|
||||
bool __attribute__((weak))
|
||||
netif_poll(struct mg_tcpip_if *ifp, bool s1, mg_tcpip_event_handler_t evcb) {
|
||||
(void) ifp;
|
||||
(void) s1;
|
||||
(void) evcb;
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct mg_tcpip_if *s_ifp;
|
||||
static uint32_t s_ip, s_mask;
|
||||
|
||||
static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) {
|
||||
struct mg_wifi_data *wifi =
|
||||
&((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi;
|
||||
if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG &&
|
||||
*(uint8_t *) ev_data == MG_TCPIP_STATE_UP) {
|
||||
MG_DEBUG(("Access Point started"));
|
||||
s_ip = ifp->ip, ifp->ip = wifi->apip;
|
||||
s_mask = ifp->mask, ifp->mask = wifi->apmask;
|
||||
ifp->enable_dhcp_client = false;
|
||||
ifp->enable_dhcp_server = true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool nxp_wifi_init(struct mg_tcpip_if *ifp) {
|
||||
struct mg_wifi_data *wifi =
|
||||
&((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi;
|
||||
s_ifp = ifp;
|
||||
s_ip = ifp->ip;
|
||||
s_mask = ifp->mask;
|
||||
ifp->pfn = wifi_cb;
|
||||
if (!netif_init(ifp)) return false;
|
||||
if (wifi->apmode) {
|
||||
return mg_wifi_ap_start(wifi);
|
||||
} else if (wifi->ssid != NULL && wifi->pass != NULL) {
|
||||
return mg_wifi_connect(wifi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nxp_wifi_poll(struct mg_tcpip_if *ifp, bool s1) {
|
||||
return netif_poll(ifp, s1, mg_tcpip_call);
|
||||
}
|
||||
|
||||
struct mg_tcpip_driver mg_tcpip_driver_nxp_wifi = {nxp_wifi_init, netif_tx,
|
||||
NULL, nxp_wifi_poll};
|
||||
|
||||
bool mg_wifi_connect(struct mg_wifi_data *wifi) {
|
||||
s_ifp->ip = s_ip;
|
||||
s_ifp->mask = s_mask;
|
||||
if (s_ifp->ip == 0) s_ifp->enable_dhcp_client = true;
|
||||
s_ifp->enable_dhcp_server = false;
|
||||
return netif_connect(wifi);
|
||||
}
|
||||
|
||||
bool __attribute__((weak)) mg_wifi_scan(void) {
|
||||
return netif_init(NULL);
|
||||
}
|
||||
bool __attribute__((weak)) mg_wifi_disconnect(void) {
|
||||
return netif_init(NULL);
|
||||
}
|
||||
bool __attribute__((weak)) mg_wifi_ap_start(struct mg_wifi_data *wifi) {
|
||||
(void) wifi;
|
||||
return netif_init(NULL);
|
||||
}
|
||||
bool __attribute__((weak)) mg_wifi_ap_stop(void) {
|
||||
return netif_init(NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#if MG_ENABLE_TCPIP && \
|
||||
defined(MG_ENABLE_DRIVER_NXP_WIFI) && MG_ENABLE_DRIVER_NXP_WIFI
|
||||
|
||||
|
||||
struct mg_tcpip_driver_nxp_wifi_data {
|
||||
struct mg_wifi_data wifi;
|
||||
};
|
||||
|
||||
|
||||
#define MG_TCPIP_DRIVER_INIT(mgr) \
|
||||
do { \
|
||||
static struct mg_tcpip_driver_nxp_wifi_data driver_data_; \
|
||||
static struct mg_tcpip_if mif_; \
|
||||
MG_SET_WIFI_CONFIG(&driver_data_); \
|
||||
mif_.ip = MG_TCPIP_IP; \
|
||||
mif_.mask = MG_TCPIP_MASK; \
|
||||
mif_.gw = MG_TCPIP_GW; \
|
||||
mif_.driver = &mg_tcpip_driver_nxp_wifi; \
|
||||
mif_.driver_data = &driver_data_; \
|
||||
mif_.recv_queue.size = 8192; \
|
||||
mif_.mac[0] = 2; /* MAC read from OTP at driver init */ \
|
||||
mg_tcpip_init(mgr, &mif_); \
|
||||
MG_INFO(("Driver: nxp wifi, MAC: %M", mg_print_mac, mif_.mac)); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user