| | |
| | | #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" |
| | |
| | | |
| | | |
| | | /* 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); |
| | | |
| | |
| | | MX_USART1_UART_Init(); |
| | | MX_USART2_UART_Init(); |
| | | MX_SPI1_Init(); |
| | | LL_SPI_EnableIT_RXNE(SPI1); |
| | | |
| | | |
| | | /* |
| | | // MX_I2C1_Init(); |
| | | Soft_I2C1_Init(); |
| | |
| | | |
| | | 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 ; |
| | |
| | | KWireLessInit(KMem.EffJumperSW&0x20,KMem.EffJumperSW&0x0f); |
| | | 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(); |
| | |
| | | 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(); |
| | | |
| | | } |