QuakeGod
2022-10-17 448d6c050697a6bb7f4b7b02f08ef8fc8e5cd027
Inc/KMachine.h
@@ -49,8 +49,32 @@
#define LoHofB(x) ((x)&0xf)
#define HiHofB(x) (((x)>>4)&0xf)
//  信息块
//  工厂参数配置块
//  用户/系统参数配置块
//
//
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;
enum enStoreCfg
{
   CFG_VER      = 0x100,
   START_SIGN = 0x55aa,
   END_SIGN   =   0x5aa5,
};
@@ -119,22 +143,6 @@
   
   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
{
@@ -144,59 +152,77 @@
// 输入输出地址映射
typedef struct tagComPortParam
typedef struct tagComPortParam         //4 Bytes
{
   USHORT PortType:4;            /* 0-5=Com,Gen,KLink,KBus,KNet,RTU */
   USHORT Station;               /* 0=From jumper */
   USHORT WorkMode;            /* 0-5=Com,Gen,KLink,KBus,KNet,RTU */
   USHORT BaudRate;       /* =*100 Baudrate at which running       */
//   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               */
  USHORT EofChar:2;         /* 0,1,2 = None, CR, CR+LF, ETX;  End of character  */
   USHORT EndType:2;               /* 0=ByChar, 1= ByTime */
  USHORT EofChar:4;         /* 0,1,2 = None, CR, CR+LF, ETX;  End of character  */
   USHORT SofChar:2;               /* 0,1,2 = None, STX */
   USHORT BaudRate;       /* =*100 Baudrate at which running       */
   USHORT EndTime;
   USHORT RecvAddr;
   USHORT RecvSize;
}stComPortParam;
typedef struct tagInputFilterParam
typedef struct tagInputFilterParam      // 1 Bytes
{
   BYTE Filter0:4;
   BYTE Filter1:4;
}stInputFilterParam;
typedef struct tagOutputHoldParam
typedef struct tagOutputHoldParam         //1 Bytes
{
   BYTE Hold1:4;
   BYTE Hold2:4;
}stOutputHoldParam;   
#pragma anon_unions
typedef struct tagMSysCfg
typedef struct tagKMSysCfg      //120 Bytes total
{
   USHORT Version;                              // SC0   // 2 Bytes
   USHORT workmode;                           // SC1  // 2 Bytes 0=From jumper
   USHORT SwitchFunc;                        // SC2  // 2 Bytes
   USHORT OutMappings[6];                              //12 Bytes //输出映射
   stComPortParam PortParams[2];                     // 8 Bytes
   stOutputHoldParam OutputParams[16];            //16 Bytes
   stInputFilterParam InputParams[16];            //16 Bytes
   UINT cfgvar3;                                             // 4 Bytes
   UINT cfgvar4;                                             // 4 Bytes
   UINT cfgvar5;                                             // 4 Bytes
   UINT cfgvar6;                                             // 4 Bytes
   UINT cfgvar7;                                             // 4 Bytes
   UINT cfgvar8;                                             // 4 Bytes
   UINT cfgvar9;                                             // 4 Bytes
   UINT cfgvar10;                                          // 4 Bytes
   UINT cfgvar11;                                          // 4 Bytes
   UINT cfgvar12;                                          // 4 Bytes
   UINT cfgvar13;                                          // 4 Bytes
   UINT cfgvar14;                                          // 4 Bytes
   UINT cfgvar15;                                          // 4 Bytes
   UINT cfgvar16;                                          // 4 Bytes
   UINT Space1[5];                                          //20 Bytes
}stKMSysCfg,* pKMSysCfg;
typedef struct tagStoredKMSysCfg
{
   unsigned short Sign1;
   unsigned short Seq1;
   UINT cfgvar2;
   stComPortParam Ports[2];
   stOutputHoldParam OutputParams[16];
   stInputFilterParam InputParams[16];
   UINT cfgvar3;
   UINT cfgvar4;
   UINT cfgvar5;
   UINT cfgvar6;
   UINT cfgvar7;
   UINT cfgvar8;
   UINT cfgvar9;
   UINT cfgvar10;
   UINT cfgvar11;
   UINT cfgvar12;
   UINT cfgvar13;
   UINT cfgvar14;
   UINT cfgvar15;
   UINT cfgvar16;
   UINT Space1[5];
   stKMSysCfg theKMSysCfg;
   unsigned short CRC1;
   unsigned short EndSign1;
}stKMSysCfg,* pKMSysCfg;
}stStoredKMSysCfg,*pStoredKMSysCfg;
/*
typedef struct tagFactData
@@ -263,7 +289,7 @@
//stStoreCfg * GetCurStoreCfgAddr(void );
//stStoreCfg * GetNextStoreCfgAddr(stStoreCfg * CurCfg );
extern stKMSysCfg KMSysCfg;
extern stStoredKMSysCfg storedKMSysCfg;
#define TYPECOIL 0x00
#define TYPEDATA 0x80
@@ -397,6 +423,7 @@
   unsigned short DT[KLDataDTCount];
   unsigned char DTB[KLDataDTCount*2];
};   
   // 配置寄存器
   // 系统状态寄存器
   // 特殊寄存器
@@ -451,8 +478,8 @@
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);
int WriteSysCfgToFlash(pStoredKMSysCfg theStoredKMSysCfg);
int ReadSysCfgFromFlash(pStoredKMSysCfg theStoredKMSysCfg);
int AddEventLog(uint32_t nTime, USHORT nEvent, USHORT nParam1, UINT nParam2);
pEventLog GetEventLogAddr(int nIndex);