| | |
| | | #include "debug.h" |
| | | #include "Functions.h" |
| | | #include "KMachine.h" |
| | | #if (ENABLE_PLC) |
| | | #include "PLCfunctions.h" |
| | | #endif |
| | | //#include "KBus.h" |
| | | #include "KLink.h" |
| | | #include "string.h" |
| | | #include "BSP.h" |
| | | #include "ModbusRTU.h" |
| | | #if (BOARD_TYPE == 13) |
| | | #if (ENABLE_NET) |
| | | #include "w5500_port.h" |
| | | #include "../src/Ethernet/socket.h" |
| | | #include "../src/Ethernet/loopback.h" |
| | | #elif (BOARD_TYPE == 14) |
| | | #endif |
| | | |
| | | #if (ENABLE_FPX) |
| | | #include "FPx.h" |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | #endif |
| | | |
| | | #if (ENABLE_RF) |
| | | #include "KWireless.h" |
| | | #endif |
| | | //#include "user.h" |
| | | //#include "../src/radio/inc/sx126x-board.h" |
| | | #endif |
| | | |
| | | |
| | | /* USER CODE END Includes */ |
| | | |
| | |
| | | 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; |
| | | stKBusDef KBus1; // |
| | | |
| | | #define RAM_START_ADDR 0x20000000 |
| | | #define VECTOR_SIZE 45 |
| | |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | } |
| | | if (Uart2Stat.bPacketRecved) |
| | | { |
| | | KBusPacketSendDone(&KBus1); |
| | | } |
| | | } |
| | | |
| | | /* |
| | |
| | | case evFPxDataUpdate: |
| | | for (int i=0;i<16;i++){ |
| | | KBusMem.WLY[i]=FPxMem.WLY[i]; |
| | | KMem.WLY[i]=FPxMem.WLY[i]; |
| | | KMem.WY[i]=FPxMem.WLY[i]; |
| | | } |
| | | for (int i=0;i<16;i++) { |
| | | FPxMem.WLX[i]=KBusMem.WLX[i]; |
| | |
| | | case KBusEvDataUpdate: |
| | | for (int i=0;i<16;i++){ |
| | | KBusMem.WLY[i]=FPxMem.WLY[i]; |
| | | KMem.WLY[i]=FPxMem.WLY[i]; |
| | | } |
| | | |
| | | for (int i=0;i<16;i++) { |
| | | KMem.WLX[i]=KBusMem.WLX[i]; |
| | | FPxMem.WLX[i]=KBusMem.WLX[i]; |
| | | KMem.WX[i]=KBusMem.WLX[i]; |
| | | } |
| | | |
| | | // KBusMem.WLY[0]=0x0301; |
| | | break; |
| | | |
| | | default: |
| | | break; |
| | | } |
| | | KMem.DT[2]++; |
| | | return 0; |
| | | } |
| | | |
| | |
| | | // RemapIrqVector(); |
| | | ///* |
| | | __set_PRIMASK(0); //打开全局中断 |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | InitUartstat(&Uart1Stat,Uart1RxBuf,sizeof(Uart1RxBuf),Uart1TxBuf,sizeof(Uart1TxBuf)); |
| | | InitUartstat(&Uart2Stat,Uart2RxBuf,sizeof(Uart2RxBuf),Uart2TxBuf,sizeof(Uart2TxBuf)); |
| | |
| | | ReadSysCfgFromFlash(&storedKMSysCfg); |
| | | |
| | | KMRunStat.bLEDFlick = 1; |
| | | |
| | | |
| | | KLinkInit(1); //注册KLink端口 |
| | | |
| | | // stPortDef PortReg1 = {.nPortHardType = 3,.nPortUseType = 2}; |
| | | // KMRegisterPort(0,&PortReg1); |
| | | |
| | | |
| | | int bKBusMaster,bKBusSlave,bKBusRepeater;; |
| | | int nChilds; |
| | | int nKBusStationId; |
| | | int nKBusChilds; |
| | | KMem.CurJumperSW=ReadJumperSW(); |
| | | KMem.EffJumperSW=KMem.CurJumperSW; |
| | | nChilds=KMem.EffJumperSW&0x0f; |
| | | |
| | | nKBusStationId=KMem.EffJumperSW&0x0f; |
| | | |
| | | nKBusChilds = nKBusStationId; |
| | | // Uart2Baud = AlterUart2Baud; |
| | | |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc), |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nChilds); |
| | | |
| | | KBusInitMaster(&KBus1, (KBusSendPktFuncDef)PutStr2, nKBusChilds); |
| | | KBusSetEvCallBackFunc(&KBus1, &KBusEvCallBackFunc); |
| | | |
| | | #if (BOARD_TYPE == 14) |
| | | KMem.EffJumperSW|=0x10; |
| | | nChilds=KMem.EffJumperSW&0x0f; |
| | | if ((KMem.EffJumperSW&0x10)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | KMem.EffJumperSW|=0x40; |
| | | |
| | | if ((KMem.EffJumperSW&0x40)!=0) {bKBusMaster=1;bKBusSlave=0;} |
| | | else{bKBusMaster=0;bKBusSlave=1;} |
| | | |
| | | FPxSetCallBackFunc(&FPxCallBackFunc); |
| | | FPx_Init(nChilds); |
| | | FPx_SetIOCount(8,5); |
| | | FPx_Init(nKBusChilds); |
| | | |
| | | int IOByteCount = nKBusChilds; |
| | | FPx_SetIOCount(IOByteCount,IOByteCount); |
| | | |
| | | #elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
| | | nStationID=1 ;//KMem.EffJumperSW&0x0f; |
| | |
| | | {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;} |
| | | 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 |
| | | |
| | | UNUSED(bKBusRepeater); |
| | | //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(); } |
| | | } |
| | | |
| | | #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; |
| | |
| | | #endif |
| | | |
| | | // 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 (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;} |
| | |
| | | for (int i=0;i<FPxStat.nOutputBytes;i++) |
| | | {KBusMem.WLYB[i]=FPxMem.WLYB[i];} |
| | | #endif |
| | | if (nChilds>0) { KBusMasterFunc(&KBus1); } |
| | | KBusLoopProcess(&KBus1); |
| | | |
| | | } |
| | | if (haltick&0x00002000) SlowFlicker=1; |
| | |
| | | if (bKBusSlave) |
| | | { |
| | | |
| | | KBusSlaveFunc(&KBus1); |
| | | KBusLoopProcess(&KBus1); |
| | | if (KBus1.nSlaveTick&0x00002000) SlowFlicker=1; |
| | | else SlowFlicker=0; |
| | | 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) |
| | | { |
| | | SetRunLed(FastFlicker); |
| | |
| | | } |
| | | else |
| | | { |
| | | #if (ENABLE_PLC) |
| | | if (KMRunStat.WorkMode==1 ) { |
| | | if (PLCMem.bPLCRunning){SetRunLed(SlowFlicker);} |
| | | else {SetRunLed(0);} |
| | | } |
| | | else { |
| | | else |
| | | #endif |
| | | { |
| | | if (!KBus1.RunStat) SetRunLed(SlowFlicker); |
| | | else SetRunLed(FastFlicker); |
| | | } |
| | | if (FPxStat.bConfiged) { |
| | | SetErrLed(0); |
| | | } |
| | | else { |
| | | SetErrLed(FastFlicker); |
| | | } |
| | | if (!KBus1.ErrStat) |
| | | { |
| | | SetErrLed(0); |
| | |
| | | } |
| | | // KMem.WY[0]=KMem.WLY[0]; |
| | | #elif (BOARD_TYPE == 14) |
| | | |
| | | for (int i=0;i<16;i++) { |
| | | KMem.WLX[i]=KBusMem.WLX[i]; |
| | | FPxMem.WLX[i]=KBusMem.WLX[i]; |
| | | KMem.WX[i]=KBusMem.WLX[i]; |
| | | } |
| | | #else |
| | | |
| | | KMem.WLX[0]=KMem.WX[0]; |
| | |
| | | // mapping bits. |
| | | for (int i=0;i<6;i++) |
| | | { |
| | | USHORT bitaddr = storedKMSysCfg.theKMSysCfg.OutMappings[i]; |
| | | USHORT bitaddr = storedKMSysCfg.theKMSysCfg.OutMappings[i].value; |
| | | UCHAR type = (bitaddr&0xf000) >>12; |
| | | USHORT byteaddr = (bitaddr&0x0ff0) >>4; |
| | | UCHAR bitpos = bitaddr &0x0f; |
| | | UCHAR bitvalue = 0 ; |
| | | if (byteaddr>0) { |
| | | if (type == 0) bitvalue = KMem.WXB[byteaddr-1] & ( 1 << bitpos ); |
| | | else if (type == 1 ) bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos ); |
| | | if (type == 0) {bitvalue = KMem.WXB[byteaddr-1] & ( 1 << bitpos );} |
| | | else if (type == 1 ) {bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos );} |
| | | //else if (type == 2 ) {bitvalue = KMem.WRB[byteaddr-1] & ( 1 << bitpos );} |
| | | else if (type == 3 ) {bitvalue = KMem.WLXB[byteaddr-1] & ( 1 << bitpos );} |
| | | else if (type == 4 ) {bitvalue = KMem.WLYB[byteaddr-1] & ( 1 << bitpos );} |
| | | // else if (type == 5 ) {bitvalue = KMem.WYB[byteaddr-1] & ( 1 << bitpos );} |
| | | } |
| | | if (bitvalue){ LL_GPIO_SetOutputPin(GPIOB,pins[i]);} |
| | | else {LL_GPIO_ResetOutputPin(GPIOB,pins[i]);} |