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 <keithp@keithp.com>
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;
}
return 1;
}
-#ifndef AO_STORAGE_ERASED_BYTE
-#define AO_STORAGE_ERASED_BYTE 0xff
-#endif
-
uint8_t
ao_storage_is_erased(uint32_t pos)
{
#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;