Berry fast_loop is now called every 5ms whatever the Sleep value (#19436)

This commit is contained in:
s-hadinger 2023-09-02 11:10:50 +02:00 committed by GitHub
parent f7c4c16a9c
commit f4b3574ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
### Breaking Changed
### Changed
- Berry fast_loop is now called every 5ms whatever the Sleep value
### Fixed
- PCF8574 mode 1 with base relays exception 3/28 regression from v12.4.0.4 (#19408)

View File

@ -1128,6 +1128,7 @@
#define USE_BERRY_TIMEOUT 4000 // Timeout in ms, will raise an exception if running time exceeds this timeout
#define USE_BERRY_PSRAM // Allocate Berry memory in PSRAM if PSRAM is connected - this might be slightly slower but leaves main memory intact
#define USE_BERRY_IRAM // Allocate some data structures in IRAM (which is ususally unused) when possible and if no PSRAM is available
#define USE_BERRY_FAST_LOOP_SLEEP_MS 5 // Minimum time in milliseconds to before calling again `tasmota.fast_loop()`, a smaller value will consume more CPU (min 1ms)
// #define USE_BERRY_DEBUG // Compile Berry bytecode with line number information, makes exceptions easier to debug. Adds +8% of memory consumption for compiled code
// #define UBE_BERRY_DEBUG_GC // Print low-level GC metrics
// #define USE_BERRY_INT64 // Add 64 bits integer support (+1.7KB Flash)

View File

@ -169,11 +169,20 @@ int32_t callBerryEventDispatcher(const char *type, const char *cmd, int32_t idx,
}
// Simplified version of event loop. Just call `tasmota.fast_loop()`
void callBerryFastLoop(void) {
// `every_5ms` is a flag to wait at least 5ms between calss to `tasmota.fast_loop()`
void callBerryFastLoop(bool every_5ms) {
static uint32_t fast_loop_last_call = 0;
bvm *vm = berry.vm;
if (nullptr == vm) { return; }
uint32_t now = millis();
if (every_5ms) {
if (!TimeReached(fast_loop_last_call + USE_BERRY_FAST_LOOP_SLEEP_MS /* 5ms */)) { return; }
}
fast_loop_last_call = now;
// TODO - can we make this dereferencing once for all?
if (be_getglobal(vm, "tasmota")) {
if (be_getmethod(vm, -1, "fast_loop")) {
be_pushvalue(vm, -2); // add instance as first arg
@ -758,6 +767,11 @@ bool Xdrv52(uint32_t function)
bool result = false;
switch (function) {
case FUNC_SLEEP_LOOP:
if (TasmotaGlobal.berry_fast_loop_enabled) { // call only if enabled at global level
callBerryFastLoop(true); // call `tasmota.fast_loop()` optimized for minimal performance impact
}
break;
case FUNC_LOOP:
if (!berry.autoexec_done) {
// we generate a synthetic event `autoexec`
@ -779,7 +793,7 @@ bool Xdrv52(uint32_t function)
}
}
if (TasmotaGlobal.berry_fast_loop_enabled) { // call only if enabled at global level
callBerryFastLoop(); // call `tasmota.fast_loop()` optimized for minimal performance impact
callBerryFastLoop(false); // call `tasmota.fast_loop()` optimized for minimal performance impact
}
break;