#include "mcu_init.h"
#include "config.h"
#include "device.h"
#include "w5500/spi2.h"
#include "httputil.h"
#include "at24c16.h"

#include <stdio.h>

uint8 reboot_flag = 0;

void main()
{
  RCC_Configuration(); // Configure the system clocks
  GPIO_Configuration(); //GPIO configuration
  NVIC_Configuration(); //NVIC Configuration
  
  USART1_Init(); //115200@8-n-1
  at24c16_init();
  printf("W5500 EVB initialization over.\r\n");
  Reset_W5500();
  WIZ_SPI_Init();

  printf("W5500 initialized!\r\n");
  
  
 
  get_config();//read config data from flash
  
  printf("Firmware ver%d.%d\r\n",ConfigMsg.sw_ver[0],ConfigMsg.sw_ver[1]);

  if(ConfigMsg.debug==0) ConfigMsg.debug=1;

  set_network();
  printf("Network is ready.\r\n");
  while(1)
  {

    do_http();
    //reboot MCU if reboot_flag==1
    if(reboot_flag) reboot();
  }
}