From e1f35018c4dec304b00f50d9dbe12204fd57a623 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期四, 29 九月 2022 15:35:10 +0800 Subject: [PATCH] update infoblock step 1 --- Inc/KMachine.h | 223 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 194 insertions(+), 29 deletions(-) diff --git a/Inc/KMachine.h b/Inc/KMachine.h index 72a5daf..827a591 100644 --- a/Inc/KMachine.h +++ b/Inc/KMachine.h @@ -16,7 +16,7 @@ #define STORE_PRG_PAGESIZE (0x00000400) //Page Size = 1K #define STORE_PRG_PAGES 4 //use 4 pages -#define ALT_PRG_BASE (FLASH_BASE + 0x00009000) //36k //and FLASH_BANK1_END +#define ALT_PRG_BASE (FLASH_BASE + 0x0000A000) //36k //and FLASH_BANK1_END #define ALT_PRG_PAGESIZE (0x00000400) //Page Size = 1K #define ALT_PRG_PAGES 4 //use 4 pages @@ -24,7 +24,7 @@ #define STORE_SYSREG_PAGESIZE (0x00000400) //Page Size = 1K #define STORE_SYSREG_PAGES 1 //use 1 pages -#define STORE_RUNSTAT_BASE (FLASH_BASE + 0x0000B000) //44k K //and +#define STORE_RUNSTAT_BASE (FLASH_BASE + 0x0000A800) //44k K //and #define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K #define STORE_RUNSTAT_PAGES 1 //use 1 pages @@ -32,6 +32,7 @@ #define STORE_LOG_BASE (FLASH_BASE + 0x0000C000) //48k and FLASH_BANK1_END #define STORE_LOG_PAGESIZE (0x00000400) //Page Size = 1K #define STORE_LOG_PAGES 4 //use 4 pages + typedef unsigned char uchar; typedef unsigned char UCHAR; @@ -97,6 +98,23 @@ EventType }; +typedef struct tagInfoBlock +{ + USHORT nDeviceType; + USHORT ProgVer; + USHORT KlinkVer; + USHORT nCapacity; + UCHAR nDInput; + UCHAR nDOutput; + UCHAR nAInput; + UCHAR nAOutput; + UCHAR nHInput; + UCHAR nHOutput; + UCHAR nExt1; + UCHAR nEXT2; + +}stKMInfoBlock; + typedef struct tagKMFuncParam { USHORT EnablePLC:1; //使能内部PLC功能 @@ -107,7 +125,7 @@ typedef struct tagComPortParam { - USHORT PortType:4; /* 0-4=None,Odd,Even,Mark,Space */ + USHORT PortType:4; /* 0-5=Com,Gen,KLink,KBus,KNet,RTU */ USHORT ByteSize:2; /* 0-1=Number of bits/byte, 7-8 */ USHORT Parity:4; /* 0-4=None,Odd,Even,Mark,Space */ USHORT StopBits:2; /* 0,1,2 = 1, 1.5, 2 */ @@ -159,19 +177,34 @@ unsigned short EndSign1; }stKMSysCfg,* pKMSysCfg; +/* +typedef struct tagFactData +{ + USHORT Sign; // + USHORT nLength; // + UCHAR LOT_NO[16]; // + UINT MANDate; // + UINT SN; // + UINT REV1[24]; // + USHORT rev9; + USHORT CRC; + +}stFactData; +*/ typedef struct tagFactoryData //工厂量产参数,数据 { - unsigned short Sign1; - unsigned short Seq1; - unsigned int nModelNo; - unsigned int nModelVer; - unsigned int SN1; - unsigned int nProtocalVer; - unsigned int nProductDateTime; - unsigned int nLotNo; - unsigned int nDefaultFunc; - char ModelStr[16]; - char SNStr[16]; + USHORT Sign1; + USHORT Seq1; + USHORT nModelNo; + USHORT nModelVer; + UINT nLotNo; + UINT nProductDateTime; + UINT SN1; + UINT nProtocalVer; + UINT nDefaultFunc; + UCHAR ModelStr[16]; + UCHAR LOT_NO[16]; // + UCHAR SNStr[16]; unsigned short CRC1; unsigned short EndSign1; @@ -191,11 +224,15 @@ { unsigned short Sign1; unsigned short Seq1; - unsigned short PowerCount; // - unsigned short Reserved1; - unsigned int UpTime; //Seconds; - unsigned int UserData1; - unsigned int Reserved2[3]; + volatile unsigned short PowerCount; // + volatile unsigned short Reserved1; + volatile unsigned int UpTime; //Seconds; + volatile unsigned int UserData1; + volatile unsigned short WorkMode; + volatile unsigned short WorkMode2; + volatile unsigned short nBinProgBank; + volatile unsigned short nBinProgSize; + unsigned int Reserved2[1]; unsigned short CRC1; unsigned short EndSign1; }stRunStat, *pRunStat; @@ -206,24 +243,138 @@ //stStoreCfg * GetNextStoreCfgAddr(stStoreCfg * CurCfg ); extern stKMSysCfg KMSysCfg; + +#define TYPECOIL 0x00 +#define TYPEDATA 0x80 + + enum enKLCoilTypes + { + KLCoilTypeX = 0 | TYPECOIL , //X Input + KLCoilTypeY = 1 | TYPECOIL, //Y Output + KLCoilTypeR = 2 | TYPECOIL, //R register + KLCoilTypeLX = 3 | TYPECOIL, //Link register + KLCoilTypeLY = 4 | TYPECOIL, //Link register + KLCoilTypeT = 5 | TYPECOIL, //Timer + KLCoilTypeC = 6 | TYPECOIL, //Counter + KLCoilTypeLR = 7 | TYPECOIL, //Link register + KLCoilTypeSR = 8 | TYPECOIL, //Link register + + }; + enum enKLDataTypes + { + KLDataTypeDEC = 0 | TYPEDATA, + KLDataTypeHEX = 1 | TYPEDATA, + KLDataTypeFloat = 2 | TYPEDATA, + KLDataTypeWX = 3 | TYPEDATA, + KLDataTypeWY = 4 | TYPEDATA, + KLDataTypeWR = 5 | TYPEDATA, + KLDataTypeWLX = 6 | TYPEDATA, + KLDataTypeWLY = 7 | TYPEDATA, + KLDataTypeDT = 8 | TYPEDATA, + KLDataTypeSDT = 9 | TYPEDATA, + KLDataTypeWSR = 10 | TYPEDATA, + KLDataTypeSV = 11 | TYPEDATA, + KLDataTypeEV = 12 | TYPEDATA, + KLDataTypeLD = 13 | TYPEDATA, + KLDataSysCfg = 25 | TYPEDATA, + KLDataTypeFlash = 33 | TYPEDATA, + KLDataTypeTest = 254 | TYPEDATA, + }; + +enum enKLDataCounts + { + KLDataDTCount = 256, + KLDataSDTCount = 256, + + KLDataWXCount = 16, + KLDataWYCount = 16, + KLDataWRCount = 16, + KLDataLDCount = 64, + KLDataWLCount = 8, + + KLCoilXCount = KLDataWXCount * 16, + KLCoilYCount = KLDataWYCount * 16, + KLCoilRCount = KLDataWRCount * 16, + + KLCoilTCount = 64, + KLCoilCCount = KLCoilTCount, + + KLDataSVCount = KLCoilTCount, + KLDataEVCount = KLCoilTCount, + + KLCoilLXCount = 128, + KLCoilLYCount = 128, + KLCoilLRCount = 128, + KLCoilSRCount = 128, + + }; +#define TOTAL_WDFS (16) //Total DF Count +#define TOTAL_CurVAL (16) // +#define TOTALTIMERS (64) + +typedef struct tagTimerStat +{ + unsigned short nScale:2;//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S + unsigned short nType:1; //0 : timer 1:counter ; + unsigned short nDir:1; //0 : count down. 1 count up; + unsigned short nInited:1; + unsigned short bSet:1; + unsigned short bTon:1; + +}stTimerStat; + +typedef struct tagTimer +{ + unsigned int LastActTime; + union { + unsigned short StatByte; + struct + { + unsigned short nScale:2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S + unsigned short nType:1; //0 : timer 1 : counter ; + unsigned short nDir:1; //0 : count down. 1 count up; + unsigned short nInited:1; + unsigned short bSet:1; + unsigned short bTon:1; + + }; +// stTimerStat Stat; + }; +}stTimer; + typedef struct tagKMem { - unsigned short WX[16]; //本机的X和Y - unsigned short WY[16]; //本机的X和Y - unsigned short WR[64]; - unsigned short DT[256]; + unsigned short WDFs[TOTAL_WDFS]; + unsigned char CurVALs[TOTAL_CurVAL]; + unsigned char CurVAL; + stTimer Timers[TOTALTIMERS]; + + unsigned short WX[KLDataWXCount]; //本机的X和Y + unsigned short WY[KLDataWYCount]; //本机的X和Y + unsigned short WR[KLDataWRCount]; + + unsigned short WT[16]; + + unsigned short WC[16]; + unsigned short EV[KLDataEVCount]; + unsigned short SV[KLDataSVCount]; + + unsigned short WLX[16]; //虚拟的X和Y,远程通讯时映射用。 unsigned short WLY[16]; + unsigned short WLR[16]; unsigned short WSR[16]; + + unsigned short DT[KLDataDTCount]; // 配置寄存器 // 系统状态寄存器 // 特殊寄存器 // 调试,监控寄存器 union { - unsigned int SDD[128]; - unsigned short SDT[256]; - unsigned char SDB[512]; + unsigned int SDD[KLDataSDTCount/2]; + unsigned short SDT[KLDataSDTCount]; + unsigned char SDB[KLDataSDTCount*2]; struct { unsigned int EffJumperSW; unsigned int CurJumperSW; @@ -252,11 +403,19 @@ extern stKMem KMem; +extern const stKMInfoBlock KMInfoBlock; int KMachineInit(void); -int ReadFlashMem(void * pBuf, void * pAddrFlash, int nSize); -int WriteToFlashMemNoErase(void * pBuf, void * pAddrFlash, unsigned int nSize); -int EraseAndWriteToFlashMem(void * pBuf, void * pAddrFlash, unsigned int nSize); +int ReadFlashMem(void * pBuf, void * pAddrFlash, int nByteSize); +int WriteToFlashMemNoErase(void * pBuf, void * pAddrFlash, unsigned int nByteSize); +int EraseAndWriteToFlashMem(void * pBuf, void * pAddrFlash, unsigned int nByteSize); + +int ReadFactoryData(void * pDatabuf, int nByteCount); +int WriteFactoryData(void * pDataBuf, int nByteCount); + +// active Program bank +int ReadProgram(int nProgByteAddr, void *pBuf, int nByteSize, int nBank); +int WriteProgram(int nProgByteAddr, void * pBuf, int nByteSize, int nBank); int WriteSysCfgToFlash(pKMSysCfg theKMSysCfg); int ReadSysCfgFromFlash(pKMSysCfg theKMSysCfg); @@ -267,4 +426,10 @@ int LoadRunStat(pRunStat theRunStat); int SaveRunStat(pRunStat theRunStat); + +unsigned char GetCoilValue(unsigned char nCoilType, unsigned short nCoilAddr); +int SetCoilValue(unsigned char nCoilType, unsigned short nCoilAddr, unsigned char nCoilValue); +int GetVarData(int nDataType, int nDataAddr); +int SetVarData(int nDataType, int nDataAddr, int nDataValue); + #endif /* __KLPROTOCOL_H__ */ -- Gitblit v1.9.1