fiatlux/firmware/system.c

37 lines
1.1 KiB
C
Raw Normal View History

2021-07-02 16:45:29 +00:00
//
// Created by jedi on 25.06.21.
//
#include "system.h"
#include <FreeRTOS.h>
#include <task.h>
#include <sysparam.h>
#include <spiflash.h>
#include <espressif/esp_common.h>
2021-07-06 20:55:38 +00:00
#include <espressif/user_interface.h>
void system_clear_config(){
vPortEnterCritical();
uint32_t num_sectors = 5 + DEFAULT_SYSPARAM_SECTORS;
uint32_t start = sdk_flashchip.chip_size - num_sectors * sdk_flashchip.sector_size;
for (uint32_t i = 0; i < num_sectors; i++) {
spiflash_erase_sector(start + i * sdk_flashchip.sector_size);
}
sdk_system_restart();
2021-07-09 19:35:41 +00:00
}
void system_init_config(){
uint32_t base_addr;
uint32_t num_sectors;
if(sysparam_get_info(&base_addr, &num_sectors) != SYSPARAM_OK) {
printf("Warning: WiFi config, sysparam not initialized\n");
num_sectors = DEFAULT_SYSPARAM_SECTORS;
base_addr = sdk_flashchip.chip_size - (5 + num_sectors) * sdk_flashchip.sector_size;
if(sysparam_create_area(base_addr, num_sectors, true) == SYSPARAM_OK) {
sysparam_init(base_addr, 0);
}
sdk_system_restart();
}
2021-07-06 20:55:38 +00:00
}