提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file : PLCfunctions.h |
|
4 |
* @brief : Header for PLCfunctions.c file. |
|
5 |
* This file contains the user functions defines of the application. |
|
6 |
****************************************************************************** |
|
7 |
*/ |
|
8 |
#ifndef __PLCFUNCTIONS_H__ |
|
9 |
#define __PLCFUNCTIONS_H__ |
|
10 |
#include "GlobalDef.h" |
|
11 |
#include "KMachine.h" |
|
12 |
|
842bb6
|
13 |
#if (ENABLE_PLC) |
Q |
14 |
|
483170
|
15 |
#define TICK_OF_MS (10) //1ms |
Q |
16 |
#define TICK_OF_RS (100) //10mS |
|
17 |
#define TICK_OF_XS (1000) //100mS |
|
18 |
#define TICK_OF_YS (10000) //1S |
842bb6
|
19 |
|
Q |
20 |
#define TOTAL_WDFS (32) //Total DF Count |
|
21 |
#define TOTAL_CurVAL (16) // |
|
22 |
#define TOTALTIMERS (64) |
|
23 |
|
|
24 |
#define PLC_PROGRAM_USE_BANK 1 |
|
25 |
|
|
26 |
typedef struct tagTimerStat |
|
27 |
{ |
|
28 |
unsigned short nScale:2;//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S |
|
29 |
unsigned short nType:1; //0 : timer 1:counter ; |
|
30 |
unsigned short nDir:1; //0 : count down. 1 count up; |
|
31 |
unsigned short nInited:1; |
|
32 |
unsigned short bSet:1; |
|
33 |
unsigned short bTon:1; |
|
34 |
|
|
35 |
}stTimerStat; |
|
36 |
|
|
37 |
typedef struct tagTimer |
|
38 |
{ |
|
39 |
unsigned int LastActTime; |
|
40 |
union { |
|
41 |
unsigned short StatByte; |
|
42 |
struct |
|
43 |
{ |
|
44 |
unsigned short nScale:2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S |
|
45 |
unsigned short nType:1; //0 : timer 1 : counter ; |
|
46 |
unsigned short nDir:1; //0 : count down. 1 count up; |
|
47 |
unsigned short nInited:1; |
|
48 |
unsigned short bSet:1; |
|
49 |
unsigned short bTon:1; |
|
50 |
|
|
51 |
}; |
|
52 |
// stTimerStat Stat; |
|
53 |
}; |
|
54 |
}stTimer; |
483170
|
55 |
|
Q |
56 |
#pragma anon_unions |
|
57 |
|
|
58 |
typedef struct tagPLCMem |
|
59 |
{ |
|
60 |
int bPLCRunning; |
|
61 |
int nScanCount; |
842bb6
|
62 |
unsigned short WDFs[TOTAL_WDFS]; |
Q |
63 |
unsigned char CurVALs[TOTAL_CurVAL]; |
|
64 |
unsigned char CurVAL; |
|
65 |
stTimer Timers[TOTALTIMERS]; |
|
66 |
unsigned short WT[16]; |
|
67 |
|
|
68 |
unsigned short WC[16]; |
|
69 |
unsigned short EV[KLDataEVCount]; |
|
70 |
unsigned short SV[KLDataSVCount]; |
|
71 |
|
483170
|
72 |
unsigned short ProgTrace[256]; |
Q |
73 |
|
|
74 |
}stPLCMem; |
|
75 |
|
|
76 |
enum enPLCOPs |
|
77 |
{ |
|
78 |
OP_NONE = 0, |
|
79 |
OP_NOP = 0, |
|
80 |
OP_ST = 1, // |
|
81 |
OP_ST_ = 2, // |
|
82 |
OP_AN = 3, // |
|
83 |
OP_AN_ = 4, // |
|
84 |
OP_OR = 5, // |
|
85 |
OP_OR_ = 6, // |
|
86 |
OP_NOT = 7, // |
|
87 |
OP_ANS = 8, // |
|
88 |
OP_ORS = 9, // |
|
89 |
|
|
90 |
OP_PSHS = 10, // |
|
91 |
OP_RDS = 11, // |
|
92 |
OP_POPS = 12, // |
|
93 |
|
|
94 |
OP_OUT = 16, // |
|
95 |
OP_SET = 17, // |
|
96 |
OP_RESET = 18, // |
|
97 |
OP_DF = 19, // |
|
98 |
OP_DF_ = 20, // |
|
99 |
|
|
100 |
OP_ST_EQ, // |
|
101 |
OP_ST_LT, // |
|
102 |
OP_ST_GT, // |
|
103 |
OP_ST_LE, // |
|
104 |
OP_ST_GE, // |
|
105 |
OP_ST_NE, // |
|
106 |
OP_AN_EQ, // |
|
107 |
OP_AN_LT, // |
|
108 |
OP_AN_GT, |
|
109 |
OP_AN_LE, |
|
110 |
OP_AN_GE, |
|
111 |
OP_AN_NE, |
|
112 |
OP_OR_EQ, |
|
113 |
OP_OR_LT, |
|
114 |
OP_OR_GT, |
|
115 |
OP_OR_LE, |
|
116 |
OP_OR_GE, |
|
117 |
OP_OR_NE, |
|
118 |
|
|
119 |
|
|
120 |
OP_MV = 51, |
|
121 |
OP_INC = 52, |
|
122 |
OP_ADD2 = 53, |
|
123 |
OP_ADD3 = 54, |
|
124 |
OP_DEC = 55, |
|
125 |
OP_SUB2 = 56, |
|
126 |
OP_SUB3 = 57, |
|
127 |
OP_MUL = 58, |
|
128 |
OP_DIV = 59, |
|
129 |
OP_BKMV = 60, |
|
130 |
OP_COPY = 61, |
|
131 |
OP_CLR = 62, |
|
132 |
|
|
133 |
OP_BRK, |
|
134 |
OP_PAUSE, |
|
135 |
OP_JP, |
|
136 |
OP_CALL, |
842bb6
|
137 |
OP_RET, |
483170
|
138 |
|
Q |
139 |
OP_TML = 0xC8, // |
|
140 |
OP_TMR = 0xDC, // |
|
141 |
OP_TMX = 0xDD, // |
|
142 |
OP_TMY = 0xFA, // |
842bb6
|
143 |
|
Q |
144 |
OP_END = 0xFF, |
483170
|
145 |
|
Q |
146 |
}; |
|
147 |
/* |
|
148 |
typedef struct tagPLCPROG |
|
149 |
{ |
|
150 |
unsigned char OP; |
|
151 |
unsigned char AddrType; |
|
152 |
unsigned short Addr; |
|
153 |
}stPLCPROG; |
|
154 |
*/ |
842bb6
|
155 |
typedef struct stBinInstrcn1 |
483170
|
156 |
{ |
Q |
157 |
unsigned char nOp; |
|
158 |
unsigned char nParamType; |
|
159 |
unsigned short nParamAddr; |
842bb6
|
160 |
}stBinInstrcn1; |
Q |
161 |
typedef struct stBinInstrcn15 |
483170
|
162 |
{ //??? |
Q |
163 |
// |
|
164 |
unsigned char nOp; |
|
165 |
unsigned char nOpNum; |
|
166 |
unsigned short nParamAddr1; |
|
167 |
unsigned char nParamType1; |
|
168 |
unsigned char resvr1; |
|
169 |
unsigned short resvr2; |
842bb6
|
170 |
}stBinInstrcn15; |
Q |
171 |
typedef struct stBinInstrcn2 |
483170
|
172 |
{ //???? |
Q |
173 |
// |
|
174 |
unsigned char nOp; |
|
175 |
unsigned char nOpNum; |
|
176 |
unsigned short nParamAddr1; |
|
177 |
unsigned char nParamType1; |
|
178 |
unsigned char nParamType2; |
|
179 |
unsigned short nParamAddr2; |
842bb6
|
180 |
}stBinInstrcn2; |
Q |
181 |
typedef struct stBinInstrcn3 |
483170
|
182 |
{ //??????? |
Q |
183 |
unsigned char nOp; |
|
184 |
unsigned char nOpNum; |
|
185 |
unsigned short nParamAddr1; |
|
186 |
unsigned char nParamType1; |
|
187 |
unsigned char nParamType2; |
|
188 |
unsigned short nParamAddr2; |
|
189 |
unsigned char resvr1; |
|
190 |
unsigned char nParamType3; |
|
191 |
unsigned short nParamAddr3; |
842bb6
|
192 |
}stBinInstrcn3; |
483170
|
193 |
|
Q |
194 |
|
842bb6
|
195 |
typedef struct tagStoredHdr |
Q |
196 |
{ |
|
197 |
unsigned short nBlockSign; |
|
198 |
unsigned char nBlockType; |
|
199 |
unsigned char nSeq; |
|
200 |
unsigned short nSize; |
|
201 |
unsigned short nCRC2; |
|
202 |
}stStoredHdr; |
|
203 |
|
|
204 |
|
|
205 |
/* |
|
206 |
typedef struct tagBinProgs |
|
207 |
{ |
|
208 |
unsigned short nSteps; |
|
209 |
unsigned short nOptions; |
|
210 |
stBinInstrcn1 BinInstrcns[1]; |
|
211 |
}stBinProgs, *pstBinProgs; |
|
212 |
*/ |
|
213 |
typedef struct tagStoredBinProgs |
|
214 |
{ |
|
215 |
stStoredHdr StoredHdr; |
|
216 |
stBinInstrcn1 BinInstrcns[1]; |
|
217 |
|
|
218 |
}stStoredBinProgs, *pstStoredBinProgs; |
|
219 |
|
|
220 |
typedef struct tagStoredAnno |
|
221 |
{ |
|
222 |
stStoredHdr StoredHdr; |
|
223 |
unsigned char Annos[1]; |
|
224 |
|
|
225 |
}stStoredAnno, *pstStoredAnno; |
|
226 |
|
|
227 |
//extern stBinInstrcn1 const prog1[]; |
|
228 |
//extern int nSizeProg1; |
|
229 |
extern stPLCMem PLCMem; |
|
230 |
|
|
231 |
|
|
232 |
int InitPLC(void); |
|
233 |
int StartPLC(void); |
|
234 |
int StopPLC(void); |
483170
|
235 |
|
Q |
236 |
int InitTimer(int nIndex, int nType); |
|
237 |
int RunTimer(int nIndex , int SV); |
|
238 |
int StopTimer(int nIndex); |
|
239 |
int ResetTimer(int nIndex); |
|
240 |
int SetTimerValue(int nIndex, int bSet, int SV); |
|
241 |
int ProcessTimer(int nIndex); |
|
242 |
int IsTimerOn(int nIndex); |
|
243 |
int GetTimerSV(int nIndex); |
|
244 |
int GetTimerEV(int nIndex); |
|
245 |
|
|
246 |
int PushInVal(void); |
|
247 |
int PopOutVal(void); |
|
248 |
|
842bb6
|
249 |
int ProcessPLCBinProg(const stBinInstrcn1 * pBinProg, int nSize); |
Q |
250 |
//int ProcessPLCPROG(const stBinInstrcn1 * prog,int nSize); |
483170
|
251 |
|
842bb6
|
252 |
#endif // (ENABLE_PLC) |
483170
|
253 |
|
Q |
254 |
#endif /* __PLCFUNCTIONS_H__ */ |