Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
960d8bc
reimplementing the ethernet drivers
andreagilardoni Dec 28, 2023
452accf
added library containing abstract network stack classes
andreagilardoni Dec 28, 2023
30725ad
reimplementing the tcp client with the aim of solving issues
andreagilardoni Dec 28, 2023
a0666af
cleaning up
andreagilardoni Dec 28, 2023
4c0123f
redefinition of network Interface classes
andreagilardoni Dec 28, 2023
2637cdf
restructuring CLwipIf singleton class
andreagilardoni Dec 28, 2023
216e3aa
rewriting CNetif base class
andreagilardoni Dec 28, 2023
28f9199
rewriting CEth CwifiStation and CSoftAP classes
andreagilardoni Dec 28, 2023
d40a06a
added possibility to pass a std::function to esphosted callbacks
andreagilardoni Dec 29, 2023
58c2860
defined Ethernet driver and interface instance
andreagilardoni Dec 29, 2023
3850758
removed unused endif
andreagilardoni Dec 29, 2023
9784bac
commented netif stats
andreagilardoni Dec 29, 2023
f5633d6
defined network interface abstrac class
andreagilardoni Dec 29, 2023
40772d1
fixing lwipClient
andreagilardoni Dec 29, 2023
cef42da
fixing imports and variable names
andreagilardoni Dec 29, 2023
e76ded7
cleaning CNetIf classes definition
andreagilardoni Dec 29, 2023
d39a90a
fixing class implementation and making it able to compile
andreagilardoni Dec 29, 2023
a28de2d
defined tmp utils library
andreagilardoni Dec 29, 2023
460a0d5
reimplementing wifi handle
andreagilardoni Dec 29, 2023
ae29df7
commnting code not yet ready to be compiled
andreagilardoni Dec 29, 2023
9a871ef
deleted lwip tcp wrapper
andreagilardoni Jan 2, 2024
0b6dd35
implemented netowrk interfaces specific clients
andreagilardoni Jan 2, 2024
f911f67
defined Wifi global variable for network interface
andreagilardoni Jan 2, 2024
4c86ebf
added scanforap method
andreagilardoni Jan 2, 2024
b371331
added comment
andreagilardoni Jan 4, 2024
1c58899
reimplementing Server class with ethernet and wifi subclasses
andreagilardoni Jan 4, 2024
ed6886d
fixing bug of missing nullptr check
andreagilardoni Jan 4, 2024
10a05bd
removed unused types
andreagilardoni Jan 4, 2024
42063d1
minor changes on file
andreagilardoni Jan 4, 2024
e41294a
Revert "defined Wifi global variable for network interface"
andreagilardoni Jan 5, 2024
f20a258
Revert "reimplementing wifi handle"
andreagilardoni Jan 5, 2024
552a153
applying a codestyle
andreagilardoni Jan 5, 2024
d239597
fixing EthernetServer class
andreagilardoni Jan 8, 2024
6e6c837
making WiFi class compile
andreagilardoni Jan 8, 2024
ea4ae60
fixing implementation of client and server
andreagilardoni Jan 8, 2024
87ae27a
fixing global definitions of WiFi interfaces
andreagilardoni Jan 8, 2024
0c210ee
making UDP derived classes compile
andreagilardoni Jan 8, 2024
2c10e0e
fixing retrocompatibility issues
andreagilardoni Jan 8, 2024
4cb8171
dealing with retrocompatibility
andreagilardoni Jan 8, 2024
c9ed50c
solving FIXME
andreagilardoni Jan 9, 2024
719e63f
fixing dns related functions
andreagilardoni Jan 9, 2024
58f9561
CNetIf - added config method to apply new static IP settings
JAndrassy Dec 14, 2023
45c85f3
adapting cherry pick
andreagilardoni Jan 9, 2024
664fc69
moving funtion in correct section in file
andreagilardoni Jan 9, 2024
3a1e29d
added dhcp_inform call
andreagilardoni Jan 9, 2024
b5eb21b
fixing compilation issue
andreagilardoni Jan 10, 2024
ae01d58
removing FIXME
andreagilardoni Jan 10, 2024
f8507fa
restoring CWiFi methods to extract scanned access point info
andreagilardoni Jan 10, 2024
e0ce22c
removing lwipMem files
andreagilardoni Jan 10, 2024
4a1e9d4
moving free_pbuf_chain to an external file in order to be shared from…
andreagilardoni Jan 10, 2024
4980778
moving lwipTypes udp_struct into udp file
andreagilardoni Jan 10, 2024
56c1d07
readapting udp class
andreagilardoni Jan 10, 2024
e1af45e
improving task syncrhonization between timer and main context
andreagilardoni Jan 12, 2024
0809792
fixing dns resolution bug
andreagilardoni Jan 12, 2024
9734322
cleaning code
andreagilardoni Jan 12, 2024
c3ba277
fine tuning lwip stack and compiling it
andreagilardoni Jan 12, 2024
66943b8
adding dns resolution with lwip example
andreagilardoni Jan 12, 2024
9cb6f55
enablig execution of network stack in interrrupt context]
andreagilardoni Jan 12, 2024
99ca0fa
added disconnect and link status for retrocompatibility
andreagilardoni Jan 17, 2024
7e88a57
fixing lwip server
andreagilardoni Jan 19, 2024
88f5091
blocking begin call on dhcp acquisition
andreagilardoni Jan 19, 2024
0f430c5
Making it possible to call multiple time the begin function on an int…
andreagilardoni Jan 22, 2024
ec3cba5
making netif compatible with connection handler usage
andreagilardoni Jan 22, 2024
e56d9f9
fixing return status of begin
andreagilardoni Jan 23, 2024
1ac341d
adding test files for lwipwrapper WIP
andreagilardoni Jan 23, 2024
0207e39
fixing connection issue on Ethernet and Wifi Client when host is passed
andreagilardoni Jan 23, 2024
3bbaccd
exporting Network stack synchronization to lwipClient
andreagilardoni Jan 23, 2024
c595cc0
fixing return codes
andreagilardoni Jan 23, 2024
ec5ea83
deleting pbuf when partially consumed
andreagilardoni Jan 23, 2024
564fcfc
Changed memory alignemnt according to renesas specifications
andreagilardoni Jan 24, 2024
6c5f0ea
improving examples
andreagilardoni Jan 24, 2024
6edeefe
setting dhcp acquired when dhcp server is informed of static ip
andreagilardoni Jan 24, 2024
896f7ca
improving performances of ssl client
andreagilardoni Jan 24, 2024
aa3c5a1
fixing counter overflow in tcp send
andreagilardoni Jan 24, 2024
9e05471
added tcp write example for tcp echo server
andreagilardoni Jan 25, 2024
e489e71
changing synchronization to timer disable
andreagilardoni Jan 26, 2024
e303948
improving write function to better handle memory errors and bigger bu…
andreagilardoni Jan 26, 2024
b58a521
making dns resolution to work automatically when interrupts are disabled
andreagilardoni Jan 26, 2024
c28b4bd
improving example
andreagilardoni Jan 26, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improving task syncrhonization between timer and main context
  • Loading branch information
andreagilardoni committed Jan 12, 2024
commit e1af45e2c7fec80d226e06e7283b0fd070a43f59
69 changes: 31 additions & 38 deletions libraries/lwIpWrapper/src/CNetIf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void _getHostByNameCBK(const char *name, const ip_addr_t *ipaddr, void *c

#ifdef LWIP_USE_TIMER
static void timer_cb(timer_callback_args_t* arg);
#endif
#endif // LWIP_USE_TIMER

// Custom Pbuf definition used to handle RX zero copy
// TODO Move this in a separate file (understand if it is required)
Expand All @@ -40,16 +40,13 @@ static void zerocopy_pbuf_mem_free(struct pbuf *p) {
// SYS_ARCH_DECL_PROTECT(zerocopy_pbuf_free);
zerocopy_pbuf_t* zcpbuf = (zerocopy_pbuf_t*) p;

// arduino::lock();
// SYS_ARCH_PROTECT(zerocopy_pbuf_free);

// FIXME pbufs may be allocated in a different memory pool, deallocate them accordingly
zcpbuf->buffer_free(zcpbuf->buffer);
zcpbuf->buffer = nullptr;
mem_free(zcpbuf); // TODO understand if pbuf_free deletes the pbuf
// SYS_ARCH_UNPROTECT(zerocopy_pbuf_free);

// arduino::unlock();
}

static inline zerocopy_pbuf_t* get_zerocopy_pbuf(uint8_t *buffer, uint32_t size, void(*buffer_free)(void*) = mem_free) {
Expand Down Expand Up @@ -512,7 +509,6 @@ err_t CEth::output(struct netif* ni, struct pbuf* p) {

void CEth::consume_callback(uint8_t* buffer, uint32_t len) {
// TODO understand if this callback can be moved into the base class
// arduino::lock();

const uint16_t trimmed_size = len;

Expand All @@ -536,7 +532,6 @@ void CEth::consume_callback(uint8_t* buffer, uint32_t len) {
} else {
// NETIF_STATS_INCREMENT_RX_BYTES(this->stats, p->len);
}
// arduino::unlock();
}

/* ########################################################################## */
Expand All @@ -556,7 +551,6 @@ int CWifiStation::begin(const IPAddress &ip, const IPAddress &nm, const IPAddres
int res = 0;
int time_num = 0;

// arduino::lock();
CEspControl::getInstance().listenForStationDisconnectEvent([this] (CCtrlMsgWrapper *resp) -> int {
netif_set_link_down(&this->ni);
return ESP_CONTROL_OK;
Expand All @@ -578,10 +572,12 @@ int CWifiStation::begin(const IPAddress &ip, const IPAddress &nm, const IPAddres
time_num++;
}

CLwipIf::getInstance().sync_timer();
res = CEspControl::getInstance().setWifiMode(WIFI_MODE_STA);
CLwipIf::getInstance().enable_timer();

CNetIf::begin(ip, nm, gw);
exit:
// arduino::unlock();
return res;
}

Expand All @@ -590,8 +586,6 @@ int CWifiStation::connectToAP(const char* ssid, const char *passphrase) {
int rv = ESP_CONTROL_CTRL_ERROR; // FIXME this should be set with an error meaning AP not found
bool found = false;
int8_t best_index = -1; // this index is used to find the ap with the best rssi
// AccessPoint_t* best_matching_ap;
// arduino::lock();

if((rv=this->scanForAp()) != WL_SCAN_COMPLETED) {
goto exit;
Expand All @@ -606,62 +600,60 @@ int CWifiStation::connectToAP(const char* ssid, const char *passphrase) {
}
}
if(best_index != -1) {
// memset(ap.ssid, 0x00, SSID_LENGTH); // I shouldn't need to zero the ssid string pointer
strncpy((char*)ap.ssid, ssid, SSID_LENGTH);
// memcpy(ap.ssid, access_points[best_index].ssid, SSID_LENGTH);

// memset(ap.pwd, 0x00, PASSWORD_LENGTH);
if(passphrase != nullptr) {
auto slen = strlen(passphrase)+1;
strncpy((char*)ap.pwd, passphrase, (slen < PASSWORD_LENGTH) ? slen : PASSWORD_LENGTH);
// memcpy(ap.pwd, passphrase, (slen < PASSWORD_LENGTH) ? slen : PASSWORD_LENGTH);
} else {
// memset(ap.pwd, 0x00, PASSWORD_LENGTH);
ap.pwd[0] = '\0';
}

memset(ap.bssid, 0x00, BSSID_LENGTH);
memcpy(ap.bssid, access_points[best_index].bssid, BSSID_LENGTH);

// arduino::lock();
CEspControl::getInstance().communicateWithEsp();

CLwipIf::getInstance().sync_timer();
rv=CEspControl::getInstance().connectAccessPoint(ap);
// arduino::unlock();

if (rv == ESP_CONTROL_OK) {
CEspControl::getInstance().getAccessPointConfig(access_point_cfg);

netif_set_link_up(&this->ni);
}
// arduino::unlock();
CLwipIf::getInstance().enable_timer();
}

exit:
// arduino::unlock();

return rv;
}

int CWifiStation::scanForAp() {
// arduino::lock();
access_points.clear();

CLwipIf::getInstance().sync_timer();

int res = CEspControl::getInstance().getAccessPointScanList(access_points);
CLwipIf::getInstance().enable_timer();

if (res == ESP_CONTROL_OK) {
res = WL_SCAN_COMPLETED;
} else {
res = WL_NO_SSID_AVAIL;
}

// arduino::unlock();

return res;
}

// disconnect
int CWifiStation::disconnectFromAp() {
return CEspControl::getInstance().disconnectAccessPoint();
CLwipIf::getInstance().sync_timer();

auto res = CEspControl::getInstance().disconnectAccessPoint();

CLwipIf::getInstance().enable_timer();

return res;
}

err_t CWifiStation::init(struct netif* ni) {
Expand Down Expand Up @@ -698,7 +690,6 @@ err_t CWifiStation::output(struct netif* _ni, struct pbuf* p) {
// NETIF_STATS_INCREMENT_TX_TRANSMIT_CALLS(this->stats);
// NETIF_STATS_TX_TIME_START(this->stats);

// arduino::lock();
// p may be a chain of pbufs
if(p->next != nullptr) {
buf = (uint8_t*) malloc(size*sizeof(uint8_t));
Expand Down Expand Up @@ -731,7 +722,6 @@ err_t CWifiStation::output(struct netif* _ni, struct pbuf* p) {
if(p->next != nullptr && buf != nullptr) {
free(buf);
}
// arduino::unlock();
return errval;
}

Expand All @@ -745,7 +735,6 @@ void CWifiStation::task() {
struct pbuf* p = nullptr;

// NETIF_STATS_RX_TIME_START(this->stats);
// arduino::lock();
// TODO do not perform this when not connected to an AP
if(hw_init) {
CEspControl::getInstance().communicateWithEsp();
Expand Down Expand Up @@ -779,7 +768,6 @@ void CWifiStation::task() {
buffer = CEspControl::getInstance().getStationRx(if_num, dim);
}
// NETIF_STATS_RX_TIME_AVERAGE(this->stats);
// arduino::unlock();
}

// void CWifiStation::consume_callback(uint8_t* buffer, uint32_t len) {
Expand Down Expand Up @@ -877,7 +865,6 @@ int CWifiSoftAp::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress
int res = 0;
int time_num = 0;

// arduino::lock();
CEspControl::getInstance().listenForInitEvent([this] (CCtrlMsgWrapper *resp) -> int {
// Serial.println("init");
this->hw_init = true;
Expand All @@ -895,21 +882,23 @@ int CWifiSoftAp::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress
time_num++;
}

CLwipIf::getInstance().sync_timer();
res = CEspControl::getInstance().setWifiMode(WIFI_MODE_AP);
CLwipIf::getInstance().enable_timer();

CNetIf::begin(
default_dhcp_server_ip,
default_nm,
default_dhcp_server_ip
);
exit:
// arduino::unlock();
return res;
}

// TODO scan the other access point first and then set the channel if 0
// TODO there are requirements for ssid and password
int CWifiSoftAp::startSoftAp(const char* ssid, const char* passphrase, uint8_t channel) {
CLwipIf::getInstance().sync_timer();
SoftApCfg_t cfg;

strncpy((char*)cfg.ssid, ssid, SSID_LENGTH);
Expand Down Expand Up @@ -942,7 +931,7 @@ int CWifiSoftAp::startSoftAp(const char* ssid, const char* passphrase, uint8_t c
// wifi_status = WL_AP_FAILED;
}


CLwipIf::getInstance().enable_timer();
return rv;
}

Expand Down Expand Up @@ -980,7 +969,6 @@ err_t CWifiSoftAp::output(struct netif* _ni, struct pbuf* p) {
// NETIF_STATS_INCREMENT_TX_TRANSMIT_CALLS(this->stats);
// NETIF_STATS_TX_TIME_START(this->stats);

// arduino::lock();
// p may be a chain of pbufs
if(p->next != nullptr) {
buf = (uint8_t*) malloc(size*sizeof(uint8_t));
Expand Down Expand Up @@ -1013,7 +1001,6 @@ err_t CWifiSoftAp::output(struct netif* _ni, struct pbuf* p) {
if(p->next != nullptr && buf != nullptr) {
free(buf);
}
// arduino::unlock();
return errval;
}

Expand All @@ -1030,7 +1017,6 @@ void CWifiSoftAp::task() {
struct pbuf* p = nullptr;

// NETIF_STATS_RX_TIME_START(this->stats);
// arduino::lock();
// TODO do not perform this when not connected to an AP
if(hw_init) {
CEspControl::getInstance().communicateWithEsp();
Expand Down Expand Up @@ -1065,7 +1051,6 @@ void CWifiSoftAp::task() {
buffer = CEspControl::getInstance().getStationRx(if_num, dim);
}
// NETIF_STATS_RX_TIME_AVERAGE(this->stats);
// arduino::unlock();
}

const char* CWifiSoftAp::getSSID() {
Expand All @@ -1086,11 +1071,19 @@ uint8_t CWifiSoftAp::getChannel() {
}

int CWifiSoftAp::setLowPowerMode() {
return CEspControl::getInstance().setPowerSaveMode(1);
CLwipIf::getInstance().sync_timer();
auto res = CEspControl::getInstance().setPowerSaveMode(1);
CLwipIf::getInstance().enable_timer();

return res;
}

int CWifiSoftAp::resetLowPowerMode() {
return CEspControl::getInstance().setPowerSaveMode(1);
CLwipIf::getInstance().sync_timer();
auto res = CEspControl::getInstance().setPowerSaveMode(1);
CLwipIf::getInstance().enable_timer();

return res;
}

/* ##########################################################################
Expand Down
19 changes: 18 additions & 1 deletion libraries/lwIpWrapper/src/CNetIf.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,27 @@ class CLwipIf {
// lwip stores the netif in a linked list called: netif_list

friend class CNetIf;
friend class CWifiSoftAp;
friend class CWifiStation;

#ifdef LWIP_USE_TIMER
FspTimer timer;
#endif

inline void sync_timer() {
timer.disable_overflow_irq();
this->task();
}

inline void enable_timer() {
timer.enable_overflow_irq();
}
#else // LWIP_USE_TIMER
inline void sync_timer() {
this->task();
}

inline void enable_timer() { }
#endif // LWIP_USE_TIMER
};

extern CEth Ethernet;
Expand Down