#include "profiler.h"

//#define USE_DEFERRED_CALLBACKS	// enables deferred callbacks

// Create two buffer chains.  One chain will be used for one of the frames,
// the other chain for the other frame. Note that in this example there
// is only 1 buffer in each chain
ADI_DEV_1D_BUFFER InboundBuffer;
ADI_DEV_1D_BUFFER OutboundBuffer;

// data for the inbound and outbound buffer
u8 InboundData;
u8 OutboundData;

// Deferred Callback Manager data (memory for 1 service plus 4 posted callbacks)
#if defined(USE_DEFERRED_CALLBACKS)
static u8 DCBMgrData[ADI_DCB_QUEUE_SIZE + (ADI_DCB_ENTRY_SIZE)*4];
#endif

// Device Manager data (base memory + memory for 1 device)
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 1)];

// Handle to the UART driver
static ADI_DEV_DEVICE_HANDLE 	DriverHandle;

/*********************************************************************
*
*	Function:	main
*
*********************************************************************/

void main(void) {
	unsigned char	outString[80];
	

	sprintf(outString, "%s\r","SN[4]");
	SendString(outString);
	
	// wait until the last push button is pressed
//GM	while (ezIsButtonPushed(EZ_LAST_BUTTON) == FALSE) ;
 	while (ezIsButtonPushed(EZ_FIRST_BUTTON) == FALSE) ;
		
	// close down the device driver
	ezErrorCheck(adi_dev_Close(DriverHandle));
	
	// close the Device Manager
	ezErrorCheck(adi_dev_Terminate(DeviceManagerHandle));
	
	// close down the Deferred Callback Manager
#if defined(USE_DEFERRED_CALLBACKS)
	ezErrorCheck(adi_dcb_Terminate());
#endif

	// turn off all LEDs
	ezTurnOffAllLEDs();
	
	// return
}
