-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent 50 day overflow in various(not all) timing related places.
This requires a fallback implementation for the ESP8266.
- Loading branch information
Showing
12 changed files
with
149 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Fallback Timer | ||
This tiny library contains an ESP8266 NonOS definition of the ESP RTOS `esp_timer_get_time` function. | ||
This fallback version only works on the ESP8266 NonOS SDK. | ||
|
||
**Warning**: This implementation only works if its called more than once every hour. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* fallback_timer.h | ||
* | ||
* This file contains the header definition for an ESP8266 NonOS fallback definition of the ESP RTOS esp_timer_get_time function. | ||
* | ||
* This fallback relies on being called more than once each hour to function. | ||
* | ||
* Created on: Sep 15, 2024 | ||
* | ||
* Copyright (C) 2023 ToMe25. | ||
* This project is licensed under the MIT License. | ||
* The MIT license can be found in the project root and at https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
#ifndef LIB_FALLBACK_TIMER_INCLUDE_FALLBACK_TIMER_H_ | ||
#define LIB_FALLBACK_TIMER_INCLUDE_FALLBACK_TIMER_H_ | ||
|
||
// Platform IO seems to ignore the platform specification in a local library.json. | ||
#ifdef ESP8266 | ||
|
||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* Returns the time in microseconds since the ESP was started. | ||
* | ||
* Needs to be called at least once each hour to function. | ||
* | ||
* @return The time in microseconds since the ESP first started. | ||
*/ | ||
int64_t esp_timer_get_time(); | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ESP8266 */ | ||
|
||
#endif /* LIB_FALLBACK_TIMER_INCLUDE_FALLBACK_TIMER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "FallbackTimer", | ||
"description": "A simple library containing a fallback definition of esp_timer_get_time.", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"platforms": [ "espressif8266" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* fallback_timer.h | ||
* | ||
* This file contains the implementation for an ESP8266 NonOS fallback definition of the ESP RTOS esp_timer_get_time function. | ||
* | ||
* This fallback relies on being called more than once each hour to function. | ||
* | ||
* Created on: Sep 15, 2024 | ||
* | ||
* Copyright (C) 2023 ToMe25. | ||
* This project is licensed under the MIT License. | ||
* The MIT license can be found in the project root and at https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
// Platform IO seems to ignore the platform specification in a local library.json. | ||
#ifdef ESP8266 | ||
|
||
#include "fallback_timer.h" | ||
#include <user_interface.h> | ||
|
||
/** | ||
* The current time collected when esp_timer_get_time was last called. | ||
*/ | ||
uint32_t last_time = 0; | ||
|
||
/** | ||
* The number of times the current system time overflowed already. | ||
*/ | ||
uint32_t time_overflows = 0; | ||
|
||
int64_t esp_timer_get_time() { | ||
const uint32_t now = system_get_time(); | ||
if (now < last_time) { | ||
time_overflows++; | ||
} | ||
last_time = now; | ||
return (((int64_t) time_overflows) << 32) + now; | ||
} | ||
|
||
#endif /* ESP8266 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters