Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define lwIP's s32/u32 to int #8560

Merged
merged 9 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions cores/esp8266/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class IPAddress: public Printable {
IPAddress(const IPAddress& from);
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
IPAddress(uint32_t address) { ctor32(address); }
IPAddress(u32_t address) { ctor32(address); }
IPAddress(unsigned long address) { ctor32(address); }
IPAddress(int address) { ctor32(address); }
IPAddress(const uint8_t *address);

Expand All @@ -80,16 +80,14 @@ class IPAddress: public Printable {
// to a four-byte uint8_t array is expected
operator uint32_t() const { return isV4()? v4(): (uint32_t)0; }
operator uint32_t() { return isV4()? v4(): (uint32_t)0; }
operator u32_t() const { return isV4()? v4(): (u32_t)0; }
operator u32_t() { return isV4()? v4(): (u32_t)0; }

bool isSet () const;
operator bool () const { return isSet(); } // <-
operator bool () { return isSet(); } // <- both are needed

// generic IPv4 wrapper to uint32-view like arduino loves to see it
const u32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const)
u32_t& v4() { return ip_2_ip4(&_ip)->addr; }
const uint32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const)
uint32_t& v4() { return ip_2_ip4(&_ip)->addr; }

bool operator==(const IPAddress& addr) const {
return ip_addr_cmp(&_ip, &addr._ip);
Expand All @@ -100,14 +98,14 @@ class IPAddress: public Printable {
bool operator==(uint32_t addr) const {
return isV4() && v4() == addr;
}
bool operator==(u32_t addr) const {
return isV4() && v4() == addr;
bool operator==(unsigned long addr) const {
return isV4() && v4() == (uint32_t)addr;
}
bool operator!=(uint32_t addr) const {
return !(isV4() && v4() == addr);
}
bool operator!=(u32_t addr) const {
return !(isV4() && v4() == addr);
bool operator!=(unsigned long addr) const {
return isV4() && v4() != (uint32_t)addr;
}
bool operator==(const uint8_t* addr) const;

Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ T* slist_append_tail(T* head, T* item) {
return head;
}

long WiFiServer::_accept(tcp_pcb* apcb, long err) {
err_t WiFiServer::_accept(tcp_pcb* apcb, err_t err) {
(void) err;
DEBUGV("WS:ac\r\n");

Expand All @@ -212,7 +212,7 @@ void WiFiServer::_discard(ClientContext* client) {
DEBUGV("WS:dis\r\n");
}

long WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, long err) {
err_t WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, err_t err) {
return reinterpret_cast<WiFiServer*>(arg)->_accept(newpcb, err);
}

Expand Down
11 changes: 6 additions & 5 deletions libraries/ESP8266WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
#define wifiserver_h

extern "C" {
#include "wl_definitions.h"
#include <wl_definitions.h>

struct tcp_pcb;
}

#include "Server.h"
#include "IPAddress.h"
#include <Server.h>
#include <IPAddress.h>
#include <lwip/err.h>

// lwIP-v2 backlog facility allows to keep memory safe by limiting the
// maximum number of incoming *pending clients*. Default number of possibly
Expand Down Expand Up @@ -103,10 +104,10 @@ class WiFiServer {
using ClientType = WiFiClient;

protected:
long _accept(tcp_pcb* newpcb, long err);
err_t _accept(tcp_pcb* newpcb, err_t err);
void _discard(ClientContext* client);

static long _s_accept(void *arg, tcp_pcb* newpcb, long err);
static err_t _s_accept(void *arg, tcp_pcb* newpcb, err_t err);
static void _s_discard(void* server, ClientContext* ctx);
};

Expand Down
2 changes: 1 addition & 1 deletion tests/host/common/user_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ extern "C"
{
auto test_ipv4
= lwip_ntohl(*(uint32_t*)&((struct sockaddr_in*)ifa->ifa_addr)->sin_addr);
mockverbose(" IPV4 (0x%08lx)", test_ipv4);
mockverbose(" IPV4 (0x%08x)", test_ipv4);
if ((test_ipv4 & 0xff000000) == 0x7f000000)
// 127./8
mockverbose(" (local, ignored)");
Expand Down
16 changes: 15 additions & 1 deletion tools/sdk/lwip2/include/arch/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,21 @@ typedef uint32_t sys_prot_t;
///////////////////////////////
//// MISSING

#define sys_now millis // arduino wire millis() definition returns 32 bits like sys_now() does
// Arduino Core exposes time func with a generic type
#ifdef __cplusplus
extern "C"
{
#endif
unsigned long millis(void);
#ifdef __cplusplus
}
#endif

// b/c we have conflicting typedefs of u32_t and ulong and can't substitute funcs,
// forcibly cast the `millis()` result to lwip's version of u32_t
// (previous version was `#define sys_now millis`)
#define sys_now() ((u32_t)millis())

#define LWIP_RAND r_rand // old lwip uses this useful undocumented function
#define IPSTR "%d.%d.%d.%d"
#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
Expand Down
5 changes: 0 additions & 5 deletions tools/sdk/lwip2/include/arch/sys_arch.h

This file was deleted.

4 changes: 2 additions & 2 deletions tools/sdk/lwip2/include/lwip-err-t.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ typedef unsigned char u8_t;
typedef signed char s8_t;
typedef unsigned short u16_t;
typedef signed short s16_t;
typedef unsigned long u32_t;
typedef signed long s32_t;
typedef unsigned int u32_t;
typedef signed int s32_t;
typedef unsigned long mem_ptr_t;
#define LWIP_ERR_T s32_t
typedef uint32_t sys_prot_t;
2 changes: 1 addition & 1 deletion tools/sdk/lwip2/include/lwip-git-hash.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// generated by makefiles/make-lwip2-hash
#ifndef LWIP_HASH_H
#define LWIP_HASH_H
#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-58-g450bb63"
#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-61-g679577b"
#endif // LWIP_HASH_H
2 changes: 1 addition & 1 deletion tools/sdk/lwip2/include/lwip/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ u32_t sys_jiffies(void);
* Not implementing this function means you cannot use some modules (e.g. TCP
* timestamps, internal timeouts for NO_SYS==1).
*/
u32_t sys_now(void);
//u32_t sys_now(void);

/* Critical Region Protection */
/* These functions must be implemented in the sys_arch.c file.
Expand Down