/*
 * @Description: 
 * @Version: 2.0
 * @Author: Seven
 * @Date: 2023-08-30 09:45:29
 * @LastEditors: Seven
 * @LastEditTime: 2024-04-19 09:05:46
 */
#include "board.h"
#include "myflash.h"
#include "update.h"
#include "delay.h"
#include "bsp.h"
#include "led.h"
#include "at24cXX.h"
#include "uart.h"
#include "ota.h"
#include "key.h"




uint32_t Count = 0;
int main(void)
{
    apb_clken = SYS->APB_CLKENABLE;
    misc_ctrl = SYS->MISC_CNTL;

    //bsp_init();
    board_init();
    //led_init();

    uart0_init();
    I2C_init();
    IWDG_Config();
    printf("\n**************************************\n");
    printf("boot begin\n");
    printf("\nInit done. CLK: %.3fMHz, RTC: %dHz \n", SYS_GetSysClkFreq()/(double)1e6, BOARD_RTC_FREQUENCY);

    eeprom_init_handle();

    myiap_task();//升级流程处理

    eeprom_info_update();

	//打印信息
	printf(" bootloader信息:\n");
	printf(" first init       = %04x\n",device_public_info.eeprom_first_flag);
	printf(" eeprom ver       = %02x\n",device_public_info.eeprom_ver);
	printf(" reset num        = %u\n",Reset_cnt);
	printf(" boot ver         = %08x\n",device_mcu_info.bootloader_ver);
    printf(" pt ver           = %08x\n",device_mcu_info.pt_ver);
	printf(" app1 ver         = %08x\n",device_mcu_info.app1_ver);
	printf(" app2 ver         = %08x\n",device_mcu_info.app2_ver);
	printf(" app3 ver         = %08x\n",device_mcu_info.app3_ver);
    printf(" fpga ver         = %08x\n",device_mcu_info.fpga_ver);

    IWDG_feed();
    delay_us(1000);
    run_app();

    while(1)
    {
        delay_ms(500);
        //GPIO_Toggle(GPIO1, GPIO_BIT1);
        IWDG_feed();
        Count++;
        if(Count > 10)
        {
            Count = 0;
            SYS_SoftwareReset();
        }
    }
}



