/*
 * TITLE		: 	SPI DRIVER FOR AT91SAM7S256
 * AUTHOR		:	BALAJI VENKATACHALAM
 * DATE			:	2ND OCTOBER 2008
 * FILENAME		:	main.c
 * DESCRIPTION	:	Program that interfaces to PC and a SPI Slave Device
 * 					Additional function wait define and declared.
 * */


#include "Board.h"
// #include "Cstartup_SAM7.h"
#include "serial.h"
#include "rprintf.h"
#include "global.h"
#include "spi.h"

#define SPEED 		(MCKKHz/10)
unsigned int LedSpeed = SPEED * 50 ;
const int led_mask[4]= { LED1, LED2, LED3, LED4 };
static void wait ( void );


//*--------------------------------------------------------------------------------------
//* Function Name       : Main
//* Object              : Software entry point
//* Input Parameters    : none.
//* Output Parameters   : none.
//*--------------------------------------------------------------------------------------
int main(void)
{//* Begin
	//volatile int i;
	
	// call low-level init - not here - already done from Assembler-Init (see Cstartup.S)
	 //AT91F_LowLevelInit(); 
	
	// enable the clock of the PIO (mt:) and UART0
	AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, ( 1 << AT91C_ID_PIOA ) | ( 1 << AT91C_ID_US0 ) ) ;
	
	
	//Configure the Chip Select Pin as Output
	//AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, AT91C_PA11_NPCS0) ;
	
	//Set Chip Select Pin Initially
	//AT91F_PIO_SetOutput( AT91C_BASE_PIOA, AT91C_PA11_NPCS0) ;
	
	//Enable the Reset Pin
	AT91F_RSTSetMode( AT91C_BASE_RSTC , AT91C_RSTC_URSTEN );
	//Initialize the UART		
	uart0_init();
	//Check whether Uart is initialized
	uart0_puts("UART INIT\r\n");
	//Initialize SPI
	spiInit();
	//Say that SPI is initialized
	uart0_puts("SPI INIT\r\n");
	
	// Loop forever
	for (;;)
	{
		spiTransferByte(0xAA);
		spiTransferWord(0x5555);
	} // End for

}
static void wait(void)
{//* Begin
    volatile unsigned int waiting_time ;
    for(waiting_time = 0; waiting_time < LedSpeed; waiting_time++);
}//* End


