123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "cfg.h"
- #include "uart.h"
- #include "ac780x_eflash.h"
- #include <string.h>
- static uint32_t reflectionBuff[(sizeof(Config_type)>>2)+1];
- Config_type *config = (Config_type *)reflectionBuff;
- static void Factory_reset(void)
- {
- config->magic = CONFIG_MAGIC;
- config->addr = DEFAULT_ADDR;
- config->br_index = BaudRate_9600;
-
- config->AppSize = 0;
- config->AppCrc = 0;
- }
- int Config_Init(void)
- {
- //EFLASH_StatusType ret = EFLASH_STATUS_SUCCESS;
- memcpy(reflectionBuff, (void *)CONFIG_ADDRESS, sizeof(Config_type));
- if (config->magic != CONFIG_MAGIC)
- {/* initiliaze config */
- memset(reflectionBuff, 0, sizeof(Config_type));
- //config->magic = CONFIG_MAGIC;
-
-
- Factory_reset();
- SaveConfig();
-
- }
-
- //Factory_reset();
- return 0;
- }
- int SaveConfig(void)
- {
- EFLASH_StatusType ret = EFLASH_STATUS_SUCCESS;
-
- EFLASH_UnlockCtrl();
- ret = EFLASH_PageErase(CONFIG_ADDRESS); ///<erase page
- if (ret != EFLASH_STATUS_SUCCESS) return -1;
- ret = EFLASH_PageEraseVerify(CONFIG_ADDRESS); ///< verify erase state
- if (ret != EFLASH_STATUS_SUCCESS) return -1;
- ret = EFLASH_PageProgram(CONFIG_ADDRESS, (uint32_t *)reflectionBuff, (sizeof(Config_type)>>2)+1); ///<
- if (ret != EFLASH_STATUS_SUCCESS) return -1;
- EFLASH_LockCtrl();
- return 0;
- }
- int ResetConfig(void)
- {
- Factory_reset();
- //SaveConfig();
-
- return 0;
- }
|