| | |
| | | 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; |
| | | |
| | | unsigned char bSLPMaster =1; |
| | | unsigned char nSLPStation = 1; |
| | | |
| | | stSLPDef SLP1; |
| | | /* 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)); |
| | | } |
| | | } |
| | | |
| | | void * KBusEvCallBackFunc(void * pParam, int nEvent, void *pBuf, int nLen1) |
| | | { |
| | | switch (nEvent){ |
| | | |
| | |
| | | |
| | | /* Initialize all configured peripherals */ |
| | | MX_GPIO_Init(); |
| | | LL_GPIO_InitTypeDef GPIO_InitStruct; |
| | | GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
| | | GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
| | | GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
| | | GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
| | | LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | MX_DMA_Init(); |
| | | |
| | | KMachineInit(); |
| | | ReadSysCfgFromFlash(&storedKMSysCfg); |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | int bKBusMaster,bKBusSlave,bKBusRepeater;; |
| | | int nKBusStationId; |
| | | int nKBusChilds; |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | nKBusStationId=KMem.EffJumperSW&0x0f; |
| | | |
| | | nKBusChilds = nKBusStationId; |
| | | |
| | | bSLPMaster = 1; // KMem.EffJumperSW&0x20 ; //master? |
| | | nStation = 1; |
| | | nSLPStation = 1; |
| | | |
| | | // Uart2Baud = AlterUart2Baud; |
| | | |
| | |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | KMem.EffJumperSW|=0x10; |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | int nKBusChilds=KMem.EffJumperSW&0x0f; |
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | nChilds=nStationID; |
| | | FPx_Init(); |
| | | |
| | | FPxSetCallBackFunc(&FPxCallBackFunc); |
| | | FPx_Init(nKBusChilds); |
| | | |
| | | int IOByteCount = nKBusChilds; |
| | | FPx_SetIOCount(IOByteCount,IOByteCount); |
| | | |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | |
| | | // else |
| | | {bKBusMaster=0;bKBusSlave=1;} |
| | | #else |
| | | nStationID=KMem.EffJumperSW&0x0f; |
| | | if (KMem.EffJumperSW == 0x1f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | nKBusStationId=KMem.EffJumperSW&0x0f; |
| | | if (KMem.EffJumperSW == 0x3f) {bKBusRepeater=1;bKBusMaster=1;bKBusSlave=0;} |
| | | else if ((KMem.EffJumperSW&0x20)!=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); |
| | | |
| | | nChilds=nStationID; |
| | | nCurPollId=1; |
| | | } else if (bKBusSlave) { |
| | | KBusInitSlave(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusStationId,&MyDeviceInfo); |
| | | } |
| | | |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
| | | |
| | | //if (KMem.EffJumperSW == 0x00) |
| | | Uart1Baud = DefaultUart1Baud; |
| | | MX_USART1_UART_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) |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | KWireLessStart(); |
| | |
| | | int haltick=HAL_GetTick(); |
| | | |
| | | 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; |
| | |
| | | // */ |
| | | |
| | | // pProgs = (stBinProg1 *) STORE_PRG_BASE; |
| | | |
| | | #if (ENABLE_PLC) |
| | | if ( KMRunStat.WorkMode==1 ) //&& bKBusMaster) |
| | | { |
| | | if (KMRunStat.nBinProgBank == 0){ |
| | |
| | | |
| | | ProcessPLCBinProg(pProgs, nSizeProg1); |
| | | } |
| | | #endif |
| | | |
| | | KMem.ScanTimeuS=us2-KMem.LastScanTime; |
| | | KMem.LastScanTime = us2; |
| | |
| | | |
| | | if (bKBusMaster) |
| | | { |
| | | |
| | | if (nChilds>0) { KBusMasterFunc(2); } |
| | | |
| | | KBusLoopProcess(&KBus1); |
| | | } |
| | | if (haltick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | |
| | | if (bKBusSlave) |
| | | { |
| | | |
| | | KBusSlaveFunc(2); |
| | | if (! KMem.RunStat) {KBusMem.WLY[0]=0;} |
| | | KBusLoopProcess(&KBus1); |
| | | // if (! KBus1.RunStat) {KBusMem.WLY[0]=0;} |
| | | KMem.WLY[0]=KBusMem.WLY[0]; |
| | | |
| | | 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; |
| | | |
| | | } |
| | |
| | | KBusMem.WLX[2]=KMem.WX[2]; |
| | | KBusMem.WLX[3]=KMem.WX[3]; |
| | | |
| | | // KMem.WY[0]=nCount2>>5; |
| | | if (KMem.RunStat) {KMem.RunStat--;} |
| | | if (KMem.ErrStat) {KMem.ErrStat--;} |
| | | |
| | | if (KMRunStat.bLEDFlick) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif |
| | | { |
| | | if (!KMem.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | KMem.ErrStat = KBus1.ErrStat + SLP1.SLPErrSign; |
| | | if (!KMem.ErrStat) |
| | | { |
| | | SetErrLed(0); |
| | |
| | | if (bKBusSlave) HAL_Delay(0); |
| | | |
| | | if (Uart6Stat.bPacketRecved){ |
| | | SLPparsePacket(Uart6RxBuf,Uart6RecvBuf1DataLen); |
| | | SLPparsePacket(&SLP1,Uart6RxBuf,Uart6RecvBuf1DataLen); |
| | | Uart6RecvBuf1DataLen =0; |
| | | Uart6Stat.bPacketRecved = 0; |
| | | } |
| | | |
| | | SLPinputB = KMem.WYB[1]; |
| | | SLPProcess(); |
| | | KMem.WXB[1] = SLPoutputB; |
| | | SLP1.SLPinputB = KMem.WYB[1]; |
| | | SLPProcess(&SLP1); |
| | | KMem.WXB[1] = SLP1.SLPoutputB; |
| | | |
| | | // YDLiDar process; |
| | | |
| | |
| | | // KMem.WX[1]++ ; |
| | | // KMem.WX[2]++; |
| | | |
| | | |
| | | // KMem.WYB[0]=1; |
| | | PutOutput (KMem.WY[0]); |
| | | |
| | | LL_IWDG_ReloadCounter(IWDG); |