| | |
| | |
|
| | | };
|
| | |
|
| | | #define BOARD_TYPE 16 |
| | | #define BOARD_VER 1
|
| | | #define XLAT_FREQ 8
|
| | | #define BOARD_TYPE 9 |
| | | #define BOARD_VER 1
|
| | |
|
| | | #if (BOARD_TYPE == 11)
|
| | |
| | | #define ALT_PRG_PAGESIZE (0x00000400) //Page Size = 1K
|
| | | #define ALT_PRG_PAGES 4 //use 4 pages
|
| | |
|
| | | #define STORE_SYSREG_BASE (FLASH_BASE + 0x0000A000) //40k //and |
| | | #define STORE_SYSREG_BASE (FLASH_BASE + 0x0000C000) //40k //and |
| | | #define STORE_SYSREG_PAGESIZE (0x00000400) //Page Size = 1K
|
| | | #define STORE_SYSREG_PAGES 1 //use 1 pages
|
| | |
|
| | | #define STORE_RUNSTAT_BASE (FLASH_BASE + 0x0000A800) //44k K //and |
| | | #define STORE_RUNSTAT_BASE (FLASH_BASE + 0x0000C800) //44k K //and |
| | | #define STORE_RUNSTAT_PAGESIZE (0x00000400) //Page Size = 1K
|
| | | #define STORE_RUNSTAT_PAGES 1 //use 1 pages
|
| | |
|
| | |
|
| | | #define STORE_LOG_BASE (FLASH_BASE + 0x0000C000) //48k and FLASH_BANK1_END
|
| | | #define STORE_LOG_BASE (FLASH_BASE + 0x0000D000) //48k and FLASH_BANK1_END
|
| | | #define STORE_LOG_PAGESIZE (0x00000400) //Page Size = 1K
|
| | | #define STORE_LOG_PAGES 4 //use 4 pages
|
| | |
|
| | |
| | |
|
| | | void LedToggle(void);
|
| | |
|
| | | typedef enum tag_KWStates
|
| | | typedef enum tagenKWStates
|
| | | {
|
| | | KW_PON,
|
| | | KW_UNINIT,
|
| | |
| | | KW_ERROR1,
|
| | | KW_ERROR2,
|
| | | KW_ERROR3,
|
| | | }KWStates;
|
| | | }enKWStates;
|
| | |
|
| | |
|
| | | int KWMasterProc(void);
|
| | |
| | |
|
| | | int KWSendPkg(void* pPkg, int len);
|
| | | int KWProcPkg(void);
|
| | | /*
|
| | | typedef struct KWStates
|
| | | {
|
| | | |
| | | }stKWStat,*pstKWstat;
|
| | | */
|
| | |
|
| | | |
| | | #endif ///* __KBUS_H__ */
|
| | |
|
| | |
| | | {
|
| | | int bPLCRunning;
|
| | | int nScanCount;
|
| | | char ProgTrace[512];
|
| | | unsigned short ProgTrace[256];
|
| | |
|
| | | }stPLCMem;
|
| | | extern stPLCMem PLCMem;
|
| | |
| | | }
|
| | | #else
|
| | | BufferIn[ChildId]=p1->data[0];
|
| | | KMem.WX[ChildId]=BufferIn[ChildId];
|
| | | KMem.WLX[ChildId]=BufferIn[ChildId];
|
| | | if (KMRunStat.WorkMode==0) {
|
| | | KMem.WY[0]= KMem.WX[1]+(KMem.WX[2]<<8) ;
|
| | | KMem.WY[0]= KMem.WLX[1]+(KMem.WLX[2]<<8) ;
|
| | | PutOutput (KMem.WY[0]);
|
| | | }
|
| | | #endif
|
| | |
| | | if (KMRunStat.WorkMode==0)
|
| | | {
|
| | | KMem.WX[0]= GetInput();
|
| | | KMem.WY[1]=KMem.WX[0]&0xff;
|
| | | KMem.WY[2]=(KMem.WX[0]>>8)&0xff; |
| | | KMem.WLY[1]=KMem.WX[0]&0xff;
|
| | | KMem.WLY[2]=(KMem.WX[0]>>8)&0xff; |
| | | }
|
| | | BufferOut[1]=KMem.WY[1];
|
| | | BufferOut[2]=KMem.WY[2]; |
| | | BufferOut[1]=KMem.WLY[1];
|
| | | BufferOut[2]=KMem.WLY[2]; |
| | | #endif
|
| | |
|
| | | Datas[0]=BufferOut[nCurPollId];
|
| | |
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,0,0);
|
| | | SendPacket(nChn, p2, PacketLen);
|
| | | break;
|
| | | |
| | |
|
| | | case KLCmdRead:
|
| | | case KLCmdReadDataWord:
|
| | | case KLCmdReadDataByte:
|
| | |
| | | case KLCmdWriteBits:
|
| | | break;
|
| | | case KLCmdChgMode:
|
| | | |
| | | if (nDataType ==0) {StopPLC();}
|
| | | if (nDataType == 1) {StartPLC();}
|
| | | PacketLen=KLMakeRplyPacket(p2,nDstHost,nKLStatus.StatByte,p1->nCMD,0,0);
|
| | | SendPacket(nChn, p2, PacketLen); |
| | | break;
|
| | | case KLCmdReadProgram:
|
| | | nWordAddr=p1->Params[0]+ (p1->Params[1]<<8);
|
| | |
| | | {
|
| | | START_SIGN,
|
| | | 0x0000,
|
| | | |
| | | CFG_VER,
|
| | | 0x0000,
|
| | | 0x0000,
|
| | | 0x0000,
|
| | | {
|
| | | {
|
| | | PortType_KLink, //PorttType
|
| | | 1, //Station
|
| | | 2304, //Buadrate = * 100;
|
| | | 0, //ByteSize
|
| | | 0, //Parity
|
| | | 0, //StopBits
|
| | | 0, //endType
|
| | | 0, //EofChar
|
| | | 0, //SofChar
|
| | | 0, //endtime
|
| | | 0, //recvbuf
|
| | | 0, //bufsize
|
| | | CFG_VER,
|
| | | 0x0000, //workmode
|
| | | 0x0000, //switchfunc
|
| | | 0x0000, //pad1;
|
| | | { //comportparam[2]
|
| | | { |
| | | PortType_KLink, //PorttType
|
| | | 1, //Station
|
| | | 2304, //Buadrate = * 100;
|
| | | 0, //ByteSize
|
| | | 0, //Parity
|
| | | 0, //StopBits
|
| | | 0, //endType
|
| | | 0, //EofChar
|
| | | 0, //SofChar
|
| | | 0, //endtime
|
| | | 0, //recvbuf
|
| | | 0, //bufsize
|
| | | },
|
| | | {
|
| | | PortType_KBus, //PorttType
|
| | | 0, //Station
|
| | | 2304, //Buadrate = * 100;
|
| | | 0, //ByteSize
|
| | | 0, //Parity
|
| | | 0, //StopBits
|
| | | 0, //endType
|
| | | 0, //EofChar
|
| | | 0, //SofChar
|
| | | 0, //endtime
|
| | | 0, //recvbuf
|
| | | 0, //bufsize
|
| | | }
|
| | | },
|
| | | {
|
| | | PortType_KBus, //PorttType
|
| | | 0, //Station
|
| | | 2304, //Buadrate = * 100;
|
| | | 0, //ByteSize
|
| | | 0, //Parity
|
| | | 0, //StopBits
|
| | | 0, //endType
|
| | | 0, //EofChar
|
| | | 0, //SofChar
|
| | | 0, //endtime
|
| | | 0, //recvbuf
|
| | | 0, //bufsize
|
| | | }
|
| | | },
|
| | | {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}},
|
| | | {{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1}},
|
| | | { //default port mapping
|
| | | 0,0,0,0,0,0
|
| | | },
|
| | | 0x0003,
|
| | | {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}}, //inputfilterparam
|
| | | {{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1},{0,1}}, //outputholdparam
|
| | | { //default port mapping
|
| | | 0,0,0,0,0,0 |
| | | }, |
| | | 0x0003, //padding s |
| | | 0x0004,
|
| | | 0x0005,
|
| | | 0x0006,
|
| | |
| | | 0x000a,
|
| | | 0x000b,
|
| | | 0x000c,
|
| | |
|
| | | 0x0011,
|
| | | },
|
| | | 0x0011, //CRC16
|
| | | END_SIGN,
|
| | | };
|
| | |
|
| | |
| | | int nNextRunStatSpace=0;
|
| | | int LoadDefaultRunStat(pRunStat theRunStat)
|
| | | {
|
| | | theRunStat->PowerCount=1;
|
| | | // theRunStat->UpTime=0;
|
| | | // theRunStat->UserData1=0;
|
| | | // theRunStat->WorkMode=0;
|
| | | // theRunStat->WorkMode2=0;
|
| | | // theRunStat->nBinProgBank=0;
|
| | | // theRunStat->nBinProgSize=0;
|
| | | return 0;
|
| | | }
|
| | | int LoadRunStat(pRunStat theRunStat)
|
| | |
| | | int8_t RssiValue = 0;
|
| | | int8_t SnrValue = 0;
|
| | |
|
| | | KWStates KW_State=KW_PON;
|
| | | //KWStates KW_State=KW_PON;
|
| | |
|
| | | void LedToggle(void)
|
| | | {
|
| | |
| | | memcpy( RX_Buffer, payload, BufferSize );
|
| | | RssiValue = rssi;
|
| | | SnrValue = snr;
|
| | | KMem.DT[40]=rssi; //Radio.Rssi(MODEM_FSK);;
|
| | | KMem.DT[41]=snr;
|
| | | KMem.DT[42]++;
|
| | | KMem.WDT[40]=rssi; //Radio.Rssi(MODEM_FSK);;
|
| | | KMem.WDT[41]=snr;
|
| | | KMem.WDT[42]++;
|
| | |
|
| | | Radio.Standby();
|
| | |
|
| | |
| | |
|
| | | void OnTxTimeout( void )
|
| | | {
|
| | | |
| | | KMem.WDT[43]++;
|
| | | |
| | | }
|
| | |
|
| | | void OnRxTimeout( void )
|
| | | {
|
| | | Radio.Standby();
|
| | | KMem.DT[43]++;
|
| | | KMem.WDT[44]++;
|
| | | KMem.ErrStat=200;
|
| | | if(RadioEnableMaster)
|
| | | {
|
| | |
| | | {
|
| | |
|
| | | Radio.Standby();
|
| | | KMem.DT[44]++;
|
| | | KMem.WDT[45]++;
|
| | | if(RadioEnableMaster)
|
| | | {
|
| | | SendPingMsg();
|
| | |
| | | int InitPLC()
|
| | | {
|
| | | PLCMem.nScanCount=0;
|
| | | for (int i=0;i<1024;i++){PLCMem.ProgTrace[i]=0;}
|
| | | for (int i=0;i<256;i++){PLCMem.ProgTrace[i]=0;}
|
| | | for (int i=0;i<16;i++) {
|
| | | KMem.WR[i]=0;
|
| | | }
|
| | |
| | | int StartPLC()
|
| | | {
|
| | | PLCMem.nScanCount = 0;
|
| | | for (int i=0;i<1024;i++){PLCMem.ProgTrace[i]=0;}
|
| | | for (int i=0;i<256;i++){PLCMem.ProgTrace[i]=0;}
|
| | | for (int i=0;i<16;i++) {
|
| | | KMem.WR[i]=0;
|
| | | }
|
| | |
| | | int StopPLC()
|
| | | {
|
| | | PLCMem.bPLCRunning=0;
|
| | | for (int i=0;i<KLDataWXCount;i++) KMem.WY[i]=0;
|
| | | for (int i=0;i<KLDataWLCount;i++) KMem.WLY[i]=0;
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
| | | default:
|
| | | break;
|
| | | }
|
| | |
|
| | | lastScanInputVal = PLCMem.ProgTrace[CurPos]; //GetBitValue(KMem.WDFs);
|
| | | PLCMem.ProgTrace[CurPos] = KMem.CurVAL;
|
| | | lastScanInputVal = GetBitValue( PLCMem.ProgTrace[CurPos>>4],CurPos&0xf); //GetBitValue(KMem.WDFs);
|
| | | SetBitValue( &PLCMem.ProgTrace[CurPos>>4],CurPos&0xf, KMem.CurVAL);
|
| | | |
| | | // lastScanInputVal = PLCMem.ProgTrace[CurPos]; //GetBitValue(KMem.WDFs);
|
| | | // PLCMem.ProgTrace[CurPos] = KMem.CurVAL;
|
| | | CurPos += nNextPos;
|
| | | }
|
| | | PLCMem.nScanCount++;
|
| | |
| | | ShowInitInfo();
|
| | | KMem.LastScanTime = GetuS();
|
| | |
|
| | | KMRunStat.WorkMode=0;
|
| | | KMRunStat.WorkMode=1;
|
| | | if (KMRunStat.WorkMode == 1){
|
| | | InitPLC();
|
| | | StartPLC();
|
| | |
| | | #endif
|
| | |
|
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE;
|
| | |
|
| | | if ( KMRunStat.WorkMode==1 && bKBusMaster)
|
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster)
|
| | | {
|
| | | if (KMRunStat.nBinProgBank == 0){
|
| | | pProgs=(stBinProg1 *)STORE_PRG_BASE;
|
| | |
| | | pProgs=(stBinProg1 *)ALT_PRG_BASE;
|
| | | }
|
| | | nSizeProg1=KMRunStat.nBinProgSize;
|
| | | // pProgs=(stBinProg1 *)prog1;
|
| | |
|
| | | ProcessPLCBinProg(pProgs, nSizeProg1);
|
| | | }
|