/**
|
******************************************************************************
|
* @file : PLCfunctions.h
|
* @brief : Header for PLCfunctions.c file.
|
* This file contains the user functions defines of the application.
|
******************************************************************************
|
*/
|
#ifndef __PLCFUNCTIONS_H__
|
#define __PLCFUNCTIONS_H__
|
#include "GlobalDef.h"
|
#include "KMachine.h"
|
|
#if (ENABLE_PLC)
|
|
#define TICK_OF_MS (10) //1ms
|
#define TICK_OF_RS (100) //10mS
|
#define TICK_OF_XS (1000) //100mS
|
#define TICK_OF_YS (10000) //1S
|
|
#define TOTAL_WDFS (32) //Total DF Count
|
#define TOTAL_CurVAL (16) //
|
#define TOTALTIMERS (64)
|
|
#define PLC_PROGRAM_USE_BANK 1
|
|
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;
|
|
#pragma anon_unions
|
|
typedef struct tagPLCMem
|
{
|
int bPLCRunning;
|
int nScanCount;
|
unsigned short WDFs[TOTAL_WDFS];
|
unsigned char CurVALs[TOTAL_CurVAL];
|
unsigned char CurVAL;
|
stTimer Timers[TOTALTIMERS];
|
unsigned short WT[16];
|
|
unsigned short WC[16];
|
unsigned short EV[KLDataEVCount];
|
unsigned short SV[KLDataSVCount];
|
|
unsigned short ProgTrace[256];
|
|
}stPLCMem;
|
|
enum enPLCOPs
|
{
|
OP_NONE = 0,
|
OP_NOP = 0,
|
OP_ST = 1, //
|
OP_ST_ = 2, //
|
OP_AN = 3, //
|
OP_AN_ = 4, //
|
OP_OR = 5, //
|
OP_OR_ = 6, //
|
OP_NOT = 7, //
|
OP_ANS = 8, //
|
OP_ORS = 9, //
|
|
OP_PSHS = 10, //
|
OP_RDS = 11, //
|
OP_POPS = 12, //
|
|
OP_OUT = 16, //
|
OP_SET = 17, //
|
OP_RESET = 18, //
|
OP_DF = 19, //
|
OP_DF_ = 20, //
|
|
OP_ST_EQ, //
|
OP_ST_LT, //
|
OP_ST_GT, //
|
OP_ST_LE, //
|
OP_ST_GE, //
|
OP_ST_NE, //
|
OP_AN_EQ, //
|
OP_AN_LT, //
|
OP_AN_GT,
|
OP_AN_LE,
|
OP_AN_GE,
|
OP_AN_NE,
|
OP_OR_EQ,
|
OP_OR_LT,
|
OP_OR_GT,
|
OP_OR_LE,
|
OP_OR_GE,
|
OP_OR_NE,
|
|
|
OP_MV = 51,
|
OP_INC = 52,
|
OP_ADD2 = 53,
|
OP_ADD3 = 54,
|
OP_DEC = 55,
|
OP_SUB2 = 56,
|
OP_SUB3 = 57,
|
OP_MUL = 58,
|
OP_DIV = 59,
|
OP_BKMV = 60,
|
OP_COPY = 61,
|
OP_CLR = 62,
|
|
OP_BRK,
|
OP_PAUSE,
|
OP_JP,
|
OP_CALL,
|
OP_RET,
|
|
OP_TML = 0xC8, //
|
OP_TMR = 0xDC, //
|
OP_TMX = 0xDD, //
|
OP_TMY = 0xFA, //
|
|
OP_END = 0xFF,
|
|
};
|
/*
|
typedef struct tagPLCPROG
|
{
|
unsigned char OP;
|
unsigned char AddrType;
|
unsigned short Addr;
|
}stPLCPROG;
|
*/
|
typedef struct stBinInstrcn1
|
{
|
unsigned char nOp;
|
unsigned char nParamType;
|
unsigned short nParamAddr;
|
}stBinInstrcn1;
|
typedef struct stBinInstrcn15
|
{ //???
|
//
|
unsigned char nOp;
|
unsigned char nOpNum;
|
unsigned short nParamAddr1;
|
unsigned char nParamType1;
|
unsigned char resvr1;
|
unsigned short resvr2;
|
}stBinInstrcn15;
|
typedef struct stBinInstrcn2
|
{ //????
|
//
|
unsigned char nOp;
|
unsigned char nOpNum;
|
unsigned short nParamAddr1;
|
unsigned char nParamType1;
|
unsigned char nParamType2;
|
unsigned short nParamAddr2;
|
}stBinInstrcn2;
|
typedef struct stBinInstrcn3
|
{ //???????
|
unsigned char nOp;
|
unsigned char nOpNum;
|
unsigned short nParamAddr1;
|
unsigned char nParamType1;
|
unsigned char nParamType2;
|
unsigned short nParamAddr2;
|
unsigned char resvr1;
|
unsigned char nParamType3;
|
unsigned short nParamAddr3;
|
}stBinInstrcn3;
|
|
|
typedef struct tagStoredHdr
|
{
|
unsigned short nBlockSign;
|
unsigned char nBlockType;
|
unsigned char nSeq;
|
unsigned short nSize;
|
unsigned short nCRC2;
|
}stStoredHdr;
|
|
|
/*
|
typedef struct tagBinProgs
|
{
|
unsigned short nSteps;
|
unsigned short nOptions;
|
stBinInstrcn1 BinInstrcns[1];
|
}stBinProgs, *pstBinProgs;
|
*/
|
typedef struct tagStoredBinProgs
|
{
|
stStoredHdr StoredHdr;
|
stBinInstrcn1 BinInstrcns[1];
|
|
}stStoredBinProgs, *pstStoredBinProgs;
|
|
typedef struct tagStoredAnno
|
{
|
stStoredHdr StoredHdr;
|
unsigned char Annos[1];
|
|
}stStoredAnno, *pstStoredAnno;
|
|
//extern stBinInstrcn1 const prog1[];
|
//extern int nSizeProg1;
|
extern stPLCMem PLCMem;
|
|
|
int InitPLC(void);
|
int StartPLC(void);
|
int StopPLC(void);
|
|
int InitTimer(int nIndex, int nType);
|
int RunTimer(int nIndex , int SV);
|
int StopTimer(int nIndex);
|
int ResetTimer(int nIndex);
|
int SetTimerValue(int nIndex, int bSet, int SV);
|
int ProcessTimer(int nIndex);
|
int IsTimerOn(int nIndex);
|
int GetTimerSV(int nIndex);
|
int GetTimerEV(int nIndex);
|
|
int PushInVal(void);
|
int PopOutVal(void);
|
|
int ProcessPLCBinProg(const stBinInstrcn1 * pBinProg, int nSize);
|
//int ProcessPLCPROG(const stBinInstrcn1 * prog,int nSize);
|
|
#endif // (ENABLE_PLC)
|
|
#endif /* __PLCFUNCTIONS_H__ */
|