From: Keith Packard Date: Tue, 18 May 2021 05:33:21 +0000 (-0700) Subject: altos/telegps-*: Fix log end discovery at startup X-Git-Tag: 1.9.7~1^2~7^2~3 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=8dec0d1be5a2d7633045c5c0e86b32a9e6b60299 altos/telegps-*: Fix log end discovery at startup We need to find the first unwritten log block to start appending data, but the code was actually looking for the first empty 256-byte chunk, which meant that we'd leave a gap of erased data after the previous log. AltosUI would stop at that point and not recover the remaining stored data. Signed-off-by: Keith Packard --- diff --git a/src/kernel/ao_log_gps.c b/src/kernel/ao_log_gps.c index bf326c1a..2b45f35e 100644 --- a/src/kernel/ao_log_gps.c +++ b/src/kernel/ao_log_gps.c @@ -81,18 +81,31 @@ ao_log_gps_tracking(uint16_t tick, struct ao_telemetry_satellite *gps_tracking_d ao_log_write(&ao_log_data); } +static uint8_t +ao_log_check_empty(void) +{ + uint8_t *b = (void *) &ao_log_data; + unsigned i; + + for (i = 0; i < sizeof (ao_log_type); i++) + if (*b++ != AO_STORAGE_ERASED_BYTE) + return 0; + return 1; +} + int8_t ao_log_check(uint32_t pos) { - if (ao_storage_is_erased(pos & ~(ao_storage_block - 1))) - return 0; - if (!ao_storage_read(pos, &ao_log_data, sizeof (struct ao_log_gps))) return AO_LOG_INVALID; + if (ao_log_check_empty()) + return AO_LOG_EMPTY; + if (!ao_log_check_data()) return AO_LOG_INVALID; + return AO_LOG_VALID; } diff --git a/src/kernel/ao_storage.c b/src/kernel/ao_storage.c index 213ec2d6..43abc43c 100644 --- a/src/kernel/ao_storage.c +++ b/src/kernel/ao_storage.c @@ -86,10 +86,6 @@ ao_storage_write(ao_pos_t pos, void *v_buf, uint16_t len) return 1; } -#ifndef AO_STORAGE_ERASED_BYTE -#define AO_STORAGE_ERASED_BYTE 0xff -#endif - uint8_t ao_storage_is_erased(uint32_t pos) { diff --git a/src/kernel/ao_storage.h b/src/kernel/ao_storage.h index 026074b5..ff8548eb 100644 --- a/src/kernel/ao_storage.h +++ b/src/kernel/ao_storage.h @@ -44,6 +44,10 @@ extern ao_pos_t ao_storage_block; #define USE_STORAGE_CONFIG 1 #endif +#ifndef AO_STORAGE_ERASED_BYTE +#define AO_STORAGE_ERASED_BYTE 0xff +#endif + #if USE_STORAGE_CONFIG /* Byte offset of config block. Will be ao_storage_block bytes long */ extern ao_pos_t ao_storage_config;