增加系统热数据配置,记录系统启动次数
This commit is contained in:
parent
75e7a4deaf
commit
9353d90a5e
46
Config.cpp
46
Config.cpp
|
@ -86,9 +86,17 @@ bool ConfigBlock::Write(Storage* storage, uint addr, const ByteArray& bs)
|
||||||
|
|
||||||
//--//
|
//--//
|
||||||
|
|
||||||
|
Config::Config(Storage* st, uint addr)
|
||||||
|
{
|
||||||
|
Device = st;
|
||||||
|
Address = addr;
|
||||||
|
}
|
||||||
|
|
||||||
// 循环查找配置块
|
// 循环查找配置块
|
||||||
const void* Config::Find(const char* name, bool fAppend)
|
const void* Config::Find(const char* name, bool fAppend)
|
||||||
{
|
{
|
||||||
|
uint c_Version = 0x534F5453; // STOS
|
||||||
|
|
||||||
assert_param2(name, "配置段名称不能为空");
|
assert_param2(name, "配置段名称不能为空");
|
||||||
|
|
||||||
uint addr = Address;
|
uint addr = Address;
|
||||||
|
@ -172,15 +180,43 @@ const void* Config::Get(const char* name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flash最后一块作为配置区
|
// Flash最后一块作为配置区
|
||||||
Config* Config::CreateFlash()
|
Config& Config::CreateFlash()
|
||||||
{
|
{
|
||||||
// 最后一块作为配置区
|
// 最后一块作为配置区
|
||||||
static Flash flash;
|
static Flash flash;
|
||||||
static Config cfg;
|
static Config cfg(&flash, flash.Start + flash.Size - flash.Block);
|
||||||
cfg.Device = &flash;
|
//cfg.Device = &flash;
|
||||||
cfg.Address = flash.Start + flash.Size - flash.Block;
|
//cfg.Address = flash.Start + flash.Size - flash.Block;
|
||||||
|
|
||||||
return &cfg;
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RAM最后一小段作为热启动配置区
|
||||||
|
Config& Config::CreateRAM()
|
||||||
|
{
|
||||||
|
// 最后一块作为配置区
|
||||||
|
static CharStorage cs;
|
||||||
|
static Config cfg(&cs, Sys.StackTop());
|
||||||
|
//cfg.Device = &cs;
|
||||||
|
//cfg.Address = Sys.StackTop();
|
||||||
|
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* HotConfig::Next() const
|
||||||
|
{
|
||||||
|
return (void*)&this[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
HotConfig& HotConfig::Current()
|
||||||
|
{
|
||||||
|
static Config& cfg = Config::CreateRAM();
|
||||||
|
|
||||||
|
// 查找配置数据,如果不存在,则清空
|
||||||
|
const void* dat = cfg.Get("Hot");
|
||||||
|
if(!dat) dat = cfg.Set("Hot", ByteArray((byte)0, sizeof(HotConfig)));
|
||||||
|
|
||||||
|
return *(HotConfig*)dat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
|
|
25
Config.h
25
Config.h
|
@ -10,12 +10,13 @@
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static const uint c_Version = 0x534F5453; // STOS
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Storage* Device;
|
Storage* Device;
|
||||||
uint Address;
|
uint Address;
|
||||||
|
|
||||||
|
Config(Storage* st, uint addr);
|
||||||
|
|
||||||
// 查找
|
// 查找
|
||||||
const void* Find(const char* name, bool fAppend = false);
|
const void* Find(const char* name, bool fAppend = false);
|
||||||
// 废弃。仅清空名称,并不删除数据区
|
// 废弃。仅清空名称,并不删除数据区
|
||||||
|
@ -30,7 +31,9 @@ public:
|
||||||
// 当前
|
// 当前
|
||||||
static Config* Current;
|
static Config* Current;
|
||||||
// Flash最后一块作为配置区
|
// Flash最后一块作为配置区
|
||||||
static Config* CreateFlash();
|
static Config& CreateFlash();
|
||||||
|
// RAM最后一小段作为热启动配置区
|
||||||
|
static Config& CreateRAM();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 必须设定为1字节对齐,否则offsetof会得到错误的位置
|
// 必须设定为1字节对齐,否则offsetof会得到错误的位置
|
||||||
|
@ -38,6 +41,24 @@ public:
|
||||||
// 强制结构体紧凑分配空间
|
// 强制结构体紧凑分配空间
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
|
// 系统配置信息
|
||||||
|
class HotConfig
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ushort Times; // 启动次数
|
||||||
|
|
||||||
|
void* Next() const;
|
||||||
|
|
||||||
|
static HotConfig& Current();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 系统配置信息
|
||||||
|
class SysConfig
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// 配置信息
|
// 配置信息
|
||||||
class TConfig
|
class TConfig
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue