#include <stdio.h>
#include <string.h>
#include <ADuCM360.h>

void delay(long int);

int main (void)
{
	pADI_CLKCTL->CLKCON0 = 0x0;
	pADI_CLKCTL->CLKSYSDIV = 0x0;							// CD0 clock - 16Mhz 
	
	pADI_GP1->GPOEN  =  0x8;                  // GPIO1.3 is output  
	pADI_GP1->GPSET  =  0x8;                  // switch LED off       
	
	pADI_GP1->GPCLR = 0x8;                    // Turn on LED      
	delay(100000);
	pADI_GP1->GPSET = 0x8;                    // Turn off LED       		 
	delay(100000);
	pADI_GP1->GPCLR = 0x8;                    // Turn on LED       
	delay(100000);
	pADI_GP1->GPSET = 0x8;                    // Turn off LED      	 
	delay(1000000);
		
	pADI_WDT->T3CON = 0x00 ; 									// vypnu watchdog timer    
	pADI_WDT->T3LD = 0x100; 									// 0x1000 = 32 sek
	pADI_WDT->T3CON = 0x69; 									// reset

	while (1)
  {
		pADI_GP1->GPCLR = 0x8;                  // Turn on LED        
		delay(200000);
		pADI_GP1->GPSET = 0x8;                  // Turn off LED      		 	
		delay(200000);
        
		SCB->SCR = 0x04; 												// sleepdeep mode
		pADI_PWRCTL->PWRKEY = 0x4859; 					// key1
		pADI_PWRCTL->PWRKEY = 0xF27B; 					// key2
		pADI_PWRCTL->PWRMOD = 0x4;							// vyber sleep modu
	
	  __WFI();

	}
} 
void delay (long int length)
{
   while (length >0)
   length--;
}
