Skip to content

Commit 4c96365

Browse files
committed
Merge branch 'pr-heap-refactor3' of github.com:mhightower83/Arduino into pr-heap-refactor3
2 parents 471f838 + d829540 commit 4c96365

File tree

140 files changed

+666
-2891
lines changed

Some content is hidden

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

140 files changed

+666
-2891
lines changed

.github/workflows/build-ide.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ permissions:
1111
jobs:
1212

1313
# Examples are built in parallel to avoid CI total job time limitation
14+
sanity-check:
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
shell: bash
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
submodules: false
23+
- uses: actions/cache@v3
24+
with:
25+
path: ./tools/dist
26+
key: ${{ runner.os }}-${{ hashFiles('package/package_esp8266com_index.template.json', 'tests/common.sh', 'tests/build.sh') }}
27+
- name: Toolchain sanity checks
28+
run: |
29+
bash ./tests/sanity_check.sh
1430
1531
build-linux:
1632
name: Linux - LwIP ${{ matrix.lwip }} (${{ matrix.chunk }})

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Arduino core for ESP8266 WiFi chip
33

44
# Quick links
55

6-
- [Latest release documentation](https://arduino-esp8266.readthedocs.io/en/3.0.2/)
6+
- [Latest release documentation](https://arduino-esp8266.readthedocs.io/en/3.1.1/)
77
- [Current "git version" documentation](https://arduino-esp8266.readthedocs.io/en/latest/)
88
- [Install git version](https://arduino-esp8266.readthedocs.io/en/latest/installing.html#using-git-version) ([sources](doc/installing.rst#using-git-version))
99

@@ -36,7 +36,7 @@ Starting with 1.6.4, Arduino allows installation of third-party platform package
3636
#### Latest release [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/)
3737
Boards manager link: `https://arduino.esp8266.com/stable/package_esp8266com_index.json`
3838

39-
Documentation: [https://arduino-esp8266.readthedocs.io/en/3.0.2/](https://arduino-esp8266.readthedocs.io/en/3.0.2/)
39+
Documentation: [https://arduino-esp8266.readthedocs.io/en/3.1.1/](https://arduino-esp8266.readthedocs.io/en/3.1.1/)
4040

4141
### Using git version
4242

boards.txt

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ menu.vt=VTables
2222
menu.exception=C++ Exceptions
2323
menu.stacksmash=Stack Protection
2424
menu.wipe=Erase Flash
25-
menu.sdk=Espressif FW
25+
menu.sdk=NONOS SDK Version
2626
menu.ssl=SSL Support
2727
menu.mmu=MMU
2828
menu.non32xfer=Non-32-Bit Access
@@ -363,19 +363,7 @@ generic.menu.sdk.nonosdk_190313=nonos-sdk 2.2.1+61 (190313)
363363
generic.menu.sdk.nonosdk_190313.build.sdk=NONOSDK22x_190313
364364
generic.menu.sdk.nonosdk221=nonos-sdk 2.2.1 (legacy)
365365
generic.menu.sdk.nonosdk221.build.sdk=NONOSDK221
366-
generic.menu.sdk.nonosdk3v0=nonos-sdk pre-3 (180626 known issues)
367-
generic.menu.sdk.nonosdk3v0.build.sdk=NONOSDK3V0
368-
generic.menu.sdk.nonosdk300=nonos-sdk 3.0.0
369-
generic.menu.sdk.nonosdk300.build.sdk=NONOSDK300
370-
generic.menu.sdk.nonosdk301=nonos-sdk 3.0.1
371-
generic.menu.sdk.nonosdk301.build.sdk=NONOSDK301
372-
generic.menu.sdk.nonosdk302=nonos-sdk 3.0.2
373-
generic.menu.sdk.nonosdk302.build.sdk=NONOSDK302
374-
generic.menu.sdk.nonosdk303=nonos-sdk 3.0.3
375-
generic.menu.sdk.nonosdk303.build.sdk=NONOSDK303
376-
generic.menu.sdk.nonosdk304=nonos-sdk 3.0.4
377-
generic.menu.sdk.nonosdk304.build.sdk=NONOSDK304
378-
generic.menu.sdk.nonosdk305=nonos-sdk 3.0.5
366+
generic.menu.sdk.nonosdk305=nonos-sdk 3.0.5 (experimental)
379367
generic.menu.sdk.nonosdk305.build.sdk=NONOSDK305
380368
generic.menu.ip.lm2f=v2 Lower Memory
381369
generic.menu.ip.lm2f.build.lwip_include=lwip2/include
@@ -720,19 +708,7 @@ esp8285.menu.sdk.nonosdk_190313=nonos-sdk 2.2.1+61 (190313)
720708
esp8285.menu.sdk.nonosdk_190313.build.sdk=NONOSDK22x_190313
721709
esp8285.menu.sdk.nonosdk221=nonos-sdk 2.2.1 (legacy)
722710
esp8285.menu.sdk.nonosdk221.build.sdk=NONOSDK221
723-
esp8285.menu.sdk.nonosdk3v0=nonos-sdk pre-3 (180626 known issues)
724-
esp8285.menu.sdk.nonosdk3v0.build.sdk=NONOSDK3V0
725-
esp8285.menu.sdk.nonosdk300=nonos-sdk 3.0.0
726-
esp8285.menu.sdk.nonosdk300.build.sdk=NONOSDK300
727-
esp8285.menu.sdk.nonosdk301=nonos-sdk 3.0.1
728-
esp8285.menu.sdk.nonosdk301.build.sdk=NONOSDK301
729-
esp8285.menu.sdk.nonosdk302=nonos-sdk 3.0.2
730-
esp8285.menu.sdk.nonosdk302.build.sdk=NONOSDK302
731-
esp8285.menu.sdk.nonosdk303=nonos-sdk 3.0.3
732-
esp8285.menu.sdk.nonosdk303.build.sdk=NONOSDK303
733-
esp8285.menu.sdk.nonosdk304=nonos-sdk 3.0.4
734-
esp8285.menu.sdk.nonosdk304.build.sdk=NONOSDK304
735-
esp8285.menu.sdk.nonosdk305=nonos-sdk 3.0.5
711+
esp8285.menu.sdk.nonosdk305=nonos-sdk 3.0.5 (experimental)
736712
esp8285.menu.sdk.nonosdk305.build.sdk=NONOSDK305
737713
esp8285.menu.ip.lm2f=v2 Lower Memory
738714
esp8285.menu.ip.lm2f.build.lwip_include=lwip2/include

cores/esp8266/Esp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ bool EspClass::checkFlashCRC() {
471471
uint32_t firstPart = (uintptr_t)&__crc_len - 0x40200000; // How many bytes to check before the 1st CRC val
472472

473473
// Start the checksum
474-
uint32_t crc = crc32((const void*)0x40200000, firstPart, 0xffffffff);
474+
uint32_t crc = crc32((const void*)0x40200000, firstPart);
475475
// Pretend the 2 words of crc/len are zero to be idempotent
476476
crc = crc32(z, 8, crc);
477477
// Finish the CRC calculation over the rest of flash

cores/esp8266/IPAddress.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ IPAddress::IPAddress(const IPAddress& from)
2727
ip_addr_copy(_ip, from._ip);
2828
}
2929

30+
IPAddress::IPAddress(IPAddress&& from)
31+
{
32+
ip_addr_copy(_ip, from._ip);
33+
}
34+
3035
IPAddress::IPAddress() {
3136
_ip = *IP_ANY_TYPE; // lwIP's v4-or-v6 generic address
3237
}
@@ -36,24 +41,14 @@ bool IPAddress::isSet () const {
3641
}
3742

3843
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) {
39-
setV4();
40-
(*this)[0] = first_octet;
41-
(*this)[1] = second_octet;
42-
(*this)[2] = third_octet;
43-
(*this)[3] = fourth_octet;
44-
}
44+
uint8_t addr[] {
45+
first_octet,
46+
second_octet,
47+
third_octet,
48+
fourth_octet,
49+
};
4550

46-
void IPAddress::ctor32(uint32_t address) {
47-
setV4();
48-
v4() = address;
49-
}
50-
51-
IPAddress::IPAddress(const uint8_t *address) {
52-
setV4();
53-
(*this)[0] = address[0];
54-
(*this)[1] = address[1];
55-
(*this)[2] = address[2];
56-
(*this)[3] = address[3];
51+
*this = &addr[0];
5752
}
5853

5954
bool IPAddress::fromString(const char *address) {
@@ -111,8 +106,10 @@ bool IPAddress::fromString4(const char *address) {
111106
}
112107

113108
IPAddress& IPAddress::operator=(const uint8_t *address) {
114-
setV4();
115-
v4() = *reinterpret_cast<const uint32_t*>(address);
109+
uint32_t value;
110+
memcpy_P(&value, address, sizeof(value));
111+
112+
*this = value;
116113
return *this;
117114
}
118115

@@ -123,7 +120,14 @@ IPAddress& IPAddress::operator=(uint32_t address) {
123120
}
124121

125122
bool IPAddress::operator==(const uint8_t* addr) const {
126-
return isV4() && v4() == *reinterpret_cast<const uint32_t*>(addr);
123+
if (!isV4()) {
124+
return false;
125+
}
126+
127+
uint32_t value;
128+
memcpy_P(&value, addr, sizeof(value));
129+
130+
return v4() == value;
127131
}
128132

129133
size_t IPAddress::printTo(Print& p) const {

cores/esp8266/IPAddress.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,16 @@ class IPAddress: public Printable {
6161
return reinterpret_cast<const uint8_t*>(&v4());
6262
}
6363

64-
void ctor32 (uint32_t);
65-
6664
public:
67-
// Constructors
6865
IPAddress();
69-
IPAddress(const IPAddress& from);
66+
IPAddress(const IPAddress&);
67+
IPAddress(IPAddress&&);
68+
7069
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
71-
IPAddress(uint32_t address) { ctor32(address); }
72-
IPAddress(unsigned long address) { ctor32(address); }
73-
IPAddress(int address) { ctor32(address); }
74-
IPAddress(const uint8_t *address);
70+
IPAddress(uint32_t address) { *this = address; }
71+
IPAddress(unsigned long address) { *this = address; }
72+
IPAddress(int address) { *this = address; }
73+
IPAddress(const uint8_t *address) { *this = address; }
7574

7675
bool fromString(const char *address);
7776
bool fromString(const String &address) { return fromString(address.c_str()); }
@@ -86,7 +85,7 @@ class IPAddress: public Printable {
8685
operator bool () { return isSet(); } // <- both are needed
8786

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

9291
bool operator==(const IPAddress& addr) const {
@@ -115,11 +114,18 @@ class IPAddress: public Printable {
115114

116115
// Overloaded index operator to allow getting and setting individual octets of the address
117116
uint8_t operator[](int index) const {
118-
return isV4()? *(raw_address() + index): 0;
117+
if (!isV4()) {
118+
return 0;
119+
}
120+
121+
return ip4_addr_get_byte_val(*ip_2_ip4(&_ip), index);
119122
}
123+
120124
uint8_t& operator[](int index) {
121125
setV4();
122-
return *(raw_address() + index);
126+
127+
uint8_t* ptr = reinterpret_cast<uint8_t*>(&v4());
128+
return *(ptr + index);
123129
}
124130

125131
// Overloaded copy operators to allow initialisation of IPAddress objects from other types

cores/esp8266/LwipIntfDev.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
#define DEFAULT_MTU 1500
4747
#endif
4848

49+
enum EthernetLinkStatus
50+
{
51+
Unknown,
52+
LinkON,
53+
LinkOFF
54+
};
55+
4956
template<class RawDev>
5057
class LwipIntfDev: public LwipIntf, public RawDev
5158
{
@@ -93,9 +100,11 @@ class LwipIntfDev: public LwipIntf, public RawDev
93100
void setDefault(bool deflt = true);
94101

95102
// true if interface has a valid IPv4 address
103+
// (and ethernet link status is not detectable or is up)
96104
bool connected()
97105
{
98-
return !!ip4_addr_get_u32(ip_2_ip4(&_netif.ip_addr));
106+
return !!ip4_addr_get_u32(ip_2_ip4(&_netif.ip_addr))
107+
&& (!RawDev::isLinkDetectable() || RawDev::isLinked());
99108
}
100109

101110
bool routable()
@@ -106,6 +115,9 @@ class LwipIntfDev: public LwipIntf, public RawDev
106115
// ESP8266WiFi API compatibility
107116
wl_status_t status();
108117

118+
// Arduino Ethernet compatibility
119+
EthernetLinkStatus linkStatus();
120+
109121
protected:
110122
err_t netif_init();
111123
void check_route();
@@ -282,6 +294,12 @@ wl_status_t LwipIntfDev<RawDev>::status()
282294
return _started ? (connected() ? WL_CONNECTED : WL_DISCONNECTED) : WL_NO_SHIELD;
283295
}
284296

297+
template<class RawDev>
298+
EthernetLinkStatus LwipIntfDev<RawDev>::linkStatus()
299+
{
300+
return RawDev::isLinkDetectable() ? _started && RawDev::isLinked() ? LinkON : LinkOFF : Unknown;
301+
}
302+
285303
template<class RawDev>
286304
err_t LwipIntfDev<RawDev>::linkoutput_s(netif* netif, struct pbuf* pbuf)
287305
{

cores/esp8266/Schedule.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include <assert.h>
20+
#include <numeric>
2021

2122
#include "Schedule.h"
2223
#include "PolledTimeout.h"
@@ -34,6 +35,7 @@ static scheduled_fn_t* sFirst = nullptr;
3435
static scheduled_fn_t* sLast = nullptr;
3536
static scheduled_fn_t* sUnused = nullptr;
3637
static int sCount = 0;
38+
static uint32_t recurrent_max_grain_mS = 0;
3739

3840
typedef std::function<bool(void)> mRecFuncT;
3941
struct recurrent_fn_t
@@ -130,9 +132,39 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
130132
}
131133
rLast = item;
132134

135+
// grain needs to be recomputed
136+
recurrent_max_grain_mS = 0;
137+
133138
return true;
134139
}
135140

141+
uint32_t compute_scheduled_recurrent_grain ()
142+
{
143+
if (recurrent_max_grain_mS == 0)
144+
{
145+
if (rFirst)
146+
{
147+
uint32_t recurrent_max_grain_uS = rFirst->callNow.getTimeout();
148+
for (auto it = rFirst->mNext; it; it = it->mNext)
149+
recurrent_max_grain_uS = std::gcd(recurrent_max_grain_uS, it->callNow.getTimeout());
150+
if (recurrent_max_grain_uS)
151+
// round to the upper millis
152+
recurrent_max_grain_mS = recurrent_max_grain_uS <= 1000? 1: (recurrent_max_grain_uS + 999) / 1000;
153+
}
154+
155+
#ifdef DEBUG_ESP_CORE
156+
static uint32_t last_grain = 0;
157+
if (recurrent_max_grain_mS != last_grain)
158+
{
159+
::printf(":rsf %u->%u\n", last_grain, recurrent_max_grain_mS);
160+
last_grain = recurrent_max_grain_mS;
161+
}
162+
#endif
163+
}
164+
165+
return recurrent_max_grain_mS;
166+
}
167+
136168
void run_scheduled_functions()
137169
{
138170
// prevent scheduling of new functions during this run
@@ -226,6 +258,9 @@ void run_scheduled_recurrent_functions()
226258
}
227259

228260
delete(to_ditch);
261+
262+
// grain needs to be recomputed
263+
recurrent_max_grain_mS = 0;
229264
}
230265
else
231266
{

cores/esp8266/Schedule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
// scheduled function happen more often: every yield() (vs every loop()),
4040
// and time resolution is microsecond (vs millisecond). Details are below.
4141

42+
// compute_scheduled_recurrent_grain() is used by delay() to give a chance to
43+
// all recurrent functions to run per their timing requirement.
44+
45+
uint32_t compute_scheduled_recurrent_grain ();
46+
4247
// scheduled functions called once:
4348
//
4449
// * internal queue is FIFO.

cores/esp8266/Stream.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ int Stream::timedPeek() {
5858

5959
// returns peek of the next digit in the stream or -1 if timeout
6060
// discards non-numeric characters
61-
int Stream::peekNextDigit() {
61+
int Stream::peekNextDigit(bool detectDecimal) {
6262
int c;
6363
while(1) {
6464
c = timedPeek();
65-
if(c < 0)
66-
return c; // timeout
67-
if(c == '-')
68-
return c;
69-
if(c >= '0' && c <= '9')
65+
if( c < 0 || // timeout
66+
c == '-' ||
67+
( c >= '0' && c <= '9' ) ||
68+
( detectDecimal && c == '.' ) ) {
7069
return c;
70+
}
7171
read(); // discard non-numeric
7272
}
7373
}
@@ -141,7 +141,7 @@ long Stream::parseInt(char skipChar) {
141141
long value = 0;
142142
int c;
143143

144-
c = peekNextDigit();
144+
c = peekNextDigit(false);
145145
// ignore non numeric leading characters
146146
if(c < 0)
147147
return 0; // zero returned if timeout
@@ -176,7 +176,7 @@ float Stream::parseFloat(char skipChar) {
176176
int c;
177177
float fraction = 1.0f;
178178

179-
c = peekNextDigit();
179+
c = peekNextDigit(true);
180180
// ignore non numeric leading characters
181181
if(c < 0)
182182
return 0; // zero returned if timeout

0 commit comments

Comments
 (0)