12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #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->lock_threshold = 0.0;
- config->lock_threshold = 0.0;
-
- //config->App2Size = 0;
- //config->App2Crc = 0;
- //config->IapFlag = 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, 0xFF, sizeof(Config_type));
- //config->magic = CONFIG_MAGIC;
-
-
- Factory_reset();
-
- //
- config->IapFlag = Startup_Normal;
- config->hw_version = 0x0000;
- config->devicetype = 0x0000;
- config->deviceid = 0x00;
-
- 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;
- }
|