提交 | 用户 | age
|
bfc108
|
1 |
/**
|
Q |
2 |
******************************************************************************
|
|
3 |
* @file : KMachine.h
|
|
4 |
* @brief : Header for KMachine.c file.
|
|
5 |
* This file contains the common defines of the application.
|
|
6 |
******************************************************************************
|
|
7 |
*/
|
|
8 |
#ifndef __KMACHINE_H__
|
|
9 |
#define __KMACHINE_H__
|
|
10 |
|
|
11 |
#define FACTORY_DATA_BASE (FLASH_BASE + 0x00007C00) //31k //and
|
|
12 |
#define FACTORY_DATA_PAGESIZE (0x00000400) //Page Size = 1K
|
|
13 |
#define FACOTRY_DATA_PAGES 1 // use 1 page(s)
|
|
14 |
|
|
15 |
#define STORE_PRG_BASE (FLASH_BASE + 0x00008000) //32k //and FLASH_BANK1_END
|
|
16 |
#define STORE_PRG_PAGESIZE (0x00000400) //Page Size = 1K
|
|
17 |
#define STORE_PRG_PAGES 4 //use 4 pages
|
|
18 |
|
e1f350
|
19 |
#define ALT_PRG_BASE (FLASH_BASE + 0x0000A000) //36k //and FLASH_BANK1_END
|
bfc108
|
20 |
#define ALT_PRG_PAGESIZE (0x00000400) //Page Size = 1K
|
Q |
21 |
#define ALT_PRG_PAGES 4 //use 4 pages
|
|
22 |
|
|
23 |
#define STORE_SYSREG_BASE (FLASH_BASE + 0x0000A000) //40k //and
|
|
24 |
#define STORE_SYSREG_PAGESIZE (0x00000400) //Page Size = 1K
|
|
25 |
#define STORE_SYSREG_PAGES 1 //use 1 pages
|
|
26 |
|
e1f350
|
27 |
#define STORE_RUNSTAT_BASE (FLASH_BASE + 0x0000A800) //44k K //and
|
bfc108
|
28 |
#define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K
|
Q |
29 |
#define STORE_RUNSTAT_PAGES 1 //use 1 pages
|
|
30 |
|
|
31 |
|
|
32 |
#define STORE_LOG_BASE (FLASH_BASE + 0x0000C000) //48k and FLASH_BANK1_END
|
|
33 |
#define STORE_LOG_PAGESIZE (0x00000400) //Page Size = 1K
|
|
34 |
#define STORE_LOG_PAGES 4 //use 4 pages
|
e1f350
|
35 |
|
bfc108
|
36 |
|
Q |
37 |
typedef unsigned char uchar;
|
|
38 |
typedef unsigned char UCHAR;
|
|
39 |
typedef unsigned short USHORT;
|
|
40 |
typedef unsigned int UINT;
|
|
41 |
typedef unsigned int uint32_t;
|
|
42 |
typedef unsigned int DWORD;
|
|
43 |
typedef unsigned short WORD;
|
|
44 |
typedef unsigned char BYTE;
|
|
45 |
|
|
46 |
enum enStoreCfg
|
|
47 |
{
|
|
48 |
START_SIGN = 0x55aa,
|
|
49 |
END_SIGN = 0x5aa5,
|
|
50 |
};
|
|
51 |
|
|
52 |
|
|
53 |
enum enInputFilter
|
|
54 |
{
|
|
55 |
InputFilter_None =0,
|
|
56 |
InputFilter_1mS =1,
|
|
57 |
InputFilter_2mS =2,
|
|
58 |
InputFilter_4mS =3,
|
|
59 |
InputFilter_8mS =4,
|
|
60 |
InputFilter_16mS =5,
|
|
61 |
InputFilter_32mS =6,
|
|
62 |
InputFilter_64mS =7,
|
|
63 |
InputFilter_128mS =8,
|
|
64 |
InputFilter_256mS =9,
|
|
65 |
};
|
|
66 |
|
|
67 |
enum enOutputHold
|
|
68 |
{
|
|
69 |
Output_Hold = 0,
|
|
70 |
Output_Set_0 = 1,
|
|
71 |
Output_Set_1 = 2,
|
|
72 |
};
|
|
73 |
|
|
74 |
enum enPortType
|
|
75 |
{
|
|
76 |
PortType_Com = 0, //计算机通讯
|
|
77 |
PortType_Gen = 1, //通用通讯,自由口
|
|
78 |
PortType_KLink = 2, //KlinkͨѶ
|
|
79 |
PortType_KBus = 3, //KBusͨѶ
|
|
80 |
PortType_KNet = 4, // KNetͨѶ
|
|
81 |
PortType_ModbusRTU = 5, //Modbus RTU ͨѶ
|
|
82 |
};
|
|
83 |
|
|
84 |
enum enKeventType
|
|
85 |
{
|
|
86 |
EventTypeNone = 0,
|
|
87 |
EventTypePowerUp = 1,
|
|
88 |
EventTypePowerDown = 2,
|
|
89 |
EventTypePowerRecover = 3,
|
|
90 |
EventTypeConnected = 4,
|
|
91 |
EventTypeLostCon = 5,
|
|
92 |
EventTypeSetTime = 6,
|
|
93 |
EventTypeSysCfg = 7,
|
|
94 |
EventTypeProg = 8,
|
|
95 |
EventTypeForce = 9,
|
|
96 |
EventTypeClearEvent = 10,
|
|
97 |
|
|
98 |
|
|
99 |
EventType
|
|
100 |
};
|
e1f350
|
101 |
typedef struct tagInfoBlock
|
Q |
102 |
{
|
|
103 |
USHORT nDeviceType;
|
|
104 |
USHORT ProgVer;
|
|
105 |
USHORT KlinkVer;
|
|
106 |
USHORT nCapacity;
|
|
107 |
UCHAR nDInput;
|
|
108 |
UCHAR nDOutput;
|
|
109 |
UCHAR nAInput;
|
|
110 |
UCHAR nAOutput;
|
|
111 |
UCHAR nHInput;
|
|
112 |
UCHAR nHOutput;
|
|
113 |
UCHAR nExt1;
|
|
114 |
UCHAR nEXT2;
|
|
115 |
|
|
116 |
}stKMInfoBlock;
|
|
117 |
|
bfc108
|
118 |
typedef struct tagKMFuncParam
|
Q |
119 |
{
|
|
120 |
USHORT EnablePLC:1; //使能内部PLC功能
|
|
121 |
USHORT RunMode; //工作模式
|
|
122 |
}stKMFuncParam;
|
|
123 |
|
|
124 |
// 输入输出地址映射
|
|
125 |
|
|
126 |
typedef struct tagComPortParam
|
|
127 |
{
|
e1f350
|
128 |
USHORT PortType:4; /* 0-5=Com,Gen,KLink,KBus,KNet,RTU */
|
bfc108
|
129 |
USHORT ByteSize:2; /* 0-1=Number of bits/byte, 7-8 */
|
Q |
130 |
USHORT Parity:4; /* 0-4=None,Odd,Even,Mark,Space */
|
|
131 |
USHORT StopBits:2; /* 0,1,2 = 1, 1.5, 2 */
|
|
132 |
USHORT EofChar:2; /* 0,1,2 = None, CR, CR+LF, ETX; End of character */
|
|
133 |
USHORT SofChar:2; /* 0,1,2 = None, STX */
|
|
134 |
USHORT BaudRate; /* =*100 Baudrate at which running */
|
|
135 |
}stComPortParam;
|
|
136 |
|
|
137 |
typedef struct tagInputFilterParam
|
|
138 |
{
|
|
139 |
BYTE Filter0:4;
|
|
140 |
BYTE Filter1:4;
|
|
141 |
|
|
142 |
}stInputFilterParam;
|
|
143 |
|
|
144 |
typedef struct tagOutputHoldParam
|
|
145 |
{
|
|
146 |
BYTE Hold1:4;
|
|
147 |
BYTE Hold2:4;
|
|
148 |
}stOutputHoldParam;
|
|
149 |
|
|
150 |
#pragma anon_unions
|
|
151 |
typedef struct tagMSysCfg
|
|
152 |
{
|
|
153 |
unsigned short Sign1;
|
|
154 |
unsigned short Seq1;
|
|
155 |
UINT cfgvar2;
|
|
156 |
stComPortParam Ports[2];
|
|
157 |
stOutputHoldParam OutputParams[16];
|
|
158 |
stInputFilterParam InputParams[16];
|
|
159 |
|
|
160 |
UINT cfgvar3;
|
|
161 |
UINT cfgvar4;
|
|
162 |
UINT cfgvar5;
|
|
163 |
UINT cfgvar6;
|
|
164 |
UINT cfgvar7;
|
|
165 |
UINT cfgvar8;
|
|
166 |
UINT cfgvar9;
|
|
167 |
UINT cfgvar10;
|
|
168 |
UINT cfgvar11;
|
|
169 |
UINT cfgvar12;
|
|
170 |
UINT cfgvar13;
|
|
171 |
UINT cfgvar14;
|
|
172 |
UINT cfgvar15;
|
|
173 |
UINT cfgvar16;
|
|
174 |
UINT Space1[5];
|
|
175 |
|
|
176 |
unsigned short CRC1;
|
|
177 |
unsigned short EndSign1;
|
|
178 |
}stKMSysCfg,* pKMSysCfg;
|
|
179 |
|
e1f350
|
180 |
/*
|
Q |
181 |
typedef struct tagFactData
|
|
182 |
{
|
|
183 |
USHORT Sign; //
|
|
184 |
USHORT nLength; //
|
|
185 |
UCHAR LOT_NO[16]; //
|
|
186 |
UINT MANDate; //
|
|
187 |
UINT SN; //
|
|
188 |
UINT REV1[24]; //
|
|
189 |
USHORT rev9;
|
|
190 |
USHORT CRC;
|
|
191 |
|
|
192 |
}stFactData;
|
|
193 |
*/
|
bfc108
|
194 |
typedef struct tagFactoryData //工厂量产参数,数据
|
Q |
195 |
{
|
e1f350
|
196 |
USHORT Sign1;
|
Q |
197 |
USHORT Seq1;
|
|
198 |
USHORT nModelNo;
|
|
199 |
USHORT nModelVer;
|
|
200 |
UINT nLotNo;
|
|
201 |
UINT nProductDateTime;
|
|
202 |
UINT SN1;
|
|
203 |
UINT nProtocalVer;
|
|
204 |
UINT nDefaultFunc;
|
|
205 |
UCHAR ModelStr[16];
|
|
206 |
UCHAR LOT_NO[16]; //
|
|
207 |
UCHAR SNStr[16];
|
bfc108
|
208 |
unsigned short CRC1;
|
Q |
209 |
unsigned short EndSign1;
|
|
210 |
|
|
211 |
}stFactoryData,* pFactoryData;
|
|
212 |
|
|
213 |
typedef struct tagEventLog
|
|
214 |
{
|
|
215 |
unsigned short Sign1;
|
|
216 |
unsigned short Seq1;
|
|
217 |
unsigned int nTime;
|
|
218 |
unsigned short nType;
|
|
219 |
unsigned short nParam1;
|
|
220 |
unsigned int nParam2;
|
|
221 |
}stEventLog,* pEventLog;
|
|
222 |
|
|
223 |
typedef struct tagRunStat
|
|
224 |
{
|
|
225 |
unsigned short Sign1;
|
|
226 |
unsigned short Seq1;
|
e1f350
|
227 |
volatile unsigned short PowerCount; //
|
Q |
228 |
volatile unsigned short Reserved1;
|
|
229 |
volatile unsigned int UpTime; //Seconds;
|
|
230 |
volatile unsigned int UserData1;
|
|
231 |
volatile unsigned short WorkMode;
|
|
232 |
volatile unsigned short WorkMode2;
|
|
233 |
volatile unsigned short nBinProgBank;
|
|
234 |
volatile unsigned short nBinProgSize;
|
|
235 |
unsigned int Reserved2[1];
|
bfc108
|
236 |
unsigned short CRC1;
|
Q |
237 |
unsigned short EndSign1;
|
|
238 |
}stRunStat, *pRunStat;
|
|
239 |
|
|
240 |
extern stRunStat KMRunStat;
|
|
241 |
|
|
242 |
//stStoreCfg * GetCurStoreCfgAddr(void );
|
|
243 |
//stStoreCfg * GetNextStoreCfgAddr(stStoreCfg * CurCfg );
|
|
244 |
|
|
245 |
extern stKMSysCfg KMSysCfg;
|
e1f350
|
246 |
|
Q |
247 |
#define TYPECOIL 0x00
|
|
248 |
#define TYPEDATA 0x80
|
|
249 |
|
|
250 |
enum enKLCoilTypes
|
|
251 |
{
|
|
252 |
KLCoilTypeX = 0 | TYPECOIL , //X Input
|
|
253 |
KLCoilTypeY = 1 | TYPECOIL, //Y Output
|
|
254 |
KLCoilTypeR = 2 | TYPECOIL, //R register
|
|
255 |
KLCoilTypeLX = 3 | TYPECOIL, //Link register
|
|
256 |
KLCoilTypeLY = 4 | TYPECOIL, //Link register
|
|
257 |
KLCoilTypeT = 5 | TYPECOIL, //Timer
|
|
258 |
KLCoilTypeC = 6 | TYPECOIL, //Counter
|
|
259 |
KLCoilTypeLR = 7 | TYPECOIL, //Link register
|
|
260 |
KLCoilTypeSR = 8 | TYPECOIL, //Link register
|
|
261 |
|
|
262 |
};
|
|
263 |
enum enKLDataTypes
|
|
264 |
{
|
|
265 |
KLDataTypeDEC = 0 | TYPEDATA,
|
|
266 |
KLDataTypeHEX = 1 | TYPEDATA,
|
|
267 |
KLDataTypeFloat = 2 | TYPEDATA,
|
|
268 |
KLDataTypeWX = 3 | TYPEDATA,
|
|
269 |
KLDataTypeWY = 4 | TYPEDATA,
|
|
270 |
KLDataTypeWR = 5 | TYPEDATA,
|
|
271 |
KLDataTypeWLX = 6 | TYPEDATA,
|
|
272 |
KLDataTypeWLY = 7 | TYPEDATA,
|
|
273 |
KLDataTypeDT = 8 | TYPEDATA,
|
|
274 |
KLDataTypeSDT = 9 | TYPEDATA,
|
|
275 |
KLDataTypeWSR = 10 | TYPEDATA,
|
|
276 |
KLDataTypeSV = 11 | TYPEDATA,
|
|
277 |
KLDataTypeEV = 12 | TYPEDATA,
|
|
278 |
KLDataTypeLD = 13 | TYPEDATA,
|
|
279 |
KLDataSysCfg = 25 | TYPEDATA,
|
|
280 |
KLDataTypeFlash = 33 | TYPEDATA,
|
|
281 |
KLDataTypeTest = 254 | TYPEDATA,
|
|
282 |
};
|
|
283 |
|
|
284 |
enum enKLDataCounts
|
|
285 |
{
|
|
286 |
KLDataDTCount = 256,
|
|
287 |
KLDataSDTCount = 256,
|
|
288 |
|
|
289 |
KLDataWXCount = 16,
|
|
290 |
KLDataWYCount = 16,
|
|
291 |
KLDataWRCount = 16,
|
|
292 |
KLDataLDCount = 64,
|
|
293 |
KLDataWLCount = 8,
|
|
294 |
|
|
295 |
KLCoilXCount = KLDataWXCount * 16,
|
|
296 |
KLCoilYCount = KLDataWYCount * 16,
|
|
297 |
KLCoilRCount = KLDataWRCount * 16,
|
|
298 |
|
|
299 |
KLCoilTCount = 64,
|
|
300 |
KLCoilCCount = KLCoilTCount,
|
|
301 |
|
|
302 |
KLDataSVCount = KLCoilTCount,
|
|
303 |
KLDataEVCount = KLCoilTCount,
|
|
304 |
|
|
305 |
KLCoilLXCount = 128,
|
|
306 |
KLCoilLYCount = 128,
|
|
307 |
KLCoilLRCount = 128,
|
|
308 |
KLCoilSRCount = 128,
|
|
309 |
|
|
310 |
};
|
|
311 |
#define TOTAL_WDFS (16) //Total DF Count
|
|
312 |
#define TOTAL_CurVAL (16) //
|
|
313 |
#define TOTALTIMERS (64)
|
|
314 |
|
|
315 |
typedef struct tagTimerStat
|
|
316 |
{
|
|
317 |
unsigned short nScale:2;//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S
|
|
318 |
unsigned short nType:1; //0 : timer 1:counter ;
|
|
319 |
unsigned short nDir:1; //0 : count down. 1 count up;
|
|
320 |
unsigned short nInited:1;
|
|
321 |
unsigned short bSet:1;
|
|
322 |
unsigned short bTon:1;
|
|
323 |
|
|
324 |
}stTimerStat;
|
|
325 |
|
|
326 |
typedef struct tagTimer
|
|
327 |
{
|
|
328 |
unsigned int LastActTime;
|
|
329 |
union {
|
|
330 |
unsigned short StatByte;
|
|
331 |
struct
|
|
332 |
{
|
|
333 |
unsigned short nScale:2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S
|
|
334 |
unsigned short nType:1; //0 : timer 1 : counter ;
|
|
335 |
unsigned short nDir:1; //0 : count down. 1 count up;
|
|
336 |
unsigned short nInited:1;
|
|
337 |
unsigned short bSet:1;
|
|
338 |
unsigned short bTon:1;
|
|
339 |
|
|
340 |
};
|
|
341 |
// stTimerStat Stat;
|
|
342 |
};
|
|
343 |
}stTimer;
|
|
344 |
|
bfc108
|
345 |
typedef struct tagKMem
|
Q |
346 |
{
|
e1f350
|
347 |
unsigned short WDFs[TOTAL_WDFS];
|
Q |
348 |
unsigned char CurVALs[TOTAL_CurVAL];
|
|
349 |
unsigned char CurVAL;
|
|
350 |
stTimer Timers[TOTALTIMERS];
|
|
351 |
|
|
352 |
unsigned short WX[KLDataWXCount]; //本机的X和Y
|
|
353 |
unsigned short WY[KLDataWYCount]; //本机的X和Y
|
|
354 |
unsigned short WR[KLDataWRCount];
|
|
355 |
|
|
356 |
unsigned short WT[16];
|
|
357 |
|
|
358 |
unsigned short WC[16];
|
|
359 |
unsigned short EV[KLDataEVCount];
|
|
360 |
unsigned short SV[KLDataSVCount];
|
|
361 |
|
|
362 |
|
bfc108
|
363 |
unsigned short WLX[16]; //虚拟的X和Y,远程通讯时映射用。
|
Q |
364 |
unsigned short WLY[16];
|
e1f350
|
365 |
unsigned short WLR[16];
|
bfc108
|
366 |
unsigned short WSR[16];
|
e1f350
|
367 |
|
Q |
368 |
unsigned short DT[KLDataDTCount];
|
bfc108
|
369 |
|
Q |
370 |
// 配置寄存器
|
|
371 |
// 系统状态寄存器
|
|
372 |
// 特殊寄存器
|
|
373 |
// 调试,监控寄存器
|
|
374 |
union {
|
e1f350
|
375 |
unsigned int SDD[KLDataSDTCount/2];
|
Q |
376 |
unsigned short SDT[KLDataSDTCount];
|
|
377 |
unsigned char SDB[KLDataSDTCount*2];
|
bfc108
|
378 |
struct {
|
Q |
379 |
unsigned int EffJumperSW;
|
|
380 |
unsigned int CurJumperSW;
|
|
381 |
unsigned int haltick;
|
|
382 |
unsigned int nRunCount;
|
|
383 |
unsigned int RunStat;
|
|
384 |
unsigned int ErrStat;
|
|
385 |
unsigned int PwrOnCount;
|
|
386 |
unsigned int ThisRunTime;
|
|
387 |
unsigned int TotalRunTime;
|
|
388 |
unsigned int CurTimeSec;
|
|
389 |
unsigned int PwrFailCount;
|
|
390 |
unsigned int LastPwrFailTime;
|
|
391 |
unsigned int LastScanTime;
|
|
392 |
unsigned int ScanTimeuS;
|
|
393 |
unsigned int MinScanTimeuS;
|
|
394 |
unsigned int MaxScanTimeuS;
|
|
395 |
unsigned int nEventCount;
|
|
396 |
unsigned int nEventMinIndex;
|
|
397 |
unsigned int nEventMaxIndex;
|
|
398 |
unsigned int Rev2[5];
|
|
399 |
unsigned short ADCValues[20];
|
|
400 |
};
|
|
401 |
};
|
|
402 |
}stKMem;
|
|
403 |
|
|
404 |
|
|
405 |
extern stKMem KMem;
|
e1f350
|
406 |
extern const stKMInfoBlock KMInfoBlock;
|
bfc108
|
407 |
|
Q |
408 |
int KMachineInit(void);
|
e1f350
|
409 |
int ReadFlashMem(void * pBuf, void * pAddrFlash, int nByteSize);
|
Q |
410 |
int WriteToFlashMemNoErase(void * pBuf, void * pAddrFlash, unsigned int nByteSize);
|
|
411 |
int EraseAndWriteToFlashMem(void * pBuf, void * pAddrFlash, unsigned int nByteSize);
|
|
412 |
|
|
413 |
int ReadFactoryData(void * pDatabuf, int nByteCount);
|
|
414 |
int WriteFactoryData(void * pDataBuf, int nByteCount);
|
|
415 |
|
|
416 |
// active Program bank
|
|
417 |
int ReadProgram(int nProgByteAddr, void *pBuf, int nByteSize, int nBank);
|
|
418 |
int WriteProgram(int nProgByteAddr, void * pBuf, int nByteSize, int nBank);
|
bfc108
|
419 |
|
Q |
420 |
int WriteSysCfgToFlash(pKMSysCfg theKMSysCfg);
|
|
421 |
int ReadSysCfgFromFlash(pKMSysCfg theKMSysCfg);
|
|
422 |
|
|
423 |
int AddEventLog(uint32_t nTime, USHORT nEvent, USHORT nParam1, UINT nParam2);
|
|
424 |
pEventLog GetEventLogAddr(int nIndex);
|
|
425 |
int ClearEventLog(void);
|
|
426 |
int LoadRunStat(pRunStat theRunStat);
|
|
427 |
int SaveRunStat(pRunStat theRunStat);
|
|
428 |
|
e1f350
|
429 |
|
Q |
430 |
unsigned char GetCoilValue(unsigned char nCoilType, unsigned short nCoilAddr);
|
|
431 |
int SetCoilValue(unsigned char nCoilType, unsigned short nCoilAddr, unsigned char nCoilValue);
|
|
432 |
int GetVarData(int nDataType, int nDataAddr);
|
|
433 |
int SetVarData(int nDataType, int nDataAddr, int nDataValue);
|
|
434 |
|
bfc108
|
435 |
#endif /* __KLPROTOCOL_H__ */
|