| | |
| | | #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)
|
| | | #include "KWireless.h"
|
| | | //#include "user.h"
|
| | | //#include "../src/radio/inc/sx126x-board.h"
|
| | | #endif
|
| | |
|
| | | /* USER CODE END Includes */
|
| | |
| | | #define TX2BUFSIZE 128
|
| | |
|
| | | unsigned char Uart1RxBuf[256];
|
| | | unsigned char Uart1TxBuf[512];
|
| | | unsigned char Uart1TxBuf[280];
|
| | |
|
| | | 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;
|
| | |
|
| | |
| | | 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);
|
| | |
|
| | | 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;}
|
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
| | | else{bKBusMaster=0;bKBusSlave=1;}
|
| | | nChilds=nAddr;
|
| | | FP0_Init();
|
| | | #elif (BOARD_TYPE == 15)
|
| | | nAddr=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;}
|
| | | 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;
|
| | | nCurPollId=1;
|
| | |
| | | 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 ) |
| | | {
|
| | | displayInput(0xffff); //
|
| | | EnableDisIn(1); //Input Diaplay Enable 595
|
| | |
| | | StartPLC();
|
| | | }
|
| | | KMem.WX[7]=0x5a;
|
| | | #if (BOARD_TYPE == 15)
|
| | | KWireLessInit(KMem.EffJumperSW&0x20);
|
| | | 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) |
| | | {
|
| | | 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)
|
| | | 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)
|
| | | // 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;
|
| | |
| | | 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) |
| | | // 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++)
|
| | |
| | | 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
|
| | |
|