This example uses the Universal Synchronous Asynchronous Receiver Transmitter (USART) of an AT91SAM9xx5 microcontroller to 
transimit and receive an audio stream through the on-board WM8731 CODEC.

This example also uses the Timer Controller (TC) output to generate the waveform of SLK and LRCLK to simulate the I2S interface.

This example plays a WAV file pre-loaded into the flash and records the audio from line-in into the flash. The audio stream is
sent or received through the USART simulated I2S interface connected to the on-board WM8731, enabling the sound to be audible 
using a pair of headphones.

This example application is limited to playing and recording files with the following format:
- Format: WAV
- Sample rate:8KHz, 32KHz, 44.1KHz, 48 kHz
- Bit per Sample: 16-bit
- Channel: 2 

Hardware Setting:
This example runs on the AT91SAM9x5-EK with AT91SAM9G15 CM board.
Before running the USART_I2S_DMA_Audio sample on the EK,
Customer needs to modify the board with the following instructions.
Step1:
	Disconnect the original connection of the following signals:
			PA21, PA22, PB2, PA7, PA8, PB1, pin3/pin4/pin5/pin6/pin7 of WM8731.
Step2:
  Connect the corresponding signals according to following direction:
 			TC0->TIOA0 (PA21) connects to USART2->SCK (PB2) and BCLK (pin3) of WM8731. 
 			TC0->TIOA1 (PA22) connects to DACLRC (pin5) and ADCLRC (pin7) of WM8731.
 			USART2->SCK (PB2) connects to TC0->TIOA0 (PA21).
 			USART2->TXD (PA7) connects to DACDAT (pin4) of WM8731.
 			USART2->RXD (PA8) connects to ADCDAT (pin6)).
 			USART2->CTS (PB1) connects to GND.
 		
Set the debug enviroment:
1. Connect the SAM-ICE between the AT91SAM9G15-EK and the PC;
2. Connect the AT91SAM9G15-EK (DBGU port) and the PC with UART cable;
3. On the computer, open and configure a terminal application (e.g. HyperTerminal on Microsoft Windows) with these settings:
		- COM port number: please check the Device Manager of the computer to get the COM which connected with the AT91SAM9G15-EK.
    - 115200 bauds
    - 8 bits of data
    - No parity
    - 1 stop bit
    - No flow control

Build the project:
1. Unzip the package: usart_i2s_dma.zip;
2. Open the workspace: usart_i2s_dma-audio.eww in directory: usart_i2s-dma\build\ewarm_550;
3. Make the project;
4. Use "download and debug" button to download the binary to the AT91SAM9G15-EK; 
	(make sure SAM-ICE is connected between the AT91SAM9G15-EK and the PC)
5. Click the "Run" button and the code begin to run and debug information displays on the Hyper terminal screen. 
6. Then following the instruction of the menu to play the demo!

How to use the example:
1. After the code running of the board, there are the following menu display on the Hyper terminal screen:
      -- USART I2S Sample --
 	Menu :
 	------
        r: Record wav file(16-bit, 48k, 2 channel)  from line-in
        W: Play the WAV file loaded
        I: Display the information of the WAV file
        w: Play the recorded wav file
        d: Dump the recorded data
        x: Receive WAV file with XModem Protocol

2. Here's the descritption for each command:
	
-       r: Record wav file(16-bit, 48k, 2 channel)  from line-in
 				This command is used to record the audio from line-in input. The maximun record length can be adjusted by setting the DMA RX LLI length.
 				
-       W: Play the WAV file loaded				
				This command is used to play the pre-loaded WAV file in the flash.
				NOTE: this command only shows when there is WAV file in the flash.
	
-       I: Display the information of the WAV file				
				This command will print the wave file formatio information.
				NOTE: this command only shows when there is WAV file in the flash.

-       w: Play the recorded wav file
				This command is used to play the recorded pcm data.
				NOTE: this command only shows when there is recorded pcm data in the flash.
				
-       d: Dump the recorded data				
				This command is used to dump the recorded pcm data.
				NOTE: this command is only for debugging usage.
	
-       x: Receive WAV file with XModem Protocol
 				This command is used to send the Wave file into the flash.
 				Usage£º Input 'x' with keyboard, when the following information displays:
 								"Transfer wav file with 1K XModem, Ctrl + D to cancel"
								" CC...	"
				 				Click "Transfer -> Send file" menu in the Hyperterminal window tools bar, then select the wave file. (the size of file better doesn't exceed  390K)
				
				During playing audio, following command will display:
-  			S: Stop playback
				This command is used to stop playing audio.
				
				During recording audio, following command will display:
- 			P: Stop record
				This command is used to stop recording audio.		
 				

 
 