Sys头增加应用版本、硬件版本、产品批次、启动次数、热启动次数等
This commit is contained in:
parent
1b7f773613
commit
15e00e6d0b
|
@ -35,8 +35,8 @@ AP0801::AP0801()
|
|||
|
||||
Data = nullptr;
|
||||
Size = 0;
|
||||
|
||||
HardVer = 0;
|
||||
|
||||
HardVer = 0;
|
||||
|
||||
Net.Spi = Spi2;
|
||||
Net.Irq = PE1;
|
||||
|
@ -62,6 +62,11 @@ void AP0801::Init(ushort code, cstring name, COM message)
|
|||
|
||||
// 初始化系统
|
||||
sys.Init();
|
||||
|
||||
auto hot = &HotConfig::Current();
|
||||
// 热启动次数
|
||||
Sys.HotStart = hot->Times + 1;
|
||||
|
||||
#if DEBUG
|
||||
sys.MessagePort = message; // 指定printf输出的串口
|
||||
Sys.ShowInfo();
|
||||
|
|
|
@ -1,27 +1,35 @@
|
|||
#include "AT24CXX.h"
|
||||
|
||||
/*
|
||||
AT24C02的存储容量为2K bit,内容分成32页,每页8Byte,共256Byte,操作时有两种寻址方式:芯片寻址和片内子地址寻址
|
||||
(1)芯片寻址:AT24C02的芯片地址为1010,其地址控制字格式为1010A2A1A0R/W。其中A2,A1,A0可编程地址选择位。
|
||||
A2,A1,A0引脚接高、低电平后得到确定的三位编码,与1010形成7位编码,即为该器件的地址码。R/W为芯片读写控制位,该位为0,表示芯片进行写操作。
|
||||
(2)片内子地址寻址:芯片寻址可对内部256B中的任一个进行读/写操作,其寻址范围为00~FF,共256个寻址单位。
|
||||
*/
|
||||
|
||||
#define AT24C01 127
|
||||
#define AT24C02 255
|
||||
#define AT24C04 511
|
||||
#define AT24C08 1023
|
||||
#define AT24C16 2047
|
||||
#define AT24C32 4095
|
||||
#define AT24C64 8191 //256 Pages of 32 bytes
|
||||
#define AT24C128 16383 //256 Pages of 64bytes
|
||||
#define AT24C256 32767 //512 Pages of 64bytes
|
||||
#define AT24C512 65535 //512 Pages of 128bytes
|
||||
#define AT24C64 8191 //256 Pages of 32 bytes
|
||||
#define AT24C128 16383 //256 Pages of 64bytes
|
||||
#define AT24C256 32767 //512 Pages of 64bytes
|
||||
#define AT24C512 65535 //512 Pages of 128bytes
|
||||
|
||||
#define EE_PAGES 512 //存储器页数目
|
||||
#define EE_BYTES 128 //每页字节数目
|
||||
#define EE_TYPE AT24C512//存储器型号
|
||||
#define EE_TDEA 10 //页延时 ms
|
||||
#define EE_PAGES 512 //存储器页数目
|
||||
#define EE_BYTES 128 //每页字节数目
|
||||
#define EE_TYPE AT24C512//存储器型号
|
||||
#define EE_TDEA 10 //页延时 ms
|
||||
|
||||
AT24CXX::AT24CXX()
|
||||
{
|
||||
IIC = nullptr;
|
||||
IIC = nullptr;
|
||||
|
||||
// A2A1A0都接低电平时,地址为 1010000,也就是0x50
|
||||
// 7位地址,到了I2C那里,需要左移1位
|
||||
Address = 0x50;
|
||||
Address = 0x50;
|
||||
}
|
||||
|
||||
AT24CXX::~AT24CXX()
|
||||
|
@ -34,22 +42,22 @@ void AT24CXX::Init()
|
|||
{
|
||||
debug_printf("\r\nAT24CXX::Init Address=0x%02X \r\n", Address);
|
||||
|
||||
IIC->SubWidth = 1;
|
||||
IIC->Address = Address << 1;
|
||||
IIC->SubWidth = 1;
|
||||
IIC->Address = Address << 1;
|
||||
}
|
||||
|
||||
bool AT24CXX::Write(ushort addr, byte data)
|
||||
{
|
||||
if(!IIC) return false;
|
||||
if (!IIC) return false;
|
||||
|
||||
IIC->Address = (Address + (addr >> 8)) << 1;
|
||||
|
||||
return IIC->Write(addr & 0xFF, data);
|
||||
}
|
||||
|
||||
byte AT24CXX::Read(ushort addr)
|
||||
byte AT24CXX::Read(ushort addr) const
|
||||
{
|
||||
if(!IIC) return 0;
|
||||
if (!IIC) return 0;
|
||||
|
||||
IIC->Address = (Address + (addr >> 8)) << 1;
|
||||
|
||||
|
@ -58,8 +66,8 @@ byte AT24CXX::Read(ushort addr)
|
|||
|
||||
bool AT24CXX::Write(uint addr, const Buffer& bs) const
|
||||
{
|
||||
if(!IIC) return false;
|
||||
|
||||
if (!IIC) return false;
|
||||
|
||||
IIC->Address = Address << 1;
|
||||
|
||||
return IIC->Write((ushort)addr, bs);
|
||||
|
@ -67,13 +75,48 @@ bool AT24CXX::Write(uint addr, const Buffer& bs) const
|
|||
|
||||
bool AT24CXX::Read(uint addr, Buffer& bs) const
|
||||
{
|
||||
if(!IIC) return false;
|
||||
if (!IIC) return false;
|
||||
|
||||
IIC->Address = Address << 1;
|
||||
|
||||
|
||||
int len = IIC->Read((ushort)addr, bs);
|
||||
if(len == 0)return false;
|
||||
if(len != bs.Length()) bs.SetLength(len);
|
||||
if (len == 0) return false;
|
||||
if (len != bs.Length()) bs.SetLength(len);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ByteArray AT24CXX::Read(ushort addr, int count) const
|
||||
{
|
||||
ByteArray bs;
|
||||
bs.SetLength(count);
|
||||
if (!Read(addr, bs)) bs.SetLength(0);
|
||||
|
||||
return bs;
|
||||
}
|
||||
|
||||
ushort AT24CXX::Read16(ushort addr) const
|
||||
{
|
||||
auto bs = Read(addr, 2);
|
||||
if (bs.Length() < 2) return 0xFFFF;
|
||||
|
||||
return bs.ToUInt16();
|
||||
}
|
||||
|
||||
uint AT24CXX::Read32(ushort addr) const
|
||||
{
|
||||
auto bs = Read(addr, 4);
|
||||
if (bs.Length() < 4) return 0xFFFFFFFF;
|
||||
|
||||
return bs.ToUInt32();
|
||||
}
|
||||
|
||||
bool AT24CXX::Write(ushort addr, ushort data)
|
||||
{
|
||||
return Write(addr, Buffer(&data, 2));
|
||||
}
|
||||
|
||||
bool AT24CXX::Write(ushort addr, uint data)
|
||||
{
|
||||
return Write(addr, Buffer(&data, 4));
|
||||
}
|
||||
|
|
|
@ -16,10 +16,26 @@ public:
|
|||
|
||||
void Init();
|
||||
bool Write(ushort addr, byte data);
|
||||
byte Read(ushort addr);
|
||||
byte Read(ushort addr) const;
|
||||
|
||||
virtual bool Write(uint addr, const Buffer& bs) const;
|
||||
virtual bool Read(uint addr, Buffer& bs) const;
|
||||
|
||||
ByteArray Read(ushort addr, int count) const;
|
||||
ushort Read16(ushort addr) const;
|
||||
uint Read32(ushort addr) const;
|
||||
|
||||
bool Write(ushort addr, ushort data);
|
||||
bool Write(ushort addr, uint data);
|
||||
};
|
||||
|
||||
/*
|
||||
AT24C02的存储容量为2K bit,内容分成32页,每页8Byte,共256Byte,操作时有两种寻址方式:芯片寻址和片内子地址寻址
|
||||
(1)芯片寻址:AT24C02的芯片地址为1010,其地址控制字格式为1010A2A1A0R/W。其中A2,A1,A0可编程地址选择位。
|
||||
A2,A1,A0引脚接高、低电平后得到确定的三位编码,与1010形成7位编码,即为该器件的地址码。R/W为芯片读写控制位,该位为0,表示芯片进行写操作。
|
||||
(2)片内子地址寻址:芯片寻址可对内部256B中的任一个进行读/写操作,其寻址范围为00~FF,共256个寻址单位。
|
||||
|
||||
A2A1A0都接低电平时,地址为 1010000,也就是0x50
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,8 +7,8 @@ TSys Sys;
|
|||
const TTime Time;
|
||||
|
||||
// 系统配置
|
||||
//const SystemConfig g_Config = {
|
||||
SystemConfig g_Config = {
|
||||
const SystemConfig g_Config = {
|
||||
//SystemConfig g_Config = {
|
||||
// 操作系统 v3.2.x
|
||||
(0x03020000 | __BUILD_DATE__),
|
||||
"SmartOS_CPU",
|
||||
|
@ -41,13 +41,19 @@ INROOT TSys::TSys()
|
|||
|
||||
Code = cfg.Code;
|
||||
Ver = cfg.Ver;
|
||||
HardVer = cfg.HardVer;
|
||||
AppVer = cfg.AppVer;
|
||||
#ifndef TINY
|
||||
Name = cfg.Name;
|
||||
Company = cfg.Company;
|
||||
Product = cfg.Product;
|
||||
|
||||
Interrupt.Init();
|
||||
#endif
|
||||
|
||||
StartTimes = 1;
|
||||
HotStart = 1;
|
||||
|
||||
Started = false;
|
||||
}
|
||||
|
||||
|
@ -62,13 +68,12 @@ void TSys::Init(void)
|
|||
void TSys::ShowInfo() const
|
||||
{
|
||||
#if DEBUG
|
||||
debug_printf("%s::%s Code:%04X ", Company, Name, Code);
|
||||
Version v(Config->Ver);
|
||||
debug_printf("Ver:%s\r\n", v.ToString().GetBuffer());
|
||||
debug_printf("Product:%s Build:%s %s\r\n", Config->Product, __BUILD_USER__, __BUILD_STIME__);
|
||||
Version v1(Config->AppVer);
|
||||
Version v2(Config->HardVer);
|
||||
debug_printf("AppVer:%s HardVer:%s\r\n", v1.ToString().GetBuffer(), v2.ToString().GetBuffer());
|
||||
debug_printf("%s::%s Code:%04X %s \r\n", Company, Name, Code, Product);
|
||||
debug_printf("Build:%s %s\r\n", __BUILD_USER__, __BUILD_STIME__);
|
||||
Version v1(AppVer);
|
||||
Version v2(HardVer);
|
||||
Version v3(Ver);
|
||||
debug_printf("AppVer:%s HardVer:%s CoreVer:%s\r\n", v1.ToString().GetBuffer(), v2.ToString().GetBuffer(), v3.ToString().GetBuffer());
|
||||
|
||||
OnShowInfo();
|
||||
|
||||
|
@ -82,7 +87,8 @@ void TSys::ShowInfo() const
|
|||
str.Show(true);
|
||||
|
||||
debug_printf("Time : ");
|
||||
DateTime::Now().Show(true);
|
||||
DateTime::Now().Show(false);
|
||||
debug_printf(" Start: %d/%d \r\n", HotStart, StartTimes);
|
||||
debug_printf("Support: http://www.WsLink.cn\r\n");
|
||||
|
||||
debug_printf("\r\n");
|
||||
|
|
11
Kernel/Sys.h
11
Kernel/Sys.h
|
@ -75,15 +75,22 @@ public:
|
|||
|
||||
cstring Name; // 系统名称
|
||||
cstring Company; // 系统厂商
|
||||
cstring Product; // 产品批次
|
||||
ushort Code; // 产品代码
|
||||
ushort Ver; // 系统版本
|
||||
byte ID[12]; // 芯片ID。
|
||||
uint Ver; // 系统版本
|
||||
uint HardVer; // 硬件版本
|
||||
uint AppVer; // 产品版本
|
||||
|
||||
byte ID[12]; // 芯片ID
|
||||
ushort DevID; // MCU编码。低字设备版本,高字子版本
|
||||
ushort RevID; // MCU编码。低字设备版本,高字子版本
|
||||
uint CPUID; // CPUID
|
||||
ushort FlashSize; // 芯片Flash容量。
|
||||
ushort RAMSize; // 芯片RAM容量
|
||||
|
||||
uint StartTimes; // 启动次数
|
||||
uint HotStart; // 热启动次数
|
||||
|
||||
const SystemConfig* Config; // 系统设置
|
||||
|
||||
TSys(); // 构造函数
|
||||
|
|
|
@ -303,7 +303,7 @@ void TSys::OnShowInfo() const
|
|||
size = end - start;
|
||||
debug_printf("Stack:(%p, %p) = 0x%x (%dk)\r\n", start, end, size, size >> 10);
|
||||
|
||||
if (IsGD) debug_printf("ChipType:%p %s\r\n", *(uint*)0x40022100, (cstring)0x40022100);
|
||||
//if (IsGD) debug_printf("ChipType:%p %s\r\n", *(uint*)0x40022100, (cstring)0x40022100);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue