| | |
| | | unsigned char FastFlicker=0; |
| | | |
| | | unsigned int Uart1IdelTimer = 0; |
| | | stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE; |
| | | |
| | | uint32_t us1,us2,us3,us4,us5,us6; |
| | | |
| | | |
| | | stKBusDef KBus1; // |
| | | |
| | | extern stDeviceInfo MyDeviceInfo; |
| | | /* USER CODE END PV */ |
| | | |
| | | /* Private function prototypes -----------------------------------------------*/ |
| | |
| | | static int Count=0; |
| | | CurTickuS += 100; |
| | | nCurTick++; |
| | | nSlaveTick++; |
| | | KBus1.nSlaveTick++; |
| | | Count++; |
| | | if (Count>=10000) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | void * KBusCallBackFunc(int nChn, int nEvent, void *pBuf, int nLen1) |
| | | 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 KBusEvTimeSync: |
| | | break; |
| | | case KBusEvDataUpdate: |
| | | // KMem.WY[0]=KBusMem.WLY[0]; //KBus Slave |
| | | // KBusMem.WLX[0]=KMem.WX[0]; |
| | | if (KBus1.bMaster) { |
| | | KMem.WLX[0]=KBusMem.WLX[0]; //KPLC with KBus Master |
| | | KBusMem.WLY[0]=KMem.WLY[0]; |
| | | } else if (KBus1.bSlave) { |
| | | KMem.WLX[0]=KBusMem.WLY[0]; //KPLC with KBus Slave |
| | | KBusMem.WLX[0]=KMem.WLY[0]; |
| | | } |
| | | break; |
| | | case KBusEvCmdResponse: |
| | | break; |
| | |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | /* USER CODE END 0 */ |
| | | |
| | |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | |
| | | KLinkInit(1); |
| | | unsigned char bKBusMaster, bKBusSlave, bKBusRepeater; |
| | | int nKBusStationID; |
| | | int nKBusChilds; |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | |
| | | // Uart2Baud = AlterUart2Baud; |
| | | nKBusStationID = KMem.EffJumperSW&0x0f; |
| | | nKBusChilds = nKBusStationID; |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | KMem.EffJumperSW|=0x10; |
| | |
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | nChilds=nStationID; |
| | | FP0_Init(); |
| | | FP0_Init(nChilds); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | |
| | | // else |
| | | {bKBusMaster=0;bKBusSlave=1;} |
| | | #else |
| | | nStationID=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{bKBusMaster=0;bKBusSlave=1;} |
| | | else if ((KMem.EffJumperSW&0x10)!=0) { |
| | | bKBusMaster=1;bKBusSlave=0; |
| | | } |
| | | else{ |
| | | bKBusMaster=0;bKBusSlave=1; |
| | | } |
| | | #endif |
| | | |
| | | KBusInit(2, bKBusMaster, nChilds); |
| | | KBusSetCallBackFunc(2, &KBusCallBackFunc), |
| | | if (bKBusMaster) { |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
| | | } else if (bKBusSlave) { |
| | | KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationID,&MyDeviceInfo); |
| | | } |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc), |
| | | |
| | | UNUSED(bKBusRepeater); |
| | | |
| | | nChilds=nStationID; |
| | | nCurPollId=1; |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | | MX_USART1_UART_Init(); |
| | |
| | | // KMem.SDD[13]=PendSvCount; |
| | | // KMem.SDD[14]=RCC->CSR; |
| | | |
| | | KMem.WDB[0] = KBus1.MyStat; |
| | | KMem.WDB[1] = KBus1.bMaster; |
| | | KMem.WDB[2] = KBus1.bMasterSent; |
| | | KMem.WDB[3] = KBus1.bMasterRecved; |
| | | KMem.WDB[4] = KBus1.bMasterRecvOK; |
| | | KMem.WDB[5] = KBus1.bSlaveRecved; |
| | | |
| | | KMem.WDB[8] = KBus1.RunStat; |
| | | KMem.WDB[9] = KBus1.ErrStat; |
| | | |
| | | int a; |
| | | a = LL_GPIO_ReadInputPort(GPIOA); |
| | | KMem.WDT[120]=a; |
| | |
| | | |
| | | #endif |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | // pProgs = (stBinInstrcn1 *) STORE_PRG_BASE; |
| | | |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | | pProgs=(stBinProg1 *)STORE_PRG_BASE; |
| | | stStoredBinProgs * pStoredBinProgs; |
| | | |
| | | if (storedKMSysCfg.theKMSysCfg.nProgBank == 0){ |
| | | pStoredBinProgs=((stStoredBinProgs *)STORE_PRG_BASE); |
| | | }else { |
| | | pProgs=(stBinProg1 *)ALT_PRG_BASE; |
| | | pStoredBinProgs=((stStoredBinProgs *)ALT_PRG_BASE); ; |
| | | } |
| | | nSizeProg1=KMRunStat.nBinProgSize; |
| | | // pProgs=(stBinProg1 *)prog1; |
| | | int nSizeProg1=pStoredBinProgs->StoredHdr.nSize ; |
| | | // pProgs=(stBinInstrcn1 *)prog1; |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | ProcessPLCBinProg(pStoredBinProgs->BinInstrcns, nSizeProg1); |
| | | } |
| | | |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | |
| | | |
| | | KBusMem.WLY[0]=KMem.WLY[0]; |
| | | |
| | | if (nChilds>0) { KBusMasterFunc(2); } |
| | | if (nKBusChilds>0) { KBusMasterFunc(&KBus1); } |
| | | |
| | | KMem.WLX[0]=KBusMem.WLX[0]; |
| | | |
| | |
| | | // if (! KMem.RunStat) {BufferIn[0]=0;} |
| | | // KMem.WY[0]=BufferIn[0]; |
| | | #else |
| | | KBusSlaveFunc(2); |
| | | KBusSlaveFunc(&KBus1); |
| | | if (! KMem.RunStat) {KMem.WLY[0]=0;} |
| | | // KMem.WLY[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 (KBus1.RunStat) {KBus1.RunStat--;} |
| | | if (KBus1.ErrStat) {KBus1.ErrStat--;} |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | |
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | KMem.ErrStat = 0 + KBus1.ErrStat; |
| | | if (!KMem.ErrStat) |
| | | { |
| | | SetErrLed(0); |