| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | #if (ENABLE_PLC) |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | |
| | | #endif |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | stKBusDef KBus1; // |
| | | |
| | | extern stDeviceInfo MyDeviceInfo; |
| | | |
| | | /* USER CODE END PV */ |
| | | |
| | |
| | | static int Count=0; |
| | | CurTickuS += 100; |
| | | nCurTick++; |
| | | nSlaveTick++; |
| | | KBus1.nSlaveTick++; |
| | | Count++; |
| | | if (Count>=10000) |
| | | { |
| | |
| | | |
| | | return; |
| | | } |
| | | |
| | | |
| | | void PendSvCallBack() |
| | | { |
| | | #if (BOARD_TYPE == 14) |
| | | ///* |
| | | if (bSPI1RecvDone) |
| | | { |
| | | bSPI1RecvDone=0; |
| | | FPxParsePkt(SPI1RecvBuf,nSPI1RecvLenInBuf); |
| | | } |
| | | //*/ |
| | | #endif |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusParsePacket(&KBus1, (pKBPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen); |
| | | Uart2RecvBuf1DataLen=0; |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | KMem.WDT[2]++; |
| | | } |
| | | } |
| | | |
| | | /* |
| | | KBus通讯回调函数,当通讯状态改变或数据更新时被调用。 |
| | | 或者系统请求时。 |
| | | */ |
| | | void * KBusEvCallBackFunc(void* pParam, int nEvent, void *pBuf, int nLen1) |
| | | { |
| | | switch (nEvent){ |
| | | |
| | | case KBusEvNone: |
| | | break; |
| | | case KBusEvCreate: |
| | | break; |
| | | case KBusEvConnected: |
| | | break; |
| | | case KBusEvDisConnected: |
| | | break; |
| | | case KBusEvClosed: |
| | | break; |
| | | case KBusEvStateChange: |
| | | break; |
| | | case KBusEvTimeSync: |
| | | break; |
| | | case KBusEvDataUpdate: |
| | | KMem.WLX[0] = KBusMem.WLX[0]; |
| | | KMem.WLY[0] = KBusMem.WLY[0]; |
| | | |
| | | if (KBus1.bMaster) { |
| | | KMem.WY[0]=KBusMem.WLX[0]; //KPLC with KBus Master |
| | | KBusMem.WLY[0]=KMem.WX[0]; |
| | | } else if (KBus1.bSlave) { |
| | | KMem.WYB[0]=KBusMem.WLYB[0]; //WireLess with KBus Slave |
| | | KBusMem.WLXB[0]=KMem.WXB[0]; |
| | | |
| | | } |
| | | break; |
| | | case KBusEvCmdResponse: |
| | | break; |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | /* USER CODE END 0 */ |
| | | |
| | |
| | | |
| | | /* USER CODE BEGIN Init */ |
| | | |
| | | for (int i=0;i<9;i++) |
| | | { |
| | | // 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; |
| | | KMem.ScanTimeuS=0; |
| | | KMem.MinScanTimeuS=99999; |
| | | KMem.MaxScanTimeuS=0; |
| | | |
| | | // KMem.SDD[14]=(unsigned int)&KMStoreSysCfg; |
| | | // KMem.SDD[15]=(unsigned int)&KMStoreSysCfg1; |
| | | KMem.SDD[12]=((uint32_t *)UID_BASE)[0]; |
| | | // KMem.SDD[13]=((uint32_t *)UID_BASE)[1]; |
| | | // KMem.SDD[14]=((uint32_t *)UID_BASE)[2]; |
| | | KMem.SDD[13]=PendSvCount; |
| | | KMem.SDD[14]=RCC->CSR; |
| | | // KMem.SDD[15]=*(uint32_t *)FLASHSIZE_BASE; |
| | | // KMem.SDD[16]=(unsigned int)&KMSysCfg; |
| | | |
| | | /* USER CODE END Init */ |
| | | |
| | |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | KLinkInit(1); //注册KLink端口 |
| | | |
| | | // stPortDef PortReg1 = {.nPortHardType = 3,.nPortUseType = 2}; |
| | | // KMRegisterPort(0,&PortReg1); |
| | | |
| | | |
| | | unsigned char bKBusMaster, bKBusSlave, bKBusRepeater; |
| | | int nKBusStationID; |
| | | int nKBusChilds; |
| | | |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | |
| | |
| | | FP0_Init(); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | | nKBusStationID=KMem.EffJumperSW&0x0f; |
| | | // if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | // else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | // else |
| | |
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | #endif |
| | | nChilds=nStationID; |
| | | nCurPollId=1; |
| | | nKBusChilds=nKBusStationID; |
| | | |
| | | if (bKBusMaster) { |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
| | | } else if (bKBusSlave) { |
| | | KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationID,&MyDeviceInfo); |
| | | } |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
| | | |
| | | UNUSED(bKBusRepeater); |
| | | // 注册KBus端口 |
| | | /* |
| | | stPortDef PortReg2 = {.nPortHardType = 4,.nPortUseType = 3}; |
| | | KMRegisterPort(1,&PortReg2); |
| | | */ |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | | Uart1Baud = DefaultUart1Baud; |
| | | MX_USART1_UART_Init(); |
| | | MX_USART2_UART_Init(); |
| | | |
| | |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | LL_USART_EnableIT_IDLE(USART2); |
| | | LL_USART_EnableIT_TC(USART2); |
| | | |
| | | #if (BOARD_TYPE == 13) |
| | | int res; |
| | | res = w5500_init(); |
| | |
| | | KMRunStat.WorkMode2=0; |
| | | |
| | | KMRunStat.WorkMode = storedKMSysCfg.theKMSysCfg.workmode; |
| | | |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode == 1){ |
| | | InitPLC(); |
| | | KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
| | | if (KMRunStat.WorkMode2) { |
| | | StartPLC(); } |
| | | } |
| | | KMem.WX[7]=0x5a; |
| | | #endif |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | LoadKwConfig(); |
| | | // KWireLessInit(&KWInitStruct); |
| | | |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | KWireLessStart(); |
| | | #endif |
| | | |
| | | |
| | | stPortDef PortReg3 = {.nPortHardType = 7,.nPortUseType = 6}; |
| | | KMRegisterPort(2,&PortReg3); |
| | | |
| | | while (1) |
| | | { |
| | |
| | | |
| | | int thisJumperSW=ReadJumperSW(); |
| | | |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode&1){ |
| | | if (thisJumperSW&0x20 && !(KMem.CurJumperSW&0x20)) // Run 开关 正 跳变。 |
| | | {StartPLC();} |
| | | if (!(thisJumperSW&0x20) && (KMem.CurJumperSW&0x20)) // Run 开关 负 跳变。 |
| | | {StopPLC();} |
| | | } |
| | | |
| | | #endif |
| | | KMem.CurJumperSW=thisJumperSW; |
| | | KMem.haltick=haltick; |
| | | // KMem.TotalRunTime=TotalRunTime; |
| | |
| | | // *((unsigned int *)&(PLCMem.SDT[2]))=nChilds; |
| | | // KMem.SDD[13]=PendSvCount; |
| | | // KMem.SDD[14]=RCC->CSR; |
| | | |
| | | |
| | | int a; |
| | | a = LL_GPIO_ReadInputPort(GPIOA); |
| | |
| | | #endif |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | } |
| | | |
| | | #endif // ENABLE_PLC |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | | KMem.LastScanTime = us2; |
| | | if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
| | |
| | | // BufferOut[1]=KMem.WX[0]&0xff; |
| | | // BufferOut[2]=(KMem.WX[0]>>8)&0xff; |
| | | #endif |
| | | if (nChilds>0) { KBusMasterFunc(2); } |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | // KMem.WX[0]=BufferIn[1]+(BufferIn[2]<<8); |
| | | #else |
| | | // KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8); |
| | | #endif |
| | | |
| | | } |
| | | KBusLoopProcess(&KBus1); |
| | | |
| | | if (haltick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (haltick&0x00000800) FastFlicker=1; |
| | |
| | | // if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | // KMem.WY[0]=BufferIn[0]; |
| | | #else |
| | | KBusSlaveFunc(2); |
| | | KBusSlaveFunc(&KBus1); |
| | | if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | KMem.WY[0]=BufferIn[0]; |
| | | #endif |
| | | if (nSlaveTick&0x00002000) SlowFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | if (nSlaveTick&0x00000800) FastFlicker=1; |
| | | if (KBus1.nSlaveTick&0x00000800) FastFlicker=1; |
| | | else FastFlicker=0; |
| | | |
| | | } |
| | | |
| | | // KMem.WY[0]=nCount2>>5; |
| | | if (KMem.RunStat) {KMem.RunStat--;} |
| | | if (KMem.ErrStat) {KMem.ErrStat--;} |
| | | |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | KMem.ErrStat = KwRunStat.ErrStat; |
| | | if ((KMem.EffJumperSW&0x10)==0x10) KMem.ErrStat += KBus1.ErrStat; |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif // ENABLE_PLC |
| | | { |
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | |
| | | if (!KMem.ErrStat) |
| | | { |
| | | SetErrLed(0); |
| | |
| | | us4=GetuS(); |
| | | // EffJumperSW = GetInput(20)&0xff; |
| | | |
| | | |
| | | #if (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | |
| | | if ((KMem.EffJumperSW&0x10)==0x10) { |
| | | KMem.WFY[1]=KMem.WLY[0]; |
| | | KMem.WLX[0]=KMem.WFX[1]; |
| | | KMem.WFY[1]=KBusMem.WLYB[1]; |
| | | KBusMem.WLXB[1]=KMem.WFX[1]; |
| | | }else |
| | | { |
| | | KMem.WFY[1]=KMem.WX[0]; |
| | |
| | | Uart1Stat.bPacketRecved=0; |
| | | Uart1IdelTimer = 0; |
| | | }else { |
| | | if (Uart1IdelTimer>600000) { |
| | | |
| | | if (Uart1IdelTimer>300000) { // 超过60秒没有数据传输,重新进入自适应波特率状态 |
| | | LL_USART_EnableAutoBaudRate(USART1); |
| | | LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
| | | }else { |
| | | Uart1IdelTimer++; |
| | | } |
| | | } |
| | | if (bKBusSlave) HAL_Delay(0); |
| | | // if (bKBusSlave) HAL_Delay(0); |
| | | /* |
| | | if (!IsEmpty(&Uart1Stat.QRx)) |
| | | { |