/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h"
#include "string.h"

#include "Data_deal.h"
#include "iap.h"
#include "md5c.h"
#include "stmflash.h"
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

#define iap_ 1
#if 1
#define IR_ROM1   0x08000000
#else
#define IR_ROM1   0x08020000
#endif
/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
#define Rx_Max 1024  	
#define Version_sys 0x23060800  	

extern uint16_t Adc2_CalibrationValue ;
extern uint16_t Adc3_CalibrationValue ;
extern uint8_t  gpioaStatus ;
extern uint8_t  gpiobStatus ; 
extern uint8_t	Rx_Flag;
extern uint16_t	Rx_Len;
extern uint8_t	Rx_Buf[Rx_Max];

extern int data_lengthU2;
extern int flagU2Rx;
/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */
uint16_t read_flash_16(uint32_t addr);
void read_new_address(uint32_t addr);
void Write_Information(uint32_t addr, uint8_t* rx_buffer, uint8_t buffer_index);
void delay_sys_us(uint32_t Delay);
void ModBus(void);
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/

/* USER CODE BEGIN Private defines */
#define FILTER_LENGTH 10
#define DEBOUNCE_COUNT 10
#define Modbus 1

#define ADDR_FLASH_PAGE_94    ((uint32_t)0x802F000)  // Flash扇区94页的起始地址      address
#define ADDR_FLASH_PAGE_104   ((uint32_t)0x8034000)  // Flash扇区104页的起始地址     PbStatus
#define ADDR_FLASH_PAGE_114   ((uint32_t)0x8039000)  // Flash扇区114页的起始地址     Baudrate
#define ADDR_FLASH_PAGE_124   ((uint32_t)0x803E000)  // Flash扇区124页的起始地址     Adc2_Calibration    4-20mA
#define ADDR_FLASH_PAGE_134   ((uint32_t)0x8043000)  // Flash扇区134页的起始地址     Adc3_Calibration    4-20mA
#define ADDR_FLASH_PAGE_144   ((uint32_t)0x8048000)  // Flash扇区144页的起始地址      
  
#define ADDR_UPDATE_FLAG               	 0x0807F078                     
#define StartMode_Addr                	 0x0807F07A                       

#define Application_Buffer_Addr      	 0x08040000
#define ADD_UPDATE_PROG             	 0x08020000                          
#define ADD_UPDATE_PROG1            	 0x08000000


/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
