Skip to content

Commit

Permalink
Merge pull request letscontrolit#4376 from TD-er/bugfix/CacheContr_ES…
Browse files Browse the repository at this point in the history
…P32_speed

[Cache Controller] Speedup ESP32 + LittleFS use.
  • Loading branch information
TD-er authored Nov 21, 2022
2 parents 41f60a2 + 065f3e4 commit 64a7f86
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 100 deletions.
2 changes: 1 addition & 1 deletion boards/esp8266_16M14M_board.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ldscript": "eagle.flash.16m14m.ld"
},
"core": "esp8266",
"extra_flags": "-DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_ESP01 -DESP8266_4M -DESP8266_4M3M",
"extra_flags": "-DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_ESP01 -DESP8266_4M -DESP8266_16M14M",
"f_cpu": "80000000L",
"f_flash": "40000000L",
"flash_mode": "dout",
Expand Down
2 changes: 1 addition & 1 deletion boards/esp8266_4M1M_board.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ldscript": "eagle.flash.4m1m.ld"
},
"core": "esp8266",
"extra_flags": "-DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_ESP01 -DESP8266_4M -DESP8266_4M3M",
"extra_flags": "-DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_ESP01 -DESP8266_4M -DESP8266_4M1M",
"f_cpu": "80000000L",
"f_flash": "40000000L",
"flash_mode": "dout",
Expand Down
12 changes: 7 additions & 5 deletions src/src/DataStructs/ESPEasyControllerCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ struct ControllerCache_struct {
~ControllerCache_struct();

// Write a single sample set to the buffer
bool write(const uint8_t *data,
unsigned int size);
bool write(const uint8_t *data,
unsigned int size);

// Read a single sample set, either from file or buffer.
// May delete a file if it is all read and not written to.
Expand All @@ -24,20 +24,22 @@ struct ControllerCache_struct {

void init();

bool isInitialized();
bool isInitialized() const;

// Clear all caches
void clearCache();

bool deleteOldestCacheBlock();

bool deleteAllCacheBlocks();

void resetpeek();

// Read data without marking it as being read.
bool peek(uint8_t *data,
unsigned int size);
unsigned int size) const;

String getPeekCacheFileName(bool& islast);
String getPeekCacheFileName(bool& islast) const;

int readFileNr = 0;
int readPos = 0;
Expand Down
13 changes: 10 additions & 3 deletions src/src/DataStructs/ESPeasyControllerCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void ControllerCache_struct::init() {
}
}

bool ControllerCache_struct::isInitialized() {
bool ControllerCache_struct::isInitialized() const {
return _RTC_cache_handler != nullptr;
}

Expand All @@ -50,21 +50,28 @@ bool ControllerCache_struct::deleteOldestCacheBlock() {
return false;
}

bool ControllerCache_struct::deleteAllCacheBlocks() {
if (_RTC_cache_handler != nullptr) {
return _RTC_cache_handler->deleteAllCacheBlocks();
}
return false;
}

void ControllerCache_struct::resetpeek() {
if (_RTC_cache_handler != nullptr) {
_RTC_cache_handler->resetpeek();
}
}

// Read data without marking it as being read.
bool ControllerCache_struct::peek(uint8_t *data, unsigned int size) {
bool ControllerCache_struct::peek(uint8_t *data, unsigned int size) const {
if (_RTC_cache_handler == nullptr) {
return false;
}
return _RTC_cache_handler->peek(data, size);
}

String ControllerCache_struct::getPeekCacheFileName(bool& islast) {
String ControllerCache_struct::getPeekCacheFileName(bool& islast) const {
if (_RTC_cache_handler == nullptr) {
return "";
}
Expand Down
75 changes: 45 additions & 30 deletions src/src/DataStructs/RTCStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,70 @@
#include "../../ESPEasy_common.h"

// this offsets are in blocks, bytes = blocks * 4
#define RTC_BASE_STRUCT 64
#define RTC_BASE_USERVAR 74
#define RTC_BASE_CACHE 124
#define RTC_BASE_STRUCT 64
#define RTC_BASE_USERVAR 74
#define RTC_BASE_CACHE 124

#ifdef ESP8266
#define RTC_CACHE_DATA_SIZE 240 // 10 elements
#endif
# define RTC_CACHE_DATA_SIZE 240 // 10 elements, limited by RTC memory
# ifdef ESP8266_16M14M
# ifdef USE_LITTLEFS
# define CACHE_FILE_MAX_SIZE 262144 // LittleFS can handle larger files just fine.
# else // ifdef USE_LITTLEFS
# define CACHE_FILE_MAX_SIZE 48000 // Try to reduce the nr. of files, but SPIFFS still slows down on lager files.
# endif // ifdef USE_LITTLEFS
# else // ifdef ESP8266_16M14M
# define CACHE_FILE_MAX_SIZE 24000
# endif // ifdef ESP8266_16M14M
#endif // ifdef ESP8266
#ifdef ESP32

// TODO TD-er: ESP32 can store much more samples in its RTC
// However we must make sure the data can be flushed on demand or else
// However we must make sure the data can be flushed on demand or else
// one may have to wait for a long time to be able to read the data from the filesystem
#define RTC_CACHE_DATA_SIZE 240 // 10 elements
#endif
#define CACHE_FILE_MAX_SIZE 24000
# define RTC_CACHE_DATA_SIZE 768 // 32 elements
# ifdef USE_LITTLEFS
# define CACHE_FILE_MAX_SIZE 262144
# else // ifdef USE_LITTLEFS
# define CACHE_FILE_MAX_SIZE 24000
# endif // ifdef USE_LITTLEFS
#endif // ifdef ESP32

/*********************************************************************************************\
* RTCStruct
* RTCStruct
\*********************************************************************************************/
//max 40 bytes: ( 74 - 64 ) * 4

// max 40 bytes: ( 74 - 64 ) * 4
struct RTCStruct
{
RTCStruct() = default;

RTCStruct(const RTCStruct& other) = delete;

RTCStruct& operator=(const RTCStruct&) = default;
RTCStruct& operator=(const RTCStruct&) = default;

void init();
void init();

void clearLastWiFi();
void clearLastWiFi();

bool lastWiFi_set() const;
bool lastWiFi_set() const;


uint8_t ID1 = 0;
uint8_t ID2 = 0;
uint8_t lastWiFiChannel = 0;
uint8_t factoryResetCounter = 0;
uint8_t deepSleepState = 0;
uint8_t bootFailedCount = 0;
uint8_t flashDayCounter = 0;
uint8_t lastWiFiSettingsIndex = 0;
unsigned long flashCounter = 0;
unsigned long bootCounter = 0;
unsigned long lastMixedSchedulerId = 0;
uint8_t lastBSSID[6] = { 0 };
uint8_t unused1 = 0; // Force alignment to 4 bytes
uint8_t unused2 = 0;
unsigned long lastSysTime = 0;
uint8_t ID1 = 0;
uint8_t ID2 = 0;
uint8_t lastWiFiChannel = 0;
uint8_t factoryResetCounter = 0;
uint8_t deepSleepState = 0;
uint8_t bootFailedCount = 0;
uint8_t flashDayCounter = 0;
uint8_t lastWiFiSettingsIndex = 0;
unsigned long flashCounter = 0;
unsigned long bootCounter = 0;
unsigned long lastMixedSchedulerId = 0;
uint8_t lastBSSID[6] = { 0 };
uint8_t unused1 = 0; // Force alignment to 4 bytes
uint8_t unused2 = 0;
unsigned long lastSysTime = 0;
};


Expand Down
Loading

0 comments on commit 64a7f86

Please sign in to comment.