mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
polledTimeout: add option to use CPU count instead of millis() (#5870)
* polledTimeout: add option to use CPU count instead of millis() * use more "using" alias * more c++/clear code, using typename (thanks @devyte) * rename class name to include unit, introduce timeMax() and check it with assert() * remove useless defines * improve api readability, add micro-second unit * update example * mock: emulate getCycleCount, add/fix polledTimeout CI test * + nano-seconds, assert -> message, comments, host test * allow 0 for timeout (enables immediate timeout, fix division by 0) * typo, set member instead of local variable * unify error message * slight change on checkExpired() allows "never expired" also removed printed message, add YieldAndDelay, simplify calculations * remove traces of debug.h/cpp in this PR * include missing <limits> header * back to original expired test, introduce boolean _neverExpires, fix reset(), getTimeout() is invalid * fix expiredOneShot with _timeout==0 check * reenable getTimeout() * expose checkExpired with unit conversion * fix timing comments, move critical code to iram * add member ::neverExpires and use it where relevant * improve clarity * remove exposed checkExpired(), adapt LEAmDNS with equivalent * add API ::resetToNeverExpires(), use it in LEAmDNS * remove offending constness from ::flagged() LEAmDNS (due do API fix in PolledTimeout) * simplify "Fast" base classes * minor variable rename * Fix examples * compliance with good c++ manners * minor changes for consistency * add missing const * expired() and bool() moved to iram * constexpr compensation computing * add/update comments * move neverExpires and alwaysExpired
This commit is contained in:
@ -32,6 +32,8 @@
|
||||
#include <Esp.h>
|
||||
#include <eboot_command.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
unsigned long long operator"" _kHz(unsigned long long x) {
|
||||
@ -215,3 +217,9 @@ void EspClass::resetFreeContStack()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t EspClass::getCycleCount()
|
||||
{
|
||||
timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return (((uint64_t)t.tv_sec) * 1000000 + t.tv_usec) * (F_CPU / 1000000);
|
||||
}
|
||||
|
@ -29,6 +29,8 @@
|
||||
DEALINGS WITH THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define CORE_MOCK 1
|
||||
|
||||
// include host's STL before any other include file
|
||||
// because core definition like max() is in the way
|
||||
|
||||
@ -138,8 +140,6 @@ void mock_stop_spiffs ();
|
||||
|
||||
//
|
||||
|
||||
#define CORE_MOCK 1
|
||||
|
||||
#define ARDUINO 267
|
||||
#define ESP8266 1
|
||||
#define A0 0
|
||||
|
Reference in New Issue
Block a user