| | |
| | | #ifndef __KMACHINE_H__ |
| | | #define __KMACHINE_H__ |
| | | |
| | | #define FLASH_PAGESIZE (0x00000400) //Page Size = 1K |
| | | |
| | | #define FACTORY_DATA_BASE (FLASH_BASE + 0x00007C00) //31k //and |
| | | #define FACTORY_DATA_PAGESIZE (0x00000400) //Page Size = 1K |
| | | //#define FACTORY_DATA_PAGESIZE (0x00000400) //Page Size = 1K |
| | | #define FACOTRY_DATA_PAGES 1 // use 1 page(s) |
| | | |
| | | #define STORE_PRG_BASE (FLASH_BASE + 0x00008000) //32k //and FLASH_BANK1_END |
| | | #define STORE_PRG_PAGESIZE (0x00000400) //Page Size = 1K |
| | | //#define STORE_PRG_PAGESIZE (0x00000400) //Page Size = 1K |
| | | #define STORE_PRG_PAGES 8 //use 4 pages |
| | | |
| | | #define ALT_PRG_BASE (FLASH_BASE + 0x0000A000) //40k //and FLASH_BANK1_END |
| | | #define ALT_PRG_PAGESIZE (0x00000400) //Page Size = 1K |
| | | //#define ALT_PRG_PAGESIZE (0x00000400) //Page Size = 1K |
| | | #define ALT_PRG_PAGES 8 //use 4 pages |
| | | |
| | | #define STORE_SYSREG_BASE (FLASH_BASE + 0x0000C000) //48k //and |
| | | #define STORE_SYSREG_PAGESIZE (0x00000400) //Page Size = 1K |
| | | //#define STORE_SYSREG_PAGESIZE (0x00000400) //Page Size = 1K |
| | | #define STORE_SYSREG_PAGES 1 //use 1 pages |
| | | |
| | | #define STORE_RUNSTAT_BASE (FLASH_BASE + 0x0000C800) //50k K //and |
| | | #define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K |
| | | //#define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K |
| | | #define STORE_RUNSTAT_PAGES 1 //use 1 pages |
| | | |
| | | #define STORE_PLC_ANNO_BASE (FLASH_BASE + 0x0000D000) //56k |
| | | #define STORE_PLC_ANNO_PAGES 4 // use 4 pages , 1K /page |
| | | |
| | | #define STORE_LOG_BASE (FLASH_BASE + 0x0000D000) //52k and FLASH_BANK1_END |
| | | #define STORE_LOG_PAGESIZE (0x00000400) //Page Size = 1K |
| | | |
| | | #define STORE_LOG_BASE (FLASH_BASE + 0x0000E000) //52k 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; |
| | | typedef unsigned short ushort; |
| | | typedef unsigned short USHORT; |
| | | typedef unsigned int UINT; |
| | | typedef unsigned int uint32_t; |
| | |
| | | // 用户/系统参数配置块 |
| | | // |
| | | // |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagInfoBlock // 23 bytes |
| | | { |
| | | // USHORT nBlockLenth; |
| | | USHORT nDeviceTypeVer; //device type x.y |
| | | // UCHAR nDevierVer; |
| | | USHORT ProgVer; //prog version x.y |
| | | union { |
| | | USHORT nProgVer; //prog version x.y |
| | | struct { |
| | | UCHAR nProgVerMinor; |
| | | UCHAR nProgVerMajor; |
| | | }; |
| | | }; |
| | | USHORT KLinkVer; //x.y |
| | | USHORT KBusVer; //x.y |
| | | // USHORT KNetVer; //x.y |
| | |
| | | |
| | | }stFactoryData,* pFactoryData; |
| | | |
| | | typedef struct tagNewAppInfoBlock |
| | | { |
| | | unsigned short Sign; |
| | | unsigned short Version; |
| | | unsigned int Length; |
| | | unsigned int nCRC; |
| | | |
| | | }stNewAppInfoBlock,*pNewAppInfoBlock; |
| | | |
| | | enum enStoreCfg |
| | | { |
| | |
| | | BYTE Hold2:4; |
| | | }stOutputHoldParam; |
| | | |
| | | #pragma anon_unions |
| | | typedef struct tagOutMapping |
| | | { |
| | | USHORT bitPos:4; |
| | | USHORT byteAddr:8; |
| | | USHORT type:4; |
| | | }stOutMapping; |
| | | |
| | | typedef struct tagCfgBlockInfo |
| | | { |
| | | UCHAR nBlockType; |
| | | UCHAR nBlockSize; |
| | | }stCfgBlockInfo; |
| | | |
| | | 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 pad1; // 2 Bytes |
| | | USHORT nCfgBlockCount; // 2 Bytes |
| | | |
| | | stComPortParam PortParams[2]; // 8 Bytes |
| | | stInputFilterParam InputParams[16]; //16 Bytes |
| | | stOutputHoldParam OutputParams[16]; //16 Bytes |
| | | |
| | | USHORT OutMappings[6]; //12 Bytes //输出映射 |
| | | union{ |
| | | USHORT value; //12 Bytes //输出映射 |
| | | stOutMapping; |
| | | }OutMappings[8]; |
| | | |
| | | USHORT nProgBank; |
| | | USHORT nProgSize; |
| | | USHORT nAnnoSize; |
| | | USHORT nCount; |
| | | |
| | | UINT cfgvar3; // 4 Bytes |
| | | UINT cfgvar4; // 4 Bytes |
| | | UINT cfgvar5; // 4 Bytes |
| | | UINT cfgvar6; // 4 Bytes |
| | | UINT cfgvar7; // 4 Bytes |
| | | stCfgBlockInfo CfgBlockInfos[8]; |
| | | UINT cfgvar8; // 4 Bytes |
| | | UINT cfgvar9; // 4 Bytes |
| | | UINT cfgvar10; // 4 Bytes |
| | | UINT cfgvar11; // 4 Bytes |
| | | UINT cfgvar12; // 4 Bytes |
| | | // UINT cfgvar11; // 4 Bytes |
| | | // UINT cfgvar12; // 4 Bytes |
| | | // UINT cfgvar13; // 4 Bytes |
| | | // UINT cfgvar14; // 4 Bytes |
| | | // UINT cfgvar15; // 4 Bytes |
| | |
| | | KLDataTypeWDT = 41 | TYPEDATA, //调试监控数据 |
| | | KLDataTypeKBD = 51 | TYPEDATA, //KBus 调试数据 |
| | | KLDataTypeKWLD = 52 | TYPEDATA, //无线调试数据 |
| | | KLDataTypeNewApp = 61 | TYPEDATA, // New FirmWare |
| | | KLDataTypeNewAppInfo = 62 | TYPEDATA, // New Firmware Info Block; |
| | | KLDataTypeTest = 254 | TYPEDATA, |
| | | }; |
| | | |
| | | #define TOTAL_WDFS (32) //Total DF Count |
| | | #define TOTAL_CurVAL (16) // |
| | | #define TOTALTIMERS (64) |
| | | |
| | | enum enKLDataCounts |
| | | { |
| | |
| | | |
| | | }; |
| | | |
| | | typedef struct tagTimerStat |
| | | |
| | | // 通信端口, 注册到 KMachine 里, 统一管理 |
| | | |
| | | enum enPortHardType |
| | | { |
| | | 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; |
| | | PortHardType_None = 0, // 空接口,无类型 |
| | | PortHardType_SOFT = 1, // 软件虚拟接口,可能是隧道等. |
| | | PortHardType_UART = 2, // 串行接口 |
| | | PortHardType_RS232 = 3, // 232接口 |
| | | PortHardType_RS485 = 4, // 485接口 |
| | | PortHardType_SLP = 5, // 单总线接口 |
| | | PortHardType_RF = 6, // 无线接口 |
| | | PortHardType_LORA = 7, // LoRa无线接口 |
| | | PortHardType_OPTI = 8, // 光纤接口 |
| | | PortHardType_ETH = 9, // 以太网接口 |
| | | PortHardType_WIFI = 10, // WiFi接口 |
| | | PortHardType_BT = 11, // 以太网接口 |
| | | |
| | | }; |
| | | enum enPortUseType |
| | | { |
| | | PortUse_Default = 0, //默认 |
| | | PortUse_Console = 1, //控制台接口 |
| | | PortUse_KLink = 2, //KLink通讯 |
| | | PortUse_KBus = 3, //KBus通讯 |
| | | PortUse_KNet = 4, // KNet通讯 |
| | | PortUse_SLP = 5, // SLP单总线 |
| | | PortUse_KRF = 6, // 无线通讯 |
| | | PortUse_ModbusRTU = 7, //Modbus RTU 通讯 |
| | | PortUse_ModbusTCP = 8, //Modbus TCP 通讯 |
| | | PortUse_Com = 9, // 计算机通讯 |
| | | PortUse_Gen = 10, //通用通讯,自由口 |
| | | }; |
| | | |
| | | typedef struct tagPortAbility |
| | | { |
| | | ushort ChildList:1; |
| | | ushort AccessChild:1; |
| | | ushort TranProg:1; |
| | | ushort TranCfg:1; |
| | | ushort Diag:1; |
| | | ushort TranOutBandData:1; |
| | | ushort Tunnel:1; |
| | | ushort TranFirmware:1; |
| | | ushort TranBlink:1; |
| | | |
| | | }stPortAbility; |
| | | |
| | | enum enServiceReqs |
| | | { |
| | | ReqNone, |
| | | ReqInit, |
| | | ReqReset, |
| | | ReqStop, |
| | | ReqRun, |
| | | ReqBlinkLED, |
| | | ReqStartDiag, |
| | | ReqStopDiag, |
| | | ReqPortChildInfo, |
| | | ReqPortChnInfo, |
| | | ReqUpdateFirm, |
| | | ReqUpdateFirmInfo, |
| | | |
| | | }stTimerStat; |
| | | ReqTransFirmware, |
| | | ReqTransCfg, |
| | | ReqTransProg, |
| | | ReqTransData, |
| | | ReqTransBlink, |
| | | ReqTransChild, |
| | | ReqTransInfo, |
| | | ReqTransOutBandData, |
| | | ReqRead1Bit, |
| | | ReqWrite1Bit, |
| | | ReqReadBits, |
| | | ReqWriteBits, |
| | | ReqReadData, |
| | | ReqWriteData, |
| | | ReqRemoteTran, |
| | | |
| | | }; |
| | | |
| | | typedef struct tagTimer |
| | | // 各端口 互联 通信 |
| | | typedef int (*CommFuncDef)(void * pInstance, int ReqId , int nParam1, int nParam2, void ** pData, unsigned short * len1); |
| | | typedef struct tagPortDef |
| | | { |
| | | 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; |
| | | USHORT nPortType; |
| | | struct { |
| | | UCHAR nPortHardType; |
| | | UCHAR nPortUseType; |
| | | }; |
| | | }; |
| | | }stTimer; |
| | | ushort ability; //能力, 获取子机信息等。 |
| | | uchar bEnable; |
| | | uchar bRunning; |
| | | uchar StationId; |
| | | uchar bMaster; |
| | | uchar nMaxStations; |
| | | uchar nCurStations; |
| | | uchar nHealth; |
| | | short PortConfigType; |
| | | short PortConfigSize; |
| | | short PortRunStatType; |
| | | short PortRunStatSize; |
| | | |
| | | void * pInstance; //通信结构实体 |
| | | void * pPortConfig; |
| | | void * pPortRunStatus; |
| | | CommFuncDef ReqCommFunc; //通信请求函数指针 |
| | | // func2 CommReq; |
| | | |
| | | }stPortDef,* pstPortDef; |
| | | |
| | | |
| | | typedef struct tagPortPtDef |
| | | { |
| | | void * pt; |
| | | |
| | | }stPortPtDef,* pstPortPtDef; |
| | | |
| | | typedef struct tagInterComm |
| | | { |
| | | int nId; |
| | | |
| | | }stInterComm; |
| | | |
| | | typedef struct tagKMem |
| | | { |
| | | unsigned short WDFs[TOTAL_WDFS]; |
| | | unsigned char CurVALs[TOTAL_CurVAL]; |
| | | unsigned char CurVAL; |
| | | stTimer Timers[TOTALTIMERS]; |
| | | |
| | | union { |
| | | unsigned short WX[KLDataWXCount]; //本机的X和Y |
| | | unsigned char WXB[KLDataWXCount*2]; |
| | |
| | | }; |
| | | 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]; |
| | | //虚拟的X和Y,远程通讯时映射用。 |
| | | union{ |
| | | ushort WLX[16]; |
| | | uchar WLXB[32]; |
| | | }; |
| | | union{ |
| | | ushort WLY[16]; |
| | | uchar WLYB[32]; |
| | | }; |
| | | unsigned short WFX[16]; |
| | | unsigned short WFY[16]; |
| | | |
| | | unsigned short WLR[16]; |
| | | unsigned short WSR[16]; |
| | | |
| | | union { |
| | |
| | | unsigned char WDB[KLDataWDTCount*2]; |
| | | }; |
| | | |
| | | int nTotalPorts; |
| | | stPortDef * pPorts[8]; |
| | | |
| | | }stKMem; |
| | | |
| | | |
| | | |
| | | extern stKMem KMem; |
| | |
| | | extern volatile int OldPowerDownEventTime; |
| | | |
| | | int KMachineInit(void); |
| | | int KMachineLoopProc(void); |
| | | |
| | | /* |
| | | 向KMachine 注册 通讯端口,以便通讯端口之间的功能互通 |
| | | */ |
| | | int KMRegisterPort(ushort nType,stPortDef * thePortParam); |
| | | |
| | | int KMPortReqFunc(int nPortIndex,int nReqId, int nParam1, int nParam2, void ** pData, unsigned short * nlen1); |
| | | |
| | | |
| | | 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 WriteToFlashMemNoErase(void * pBuf, void * pAddrFlash, unsigned int nByteSize); |
| | | int WriteToFlashAutoErase(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 ReadPLCProgram(int nBank, int nProgByteAddr, void *pBuf, int nByteSize); |
| | | int StartPLCProgram(int nBank, int nByteSize, int nCRC); |
| | | int WritePLCProgram(int nBank, int nProgByteAddr, void * pBuf, int nByteSize); |
| | | int FinishiPLCProgram(int nBank, int nByteSize, int nCRC ); |
| | | |
| | | int ReadPLCAnno(int nType, int nProgByteAddr, void *pBuf, int nByteSize); |
| | | int StartPLCAnno(int nType, int nByteSize, int nCRC); |
| | | int WritePLCAnno(int nType, int nProgByteAddr, void * pBuf, int nByteSize); |
| | | int FinishiPLCAnno(int nType, int nByteSize, int nCRC ); |
| | | |
| | | int WriteSysCfgToFlash(pStoredKMSysCfg theStoredKMSysCfg); |
| | | int ReadSysCfgFromFlash(pStoredKMSysCfg theStoredKMSysCfg); |
| | | |
| | | int KMRunService(int nSvrId, int nParam1, int nParam2, void **pData, unsigned short *nled1); |
| | | |
| | | int CheckEventLog(void); |
| | | int AddEventLog(uint32_t nTime, USHORT nEvent, USHORT nParam1, UINT nParam2); |
| | | pEventLog GetEventLogAddr(int nIndex); |
| | | int ClearEventLog(void); |
| | | int LoadRunStat(pRunStat theRunStat); |
| | | int SaveRunStat(pRunStat theRunStat); |
| | | |
| | | int WriteNewApp(int nProgByteAddr, void *pBuf, int nByteSize); |
| | | int WriteNewAppInfo(int nProgByteAddr, void *pBuf, int nByteSize); |
| | | |
| | | 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__ */ |
| | | typedef int (*KMSvCBDef) (int nChn, int nSvType, int ,void *, int); //Service Req callback func ,param is int ,int, int, void *,int; return int; |
| | | |
| | | |
| | | #endif /* __KMACHINE_H__ */ |