Skip to content

Commit d65d19f

Browse files
authored
Merge branch 'master' into bug-esp8266#3795
2 parents 7ea919e + d1e8fe9 commit d65d19f

File tree

7 files changed

+41
-28
lines changed

7 files changed

+41
-28
lines changed

cores/esp8266/Arduino.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ void analogWriteRange(uint32_t range);
202202

203203
unsigned long millis(void);
204204
unsigned long micros(void);
205+
uint64_t micros64(void);
205206
void delay(unsigned long);
206207
void delayMicroseconds(unsigned int us);
207208
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
@@ -236,7 +237,7 @@ void optimistic_yield(uint32_t interval_us);
236237
#endif
237238

238239
#ifdef __cplusplus
239-
240+
#include <algorithm>
240241
#include "pgmspace.h"
241242

242243
#include "WCharacter.h"
@@ -247,11 +248,10 @@ void optimistic_yield(uint32_t interval_us);
247248
#include "Updater.h"
248249
#include "debug.h"
249250

250-
#ifndef _GLIBCXX_VECTOR
251-
// arduino is not compatible with std::vector
252-
#define min(a,b) ((a)<(b)?(a):(b))
253-
#define max(a,b) ((a)>(b)?(a):(b))
254-
#endif
251+
using std::min;
252+
using std::max;
253+
using std::isinf;
254+
using std::isnan;
255255

256256
#define _min(a,b) ((a)<(b)?(a):(b))
257257
#define _max(a,b) ((a)>(b)?(a):(b))

cores/esp8266/core_esp8266_wiring.c

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ unsigned long ICACHE_RAM_ATTR micros() {
7171
return system_get_time();
7272
}
7373

74+
uint64_t ICACHE_RAM_ATTR micros64() {
75+
uint32_t low32_us = system_get_time();
76+
uint32_t high32_us = micros_overflow_count + ((low32_us < micros_at_last_overflow_tick) ? 1 : 0);
77+
uint64_t duration64_us = (uint64_t)high32_us << 32 | low32_us;
78+
return duration64_us;
79+
}
80+
7481
void ICACHE_RAM_ATTR delayMicroseconds(unsigned int us) {
7582
os_delay_us(us);
7683
}

cores/esp8266/time.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,27 @@ struct timeval {
3131

3232
extern char* sntp_asctime(const struct tm *t);
3333
extern struct tm* sntp_localtime(const time_t *clock);
34+
extern uint64_t micros64();
3435

3536
// time gap in seconds from 01.01.1900 (NTP time) to 01.01.1970 (UNIX time)
3637
#define DIFF1900TO1970 2208988800UL
3738

3839
static int s_daylightOffset_sec = 0;
3940
static long s_timezone_sec = 0;
40-
static time_t s_bootTime = 0;
41+
static bool s_bootTimeSet = false;
42+
static uint64_t s_bootTime_us = 0;
4143

4244
// calculate offset used in gettimeofday
4345
static void ensureBootTimeIsSet()
4446
{
45-
if (!s_bootTime)
47+
// Check just a bool flag instead of the full 64-bit s_bootTime for zero.
48+
if (!s_bootTimeSet)
4649
{
47-
time_t now = sntp_get_current_timestamp();
48-
if (now)
50+
time_t now_s = sntp_get_current_timestamp();
51+
if (now_s)
4952
{
50-
s_bootTime = now - millis() / 1000;
53+
s_bootTime_us = now_s * 1000000ULL - micros64();
54+
s_bootTimeSet = true;
5155
}
5256
}
5357
}
@@ -100,8 +104,9 @@ int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
100104
if (tp)
101105
{
102106
ensureBootTimeIsSet();
103-
tp->tv_sec = s_bootTime + millis() / 1000;
104-
tp->tv_usec = micros();
107+
uint64_t currentTime_us = s_bootTime_us + micros64();
108+
tp->tv_sec = currentTime_us / 1000000ULL;
109+
tp->tv_usec = currentTime_us % 1000000ULL;
105110
}
106111
return 0;
107112
}

libraries/ESP8266LLMNR/ESP8266LLMNR.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern "C" {
5050

5151
//#define LLMNR_DEBUG
5252

53-
#define BIT(x) (1 << (x))
53+
//BIT(x) is defined in tools/sdk/c_types.h
5454

5555
#define FLAGS_QR BIT(15)
5656
#define FLAGS_OP_SHIFT 11
@@ -226,14 +226,15 @@ void LLMNRResponder::_process_packet() {
226226
Serial.println("(no matching RRs)");
227227
#endif
228228

229-
struct ip_info remote_ip_info;
230-
remote_ip_info.ip.addr = _conn->getRemoteAddress();
229+
ip_addr_t remote_ip;
230+
remote_ip.addr = _conn->getRemoteAddress();
231+
231232
struct ip_info ip_info;
232233
bool match_ap = false;
233234
if (wifi_get_opmode() & SOFTAP_MODE) {
234235
wifi_get_ip_info(SOFTAP_IF, &ip_info);
235-
if (ip_info.ip.addr && ip_addr_netcmp(&remote_ip_info.ip, &ip_info.ip, &ip_info.netmask))
236-
match_ap = true;
236+
if (ip_info.ip.addr && ip_addr_netcmp(&remote_ip, &ip_info.ip, &ip_info.netmask))
237+
match_ap = true;
237238
}
238239
if (!match_ap)
239240
wifi_get_ip_info(STATION_IF, &ip_info);
@@ -272,8 +273,8 @@ void LLMNRResponder::_process_packet() {
272273
};
273274
_conn->append(reinterpret_cast<const char*>(rr), sizeof(rr));
274275
}
275-
_conn->setMulticastInterface(remote_ip_info.ip);
276-
_conn->send(&remote_ip_info.ip, _conn->getRemotePort());
276+
_conn->setMulticastInterface(remote_ip);
277+
_conn->send(&remote_ip, _conn->getRemotePort());
277278
}
278279

279280
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_LLMNR)

libraries/ESP8266SSDP/ESP8266SSDP.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ bool SSDPClass::begin(){
201201

202202
void SSDPClass::_send(ssdp_method_t method){
203203
char buffer[1460];
204-
uint32_t ip = WiFi.localIP();
204+
IPAddress ip = WiFi.localIP();
205205

206206
char valueBuffer[strlen_P(_ssdp_notify_template)+1];
207207
strcpy_P(valueBuffer, (method == NONE)?_ssdp_response_template:_ssdp_notify_template);
@@ -214,7 +214,7 @@ void SSDPClass::_send(ssdp_method_t method){
214214
_uuid,
215215
(method == NONE)?"ST":"NT",
216216
_deviceType,
217-
IP2STR(&ip), _port, _schemaURL
217+
ip[0], ip[1], ip[2], ip[3], _port, _schemaURL
218218
);
219219

220220
_server->append(buffer, len);
@@ -244,11 +244,11 @@ void SSDPClass::_send(ssdp_method_t method){
244244
}
245245

246246
void SSDPClass::schema(WiFiClient client){
247-
uint32_t ip = WiFi.localIP();
247+
IPAddress ip = WiFi.localIP();
248248
char buffer[strlen_P(_ssdp_schema_template)+1];
249249
strcpy_P(buffer, _ssdp_schema_template);
250250
client.printf(buffer,
251-
IP2STR(&ip), _port,
251+
ip[0], ip[1], ip[2], ip[3], _port,
252252
_deviceType,
253253
_friendlyName,
254254
_presentationURL,

libraries/Servo/src/Servo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Servo
7777
public:
7878
Servo();
7979
uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
80-
uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
80+
uint8_t attach(int pin, uint16_t min, uint16_t max); // as above but also sets min and max values for writes.
8181
void detach();
8282
void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
8383
void writeMicroseconds(int value); // Write pulse width in microseconds

libraries/Servo/src/esp8266/Servo.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ uint8_t Servo::attach(int pin)
221221
return attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
222222
}
223223

224-
uint8_t Servo::attach(int pin, int minUs, int maxUs)
224+
uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
225225
{
226226
ServoTimerSequence timerId;
227227

@@ -235,8 +235,8 @@ uint8_t Servo::attach(int pin, int minUs, int maxUs)
235235
// keep the min and max within 200-3000 us, these are extreme
236236
// ranges and should support extreme servos while maintaining
237237
// reasonable ranges
238-
_maxUs = max(250, min(3000, maxUs));
239-
_minUs = max(200, min(_maxUs, minUs));
238+
_maxUs = max((uint16_t)250, min((uint16_t)3000, maxUs));
239+
_minUs = max((uint16_t)200, min(_maxUs, minUs));
240240

241241
// initialize the timerId if it has not already been initialized
242242
timerId = SERVO_INDEX_TO_TIMER(_servoIndex);

0 commit comments

Comments
 (0)