Skip to content

Commit 46c81fa

Browse files
authored
Merge pull request #6 from esp8266/master
Update 20.08
2 parents 326b17d + 1ff927d commit 46c81fa

Some content is hidden

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

42 files changed

+324
-150
lines changed

cores/esp8266/Arduino.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,6 @@ void analogWriteFreq(uint32_t freq);
177177
void analogWriteResolution(int res);
178178
void analogWriteRange(uint32_t range);
179179

180-
unsigned long millis(void);
181-
unsigned long micros(void);
182-
uint64_t micros64(void);
183-
void delay(unsigned long);
184-
void delayMicroseconds(unsigned int us);
185180
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
186181
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
187182

cores/esp8266/Crypto.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void *createBearsslHmac(const br_hash_class *hashType, const void *data, const s
100100

101101
String createBearsslHmac(const br_hash_class *hashType, const uint8_t hashTypeNaturalLength, const String &message, const void *hashKey, const size_t hashKeyLength, const size_t hmacLength)
102102
{
103+
(void) hashTypeNaturalLength;
103104
assert(1 <= hmacLength && hmacLength <= hashTypeNaturalLength);
104105

105106
uint8_t hmac[hmacLength];
@@ -152,6 +153,7 @@ void *createBearsslHmacCT(const br_hash_class *hashType, const void *data, const
152153

153154
String createBearsslHmacCT(const br_hash_class *hashType, const uint8_t hashTypeNaturalLength, const String &message, const void *hashKey, const size_t hashKeyLength, const size_t hmacLength)
154155
{
156+
(void) hashTypeNaturalLength;
155157
assert(1 <= hmacLength && hmacLength <= hashTypeNaturalLength);
156158

157159
uint8_t hmac[hmacLength];

cores/esp8266/Esp.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,15 +697,16 @@ static SpiFlashOpResult spi_flash_write_puya(uint32_t offset, uint32_t *data, si
697697
} else {
698698
bytesLeft = 0;
699699
}
700-
rc = spi_flash_read(pos, flash_write_puya_buf, bytesNow);
700+
size_t bytesAligned = (bytesNow + 3) & ~3;
701+
rc = spi_flash_read(pos, flash_write_puya_buf, bytesAligned);
701702
if (rc != SPI_FLASH_RESULT_OK) {
702703
return rc;
703704
}
704-
for (size_t i = 0; i < bytesNow / 4; ++i) {
705+
for (size_t i = 0; i < bytesAligned / 4; ++i) {
705706
flash_write_puya_buf[i] &= *ptr;
706707
++ptr;
707708
}
708-
rc = spi_flash_write(pos, flash_write_puya_buf, bytesNow);
709+
rc = spi_flash_write(pos, flash_write_puya_buf, bytesAligned);
709710
pos += bytesNow;
710711
}
711712
return rc;

cores/esp8266/Esp.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,13 @@ class EspClass {
124124
#if defined(F_CPU) || defined(CORE_MOCK)
125125
constexpr uint8_t getCpuFreqMHz() const
126126
{
127-
return clockCyclesPerMicrosecond();
127+
return esp_get_cpu_freq_mhz();
128128
}
129129
#else
130-
uint8_t getCpuFreqMHz();
130+
uint8_t getCpuFreqMHz() const
131+
{
132+
return esp_get_cpu_freq_mhz();
133+
}
131134
#endif
132135

133136
uint32_t getFlashChipId();

cores/esp8266/HardwareSerial.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
#include "HardwareSerial.h"
3333
#include "Esp.h"
3434

35+
36+
// SerialEvent functions are weak, so when the user doesn't define them,
37+
// the linker just sets their address to 0 (which is checked below).
38+
// The Serialx_available is just a wrapper around Serialx.available(),
39+
// but we can refer to it weakly so we don't pull in the entire
40+
// HardwareSerial instance if the user doesn't also refer to it.
41+
void serialEvent() __attribute__((weak));
42+
3543
HardwareSerial::HardwareSerial(int uart_nr)
3644
: _uart_nr(uart_nr), _rx_size(256)
3745
{}
@@ -162,6 +170,14 @@ size_t HardwareSerial::readBytes(char* buffer, size_t size)
162170

163171
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
164172
HardwareSerial Serial(UART0);
173+
174+
// Executed at end of loop() processing when > 0 bytes available in the Serial port
175+
void serialEventRun(void)
176+
{
177+
if (serialEvent && Serial.available()) {
178+
serialEvent();
179+
}
180+
}
165181
#endif
166182
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1)
167183
HardwareSerial Serial1(UART1);

cores/esp8266/HardwareSerial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,6 @@ class HardwareSerial: public Stream
207207
extern HardwareSerial Serial;
208208
extern HardwareSerial Serial1;
209209

210+
extern void serialEventRun(void) __attribute__((weak));
211+
210212
#endif

cores/esp8266/PolledTimeout.h

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
PolledTimeout.h - Encapsulation of a polled Timeout
7-
7+
88
Copyright (c) 2018 Daniel Salazar. All rights reserved.
99
This file is part of the esp8266 core for Arduino environment.
1010
@@ -23,9 +23,10 @@
2323
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2424
*/
2525

26-
#include <limits>
27-
28-
#include <Arduino.h>
26+
#include <c_types.h> // IRAM_ATTR
27+
#include <limits> // std::numeric_limits
28+
#include <type_traits> // std::is_unsigned
29+
#include <core_esp8266_features.h>
2930

3031
namespace esp8266
3132
{
@@ -70,13 +71,13 @@ struct TimeSourceMillis
7071

7172
struct TimeSourceCycles
7273
{
73-
// time policy based on ESP.getCycleCount()
74+
// time policy based on esp_get_cycle_count()
7475
// this particular time measurement is intended to be called very often
7576
// (every loop, every yield)
7677

77-
using timeType = decltype(ESP.getCycleCount());
78-
static timeType time() {return ESP.getCycleCount();}
79-
static constexpr timeType ticksPerSecond = ESP.getCpuFreqMHz() * 1000000UL; // 80'000'000 or 160'000'000 Hz
78+
using timeType = decltype(esp_get_cycle_count());
79+
static timeType time() {return esp_get_cycle_count();}
80+
static constexpr timeType ticksPerSecond = esp_get_cpu_freq_mhz() * 1000000UL; // 80'000'000 or 160'000'000 Hz
8081
static constexpr timeType ticksPerSecondMax = 160000000; // 160MHz
8182
};
8283

@@ -161,13 +162,13 @@ class timeoutTemplate
161162
return expiredRetrigger();
162163
return expiredOneShot();
163164
}
164-
165+
165166
IRAM_ATTR // fast
166167
operator bool()
167168
{
168-
return expired();
169+
return expired();
169170
}
170-
171+
171172
bool canExpire () const
172173
{
173174
return !_neverExpires;
@@ -178,6 +179,7 @@ class timeoutTemplate
178179
return _timeout != alwaysExpired;
179180
}
180181

182+
// Resets, will trigger after this new timeout.
181183
IRAM_ATTR // called from ISR
182184
void reset(const timeType newUserTimeout)
183185
{
@@ -186,12 +188,30 @@ class timeoutTemplate
186188
_neverExpires = (newUserTimeout < 0) || (newUserTimeout > timeMax());
187189
}
188190

191+
// Resets, will trigger after the timeout previously set.
189192
IRAM_ATTR // called from ISR
190193
void reset()
191194
{
192195
_start = TimePolicyT::time();
193196
}
194197

198+
// Resets to just expired so that on next poll the check will immediately trigger for the user,
199+
// also change timeout (after next immediate trigger).
200+
IRAM_ATTR // called from ISR
201+
void resetAndSetExpired (const timeType newUserTimeout)
202+
{
203+
reset(newUserTimeout);
204+
_start -= _timeout;
205+
}
206+
207+
// Resets to just expired so that on next poll the check will immediately trigger for the user.
208+
IRAM_ATTR // called from ISR
209+
void resetAndSetExpired ()
210+
{
211+
reset();
212+
_start -= _timeout;
213+
}
214+
195215
void resetToNeverExpires ()
196216
{
197217
_timeout = alwaysExpired + 1; // because canWait() has precedence
@@ -202,7 +222,7 @@ class timeoutTemplate
202222
{
203223
return TimePolicyT::toUserUnit(_timeout);
204224
}
205-
225+
206226
static constexpr timeType timeMax()
207227
{
208228
return TimePolicyT::timeMax;
@@ -235,14 +255,14 @@ class timeoutTemplate
235255
}
236256
return false;
237257
}
238-
258+
239259
IRAM_ATTR // fast
240260
bool expiredOneShot() const
241261
{
242262
// returns "always expired" or "has expired"
243263
return !canWait() || checkExpired(TimePolicyT::time());
244264
}
245-
265+
246266
timeType _timeout;
247267
timeType _start;
248268
bool _neverExpires;
@@ -259,14 +279,14 @@ using periodic = polledTimeout::timeoutTemplate<true> /*__attribute__((deprecate
259279
using oneShotMs = polledTimeout::timeoutTemplate<false>;
260280
using periodicMs = polledTimeout::timeoutTemplate<true>;
261281

262-
// Time policy based on ESP.getCycleCount(), and intended to be called very often:
282+
// Time policy based on esp_get_cycle_count(), and intended to be called very often:
263283
// "Fast" versions sacrifices time range for improved precision and reduced execution time (by 86%)
264-
// (cpu cycles for ::expired(): 372 (millis()) vs 52 (ESP.getCycleCount()))
284+
// (cpu cycles for ::expired(): 372 (millis()) vs 52 (esp_get_cycle_count()))
265285
// timeMax() values:
266286
// Ms: max is 26843 ms (26.8 s)
267287
// Us: max is 26843545 us (26.8 s)
268288
// Ns: max is 1073741823 ns ( 1.07 s)
269-
// (time policy based on ESP.getCycleCount() is intended to be called very often)
289+
// (time policy based on esp_get_cycle_count() is intended to be called very often)
270290

271291
using oneShotFastMs = polledTimeout::timeoutTemplate<false, YieldPolicy::DoNothing, TimePolicy::TimeFastMillis>;
272292
using periodicFastMs = polledTimeout::timeoutTemplate<true, YieldPolicy::DoNothing, TimePolicy::TimeFastMillis>;

cores/esp8266/Updater.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
113113

114114
_reset();
115115
clearError(); // _error = 0
116+
_target_md5 = emptyString;
117+
_md5 = MD5Builder();
116118

117119
#ifndef HOST_MOCK
118120
wifi_set_sleep_type(NONE_SLEEP_T);

cores/esp8266/base64.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef CORE_BASE64_H_
2626
#define CORE_BASE64_H_
2727

28+
#include <WString.h>
29+
2830
class base64
2931
{
3032
public:

cores/esp8266/core_esp8266_features.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ extern "C" {
123123
#endif
124124

125125
void precache(void *f, uint32_t bytes);
126+
unsigned long millis(void);
127+
unsigned long micros(void);
128+
uint64_t micros64(void);
129+
void delay(unsigned long);
130+
void delayMicroseconds(unsigned int us);
131+
132+
#if defined(F_CPU) || defined(CORE_MOCK)
133+
#ifdef __cplusplus
134+
constexpr
135+
#else
136+
inline
137+
#endif
138+
int esp_get_cpu_freq_mhz()
139+
{
140+
return F_CPU / 1000000L;
141+
}
142+
#else
143+
inline int esp_get_cpu_freq_mhz()
144+
{
145+
return system_get_cpu_freq();
146+
}
147+
#endif
148+
126149

127150
#ifdef __cplusplus
128151
}

0 commit comments

Comments
 (0)