| | |
| | | #include "string.h" |
| | | #include "BSP.h" |
| | | #include "ModbusRTU.h" |
| | | #include "spiflash.h" |
| | | |
| | | #if (BOARD_TYPE == 13) |
| | | #include "w5500_port.h" |
| | | #include "../src/Ethernet/socket.h" |
| | |
| | | unsigned char Uart2RxBuf[RX2BUFSIZE]; |
| | | unsigned char Uart2TxBuf[TX2BUFSIZE]; |
| | | |
| | | unsigned char Uart1RxBuf1[Uart1RxBufSize]; |
| | | unsigned char Uart1TxBuf1[260]; |
| | | |
| | | unsigned char Uart2RxBuf1[RX2BUFSIZE]; |
| | | unsigned char Uart2TxBuf1[TX2BUFSIZE]; |
| | | |
| | | unsigned short Uart1RxBuf1DataLen = 0; |
| | | unsigned short Uart2RxBuf1DataLen = 0; |
| | | |
| | | unsigned char Uart1Mode = 1; //Uart1工作模式, 0 : 普通, 1 : 透传模式 |
| | | |
| | | unsigned int Uart1Baud = DefaultUart1Baud; |
| | | unsigned int Uart2Baud = DefaultUart2Baud; |
| | | |
| | | //unsigned char Uart1RecvBuf1[Uart1RecvBufSize]; |
| | | //unsigned short Uart1RecvBuf1DataLen=0; |
| | | |
| | | //unsigned char Uart2RecvBuf1[128]; |
| | | //unsigned short Uart2RecvBuf1DataLen=0; |
| | | |
| | | volatile char Uart1BaudGot=0; |
| | | volatile char Uart1BaudFirstGot=0; |
| | | volatile char Uart1DmaInts=0; |
| | | |
| | | |
| | | unsigned char SlowFlicker=0; |
| | | 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 -----------------------------------------------*/ |
| | |
| | | /* USER CODE END PFP */ |
| | | |
| | | /* USER CODE BEGIN 0 */ |
| | | #define SET_SCL LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6) |
| | | #define CLR_SCL LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_6) |
| | | #define GET_SCL LL_GPIO_IsInputPinSet(GPIOB,LL_GPIO_PIN_6) |
| | | #define SET_SDA LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_7) |
| | | #define CLR_SDA LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_7) |
| | | #define GET_SDA LL_GPIO_IsInputPinSet(GPIOB,LL_GPIO_PIN_7) |
| | | |
| | | |
| | | void soft_i2c_start() |
| | | { |
| | | SET_SDA; |
| | | SET_SCL; |
| | | Delay100nS(1); |
| | | CLR_SDA; |
| | | Delay100nS(1); |
| | | CLR_SCL; |
| | | Delay100nS(1); |
| | | } |
| | | void soft_i2c_stop() |
| | | { |
| | | CLR_SDA; |
| | | Delay100nS(1); |
| | | SET_SCL; |
| | | Delay100nS(1); |
| | | SET_SDA; |
| | | Delay100nS(1); |
| | | } |
| | | void soft_i2c_send8(int nData) |
| | | { |
| | | int mask; |
| | | mask = 0x80; |
| | | for (int j=0;j<8;j++) |
| | | { |
| | | if (nData & mask) {SET_SDA;} |
| | | else {CLR_SDA;} |
| | | Delay100nS(1); |
| | | SET_SCL; |
| | | mask>>=1; |
| | | Delay100nS(1); |
| | | CLR_SCL; |
| | | } |
| | | return; |
| | | } |
| | | |
| | | uint8_t soft_i2c_recv8() |
| | | { |
| | | unsigned char nData=0; |
| | | for (int j=0;j<8;j++) |
| | | { |
| | | nData <<=1; |
| | | Delay100nS(1); |
| | | SET_SCL; |
| | | nData |= GET_SDA; |
| | | Delay100nS(1); |
| | | CLR_SCL; |
| | | } |
| | | return nData; |
| | | } |
| | | |
| | | void soft_i2c_send_ack() |
| | | { |
| | | CLR_SDA; |
| | | Delay100nS(2); |
| | | SET_SCL; |
| | | Delay100nS(2); |
| | | CLR_SCL; |
| | | SET_SDA; |
| | | Delay100nS(2); |
| | | |
| | | } |
| | | |
| | | void soft_i2c_send_nack() |
| | | { |
| | | SET_SDA; |
| | | Delay100nS(1); |
| | | SET_SCL; |
| | | Delay100nS(1); |
| | | CLR_SCL; |
| | | Delay100nS(1); |
| | | SET_SDA; |
| | | } |
| | | uint8_t soft_i2c_wait_ack(int nTime) |
| | | { |
| | | SET_SDA; // Open Drain; |
| | | Delay100nS(1); |
| | | SET_SCL; |
| | | for (int j=0;j<nTime;j++){ |
| | | Delay100nS(1); |
| | | if (GET_SDA == 0) break; |
| | | if (j==nTime-1) return 0; |
| | | } |
| | | CLR_SCL; |
| | | return 1; |
| | | } |
| | | uint8_t soft_i2c_check_addr(uint8_t Addr) |
| | | { |
| | | uint8_t res=0; |
| | | soft_i2c_start(); |
| | | // Send Device Addr 7bit; |
| | | soft_i2c_send8(Addr); |
| | | if (soft_i2c_wait_ack(10)) {res=1;} |
| | | //Stop |
| | | soft_i2c_stop(); |
| | | // */ |
| | | return res; |
| | | |
| | | } |
| | | uint8_t soft_i2c_read_len( uint8_t Addr , uint8_t Reg, uint8_t len,uint8_t *buf) |
| | | { |
| | | int res=0; |
| | | //Start |
| | | soft_i2c_start(); |
| | | // Send Device Addr 7bit; |
| | | soft_i2c_send8(Addr &0xfe); |
| | | // wait Ack; |
| | | if (!soft_i2c_wait_ack(1000)) {soft_i2c_stop();return 1;} |
| | | CLR_SCL; |
| | | // Send Reg Addr 8bit; |
| | | soft_i2c_send8(Reg); |
| | | if (!soft_i2c_wait_ack(1000)) {soft_i2c_stop();return 2;} |
| | | //Start |
| | | soft_i2c_start(); |
| | | // Send Device Addr 7bit; |
| | | soft_i2c_send8(Addr | 1); |
| | | if (!soft_i2c_wait_ack(1000)) {soft_i2c_stop();return 3;} |
| | | |
| | | // /* |
| | | // Recv Data(s) n * 8bit; |
| | | SET_SDA; // Open Drain; |
| | | for (int i=0;i<len;i++) |
| | | { |
| | | // recv 1 data 8bit; |
| | | unsigned char nData = 0; |
| | | nData = soft_i2c_recv8(); |
| | | buf[i]=nData; |
| | | // Send ACK / NACK; |
| | | if (i != len -1) { //ACK |
| | | soft_i2c_send_ack(); |
| | | } else { // NACK |
| | | soft_i2c_send_nack(); |
| | | } |
| | | } |
| | | |
| | | //Stop |
| | | soft_i2c_stop(); |
| | | // */ |
| | | return res; |
| | | } |
| | | |
| | | uint8_t soft_i2c_write_len(uint8_t Addr , uint8_t Reg, uint8_t len, uint8_t *buf) |
| | | { |
| | | int res=0; |
| | | //Start |
| | | soft_i2c_start(); |
| | | // Send Device Addr 7bit; |
| | | soft_i2c_send8(Addr &0xfe); |
| | | // wait Ack; |
| | | if (!soft_i2c_wait_ack(1000)) return 1; |
| | | CLR_SCL; |
| | | // Send Reg Addr 8bit; |
| | | soft_i2c_send8(Reg); |
| | | if (!soft_i2c_wait_ack(1000)) return 2; |
| | | for (int i=0;i<len;i++) |
| | | { |
| | | // send 1 data 8bit; |
| | | unsigned char nData = buf[i]; |
| | | soft_i2c_send8(nData); |
| | | // wait Ack; |
| | | if (!soft_i2c_wait_ack(1000)) {res = 5; break;} |
| | | } |
| | | //Stop |
| | | soft_i2c_stop(); |
| | | return res; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | int HexToInt(char ch) |
| | | { |
| | |
| | | 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)Uart2RxBuf1, Uart2RxBuf1DataLen); |
| | | Uart2RxBuf1DataLen=0; |
| | | Uart2Stat.bPacketRecved=0; |
| | | Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); |
| | | 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) { |
| | | for (int i=0;i<16;i++) |
| | | { |
| | | KMem.WLX[i]=KBusMem.WLX[i]; //KPLC with KBus Master |
| | | KBusMem.WLY[i]=KMem.WLY[i]; |
| | | } |
| | | } else if (KBus1.bSlave) { |
| | | KMem.WLX[0]=KBusMem.WLY[0]; //KPLC with KBus Slave |
| | | KBusMem.WLX[0]=KMem.WLY[0]; |
| | | KMem.WLX[1]=KBusMem.WLY[1]; //KPLC with KBus Slave |
| | | KBusMem.WLX[1]=KMem.WLY[1]; |
| | | KMem.WLX[2]=KBusMem.WLY[2]; //KPLC with KBus Slave |
| | | KBusMem.WLX[2]=KMem.WLY[2]; |
| | | KMem.WLX[3]=KBusMem.WLY[3]; //KPLC with KBus Slave |
| | | KBusMem.WLX[3]=KMem.WLY[3]; |
| | | } |
| | | |
| | | break; |
| | | case KBusEvCmdResponse: |
| | | break; |
| | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | /* USER CODE END 0 */ |
| | | /** |
| | | * @brief This function handles EXTI line 0 and 1 interrupts. |
| | | */ |
| | | void EXTI0_1_IRQHandler(void) |
| | | { |
| | | /* USER CODE BEGIN EXTI0_1_IRQn 0 */ |
| | | |
| | | /* USER CODE END EXTI0_1_IRQn 0 */ |
| | | if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_0) != RESET) |
| | | { |
| | | LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_0); |
| | | /* USER CODE BEGIN LL_EXTI_LINE_1 */ |
| | | |
| | | unsigned char PowerVolt = LL_GPIO_IsInputPinSet(GPIOA,LL_GPIO_PIN_0); |
| | | // KMem.WDT[79]++;// KMem.WDT[79]++; |
| | | /* |
| | | if (PowerVolt == 0) |
| | | { |
| | | PowerDownFlag=1; |
| | | }else |
| | | { |
| | | PowerDownFlag=0; |
| | | } |
| | | // */ |
| | | /* USER CODE END LL_EXTI_LINE_1 */ |
| | | } |
| | | /* USER CODE BEGIN EXTI0_1_IRQn 1 */ |
| | | |
| | | /* USER CODE END EXTI0_1_IRQn 1 */ |
| | | } |
| | | |
| | | void EXIT_Init() |
| | | { |
| | | LL_EXTI_InitTypeDef EXTI_InitStruct = {0}; |
| | | |
| | | /* GPIO Ports Clock Enable */ |
| | | LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
| | | |
| | | /**/ |
| | | LL_SYSCFG_SetEXTISource(LL_SYSCFG_EXTI_PORTA, LL_SYSCFG_EXTI_LINE0); |
| | | |
| | | /**/ |
| | | LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_0, LL_GPIO_PULL_NO); |
| | | |
| | | /**/ |
| | | LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_0, LL_GPIO_MODE_INPUT); |
| | | |
| | | /**/ |
| | | EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_0; |
| | | EXTI_InitStruct.LineCommand = ENABLE; |
| | | EXTI_InitStruct.Mode = LL_EXTI_MODE_IT; |
| | | EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING_FALLING; |
| | | LL_EXTI_Init(&EXTI_InitStruct); |
| | | |
| | | /* EXTI interrupt init*/ |
| | | NVIC_SetPriority(EXTI0_1_IRQn, 0); |
| | | NVIC_EnableIRQ(EXTI0_1_IRQn); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @brief The application entry point. |
| | |
| | | /* Initialize all configured peripherals */ |
| | | MX_GPIO_Init(); |
| | | MX_DMA_Init(); |
| | | |
| | | // EXIT_Init(); |
| | | KMachineInit(); |
| | | ReadSysCfgFromFlash(&storedKMSysCfg); |
| | | |
| | | 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(); |
| | | MX_USART2_UART_Init(); |
| | | |
| | | MX_SPI1_Init(); |
| | | LL_SPI_EnableIT_RXNE(SPI1); |
| | | |
| | | |
| | | /* |
| | | // MX_I2C1_Init(); |
| | | Soft_I2C1_Init(); |
| | | |
| | | unsigned char buf1[10] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa}; |
| | | unsigned char buf2[10]; |
| | | // KMem.WDB[80] = soft_i2c_read_len(0xa0,0x00,8,buf2); |
| | | // for (int i=0;i<8;i++){ |
| | | // buf2[i]+=1; |
| | | // } |
| | | // soft_i2c_write_len (0xa0,0x00,8,buf2); |
| | | // DelayUs(500); |
| | | // KMem.WDB[80] = soft_i2c_read_len(0xa0,0x00,8,&KMem.WDB[81]); |
| | | // DelayUs(500); |
| | | // KMem.WDB[90] = soft_i2c_read_len(0xa0,0x00,8,&KMem.WDB[91]); |
| | | |
| | | int nPos = 80; |
| | | int nCount =0; |
| | | for (int i=0;i<256;i++) |
| | | { |
| | | if (soft_i2c_check_addr(i)){ |
| | | KMem.WDB[nPos + 1 + nCount ] = i; |
| | | nCount+=1; |
| | | } |
| | | DelayUs(10); |
| | | } |
| | | KMem.WDB[nPos] = nCount; |
| | | */ |
| | | #if (BOARD_TYPE == 14) |
| | | // MX_SPI2_Init(); |
| | | // MX_ADC_Init(); |
| | |
| | | MX_SPI2_Init(); |
| | | MX_ADC_Init(); |
| | | #endif |
| | | |
| | | |
| | | MX_IWDG_Init(); |
| | | |
| | | MX_TIM6_Init(); |
| | |
| | | LL_USART_EnableIT_TC(USART1); |
| | | |
| | | // LL_USART_EnableIT_RXNE(USART2); |
| | | Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1)); |
| | | Uart2RecvDMA(Uart2RxBuf1,sizeof(Uart2RxBuf1)); |
| | | LL_USART_EnableIT_IDLE(USART2); |
| | | LL_USART_EnableIT_TC(USART2); |
| | | #if (BOARD_TYPE == 13) |
| | |
| | | // LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
| | | } |
| | | //LL_USART_EnableIT_TXE(USART1); |
| | | |
| | | // KMem.WDT[50] = SPI_Flash_ReadID(); |
| | | |
| | | /* USER CODE END 2 */ |
| | | |
| | | |
| | |
| | | |
| | | KMRunStat.WorkMode = 1; |
| | | //KMRunStat.WorkMode2 = 0; |
| | | |
| | | W25QXX_Read((uchar *)(&KMem.DT[100]),256,28*2); |
| | | |
| | | if (KMRunStat.WorkMode == 1){ |
| | | InitPLC(); |
| | | KMRunStat.WorkMode2 = KMem.CurJumperSW&0x20 ; |
| | |
| | | KWireLessStart(); |
| | | #endif |
| | | |
| | | LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_15); |
| | | KMem.WDT[82]=0; |
| | | |
| | | W25QXX_Read(&KMem.WDB[160],0,64); |
| | | KMem.WDT[82]++; |
| | | KMem.WDT[81]++; |
| | | W25QXX_Erase_Sector(0); |
| | | int time1=GetuS(); |
| | | // W25QXX_Write_Page(&KMem.WDB[160],0,64); |
| | | // SPI_Flash_Wait_Busy(); |
| | | int time2=GetuS(); |
| | | KMem.WDD[38] =time2-time1; |
| | | // W25QXX_Erase_Sector(0); |
| | | |
| | | KMem.SDT[64] = SPI_Flash_ReadID(); |
| | | while (1) |
| | | { |
| | | //int MyKeyStat1,MyKeyStat2; |
| | |
| | | |
| | | //*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount; |
| | | // KMem.nRunCount=nRunCount; |
| | | // LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_5); |
| | | // KMem.SDT[64] = SPI_Flash_ReadID(); |
| | | // SPI_FLASH_Write_Enable(); |
| | | // KMem.SDT[65] = SPI1_Flash_ReadSR(); |
| | | |
| | | |
| | | SlowFlicker=0; |
| | | FastFlicker=1; |
| | | us1=GetuS(); |
| | |
| | | // *((unsigned int *)&(PLCMem.SDT[2]))=nChilds; |
| | | // 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); |
| | |
| | | displayInput(KMem.WX[0]); |
| | | } |
| | | us2=GetuS(); |
| | | if (PowerDownEvent) { KMem.WX[0]=0;} |
| | | if (PowerDownFlag) {KMem.WX[0]=0;} |
| | | ///* |
| | | if ((KMem.nRunCount &0x1f) == 0x02) |
| | | if ((KMem.nRunCount &0xf) == 0x02) |
| | | { |
| | | ADCProcess(); |
| | | if (PowerDownEvent) |
| | | if (PowerDownFlag) |
| | | { |
| | | KMem.WX[0]=0; |
| | | if (!OldPowerDownEvent) |
| | | if (!OldPowerDownFlag) |
| | | { |
| | | OldPowerDownEvent = PowerDownEvent; |
| | | OldPowerDownFlag = PowerDownFlag; |
| | | OldPowerDownEventTime = nCurTick; |
| | | |
| | | KMem.WDT[80]++; |
| | | KMem.WDT[81]++; |
| | | CLR_SDA; |
| | | W25QXX_Erase_Sector(0); |
| | | W25QXX_Write_Page((uchar *)(&KMem.DT[100]),256,28*2); |
| | | W25QXX_Write_Page(&KMem.WDB[160],0,64); |
| | | SET_SDA; |
| | | PowerDownProcess(); |
| | | } |
| | | }else |
| | | { |
| | | if (OldPowerDownEvent) |
| | | if (OldPowerDownFlag) |
| | | { |
| | | OldPowerDownEvent=PowerDownEvent; |
| | | OldPowerDownFlag=PowerDownFlag; |
| | | PowerRecoverProcess(); |
| | | |
| | | } |
| | |
| | | |
| | | #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); |
| | |
| | | // 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) |
| | | if (Uart1RxBuf1DataLen >0 && Uart1Stat.bPacketRecved) |
| | | { |
| | | int res1 = -1; |
| | | res1 = ModBusSlaveParsePkg(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
| | | res1 = ModBusSlaveParsePkg(1, Uart1RxBuf1, Uart1RxBuf1DataLen); |
| | | if (res1 !=0) |
| | | { |
| | | KLParsePacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen); |
| | | KLParsePacket(1, Uart1RxBuf1, Uart1RxBuf1DataLen); |
| | | } |
| | | Uart1RecvBuf1DataLen=0; |
| | | Uart1RxBuf1DataLen=0; |
| | | Uart1Stat.bPacketRecved=0; |
| | | Uart1IdelTimer = 0; |
| | | }else { |