Many things, including a log timing report in the test
Timing report: I (52322) LOG_TEST: === WRITE TIMING REPORT === I (52322) LOG_TEST: Iterations: 200 I (52322) LOG_TEST: Payload size: 39 bytes I (52322) LOG_TEST: Min: 49960 us I (52332) LOG_TEST: Max: 54476 us I (52332) LOG_TEST: Avg: 50005 us I (52342) LOG_TEST: Sector crossings: 2 (max 49983 us) I (52342) LOG_TEST: WDT margin: 4.9s (WDT=5s, worst=54476us) I (52352) LOG_TEST: =========================== so a write takes up to 54ms - not negligible!
This commit is contained in:
@@ -113,8 +113,10 @@ static const esp_partition_t *params_partition = NULL;
|
||||
static const esp_partition_t *log_partition = NULL;
|
||||
static const esp_partition_t *post_partition = NULL;
|
||||
|
||||
// Log head/tail tracking with mutex protection
|
||||
// These track byte offsets within the log partition (0-based)
|
||||
// Log head/tail tracking with mutex protection.
|
||||
// These track byte offsets within the log partition (0-based).
|
||||
// RTC_DATA_ATTR is historical — log_init() always recovers these from a flash scan,
|
||||
// so the RTC values are overwritten on every boot. No partial-write risk.
|
||||
RTC_DATA_ATTR static uint32_t log_head_offset = 0;
|
||||
RTC_DATA_ATTR static uint32_t log_tail_offset = 0;
|
||||
RTC_DATA_ATTR static bool log_initialized = false;
|
||||
@@ -407,21 +409,46 @@ esp_err_t commit_params(void) {
|
||||
// ============================================================================
|
||||
esp_err_t factory_reset(void) {
|
||||
ESP_LOGI(TAG, "Performing factory reset...");
|
||||
|
||||
|
||||
// Reset all parameters to defaults
|
||||
for (int i = 0; i < NUM_PARAMS; i++) {
|
||||
memcpy(¶meter_table[i], ¶meter_defaults[i], sizeof(param_value_t));
|
||||
}
|
||||
|
||||
// TODO: WIPE ENTIRE PARTITION
|
||||
|
||||
// Commit defaults to flash
|
||||
|
||||
// Commit defaults to params partition
|
||||
esp_err_t err = commit_params();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to commit defaults during factory reset");
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
// Erase the log partition
|
||||
const esp_partition_t *log_part = esp_partition_find_first(
|
||||
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "log");
|
||||
if (log_part != NULL) {
|
||||
ESP_LOGI(TAG, "Erasing log partition (%lu bytes)...", (unsigned long)log_part->size);
|
||||
err = esp_partition_erase_range(log_part, 0, log_part->size);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to erase log partition: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
// Erase the POST test partition
|
||||
const esp_partition_t *post_part = esp_partition_find_first(
|
||||
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "post_test");
|
||||
if (post_part != NULL) {
|
||||
err = esp_partition_erase_range(post_part, 0, post_part->size);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Failed to erase post_test partition: %s", esp_err_to_name(err));
|
||||
}
|
||||
}
|
||||
|
||||
// Reset log state so next boot starts fresh
|
||||
log_head_offset = 0;
|
||||
log_tail_offset = 0;
|
||||
log_initialized = false;
|
||||
|
||||
ESP_LOGI(TAG, "Factory reset complete");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user