| | |
| | | #include "string.h"
|
| | | #include "BSP.h"
|
| | | #include "ModbusRTU.h"
|
| | | #if (BOARD_TYPE == 12)
|
| | | #include "FP0.h"
|
| | | #elif (BOARD_TYPE == 13)
|
| | | #if (BOARD_TYPE == 13)
|
| | | #include "w5500_port.h"
|
| | | #include "../src/Ethernet/socket.h"
|
| | | #include "../src/Ethernet/loopback.h"
|
| | | #elif (BOARD_TYPE == 14)
|
| | | #include "FP0.h"
|
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | #include "KWireless.h"
|
| | | //#include "user.h"
|
| | | //#include "../src/radio/inc/sx126x-board.h"
|
| | | #endif
|
| | |
|
| | | /* USER CODE END Includes */
|
| | |
| | | /* USER CODE BEGIN PV */
|
| | | /* Private variables ---------------------------------------------------------*/
|
| | |
|
| | | #define RX2BUFSIZE 128
|
| | | #define TX2BUFSIZE 128
|
| | | #define RX2BUFSIZE 64
|
| | | #define TX2BUFSIZE 64
|
| | |
|
| | | unsigned char Uart1RxBuf[256];
|
| | | unsigned char Uart1TxBuf[512];
|
| | | unsigned char Uart1RxBuf[128];
|
| | | unsigned char Uart1TxBuf[260];
|
| | |
|
| | | unsigned char Uart2RxBuf[RX2BUFSIZE];
|
| | | unsigned char Uart2TxBuf[TX2BUFSIZE];
|
| | |
|
| | | unsigned int SlowFlicker=0;
|
| | | unsigned int FastFlicker=0;
|
| | |
|
| | | int ContinueSend=0;
|
| | | unsigned char SlowFlicker=0;
|
| | | unsigned char FastFlicker=0;
|
| | |
|
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE;
|
| | |
|
| | |
| | | Count=0;
|
| | | KMem.CurTimeSec++;
|
| | | KMem.ThisRunTime++; KMem.TotalRunTime++;
|
| | | if (KMRunStat.bLEDFlick) KMRunStat.bLEDFlick--;
|
| | | if (KMRunStat.bLEDFlick >120) KMRunStat.bLEDFlick=120;
|
| | | }
|
| | |
|
| | | return;
|
| | |
| | | int main(void)
|
| | | {
|
| | | /* USER CODE BEGIN 1 */
|
| | |
|
| | | InitUartstat(&Uart1Stat,Uart1TxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf));
|
| | | InitUartstat(&Uart2Stat,Uart2TxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf));
|
| | | KMRunStat.bLEDFlick = 1;
|
| | | |
| | | InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf));
|
| | | InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf));
|
| | | /* USER CODE END 1 */
|
| | |
|
| | | /* MCU Configuration----------------------------------------------------------*/
|
| | |
| | |
|
| | | for (int i=0;i<9;i++)
|
| | | {
|
| | | // memset(ChnStats[i],0,0); |
| | | ChnStats[i].SendPackets=0;
|
| | | ChnStats[i].RecvPackets=0;
|
| | | ChnStats[i].LostPackets=0;
|
| | | ChnStats[i].CtnLstPkts=0;
|
| | | ChnStats[i].MaxCtnLstPkts=0;
|
| | | ChnStats[i].NotPkgErr=0;
|
| | | ChnStats[i].PkgLenErr=0;
|
| | | ChnStats[i].TimeOutErr=0;
|
| | | ChnStats[i].BCCErr=0;
|
| | | ChnStats[i].Delay=0;
|
| | | ChnStats[i].MaxDelay=0;
|
| | | // memset(KBusChnStats[i],0,0); |
| | | KBusChnStats[i].SendPackets=0;
|
| | | KBusChnStats[i].RecvPackets=0;
|
| | | KBusChnStats[i].LostPackets=0;
|
| | | KBusChnStats[i].CtnLstPkts=0;
|
| | | KBusChnStats[i].MaxCtnLstPkts=0;
|
| | | KBusChnStats[i].NotPkgErr=0;
|
| | | KBusChnStats[i].PkgLenErr=0;
|
| | | KBusChnStats[i].TimeOutErr=0;
|
| | | KBusChnStats[i].BCCErr=0;
|
| | | KBusChnStats[i].Delay=0;
|
| | | KBusChnStats[i].MaxDelay=0;
|
| | | }
|
| | |
|
| | | KMem.LastScanTime=0;
|
| | |
| | | SystemClock_Config();
|
| | |
|
| | | /* USER CODE BEGIN SysInit */
|
| | | TickFreq=10000; //Tick频率
|
| | | TickFreq=10000; //Tick频率
|
| | | InituS(TickFreq);
|
| | | // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //ÖØж¨ÒåSysTickµÄƵÂÊÎ
|
| | | // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/TickFreq); //重新定义SysTick的频率
|
| | |
|
| | | /* USER CODE END SysInit */
|
| | |
|
| | |
| | | MX_DMA_Init();
|
| | |
|
| | | KMachineInit();
|
| | | ReadSysCfgFromFlash(&KMSysCfg);
|
| | | ReadSysCfgFromFlash(&storedKMSysCfg);
|
| | | |
| | | KMRunStat.bLEDFlick = 1;
|
| | |
|
| | | KMem.EffJumperSW=ReadJumperSW();
|
| | | #if (BOARD_TYPE == 12)
|
| | | #if (BOARD_TYPE == 14)
|
| | | KMem.EffJumperSW|=0x10;
|
| | | nAddr=KMem.EffJumperSW&0x0f;
|
| | | if ((KMem.EffJumperSW&0x10)!=0) {bMaster=1;bSlave=0;}
|
| | | else{bMaster=0;bSlave=1;}
|
| | | nChilds=nAddr;
|
| | | nStationID=KMem.EffJumperSW&0x0f;
|
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
| | | else{bKBusMaster=0;bKBusSlave=1;}
|
| | | nChilds=nStationID;
|
| | | FP0_Init();
|
| | |
|
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | nStationID=KMem.EffJumperSW&0x0f;
|
| | | if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;}
|
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | #else
|
| | | nAddr=KMem.EffJumperSW&0x7;
|
| | | if (KMem.EffJumperSW == 0x0f) {bRepeater=1;bMaster=1;bSlave=0;}
|
| | | else if ((KMem.EffJumperSW&0x08)!=0) {bMaster=1;bSlave=0;}
|
| | | else{bMaster=0;bSlave=1;}
|
| | | nStationID=KMem.EffJumperSW&0x7;
|
| | | if (KMem.EffJumperSW == 0x0f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;}
|
| | | else if ((KMem.EffJumperSW&0x08)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
| | | else{bKBusMaster=0;bKBusSlave=1;}
|
| | | #endif
|
| | | nChilds=nAddr;
|
| | | nChilds=nStationID;
|
| | | nCurPollId=1;
|
| | | //if (KMem.EffJumperSW == 0x00)
|
| | | Uart1Baud = DefaultUart1Baud;
|
| | |
| | | MX_SPI1_Init();
|
| | | LL_SPI_EnableIT_RXNE(SPI1);
|
| | |
|
| | | #if (BOARD_TYPE == 12)
|
| | | #if (BOARD_TYPE == 14)
|
| | | // MX_SPI2_Init();
|
| | | // MX_ADC_Init();
|
| | | #else
|
| | |
| | |
|
| | | // res = listen(0);
|
| | | #endif
|
| | | // if (bSlave)
|
| | | // if (bKBusSlave)
|
| | | {
|
| | | // LL_USART_EnableAutoBaudRate(USART1);
|
| | | // LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
| | |
| | | SetRunLed(1); //Turn On Run Led
|
| | | SetErrLed(0); //Turn Off Err Led
|
| | |
|
| | | #if (BOARD_TYPE == 12)
|
| | | #if (BOARD_TYPE == 14)
|
| | | // PutOutput (0); //Clear all Output
|
| | | // Enable595(1); //Enable 595 Output
|
| | | #else
|
| | |
| | | #endif
|
| | |
|
| | | if (GetBoardType() == 7 || GetBoardType() ==8
|
| | | || GetBoardType() == 9 || GetBoardType() ==10 ) |
| | | || GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 || BOARD_TYPE == 16) |
| | | {
|
| | | displayInput(0xffff); //
|
| | | EnableDisIn(1); //Input Diaplay Enable 595
|
| | |
| | | StartPLC();
|
| | | }
|
| | | KMem.WX[7]=0x5a;
|
| | |
|
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x1f);
|
| | | KWireLessStart();
|
| | | #endif
|
| | | while (1)
|
| | | {
|
| | | //int MyKeyStat1,MyKeyStat2;
|
| | | //MyKeyStat1=GetInput();
|
| | | #if (BOARD_TYPE == 12)
|
| | | FP0_Proc();
|
| | | #endif
|
| | |
|
| | | //*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount;
|
| | | // KMem.nRunCount=nRunCount;
|
| | | SlowFlicker=0;
|
| | |
| | | // KMem.SDD[13]=PendSvCount;
|
| | | // KMem.SDD[14]=RCC->CSR;
|
| | |
|
| | | #if (BOARD_TYPE == 12)
|
| | | #if (BOARD_TYPE == 14)
|
| | | // KMem.WX[0]= GetInput();
|
| | | FP0_Proc();
|
| | | #else
|
| | | KMem.WX[0]= GetInput();
|
| | | #endif
|
| | |
|
| | | if (GetBoardType() == 7 || GetBoardType() ==8
|
| | | || GetBoardType() == 9 || GetBoardType() ==10 ) |
| | | || GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16) |
| | | {
|
| | | displayInput(KMem.WX[0]);
|
| | | }
|
| | | us2=GetuS();
|
| | | |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE;
|
| | |
|
| | | if ( KMRunStat.WorkMode==1)
|
| | | {
|
| | | if (KMRunStat.nBinProgBank == 0){
|
| | | pProgs=(stBinProg1 *)STORE_PRG_BASE;
|
| | | }else {
|
| | | pProgs=(stBinProg1 *)ALT_PRG_BASE;
|
| | | }
|
| | | nSizeProg1=KMRunStat.nBinProgSize;
|
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1);
|
| | | }
|
| | |
|
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime;
|
| | | KMem.LastScanTime = us2;
|
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;}
|
| | | if (KMem.ScanTimeuS > KMem.MaxScanTimeuS) {KMem.MaxScanTimeuS = KMem.ScanTimeuS;}
|
| | | // if (repeater) { RepeaterFunc(); }
|
| | |
|
| | | us3=GetuS();
|
| | |
|
| | | ///*
|
| | | if ((KMem.nRunCount &0x1f) == 0x02)
|
| | | {
|
| | | ADCProcess();
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | //*/
|
| | |
|
| | | if (bMaster) |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | Radio.IrqProcess( ); // Process Radio IRQ
|
| | | #endif
|
| | |
|
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE;
|
| | |
|
| | | if ( KMRunStat.WorkMode==1 && bKBusMaster)
|
| | | {
|
| | | #if (BOARD_TYPE == 12)
|
| | | if (KMRunStat.nBinProgBank == 0){
|
| | | pProgs=(stBinProg1 *)STORE_PRG_BASE;
|
| | | }else {
|
| | | pProgs=(stBinProg1 *)ALT_PRG_BASE;
|
| | | }
|
| | | nSizeProg1=KMRunStat.nBinProgSize;
|
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1);
|
| | | }
|
| | |
|
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime;
|
| | | KMem.LastScanTime = us2;
|
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;}
|
| | | if (KMem.ScanTimeuS > KMem.MaxScanTimeuS) {KMem.MaxScanTimeuS = KMem.ScanTimeuS;}
|
| | |
|
| | | // if (bKBusRepeater) { KBusRepeaterFunc(); }
|
| | |
|
| | | us3=GetuS();
|
| | |
|
| | | if (bKBusMaster) |
| | | {
|
| | | #if (BOARD_TYPE == 14)
|
| | | for (int i=0;i<nOutputBytes;i++)
|
| | | {BufferOut[i+1]=KMem.WYB[i];}
|
| | | #else
|
| | | // BufferOut[1]=KMem.WX[0]&0xff;
|
| | | // BufferOut[2]=(KMem.WX[0]>>8)&0xff;
|
| | | #endif
|
| | | if (nChilds>0) { MasterFunc(2); }
|
| | | if (nChilds>0) { KBusMasterFunc(2); }
|
| | |
|
| | | #if (BOARD_TYPE == 12) |
| | | #if (BOARD_TYPE == 14) |
| | | // KMem.WX[0]=BufferIn[1]+(BufferIn[2]<<8);
|
| | | #else
|
| | | // KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8);
|
| | |
| | | if (haltick&0x00000800) FastFlicker=1;
|
| | | else FastFlicker=0;
|
| | |
|
| | | if (bSlave) |
| | | if (bKBusSlave) |
| | | {
|
| | | // BufferOut[0]=KMem.WX[0];
|
| | | SlaveFunc(2); |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | // KBusSlaveFunc(2); |
| | | // if (! KMem.RunStat) {BufferIn[0]=0;}
|
| | | // KMem.WY[0]=BufferIn[0];
|
| | | #else
|
| | | KBusSlaveFunc(2); |
| | | if (! KMem.RunStat) {BufferIn[0]=0;}
|
| | | KMem.WY[0]=BufferIn[0];
|
| | | |
| | | #endif
|
| | | if (nSlaveTick&0x00002000) SlowFlicker=1;
|
| | | else SlowFlicker=0;
|
| | | if (nSlaveTick&0x00000800) FastFlicker=1;
|
| | |
| | | // KMem.WY[0]=nCount2>>5;
|
| | | if (KMem.RunStat) {KMem.RunStat--;}
|
| | | if (KMem.ErrStat) {KMem.ErrStat--;}
|
| | |
|
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker);
|
| | | else SetRunLed(FastFlicker);
|
| | |
|
| | | if (!KMem.ErrStat) |
| | | if (KMRunStat.bLEDFlick)
|
| | | {
|
| | | SetErrLed(0);
|
| | | SetOutStat(1);
|
| | | }
|
| | | else |
| | | {
|
| | | SetRunLed(FastFlicker);
|
| | | SetErrLed(FastFlicker);
|
| | | SetOutStat(0);
|
| | | SetErr2Led(FastFlicker);
|
| | | SetOutStat(!FastFlicker);
|
| | | //KMRunStat.bLEDFlick-- ;
|
| | | }
|
| | | else
|
| | | {
|
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker);
|
| | | else SetRunLed(FastFlicker);
|
| | |
|
| | | if (!KMem.ErrStat) |
| | | {
|
| | | SetErrLed(0);
|
| | | SetErr2Led(0);
|
| | | SetOutStat(1);
|
| | | }
|
| | | else |
| | | {
|
| | | SetErrLed(FastFlicker);
|
| | | SetErr2Led(FastFlicker);
|
| | | SetOutStat(0);
|
| | | |
| | | }
|
| | | }
|
| | |
|
| | | // SetRunLed(RunStat);
|
| | |
| | | us4=GetuS();
|
| | | // EffJumperSW = GetInput(20)&0xff;
|
| | |
|
| | | #if (BOARD_TYPE == 12)
|
| | | PutOutput (KMem.WY[0]);
|
| | | #else
|
| | | #if (BOARD_TYPE == 14)
|
| | | // PutOutput (KMem.WY[0]);
|
| | | #else
|
| | | PutOutput (KMem.WY[0]);
|
| | | #endif
|
| | | //PutOutput (KMem.nRunCount>>8);
|
| | | //PutOutput(0x0f70);
|
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | // KMem.WY[1]=KMem.nRunCount>>6;
|
| | | KMem.WY[1]=KMem.WX[0];
|
| | | KMem.WY[0]=KMem.WX[1];
|
| | | #endif
|
| | | us5=GetuS();
|
| | | // if (bMaster) ShowInfo();
|
| | | // if (bSlave) ShowInfo();
|
| | | // if (bKBusMaster) ShowInfo();
|
| | | // if (bKBusSlave) ShowInfo();
|
| | | us6=GetuS();
|
| | | add1(10,10);
|
| | | for (int i=0;i<64;i++)
|
| | |
| | | }
|
| | | KMem.nRunCount++;
|
| | | // int nSize=sizeof(stChnStat);
|
| | | // memcpy(&KMem.SDT[64],&ChnStats[1],nSize);
|
| | | // memcpy(&KMem.SDT[64+nSize/2],&ChnStats[2],nSize);
|
| | | // memcpy(&KMem.SDT[64],&KBusChnStats[1],nSize);
|
| | | // memcpy(&KMem.SDT[64+nSize/2],&KBusChnStats[2],nSize);
|
| | | // for (int i=0;i<128;i++) { SDT[i]=i; }
|
| | | // SDT[48]=55;
|
| | | if (Uart1RecvBuf1DataLen >0 && Uart1Stat.bPacketRecved)
|
| | |
| | | Uart1RecvBuf1DataLen=0;
|
| | | Uart1Stat.bPacketRecved=0;
|
| | | }
|
| | | if (bSlave) HAL_Delay(0);
|
| | | if (bKBusSlave) HAL_Delay(0);
|
| | | /*
|
| | | if (!IsEmpty(&Uart1Stat.QRx))
|
| | | {
|
| | |
| | | }
|
| | | */
|
| | |
|
| | | #if (BOARD_TYPE == 12)
|
| | | #if (BOARD_TYPE == 14)
|
| | | //process 6 output
|
| | | {
|
| | | // mapping bits.
|
| | |
| | | }
|
| | | #endif
|
| | |
|
| | | /* |
| | | {
|
| | | unsigned char pos,seg;
|
| | | unsigned short val;
|
| | |
| | | seg=~seg;
|
| | | // PutOutputSPI1(pos|(seg<<8));
|
| | | }
|
| | | */
|
| | |
|
| | | #if (BOARD_TYPE == 13)
|
| | | w5500_network_info_show();
|
| | | |
| | | // loopback_tcps(0,str1,5000);
|
| | | #endif
|
| | |
|