diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 26383dd43e..aaaad20fb3 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -140,7 +140,7 @@ unsigned long HardwareSerial::testBaudrate() unsigned long HardwareSerial::detectBaudrate(time_t timeoutMillis) { - esp8266::polledTimeout::oneShotFastMs timeOut(timeoutMillis); + PolledTimeout::oneShotFastMs timeOut(timeoutMillis); unsigned long detectedBaudrate = 0; while (!timeOut) { if ((detectedBaudrate = testBaudrate())) { @@ -158,7 +158,7 @@ size_t HardwareSerial::readBytes(char* buffer, size_t size) while (got < size) { - esp8266::polledTimeout::oneShotFastMs timeOut(_timeout); + PolledTimeout::oneShotFastMs timeOut(_timeout); size_t avail; while ((avail = available()) == 0 && !timeOut); if (avail == 0) diff --git a/cores/esp8266/PolledTimeout.h b/cores/esp8266/PolledTimeout.h index 7eec547e48..334f553ae6 100644 --- a/cores/esp8266/PolledTimeout.h +++ b/cores/esp8266/PolledTimeout.h @@ -1,309 +1,85 @@ -#ifndef __POLLEDTIMING_H__ -#define __POLLEDTIMING_H__ +#ifndef __POLLEDTIMEOUT_H__ +#define __POLLEDTIMEOUT_H__ -/* - PolledTimeout.h - Encapsulation of a polled Timeout - Copyright (c) 2018 Daniel Salazar. All rights reserved. - This file is part of the esp8266 core for Arduino environment. +#include - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. +namespace TimePolicy +{ - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + using TimeMillis = TimeUnit< TimeSourcePolicy::TimeSourceMillis, 1000 >; + +} //TimePolicy - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include // IRAM_ATTR -#include // std::numeric_limits -#include // std::is_unsigned -#include -namespace esp8266 +namespace PolledTimeout { + //Construction of types using the policies + // legacy type names, deprecated (unit is milliseconds) + using oneShot = TimeoutTemplate; + using periodic = TimeoutTemplate; -namespace polledTimeout -{ + // standard versions (based on millis()) + // timeMax() is 49.7 days ((2^32)-2 ms) + using oneShotMs = TimeoutTemplate; + using periodicMs = TimeoutTemplate; + +} //PolledTimeout -namespace YieldPolicy -{ -struct DoNothing -{ - static void execute() {} -}; -struct YieldOrSkip -{ - static void execute() {delay(0);} -}; -template -struct YieldAndDelayMs -{ - static void execute() {delay(delayMs);} -}; -} //YieldPolicy +#include namespace TimePolicy { + + using TimeFastMillis = TimeUnit< TimeSourcePolicy::TimeSourceCycles, 1000 >; + using TimeFastMicros = TimeUnit< TimeSourcePolicy::TimeSourceCycles, 1000000 >; + using TimeFastNanos = TimeUnit< TimeSourcePolicy::TimeSourceCycles, 1000000000 >; -struct TimeSourceMillis -{ - // time policy in milli-seconds based on millis() +} //TimePolicy - using timeType = decltype(millis()); - static timeType time() {return millis();} - static constexpr timeType ticksPerSecond = 1000; - static constexpr timeType ticksPerSecondMax = 1000; -}; -struct TimeSourceCycles -{ - // time policy based on esp_get_cycle_count() - // this particular time measurement is intended to be called very often - // (every loop, every yield) - - using timeType = decltype(esp_get_cycle_count()); - static timeType time() {return esp_get_cycle_count();} - static constexpr timeType ticksPerSecond = esp_get_cpu_freq_mhz() * 1000000UL; // 80'000'000 or 160'000'000 Hz - static constexpr timeType ticksPerSecondMax = 160000000; // 160MHz -}; - -template - // "second_th" units of timeType for one second -struct TimeUnit + + +namespace PolledTimeout { - using timeType = typename TimeSourceType::timeType; - -#if __GNUC__ < 5 - // gcc-4.8 cannot compile the constexpr-only version of this function - // using #defines instead luckily works - static constexpr timeType computeRangeCompensation () - { - #define number_of_secondTh_in_one_tick ((1.0 * second_th) / ticksPerSecond) - #define fractional (number_of_secondTh_in_one_tick - (long)number_of_secondTh_in_one_tick) - - return ({ - fractional == 0? - 1: // no need for compensation - (number_of_secondTh_in_one_tick / fractional) + 0.5; // scalar multiplier allowing exact division - }); - - #undef number_of_secondTh_in_one_tick - #undef fractional - } -#else - static constexpr timeType computeRangeCompensation () - { - return ({ - constexpr double number_of_secondTh_in_one_tick = (1.0 * second_th) / ticksPerSecond; - constexpr double fractional = number_of_secondTh_in_one_tick - (long)number_of_secondTh_in_one_tick; - fractional == 0? - 1: // no need for compensation - (number_of_secondTh_in_one_tick / fractional) + 0.5; // scalar multiplier allowing exact division - }); - } -#endif + //Construction of types using the policies - static constexpr timeType ticksPerSecond = TimeSourceType::ticksPerSecond; - static constexpr timeType ticksPerSecondMax = TimeSourceType::ticksPerSecondMax; - static constexpr timeType rangeCompensate = computeRangeCompensation(); - static constexpr timeType user2UnitMultiplierMax = (ticksPerSecondMax * rangeCompensate) / second_th; - static constexpr timeType user2UnitMultiplier = (ticksPerSecond * rangeCompensate) / second_th; - static constexpr timeType user2UnitDivider = rangeCompensate; - // std::numeric_limits::max() is reserved - static constexpr timeType timeMax = (std::numeric_limits::max() - 1) / user2UnitMultiplierMax; - - static timeType toTimeTypeUnit (const timeType userUnit) {return (userUnit * user2UnitMultiplier) / user2UnitDivider;} - static timeType toUserUnit (const timeType internalUnit) {return (internalUnit * user2UnitDivider) / user2UnitMultiplier;} - static timeType time () {return TimeSourceType::time();} -}; - -using TimeMillis = TimeUnit< TimeSourceMillis, 1000 >; -using TimeFastMillis = TimeUnit< TimeSourceCycles, 1000 >; -using TimeFastMicros = TimeUnit< TimeSourceCycles, 1000000 >; -using TimeFastNanos = TimeUnit< TimeSourceCycles, 1000000000 >; -} //TimePolicy + // Time policy based on esp_get_cycle_count(), and intended to be called very often: + // "Fast" versions sacrifices time range for improved precision and reduced execution time (by 86%) + // (cpu cycles for ::expired(): 372 (millis()) vs 52 (esp_get_cycle_count())) + // timeMax() values: + // Ms: max is 26843 ms (26.8 s) + // Us: max is 26843545 us (26.8 s) + // Ns: max is 1073741823 ns ( 1.07 s) + // (time policy based on esp_get_cycle_count() is intended to be called very often) -template -class timeoutTemplate -{ -public: - using timeType = typename TimePolicyT::timeType; - static_assert(std::is_unsigned::value == true, "timeType must be unsigned"); - - static constexpr timeType alwaysExpired = 0; - static constexpr timeType neverExpires = std::numeric_limits::max(); - static constexpr timeType rangeCompensate = TimePolicyT::rangeCompensate; //debug - - timeoutTemplate(const timeType userTimeout) - { - reset(userTimeout); - } - - IRAM_ATTR // fast - bool expired() - { - YieldPolicyT::execute(); //in case of DoNothing: gets optimized away - if(PeriodicT) //in case of false: gets optimized away - return expiredRetrigger(); - return expiredOneShot(); - } - - IRAM_ATTR // fast - operator bool() - { - return expired(); - } - - bool canExpire () const - { - return !_neverExpires; - } - - bool canWait () const - { - return _timeout != alwaysExpired; - } - - // Resets, will trigger after this new timeout. - IRAM_ATTR // called from ISR - void reset(const timeType newUserTimeout) - { - reset(); - _timeout = TimePolicyT::toTimeTypeUnit(newUserTimeout); - _neverExpires = (newUserTimeout < 0) || (newUserTimeout > timeMax()); - } - - // Resets, will trigger after the timeout previously set. - IRAM_ATTR // called from ISR - void reset() - { - _start = TimePolicyT::time(); - } - - // Resets to just expired so that on next poll the check will immediately trigger for the user, - // also change timeout (after next immediate trigger). - IRAM_ATTR // called from ISR - void resetAndSetExpired (const timeType newUserTimeout) - { - reset(newUserTimeout); - _start -= _timeout; - } - - // Resets to just expired so that on next poll the check will immediately trigger for the user. - IRAM_ATTR // called from ISR - void resetAndSetExpired () - { - reset(); - _start -= _timeout; - } - - void resetToNeverExpires () - { - _timeout = alwaysExpired + 1; // because canWait() has precedence - _neverExpires = true; - } - - timeType getTimeout() const - { - return TimePolicyT::toUserUnit(_timeout); - } - - static constexpr timeType timeMax() - { - return TimePolicyT::timeMax; - } - -private: - - IRAM_ATTR // fast - bool checkExpired(const timeType internalUnit) const - { - // canWait() is not checked here - // returns "can expire" and "time expired" - return (!_neverExpires) && ((internalUnit - _start) >= _timeout); - } - -protected: - - IRAM_ATTR // fast - bool expiredRetrigger() - { - if (!canWait()) - return true; - - timeType current = TimePolicyT::time(); - if(checkExpired(current)) - { - unsigned long n = (current - _start) / _timeout; //how many _timeouts periods have elapsed, will usually be 1 (current - _start >= _timeout) - _start += n * _timeout; - return true; - } - return false; - } - - IRAM_ATTR // fast - bool expiredOneShot() const - { - // returns "always expired" or "has expired" - return !canWait() || checkExpired(TimePolicyT::time()); - } - - timeType _timeout; - timeType _start; - bool _neverExpires; -}; - -// legacy type names, deprecated (unit is milliseconds) - -using oneShot = polledTimeout::timeoutTemplate /*__attribute__((deprecated("use oneShotMs")))*/; -using periodic = polledTimeout::timeoutTemplate /*__attribute__((deprecated("use periodicMs")))*/; - -// standard versions (based on millis()) -// timeMax() is 49.7 days ((2^32)-2 ms) - -using oneShotMs = polledTimeout::timeoutTemplate; -using periodicMs = polledTimeout::timeoutTemplate; - -// Time policy based on esp_get_cycle_count(), and intended to be called very often: -// "Fast" versions sacrifices time range for improved precision and reduced execution time (by 86%) -// (cpu cycles for ::expired(): 372 (millis()) vs 52 (esp_get_cycle_count())) -// timeMax() values: -// Ms: max is 26843 ms (26.8 s) -// Us: max is 26843545 us (26.8 s) -// Ns: max is 1073741823 ns ( 1.07 s) -// (time policy based on esp_get_cycle_count() is intended to be called very often) - -using oneShotFastMs = polledTimeout::timeoutTemplate; -using periodicFastMs = polledTimeout::timeoutTemplate; -using oneShotFastUs = polledTimeout::timeoutTemplate; -using periodicFastUs = polledTimeout::timeoutTemplate; -using oneShotFastNs = polledTimeout::timeoutTemplate; -using periodicFastNs = polledTimeout::timeoutTemplate; + using oneShotFastMs = TimeoutTemplate; + using periodicFastMs = TimeoutTemplate; + + using oneShotFastUs = TimeoutTemplate; + using periodicFastUs = TimeoutTemplate; + + using oneShotFastNs = TimeoutTemplate; + using periodicFastNs = TimeoutTemplate; } //polledTimeout /* A 1-shot timeout that auto-yields when in CONT can be built as follows: - * using oneShotYieldMs = esp8266::polledTimeout::timeoutTemplate; + * using oneShotYieldMs = PolledTimeout::TimeoutTemplate; * * Other policies can be implemented by the user, e.g.: simple yield that panics in SYS, and the polledTimeout types built as needed as shown above, without modifying this file. */ -}//esp8266 + + #endif diff --git a/cores/esp8266/PolledTimeoutPolicies.h b/cores/esp8266/PolledTimeoutPolicies.h new file mode 100644 index 0000000000..48f12622b0 --- /dev/null +++ b/cores/esp8266/PolledTimeoutPolicies.h @@ -0,0 +1,72 @@ +#ifndef __POLLEDTIMEOUTPOLICIES_H__ +#define __POLLEDTIMEOUTPOLICIES_H__ + + +/* + PolledTimeoutPolicies.h - Policy classes meant for use with polledTimeout + + Copyright (c) 2018 Daniel Salazar. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include + +namespace YieldPolicy +{ + + struct DoNothing + { + static void execute() {} + }; + + + template + struct YieldAndDelayMs + { + static void execute() {delay(delayMs);} //yield is implied in delay + }; + +} //YieldPolicy + + + + +namespace TimeSourcePolicy +{ + + struct TimeSourceMillis + { + // time policy in milli-seconds based on millis() + + using timeType = decltype(millis()); + static timeType time() {return millis();} + static constexpr timeType ticksPerSecond = 1000; + static constexpr timeType ticksPerSecondMax = 1000; + }; + + +} //TimeSourcePolicy + + + + + + + +#endif diff --git a/cores/esp8266/PolledTimeoutPolicies_esp8266.h b/cores/esp8266/PolledTimeoutPolicies_esp8266.h new file mode 100644 index 0000000000..6164d62e3f --- /dev/null +++ b/cores/esp8266/PolledTimeoutPolicies_esp8266.h @@ -0,0 +1,64 @@ +#ifndef __POLLEDTIMEOUTPOLICIES_ESP8266_H__ +#define __POLLEDTIMEOUTPOLICIES_ESP8266_H__ + + +/* + PolledTimeoutPolicies.h - Policy classes specific to the ESP8266 + meant for use with polledTimeout + + Copyright (c) 2018 Daniel Salazar. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +namespace YieldPolicy +{ + + struct YieldOrSkip + { + static void execute() {delay(0);} + }; + +} //YieldPolicy + + + + +namespace TimeSourcePolicy +{ + + struct TimeSourceCycles + { + // time policy based on esp_get_cycle_count() + // this particular time measurement is intended to be called very often + // (every loop, every yield) + + using timeType = decltype(esp_get_cycle_count()); + static timeType time() {return esp_get_cycle_count();} + static constexpr timeType ticksPerSecond = esp_get_cpu_freq_mhz() * 1000000UL; // 80'000'000 or 160'000'000 Hz + static constexpr timeType ticksPerSecondMax = 160000000; // 160MHz + }; + +} //TimeSourcePolicy + + + + + +#endif diff --git a/cores/esp8266/PolledTimeoutTemplate.h b/cores/esp8266/PolledTimeoutTemplate.h new file mode 100644 index 0000000000..24c1406bd6 --- /dev/null +++ b/cores/esp8266/PolledTimeoutTemplate.h @@ -0,0 +1,271 @@ +#ifndef __POLLEDTIMEOUTTEMPLATE_H__ +#define __POLLEDTIMEOUTTEMPLATE_H__ + + +/* + PolledTimeout.h - Encapsulation of a polled Timeout + + Copyright (c) 2018 Daniel Salazar. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include // IRAM_ATTR +#include // std::numeric_limits +#include // std::is_unsigned + + +namespace TimePolicy +{ + + //Template implementation for TimeUnit + template // "second_th" units of timeType for one second + struct TimeUnit + { + using timeType = typename TimeSourceType::timeType; + +#if __GNUC__ < 5 + // gcc-4.8 cannot compile the constexpr-only version of this function + // using #defines instead luckily works + static constexpr timeType computeRangeCompensation () + { + #define number_of_secondTh_in_one_tick ((1.0 * second_th) / ticksPerSecond) + #define fractional (number_of_secondTh_in_one_tick - (long)number_of_secondTh_in_one_tick) + + return ({ + fractional == 0? + 1: // no need for compensation + (number_of_secondTh_in_one_tick / fractional) + 0.5; // scalar multiplier allowing exact division + }); + + #undef number_of_secondTh_in_one_tick + #undef fractional + } +#else + static constexpr timeType computeRangeCompensation () + { + return ({ + constexpr double number_of_secondTh_in_one_tick = (1.0 * second_th) / ticksPerSecond; + constexpr double fractional = number_of_secondTh_in_one_tick - (long)number_of_secondTh_in_one_tick; + fractional == 0? + 1: // no need for compensation + (number_of_secondTh_in_one_tick / fractional) + 0.5; // scalar multiplier allowing exact division + }); + } +#endif + + static constexpr timeType ticksPerSecond = TimeSourceType::ticksPerSecond; + static constexpr timeType ticksPerSecondMax = TimeSourceType::ticksPerSecondMax; + static constexpr timeType rangeCompensate = computeRangeCompensation(); + static constexpr timeType user2UnitMultiplierMax = (ticksPerSecondMax * rangeCompensate) / second_th; + static constexpr timeType user2UnitMultiplier = (ticksPerSecond * rangeCompensate) / second_th; + static constexpr timeType user2UnitDivider = rangeCompensate; + // std::numeric_limits::max() is reserved + static constexpr timeType timeMax = (std::numeric_limits::max() - 1) / user2UnitMultiplierMax; + + static timeType toTimeTypeUnit (const timeType userUnit) {return (userUnit * user2UnitMultiplier) / user2UnitDivider;} + static timeType toUserUnit (const timeType internalUnit) {return (internalUnit * user2UnitDivider) / user2UnitMultiplier;} + static timeType time () {return TimeSourceType::time();} + }; //TimeUnit + +} //TimePolicy + + + + + +namespace PolledTimeout +{ + + + template + class TimeoutTemplate + { + public: + using timeType = typename TimePolicyT::timeType; + static_assert(std::is_unsigned::value == true, "timeType must be unsigned"); + + static constexpr timeType alwaysExpired = 0; + static constexpr timeType neverExpires = std::numeric_limits::max(); + static constexpr timeType rangeCompensate = TimePolicyT::rangeCompensate; //debug + + //Constructor + TimeoutTemplate(const timeType userTimeout) + { + reset(userTimeout); + } + + //Checks if the timeout has elapsed + IRAM_ATTR // fast + bool expired() + { + const bool hasExpired = PeriodicT ? expiredRetrigger() : expiredOneShot(); + if (!hasExpired) //in case of DoNothing: gets optimized away + YieldPolicyT::execute(); + return hasExpired; + } + + //Convenience shorthand for expired() + IRAM_ATTR // fast + operator bool() + { + return expired(); + } + + //Returns time since creation or last reset + IRAM_ATTR + timeType elapsed() const + { + if(_neverExpires) + return TimePolicyT::toUserUnit(0); + + return TimePolicyT::time() - _start; + } + + //Returns time until next expiration + IRAM_ATTR // fast + timeType remaining() const + { + if (_neverExpires) + return timeMax(); + + timeType current = TimePolicyT::time(); + + if (checkExpired(current)) + return TimePolicyT::toUserUnit(0); + + return TimePolicyT::toUserUnit(_timeout - (current - _start)); + } + + //Checks if the timeout can expire or not (if false, expired() will always return false) + bool canExpire () const + { + return !_neverExpires; + } + + //Checks if the timeout is always expired or not (if false, expired() will always return true) + bool canWait () const + { + return _timeout != alwaysExpired; + } + + // Resets, will trigger after this new timeout. + IRAM_ATTR // called from ISR + void reset(const timeType newUserTimeout) + { + reset(); + _timeout = TimePolicyT::toTimeTypeUnit(newUserTimeout); + _neverExpires = (newUserTimeout < 0) || (newUserTimeout > timeMax()); + } + + // Resets, will trigger after the timeout previously set. + IRAM_ATTR // called from ISR + void reset() + { + _start = TimePolicyT::time(); + } + + // Resets to just expired so that on next poll the check will immediately trigger for the user, + // also change timeout (after next immediate trigger). + IRAM_ATTR // called from ISR + void resetAndSetExpired (const timeType newUserTimeout) + { + reset(newUserTimeout); + _start -= _timeout; + } + + // Resets to just expired so that on next poll the check will immediately trigger for the user. + IRAM_ATTR // called from ISR + void resetAndSetExpired () + { + reset(); + _start -= _timeout; + } + + //Resets to a state that can never expire + void resetToNeverExpires () + { + _timeout = alwaysExpired + 1; // because canWait() has precedence + _neverExpires = true; + } + + //Getter for the timeout value + timeType getTimeout() const + { + return TimePolicyT::toUserUnit(_timeout); + } + + //Getter for the time value of the last reset + timeType getStart() const + { + return _start; + } + + //Convenience method for the current time value + timeType time() const + { + return TimePolicyT::time(); + } + + //Returns the max valid time value that the time policy allows + static constexpr timeType timeMax() + { + return TimePolicyT::timeMax; + } + + private: + + IRAM_ATTR // fast + bool checkExpired(const timeType internalUnit) const + { + // canWait() is not checked here + // returns "can expire" and "time expired" + return (!_neverExpires) && ((internalUnit - _start) >= _timeout); + } + + protected: + + IRAM_ATTR // fast + bool expiredRetrigger() + { + if (!canWait()) + return true; + + timeType current = TimePolicyT::time(); + if(checkExpired(current)) + { + unsigned long n = (current - _start) / _timeout; //how many _timeouts periods have elapsed, will usually be 1 (current - _start >= _timeout) + _start += n * _timeout; + return true; + } + return false; + } + + IRAM_ATTR // fast + bool expiredOneShot() const + { + // returns "always expired" or "has expired" + return !canWait() || checkExpired(TimePolicyT::time()); + } + + timeType _timeout; + timeType _start; + bool _neverExpires; + }; + +} //PolledTimeout + +#endif diff --git a/cores/esp8266/Schedule.cpp b/cores/esp8266/Schedule.cpp index b1230ed675..0e6aeab982 100644 --- a/cores/esp8266/Schedule.cpp +++ b/cores/esp8266/Schedule.cpp @@ -40,9 +40,9 @@ struct recurrent_fn_t { recurrent_fn_t* mNext = nullptr; mRecFuncT mFunc; - esp8266::polledTimeout::periodicFastUs callNow; + PolledTimeout::periodicFastUs callNow; std::function alarm = nullptr; - recurrent_fn_t(esp8266::polledTimeout::periodicFastUs interval) : callNow(interval) { } + recurrent_fn_t(PolledTimeout::periodicFastUs interval) : callNow(interval) { } }; static recurrent_fn_t* rFirst = nullptr; @@ -135,7 +135,7 @@ bool schedule_recurrent_function_us(const std::function& fn, void run_scheduled_functions() { - esp8266::polledTimeout::periodicFastMs yieldNow(100); // yield every 100ms + PolledTimeout::periodicFastMs yieldNow(100); // yield every 100ms // prevent scheduling of new functions during this run auto stop = sLast; @@ -173,7 +173,7 @@ void run_scheduled_functions() void run_scheduled_recurrent_functions() { - esp8266::polledTimeout::periodicFastMs yieldNow(100); // yield every 100ms + PolledTimeout::periodicFastMs yieldNow(100); // yield every 100ms // Note to the reader: // There is no exposed API to remove a scheduled function: diff --git a/cores/esp8266/Stream.h b/cores/esp8266/Stream.h index 340d4f9c78..6139cdb47f 100644 --- a/cores/esp8266/Stream.h +++ b/cores/esp8266/Stream.h @@ -156,7 +156,7 @@ class Stream: public Print { // - for an efficient timeout management, Print/Stream classes // should implement {output,input}CanTimeout() - using oneShotMs = esp8266::polledTimeout::oneShotFastMs; + using oneShotMs = PolledTimeout::oneShotFastMs; static constexpr int temporaryStackBufferSize = 64; // ::send*() methods: diff --git a/cores/esp8266/StreamSend.cpp b/cores/esp8266/StreamSend.cpp index f743889b62..c545a18709 100644 --- a/cores/esp8266/StreamSend.cpp +++ b/cores/esp8266/StreamSend.cpp @@ -26,7 +26,7 @@ size_t Stream::sendGeneric(Print* to, const ssize_t len, const int readUntilChar, - const esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs) + const PolledTimeout::oneShotFastMs::timeType timeoutMs) { setReport(Report::Success); @@ -58,10 +58,10 @@ size_t Stream::sendGeneric(Print* to, } -size_t Stream::SendGenericPeekBuffer(Print* to, const ssize_t len, const int readUntilChar, const esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs) +size_t Stream::SendGenericPeekBuffer(Print* to, const ssize_t len, const int readUntilChar, const PolledTimeout::oneShotFastMs::timeType timeoutMs) { // "neverExpires (default, impossible)" is translated to default timeout - esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs); + PolledTimeout::oneShotFastMs timedOut(timeoutMs >= PolledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs); // len==-1 => maxLen=0 <=> until starvation const size_t maxLen = std::max((ssize_t)0, len); size_t written = 0; @@ -154,13 +154,13 @@ size_t Stream::SendGenericPeekBuffer(Print* to, const ssize_t len, const int rea return written; } -size_t Stream::SendGenericRegularUntil(Print* to, const ssize_t len, const int readUntilChar, const esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs) +size_t Stream::SendGenericRegularUntil(Print* to, const ssize_t len, const int readUntilChar, const PolledTimeout::oneShotFastMs::timeType timeoutMs) { // regular Stream API // no other choice than reading byte by byte // "neverExpires (default, impossible)" is translated to default timeout - esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs); + PolledTimeout::oneShotFastMs timedOut(timeoutMs >= PolledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs); // len==-1 => maxLen=0 <=> until starvation const size_t maxLen = std::max((ssize_t)0, len); size_t written = 0; @@ -239,13 +239,13 @@ size_t Stream::SendGenericRegularUntil(Print* to, const ssize_t len, const int r return written; } -size_t Stream::SendGenericRegular(Print* to, const ssize_t len, const esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs) +size_t Stream::SendGenericRegular(Print* to, const ssize_t len, const PolledTimeout::oneShotFastMs::timeType timeoutMs) { // regular Stream API // use an intermediary buffer // "neverExpires (default, impossible)" is translated to default timeout - esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs); + PolledTimeout::oneShotFastMs timedOut(timeoutMs >= PolledTimeout::oneShotFastMs::neverExpires ? getTimeout() : timeoutMs); // len==-1 => maxLen=0 <=> until starvation const size_t maxLen = std::max((ssize_t)0, len); size_t written = 0; diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index 3528a324a8..eb445041d1 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -490,7 +490,7 @@ size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) { _reset(); return 0; } - esp8266::polledTimeout::oneShotMs timeOut(streamTimeout); + PolledTimeout::oneShotMs timeOut(streamTimeout); if (_progress_callback) { _progress_callback(0, _size); } diff --git a/cores/esp8266/core_esp8266_si2c.cpp b/cores/esp8266/core_esp8266_si2c.cpp index e4bb1c2b07..750ebb8889 100644 --- a/cores/esp8266/core_esp8266_si2c.cpp +++ b/cores/esp8266/core_esp8266_si2c.cpp @@ -124,8 +124,8 @@ class Twi // Handle the case where a slave needs to stretch the clock with a time-limited busy wait inline void WAIT_CLOCK_STRETCH() { - esp8266::polledTimeout::oneShotFastUs timeout(twi_clockStretchLimit); - esp8266::polledTimeout::periodicFastUs yieldTimeout(5000); + PolledTimeout::oneShotFastUs timeout(twi_clockStretchLimit); + PolledTimeout::periodicFastUs yieldTimeout(5000); while (!timeout && !SCL_READ(twi_scl)) // outer loop is stretch duration up to stretch limit { if (yieldTimeout) // inner loop yields every 5ms diff --git a/libraries/ESP8266WebServer/examples/Graph/Graph.ino b/libraries/ESP8266WebServer/examples/Graph/Graph.ino index 4f73455676..f201f0a9b5 100644 --- a/libraries/ESP8266WebServer/examples/Graph/Graph.ino +++ b/libraries/ESP8266WebServer/examples/Graph/Graph.ino @@ -265,7 +265,7 @@ unsigned int defaultMask() { int rgbMode = 1; // 0=off - 1=auto - 2=manual int rgbValue = 0; -esp8266::polledTimeout::periodicMs timeToChange(1000); +PolledTimeout::periodicMs timeToChange(1000); bool modeChangeRequested = false; void loop(void) { diff --git a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino index 62b5f03343..ece388ba9a 100644 --- a/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino +++ b/libraries/ESP8266WiFi/examples/BearSSL_MaxFragmentLength/BearSSL_MaxFragmentLength.ino @@ -18,7 +18,7 @@ const char *pass = STAPSK; void fetch(BearSSL::WiFiClientSecure *client) { client->write("GET / HTTP/1.0\r\nHost: tls.mbed.org\r\nUser-Agent: ESP8266\r\n\r\n"); client->flush(); - using oneShot = esp8266::polledTimeout::oneShot; + using oneShot = PolledTimeout::oneShot; oneShot timeout(5000); do { char tmp[32]; diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index 48bd5a449b..04e4ee6881 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -35,7 +35,7 @@ WiFiServer statusServer(TCP_PORT); WiFiUDP udp; -esp8266::polledTimeout::periodicMs showStatusOnSerialNow(STATUSDELAY_MS); +PolledTimeout::periodicMs showStatusOnSerialNow(STATUSDELAY_MS); void fqdn(Print& out, const String& fqdn) { out.print(F("resolving ")); diff --git a/libraries/ESP8266WiFi/examples/WiFiEcho/WiFiEcho.ino b/libraries/ESP8266WiFi/examples/WiFiEcho/WiFiEcho.ino index 0962b08365..3d71648a9a 100644 --- a/libraries/ESP8266WiFi/examples/WiFiEcho/WiFiEcho.ino +++ b/libraries/ESP8266WiFi/examples/WiFiEcho/WiFiEcho.ino @@ -21,8 +21,8 @@ WiFiClient client; constexpr size_t sizes [] = { 0, 512, 384, 256, 128, 64, 16, 8, 4 }; constexpr uint32_t breathMs = 200; -esp8266::polledTimeout::oneShotFastMs enoughMs(breathMs); -esp8266::polledTimeout::periodicFastMs test(2000); +PolledTimeout::oneShotFastMs enoughMs(breathMs); +PolledTimeout::periodicFastMs test(2000); int t = 1; // test (1, 2 or 3, see below) int s = 0; // sizes[] index diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index cbb0fe36c4..f823bd6c62 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -449,7 +449,7 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m, WiFiState* state) { //tasks to wait correctly. constexpr unsigned int timeoutValue = 1000; //1 second if(can_yield()) { - using oneShot = esp8266::polledTimeout::oneShotFastMs; + using oneShot = PolledTimeout::oneShotFastMs; oneShot timeout(timeoutValue); while(wifi_get_opmode() != (uint8) m && !timeout) delay(5); diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp index f41699d01d..02c54f6751 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp @@ -85,7 +85,7 @@ static wl_status_t waitWiFiConnect(uint32_t connectTimeoutMs) wl_status_t status; // Set WiFi connect timeout - using esp8266::polledTimeout::oneShotMs; + using PolledTimeout::oneShotMs; oneShotMs connectTimeout(connectTimeoutMs); // Wait for WiFi status change or timeout @@ -243,7 +243,7 @@ int8_t ESP8266WiFiMulti::startScan() WiFi.scanNetworks(true); // Set WiFi scan timeout - using esp8266::polledTimeout::oneShotMs; + using PolledTimeout::oneShotMs; oneShotMs scanTimeout(WIFI_SCAN_TIMEOUT_MS); // Wait for WiFi scan change or timeout diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index 38f197c915..a7f39255b8 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -431,7 +431,7 @@ int8_t ESP8266WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength) { if((wifi_get_opmode() & 1) == 0) { return WL_DISCONNECTED; } - using esp8266::polledTimeout::oneShot; + using PolledTimeout::oneShot; oneShot timeout(timeoutLength); // number of milliseconds to wait before returning timeout error while(!timeout) { yield(); diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp index 9064377c9f..1f3383a19b 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp @@ -476,7 +476,7 @@ int WiFiClientSecureCtx::_run_until(unsigned target, bool blocking) { return -1; } - esp8266::polledTimeout::oneShotMs loopTimeout(_timeout); + PolledTimeout::oneShotMs loopTimeout(_timeout); for (int no_work = 0; blocking || no_work < 2;) { optimistic_yield(100); diff --git a/libraries/ESP8266WiFi/src/include/UdpContext.h b/libraries/ESP8266WiFi/src/include/UdpContext.h index 0c43cd2adb..c63cf76f98 100644 --- a/libraries/ESP8266WiFi/src/include/UdpContext.h +++ b/libraries/ESP8266WiFi/src/include/UdpContext.h @@ -406,10 +406,10 @@ class UdpContext } bool sendTimeout(const ip_addr_t* addr, uint16_t port, - esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs) + PolledTimeout::oneShotFastMs::timeType timeoutMs) { err_t err; - esp8266::polledTimeout::oneShotFastMs timeout(timeoutMs); + PolledTimeout::oneShotFastMs timeout(timeoutMs); while (((err = trySend(addr, port, /* keep buffer on error */true)) != ERR_OK) && !timeout) delay(0); if (err != ERR_OK) diff --git a/libraries/ESP8266WiFiMesh/src/ExpiringTimeTracker.cpp b/libraries/ESP8266WiFiMesh/src/ExpiringTimeTracker.cpp index 5151c0bc5a..c8d0af6419 100644 --- a/libraries/ESP8266WiFiMesh/src/ExpiringTimeTracker.cpp +++ b/libraries/ESP8266WiFiMesh/src/ExpiringTimeTracker.cpp @@ -25,14 +25,14 @@ #include "ExpiringTimeTracker.h" ExpiringTimeTracker::ExpiringTimeTracker(const uint32_t duration, const uint32_t creationTimeMs) : - timeoutTemplate(0) + TimeoutTemplate(0) { setDuration(duration); _start = creationTimeMs; } ExpiringTimeTracker::ExpiringTimeTracker(const calculatorType durationCalculator, const uint32_t creationTimeMs) : - timeoutTemplate(0) + TimeoutTemplate(0) { setDuration(durationCalculator); _start = creationTimeMs; @@ -103,7 +103,7 @@ bool ExpiringTimeTracker::expired() const void ExpiringTimeTracker::reset() { - timeoutTemplate::reset(); + TimeoutTemplate::reset(); } void ExpiringTimeTracker::reset(const uint32_t newDuration) diff --git a/libraries/ESP8266WiFiMesh/src/ExpiringTimeTracker.h b/libraries/ESP8266WiFiMesh/src/ExpiringTimeTracker.h index 4a83f979ae..b9834166ca 100644 --- a/libraries/ESP8266WiFiMesh/src/ExpiringTimeTracker.h +++ b/libraries/ESP8266WiFiMesh/src/ExpiringTimeTracker.h @@ -28,7 +28,7 @@ #include #include -class ExpiringTimeTracker : private esp8266::polledTimeout::oneShotMs { +class ExpiringTimeTracker : private PolledTimeout::oneShotMs { public: diff --git a/libraries/ESP8266mDNS/examples/LEAmDNS/mDNS_Clock/mDNS_Clock.ino b/libraries/ESP8266mDNS/examples/LEAmDNS/mDNS_Clock/mDNS_Clock.ino index ec0320fdb2..39383bc7c0 100644 --- a/libraries/ESP8266mDNS/examples/LEAmDNS/mDNS_Clock/mDNS_Clock.ino +++ b/libraries/ESP8266mDNS/examples/LEAmDNS/mDNS_Clock/mDNS_Clock.ino @@ -256,7 +256,7 @@ void loop(void) { // Allow MDNS processing MDNS.update(); - static esp8266::polledTimeout::periodicMs timeout(UPDATE_CYCLE); + static PolledTimeout::periodicMs timeout(UPDATE_CYCLE); if (timeout.expired()) { if (hMDNSService) { diff --git a/libraries/ESP8266mDNS/src/LEAmDNS.h b/libraries/ESP8266mDNS/src/LEAmDNS.h index bf2f1e9832..253cd6d85c 100644 --- a/libraries/ESP8266mDNS/src/LEAmDNS.h +++ b/libraries/ESP8266mDNS/src/LEAmDNS.h @@ -955,7 +955,7 @@ class MDNSResponder { enuProbingStatus m_ProbingStatus; uint8_t m_u8SentCount; // Used for probes and announcements - esp8266::polledTimeout::oneShotMs m_Timeout; // Used for probes and announcements + PolledTimeout::oneShotMs m_Timeout; // Used for probes and announcements //clsMDNSTimeFlag m_TimeFlag; // Used for probes and announcements bool m_bConflict; bool m_bTiebreakNeeded; @@ -1027,7 +1027,7 @@ class MDNSResponder const timeoutLevel_t TIMEOUTLEVEL_FINAL = 100; uint32_t m_u32TTL; - esp8266::polledTimeout::oneShotMs m_TTLTimeout; + PolledTimeout::oneShotMs m_TTLTimeout; timeoutLevel_t m_timeoutLevel; stcTTL(void); @@ -1132,7 +1132,7 @@ class MDNSResponder MDNSServiceQueryCallbackFunc m_fnCallback; bool m_bLegacyQuery; uint8_t m_u8SentCount; - esp8266::polledTimeout::oneShotMs m_ResendTimeout; + PolledTimeout::oneShotMs m_ResendTimeout; bool m_bAwaitingAnswers; stcAnswer* m_pAnswers; diff --git a/libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp b/libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp index 677456fcc5..9c40742e01 100644 --- a/libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp +++ b/libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp @@ -1689,7 +1689,7 @@ bool MDNSResponder::_checkServiceQueryCache(void) ++pServiceQuery->m_u8SentCount; pServiceQuery->m_ResendTimeout.reset((MDNS_DYNAMIC_QUERY_RESEND_COUNT > pServiceQuery->m_u8SentCount) ? (MDNS_DYNAMIC_QUERY_RESEND_DELAY * (pServiceQuery->m_u8SentCount - 1)) - : esp8266::polledTimeout::oneShotMs::neverExpires); + : PolledTimeout::oneShotMs::neverExpires); } DEBUG_EX_INFO( DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _checkServiceQueryCache: %s to resend service query!"), (bResult ? "Succeeded" : "FAILED")); diff --git a/libraries/ESP8266mDNS/src/LEAmDNS_Structs.cpp b/libraries/ESP8266mDNS/src/LEAmDNS_Structs.cpp index 0e128aea8a..330669a846 100644 --- a/libraries/ESP8266mDNS/src/LEAmDNS_Structs.cpp +++ b/libraries/ESP8266mDNS/src/LEAmDNS_Structs.cpp @@ -1293,7 +1293,7 @@ bool MDNSResponder::stcMDNS_RRAnswerGeneric::clear(void) MDNSResponder::stcProbeInformation::stcProbeInformation(void) : m_ProbingStatus(ProbingStatus_WaitingForData), m_u8SentCount(0), - m_Timeout(esp8266::polledTimeout::oneShotMs::neverExpires), + m_Timeout(PolledTimeout::oneShotMs::neverExpires), m_bConflict(false), m_bTiebreakNeeded(false), m_fnHostProbeResultCallback(0), @@ -1578,7 +1578,7 @@ bool MDNSResponder::stcMDNSService::releaseProtocol(void) */ MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::stcTTL(void) : m_u32TTL(0), - m_TTLTimeout(esp8266::polledTimeout::oneShotMs::neverExpires), + m_TTLTimeout(PolledTimeout::oneShotMs::neverExpires), m_timeoutLevel(TIMEOUTLEVEL_UNSET) { @@ -1666,7 +1666,7 @@ bool MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::finalTimeoutLevel(vo unsigned long MDNSResponder::stcMDNSServiceQuery::stcAnswer::stcTTL::timeout(void) const { - uint32_t u32Timeout = esp8266::polledTimeout::oneShotMs::neverExpires; + uint32_t u32Timeout = PolledTimeout::oneShotMs::neverExpires; if (TIMEOUTLEVEL_BASE == m_timeoutLevel) // 80% { @@ -2144,7 +2144,7 @@ MDNSResponder::stcMDNSServiceQuery::stcMDNSServiceQuery(void) m_fnCallback(0), m_bLegacyQuery(false), m_u8SentCount(0), - m_ResendTimeout(esp8266::polledTimeout::oneShotMs::neverExpires), + m_ResendTimeout(PolledTimeout::oneShotMs::neverExpires), m_bAwaitingAnswers(true), m_pAnswers(0) { diff --git a/libraries/Wire/examples/master_reader/master_reader.ino b/libraries/Wire/examples/master_reader/master_reader.ino index 323830f847..04ed0e61d6 100644 --- a/libraries/Wire/examples/master_reader/master_reader.ino +++ b/libraries/Wire/examples/master_reader/master_reader.ino @@ -23,7 +23,7 @@ void setup() { } void loop() { - using periodic = esp8266::polledTimeout::periodicMs; + using periodic = PolledTimeout::periodicMs; static periodic nextPing(1000); if (nextPing) { diff --git a/libraries/Wire/examples/master_writer/master_writer.ino b/libraries/Wire/examples/master_writer/master_writer.ino index 1e9719e23c..0706d80e94 100644 --- a/libraries/Wire/examples/master_writer/master_writer.ino +++ b/libraries/Wire/examples/master_writer/master_writer.ino @@ -24,7 +24,7 @@ void setup() { byte x = 0; void loop() { - using periodic = esp8266::polledTimeout::periodicMs; + using periodic = PolledTimeout::periodicMs; static periodic nextPing(1000); if (nextPing) { diff --git a/libraries/esp8266/examples/BlinkPolledTimeout/BlinkPolledTimeout.ino b/libraries/esp8266/examples/BlinkPolledTimeout/BlinkPolledTimeout.ino index 11e2aff482..8f8bcbd6ba 100644 --- a/libraries/esp8266/examples/BlinkPolledTimeout/BlinkPolledTimeout.ino +++ b/libraries/esp8266/examples/BlinkPolledTimeout/BlinkPolledTimeout.ino @@ -38,28 +38,28 @@ void ledToggle() { } -esp8266::polledTimeout::periodicFastUs halfPeriod(500000); //use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace +PolledTimeout::periodicFastUs halfPeriod(500000); //use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace // the setup function runs only once at start void setup() { Serial.begin(115200); Serial.println(); - Serial.printf("periodic/oneShotMs::timeMax() = %u ms\n", (uint32_t)esp8266::polledTimeout::periodicMs::timeMax()); - Serial.printf("periodic/oneShotFastMs::timeMax() = %u ms\n", (uint32_t)esp8266::polledTimeout::periodicFastMs::timeMax()); - Serial.printf("periodic/oneShotFastUs::timeMax() = %u us\n", (uint32_t)esp8266::polledTimeout::periodicFastUs::timeMax()); - Serial.printf("periodic/oneShotFastNs::timeMax() = %u ns\n", (uint32_t)esp8266::polledTimeout::periodicFastNs::timeMax()); + Serial.printf("periodic/oneShotMs::timeMax() = %u ms\n", (uint32_t)PolledTimeout::periodicMs::timeMax()); + Serial.printf("periodic/oneShotFastMs::timeMax() = %u ms\n", (uint32_t)PolledTimeout::periodicFastMs::timeMax()); + Serial.printf("periodic/oneShotFastUs::timeMax() = %u us\n", (uint32_t)PolledTimeout::periodicFastUs::timeMax()); + Serial.printf("periodic/oneShotFastNs::timeMax() = %u ns\n", (uint32_t)PolledTimeout::periodicFastNs::timeMax()); #if 0 // 1 for debugging polledTimeout - Serial.printf("periodic/oneShotMs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicMs::rangeCompensate); - Serial.printf("periodic/oneShotFastMs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastMs::rangeCompensate); - Serial.printf("periodic/oneShotFastUs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastUs::rangeCompensate); - Serial.printf("periodic/oneShotFastNs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastNs::rangeCompensate); + Serial.printf("periodic/oneShotMs::rangeCompensate = %u\n", (uint32_t)PolledTimeout::periodicMs::rangeCompensate); + Serial.printf("periodic/oneShotFastMs::rangeCompensate = %u\n", (uint32_t)PolledTimeout::periodicFastMs::rangeCompensate); + Serial.printf("periodic/oneShotFastUs::rangeCompensate = %u\n", (uint32_t)PolledTimeout::periodicFastUs::rangeCompensate); + Serial.printf("periodic/oneShotFastNs::rangeCompensate = %u\n", (uint32_t)PolledTimeout::periodicFastNs::rangeCompensate); #endif pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output - using esp8266::polledTimeout::oneShotMs; //import the type to the local namespace + using PolledTimeout::oneShotMs; //import the type to the local namespace //STEP1; turn the led ON ledOn(); diff --git a/libraries/esp8266/examples/FadePolledTimeout/FadePolledTimeout.ino b/libraries/esp8266/examples/FadePolledTimeout/FadePolledTimeout.ino index 57a9e6beb8..ddd9d3573b 100644 --- a/libraries/esp8266/examples/FadePolledTimeout/FadePolledTimeout.ino +++ b/libraries/esp8266/examples/FadePolledTimeout/FadePolledTimeout.ino @@ -26,7 +26,7 @@ #include #include -esp8266::polledTimeout::periodicFastUs stepPeriod(50000); +PolledTimeout::periodicFastUs stepPeriod(50000); // the setup function runs only once at start void setup() { @@ -43,7 +43,7 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output analogWriteRange(1000); - using esp8266::polledTimeout::oneShotMs; //import the type to the local namespace + using PolledTimeout::oneShotMs; //import the type to the local namespace digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level diff --git a/libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino b/libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino index 7556c58820..2fdd40cb29 100644 --- a/libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino +++ b/libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino @@ -99,9 +99,9 @@ static nv_s* nv = (nv_s*)RTC_USER_MEM; // user RTC RAM area uint32_t resetCount = 0; // keeps track of the number of Deep Sleep tests / resets const uint32_t blinkDelay = 100; // fast blink rate for the LED when waiting for the user -esp8266::polledTimeout::periodicMs blinkLED(blinkDelay); // LED blink delay without delay() -esp8266::polledTimeout::oneShotMs altDelay(blinkDelay); // tight loop to simulate user code -esp8266::polledTimeout::oneShotMs wifiTimeout(timeout); // 30 second timeout on WiFi connection +PolledTimeout::periodicMs blinkLED(blinkDelay); // LED blink delay without delay() +PolledTimeout::oneShotMs altDelay(blinkDelay); // tight loop to simulate user code +PolledTimeout::oneShotMs wifiTimeout(timeout); // 30 second timeout on WiFi connection // use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace void wakeupCallback() { // unlike ISRs, you can do a print() from a callback function diff --git a/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino b/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino index 376086fb61..9397f35d18 100644 --- a/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino +++ b/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino @@ -63,7 +63,7 @@ static timespec tp; static time_t now; static uint32_t now_ms, now_us; -static esp8266::polledTimeout::periodicMs showTimeNow(60000); +static PolledTimeout::periodicMs showTimeNow(60000); static int time_machine_days = 0; // 0 = present static bool time_machine_running = false; static bool time_machine_run_once = false; diff --git a/tests/host/common/include/UdpContext.h b/tests/host/common/include/UdpContext.h index bf104bc40f..78ca42d1fa 100644 --- a/tests/host/common/include/UdpContext.h +++ b/tests/host/common/include/UdpContext.h @@ -237,10 +237,10 @@ class UdpContext } bool sendTimeout(ip_addr_t* addr, uint16_t port, - esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs) + PolledTimeout::oneShotFastMs::timeType timeoutMs) { err_t err; - esp8266::polledTimeout::oneShotFastMs timeout(timeoutMs); + PolledTimeout::oneShotFastMs timeout(timeoutMs); while (((err = trySend(addr, port)) != ERR_OK) && !timeout) delay(0); if (err != ERR_OK) diff --git a/tests/host/core/test_PolledTimeout.cpp b/tests/host/core/test_PolledTimeout.cpp index 37b31d8544..e50a4e3f06 100644 --- a/tests/host/core/test_PolledTimeout.cpp +++ b/tests/host/core/test_PolledTimeout.cpp @@ -15,7 +15,7 @@ fuzzycomp(argT a, argT b) TEST_CASE("OneShot Timeout 500000000ns (0.5s)", "[polledTimeout]") { - using esp8266::polledTimeout::oneShotFastNs; + using PolledTimeout::oneShotFastNs; using timeType = oneShotFastNs::timeType; timeType before, after, delta; @@ -49,7 +49,7 @@ TEST_CASE("OneShot Timeout 500000000ns (0.5s)", "[polledTimeout]") TEST_CASE("OneShot Timeout 3000000us", "[polledTimeout]") { - using esp8266::polledTimeout::oneShotFastUs; + using PolledTimeout::oneShotFastUs; using timeType = oneShotFastUs::timeType; timeType before, after, delta; @@ -83,7 +83,7 @@ TEST_CASE("OneShot Timeout 3000000us", "[polledTimeout]") TEST_CASE("OneShot Timeout 3000ms", "[polledTimeout]") { - using esp8266::polledTimeout::oneShotMs; + using PolledTimeout::oneShotMs; using timeType = oneShotMs::timeType; timeType before, after, delta; @@ -117,7 +117,7 @@ TEST_CASE("OneShot Timeout 3000ms", "[polledTimeout]") TEST_CASE("OneShot Timeout 3000ms reset to 1000ms", "[polledTimeout]") { - using esp8266::polledTimeout::oneShotMs; + using PolledTimeout::oneShotMs; using timeType = oneShotMs::timeType; timeType before, after, delta; @@ -151,7 +151,7 @@ TEST_CASE("OneShot Timeout 3000ms reset to 1000ms", "[polledTimeout]") TEST_CASE("Periodic Timeout 1T 3000ms", "[polledTimeout]") { - using esp8266::polledTimeout::periodicMs; + using PolledTimeout::periodicMs; using timeType = periodicMs::timeType; timeType before, after, delta; @@ -183,7 +183,7 @@ TEST_CASE("Periodic Timeout 1T 3000ms", "[polledTimeout]") TEST_CASE("Periodic Timeout 10T 1000ms", "[polledTimeout]") { - using esp8266::polledTimeout::periodicMs; + using PolledTimeout::periodicMs; using timeType = periodicMs::timeType; timeType before, after, delta; @@ -212,8 +212,9 @@ TEST_CASE("Periodic Timeout 10T 1000ms", "[polledTimeout]") TEST_CASE("OneShot Timeout 3000ms reset to 1000ms custom yield", "[polledTimeout]") { - using YieldOrSkipPolicy = esp8266::polledTimeout::YieldPolicy::YieldOrSkip; - using oneShotMsYield = esp8266::polledTimeout::timeoutTemplate; + using YieldOrSkipPolicy = YieldPolicy::YieldOrSkip; + using TimeMillisPolicy = TimePolicy::TimeMillis; + using oneShotMsYield = PolledTimeout::TimeoutTemplate; using timeType = oneShotMsYield::timeType; timeType before, after, delta;