| | |
| | | #include "../src/Ethernet/loopback.h"
|
| | | #elif (BOARD_TYPE == 14)
|
| | | #include "FP0.h"
|
| | | #elif (BOARD_TYPE == 15)
|
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | #include "KWireless.h"
|
| | | //#include "user.h"
|
| | | //#include "../src/radio/inc/sx126x-board.h"
|
| | |
| | | /* 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[280];
|
| | | unsigned char Uart1RxBuf[128];
|
| | | unsigned char Uart1TxBuf[260];
|
| | |
|
| | | unsigned char Uart2RxBuf[RX2BUFSIZE];
|
| | | unsigned char Uart2TxBuf[TX2BUFSIZE];
|
| | |
| | | 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;
|
| | |
| | | /* USER CODE BEGIN SysInit */
|
| | | 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 */
|
| | |
|
| | |
| | | KMachineInit();
|
| | | ReadSysCfgFromFlash(&storedKMSysCfg);
|
| | |
|
| | | KMRunStat.bLEDFlick = 1;
|
| | | |
| | | KMem.EffJumperSW=ReadJumperSW();
|
| | | #if (BOARD_TYPE == 14)
|
| | | KMem.EffJumperSW|=0x10;
|
| | | nAddr=KMem.EffJumperSW&0x0f;
|
| | | nStationID=KMem.EffJumperSW&0x0f;
|
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;}
|
| | | else{bKBusMaster=0;bKBusSlave=1;}
|
| | | nChilds=nAddr;
|
| | | nChilds=nStationID;
|
| | | FP0_Init();
|
| | | #elif (BOARD_TYPE == 15)
|
| | | nAddr=KMem.EffJumperSW&0x0f;
|
| | |
|
| | | #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;
|
| | | 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;
|
| | |
| | | #endif
|
| | |
|
| | | if (GetBoardType() == 7 || GetBoardType() ==8
|
| | | || GetBoardType() == 9 || GetBoardType() ==10 ||GetBoardType() ==13 ||GetBoardType() ==15 ) |
| | | || 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)
|
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x1f);
|
| | | KWireLessStart();
|
| | | #endif
|
| | |
|
| | | while (1)
|
| | | {
|
| | | //int MyKeyStat1,MyKeyStat2;
|
| | |
| | | #endif
|
| | |
|
| | | if (GetBoardType() == 7 || GetBoardType() ==8
|
| | | || GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15) |
| | | || GetBoardType() == 9 || GetBoardType() ==10 || GetBoardType() ==15 || GetBoardType() ==16) |
| | | {
|
| | | displayInput(KMem.WX[0]);
|
| | | }
|
| | |
| | | }
|
| | | //*/
|
| | |
|
| | | #if (BOARD_TYPE == 15)
|
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | Radio.IrqProcess( ); // Process Radio IRQ
|
| | | #endif
|
| | |
|
| | |
| | | if (bKBusSlave)
|
| | | {
|
| | | // BufferOut[0]=KMem.WX[0];
|
| | | #if (BOARD_TYPE == 15)
|
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16)
|
| | | // KBusSlaveFunc(2);
|
| | | // if (! KMem.RunStat) {BufferIn[0]=0;}
|
| | | // KMem.WY[0]=BufferIn[0];
|
| | |
| | | // 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);
|
| | |
| | | #endif
|
| | | //PutOutput (KMem.nRunCount>>8);
|
| | | //PutOutput(0x0f70);
|
| | | #if (BOARD_TYPE == 15) |
| | | #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];
|
| | |
| | | }
|
| | | 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)
|