|
|
@ -8,15 +8,22 @@ |
|
|
|
#include "zflash.h" |
|
|
|
#include "zboard.h" |
|
|
|
|
|
|
|
#define FLASH_WRITE(data) \ |
|
|
|
status = FlashWrite(config_flash_write_start_address, data); \ |
|
|
|
if (status != HAL_OK) \ |
|
|
|
{ \ |
|
|
|
printf("flash write error, status:%d\r\n", status); \ |
|
|
|
return -2; \ |
|
|
|
} \ |
|
|
|
config_flash_write_start_address += 4; |
|
|
|
|
|
|
|
#define CONFIG_SIZE ((sizeof(config_t) / 4) + ((sizeof(config_t) % 4) > 0 ? 1 : 0)) |
|
|
|
|
|
|
|
static config_t s_config; |
|
|
|
|
|
|
|
static bool s_is_first_init = false; |
|
|
|
|
|
|
|
void config_init(void) |
|
|
|
{ |
|
|
|
#if 1 |
|
|
|
IP4_ADDR((ip4_addr_t *)&s_config.ip, 192, 168, 8, 10); |
|
|
|
IP4_ADDR((ip4_addr_t *)&s_config.gw, 192, 168, 8, 1); |
|
|
|
IP4_ADDR((ip4_addr_t *)&s_config.netmask, 255, 255, 255, 0); |
|
|
@ -24,8 +31,6 @@ void config_init(void) |
|
|
|
s_config.obtaining_ip_mode = OBTAINING_IP_MODE_DHCP; // dhcp |
|
|
|
s_config.mask = 1; // |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
if (config_flash_write() < 0) |
|
|
|
{ |
|
|
|
printf("flash write config error\r\n"); |
|
|
@ -40,7 +45,9 @@ void config_init(void) |
|
|
|
/*dumpconfig*/ |
|
|
|
config_dump_config(); |
|
|
|
} |
|
|
|
|
|
|
|
bool config_is_first_init(void) { return s_is_first_init; } |
|
|
|
|
|
|
|
void config_dump_config(void) |
|
|
|
{ |
|
|
|
printf("=================config================\r\n"); |
|
|
@ -51,18 +58,6 @@ void config_dump_config(void) |
|
|
|
printf("= config localport: %u\r\n", s_config.localport); |
|
|
|
} |
|
|
|
|
|
|
|
bool config_update(void) |
|
|
|
{ |
|
|
|
// if (stmflash_write(FLASH_SAVE_ADDR, (uint32_t *)&s_config, CONFIG_SIZE) < 0) |
|
|
|
// { |
|
|
|
// printf("flash write config error\r\n"); |
|
|
|
// return false; |
|
|
|
// } |
|
|
|
|
|
|
|
// config_dump_config(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
void config_flash_read(void) |
|
|
|
{ |
|
|
|
uint32_t config_flash_write_start_address = FLASH_START_ADDRESS; |
|
|
@ -88,47 +83,13 @@ int8_t config_flash_write(void) |
|
|
|
printf("flash erase error, status:%d\r\n", status); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
FLASH_WRITE(s_config.mask); |
|
|
|
FLASH_WRITE(s_config.obtaining_ip_mode); |
|
|
|
FLASH_WRITE(s_config.ip); |
|
|
|
FLASH_WRITE(s_config.gw); |
|
|
|
FLASH_WRITE(s_config.netmask); |
|
|
|
FLASH_WRITE(s_config.localport); |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 0, s_config.mask); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -2; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 4, s_config.obtaining_ip_mode); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -3; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 8, s_config.ip); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -4; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 12, s_config.gw); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -5; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 16, s_config.netmask); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -6; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 20, s_config.localport); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -7; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |