//Demo Main Program

#include "hhd32f0xx.h"
#include "hhd_sys.h"
#include "hhd_rtc.h"
#include "hhd_gpio.h"

//Main function entry
int main(void)
{
	//Initial System
	SYS_SystemInitial();

	//Enable RTC Counter
	RTC_EnableTimerCounter;
	//Enable RTC Alarm int
	//RTC_EnableAlarmInt();

	//Set 1sec timeout
	//RTC_SetAlarmInTickLater(5);
	
	NVIC_EnableIRQ(RTC_IRQn);

	//if you want go to power testing mode, trigger PA0 to 0, system will do that.
	//通过拉低PA0 to 0, 系统将进入功耗测试模式，工作模式，睡眠模式，停止模式，及待机模式
	//请分别打开或注释对应模式的程序
	while (1)
	{
		if (!GPIO_GetPinState(GPIOA,IO_PIN0))
		
		
		//Enter active power testing mode.
		//下面这句是用来测试芯片工作模式功耗的
		//while(1);

		
		
    //Enter Sleep mode.		
		//下面这句是用来测试芯片睡眠模式功耗的
		//SYS_EnterSleep();


		
		//Enter Stop mode.
		//下面这句是用来测试芯片停止模式功耗的
		SYS_EnterDeepSleep(PD_RTCOSC, 0);


		
		//Enter Standby mode.
		//下面这句是用来测试芯片待机模式功耗的
		//SYS_EnterPowerDown(PD_RTCOSC);
		
	}
}

/*****************************************************************************
** Function name:		RTC_IRQHandler
**
** Descriptions:		RTC timeout int handler
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void RTC_IRQHandler(void)
{
  //
	RTC_ClearIntFlag();
	//Set next 1sec timeout
	RTC_SetAlarmInTickLater(5);

	return;
}
