//Watchdog demo Main Program
//EVB only
#include "g32f0xx.h"
#include "gt_wdt.h"
#include "gt_uart.h"
#include "gt_sys.h"

//Main function entry
int main(void)
{
	//Initial system
	SYS_SystemInitial();
	SystemCoreClockUpdate();
	//init UART
	UART_Open(UART0,115200,UART_NO_PARITY,0);
	//Send System Inital String
	UART_PutString(UART0,"System Reset...");
	UART_ByteWrite(UART0,'\n');
	
	//Setup WDT 10ms Timeout Time
	WDT_SetIntervalinMiliSec(10);
	NVIC_EnableIRQ(WDT_IRQn);
	//WDT_EnableTimeOutResetSystem()
	//Enable wdt
	WDT_Enable_Timer;

	while (1) 
	{				
		// Loop forever 
		WDT_Feed(); //keep feed watchdog
	}
}

/*****************************************************************************
** Function name:		WDT_IRQHandler
**
** Descriptions:		WDT timeout int handler
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void WDT_IRQHandler(void)
{
	UART_PutString(UART0,"System Enter WDT Int...");
	UART_ByteWrite(UART0,'\n');
  //clr WDT int flag
	WDT_ClearIntFlag();

	return;
}
