/** \file maximPmod.c ******************************************************
 * 
 *             Project: Maxim Plug-in Peripheral Modules
 *            Filename: maximPMOD.c
 *         Description: This module contains the Main application for the
 *                      Avnet Zedboard board implementation of example
 *                      programs for the Maxim Plug-in Peripheral Modules
 *
 *    Revision History:
 *\n       7-20-12 Rev 1.4 Nathan Young    Initial release
 *\n       9-04-12 Rev 1.5 Nathan Young    Multiple PMOD port support
 *\n       10-15-12 Rev 1.6 Nathan Young	OLED display support
 * 
 *  --------------------------------------------------------------------
 * 
 *    This code follows the following naming conventions.
 * 
 * 	  char                   chPmodValue
 * 	  char (array)           sPmodString[16]
 * 	  float                  fPmodValue
 * 	  int                    nPmodValue
 * 	  int (array)            anPmodValue[16]
 * 	  u16                    uPmodValue
 * 	  u8                     uchPmodValue
 * 	  u8 (array)             auchPmodBuffer[16]
 * 	  unsigned int           unPmodValue
 * 	  int *                  punPmodValue
 * 
 * ------------------------------------------------------------------------- */
/*
 * Copyright (C) 2012 Maxim Integrated Products, All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of Maxim Integrated Products
 * shall not be used except as stated in the Maxim Integrated Products
 * Branding Policy.
 *
 * The mere transfer of this software does not imply any licenses
 * of trade secrets, proprietary technology, copyrights, patents,
 * trademarks, maskwork rights, or any other form of intellectual
 * property whatsoever. Maxim Integrated Products retains all ownership rights.
 *
 ***************************************************************************/

#include <stdio.h>
#include "platform.h"
#include "menu.h"
#include "utilities.h"
#include "maximDeviceSpecificUtilities.h"
#include "MAXREFDES4.h"

#define MAJOR_REVISION 00
#define MINOR_REVISION 02

// Globals
XGpio g_xGpioSevenSegment;
unsigned int g_unSevenSegmentValue=0;
char g_sInputString[ INPUT_STRING_MAX_SIZE ];				//This string will hold user input from terminal.
XGpio g_xGpioPmodPortA;
XGpio g_xGpioPmodPortB;
XGpio g_xGpioPmodPortC;
XGpio g_xGpioPmodPortD;
XGpio g_xGpioPmodPortMuxIO;
XGpio g_xGpioLed;
struct maximOLEDDisplay g_structureOLED;
char g_tempString[32];

u8 g_PmodPortMuxSettings=0;
int g_nActivePMODPort=0;
u32 g_unActivePeripheralAddressI2C	=XPAR_IIC_0_BASEADDR;
u32 g_unActivePeripheralAddressSPI	=XPAR_SPI_0_BASEADDR;
u32 g_unActivePeripheralAddressUart	=XPAR_AXI_UARTLITE_0_BASEADDR;
XGpio *g_pActiveGPIOPort = &g_xGpioPmodPortA;
unsigned char g_auchPortType[4];

u8 font[1024] = {	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x00, NUL
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x01, SOH
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x02, STX
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x03, ETX
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x03, EOT
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x05, ENQ
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x06, ACK
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x07, BEL
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x08, BS
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x09, HT
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x0A, LF
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x0B, VT
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x0C, FF
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x0D, CR
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x0E, SO
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x0F, SI
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x10, DLE
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x11, DC1
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x12, DC2
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x13, DC3
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x13, DC4
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x15, NAK
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x16, SYN
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x17, ETB
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x18, CAN
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x19, EM
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x1A, SUB
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x1B, ESC
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x1C, FS
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x1D, GS
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x1E, RS
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x1F, US
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,		// 0x20, space
		0x00,0x00,0x00,0x5f,0x00,0x00,0x00,0x00,		// 0x21, !
		0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00,		// 0x22, "
		0x64,0x3c,0x26,0x64,0x3c,0x26,0x24,0x00,		// 0x23, #
		0x26,0x49,0x49,0x7f,0x49,0x49,0x32,0x00,		// 0x23, $
		0x42,0x25,0x12,0x08,0x24,0x52,0x21,0x00,		// 0x25, %
		0x20,0x50,0x4e,0x55,0x22,0x58,0x28,0x00,		// 0x26, &
		0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,		// 0x27, '
		0x00,0x00,0x1c,0x22,0x41,0x00,0x00,0x00,		// 0x28, (
		0x00,0x00,0x00,0x41,0x22,0x1c,0x00,0x00,		// 0x29, )
		0x00,0x15,0x15,0x0e,0x0e,0x15,0x15,0x00,		// 0x2A, *
		0x00,0x08,0x08,0x3e,0x08,0x08,0x00,0x00,		// 0x2B, +
		0x00,0x00,0x00,0x50,0x30,0x00,0x00,0x00,		// 0x2C, ,
		0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00,		// 0x2D, -
		0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,		// 0x2E, .
		0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00,		// 0x2F, /
		0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00,		// 0x30, 0
		0x00,0x00,0x41,0x7f,0x40,0x00,0x00,0x00,		// 0x31, 1
		0x00,0x42,0x61,0x51,0x49,0x6e,0x00,0x00,		// 0x32, 2
		0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00,		// 0x33, 3
		0x00,0x18,0x14,0x12,0x7f,0x10,0x00,0x00,		// 0x33, 4
		0x00,0x27,0x49,0x49,0x49,0x71,0x00,0x00,		// 0x35, 5
		0x00,0x3c,0x4a,0x49,0x48,0x70,0x00,0x00,		// 0x36, 6
		0x00,0x43,0x21,0x11,0x0d,0x03,0x00,0x00,		// 0x37, 7
		0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,		// 0x38, 8
		0x00,0x06,0x09,0x49,0x29,0x1e,0x00,0x00,		// 0x39, 9
		0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00,		// 0x3A, :
		0x00,0x00,0x00,0x52,0x30,0x00,0x00,0x00,		// 0x3B, //
		0x00,0x00,0x08,0x14,0x14,0x22,0x00,0x00,		// 0x3C, <
		0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00,		// 0x3D, =
		0x00,0x00,0x22,0x14,0x14,0x08,0x00,0x00,		// 0x3E, >
		0x00,0x02,0x01,0x59,0x05,0x02,0x00,0x00,		// 0x3F, ?
		0x3e,0x41,0x5d,0x55,0x4d,0x51,0x2e,0x00,		// 0x40, @
		0x40,0x7c,0x4a,0x09,0x4a,0x7c,0x40,0x00,		// 0x41, A
		0x41,0x7f,0x49,0x49,0x49,0x49,0x36,0x00,		// 0x42, B
		0x1c,0x22,0x41,0x41,0x41,0x41,0x22,0x00,		// 0x43, C
		0x41,0x7f,0x41,0x41,0x41,0x22,0x1c,0x00,		// 0x44, D
		0x41,0x7f,0x49,0x49,0x5d,0x41,0x63,0x00,		// 0x45, E
		0x41,0x7f,0x49,0x09,0x1d,0x01,0x03,0x00,		// 0x46, F
		0x1c,0x22,0x41,0x49,0x49,0x3a,0x08,0x00,		// 0x47, G
		0x41,0x7f,0x08,0x08,0x08,0x7f,0x41,0x00,		// 0x48, H
		0x00,0x41,0x41,0x7F,0x41,0x41,0x00,0x00,		// 0x49, I
		0x30,0x40,0x41,0x41,0x3F,0x01,0x01,0x00,		// 0x4A, J
		0x41,0x7f,0x08,0x0c,0x12,0x61,0x41,0x00,		// 0x4B, K
		0x41,0x7f,0x41,0x40,0x40,0x40,0x60,0x00,		// 0x4C, L
		0x41,0x7f,0x42,0x0c,0x42,0x7f,0x41,0x00,		// 0x4D, M
		0x41,0x7f,0x42,0x0c,0x11,0x7f,0x01,0x00,		// 0x4E, N
		0x1c,0x22,0x41,0x41,0x41,0x22,0x1c,0x00,		// 0x4F, O
		0x41,0x7f,0x49,0x09,0x09,0x09,0x06,0x00,		// 0x50, P
		0x0c,0x12,0x21,0x21,0x61,0x52,0x4c,0x00,		// 0x51, Q
		0x41,0x7f,0x09,0x09,0x19,0x69,0x46,0x00,		// 0x52, R
		0x66,0x49,0x49,0x49,0x49,0x49,0x33,0x00,		// 0x53, S
		0x03,0x01,0x41,0x7f,0x41,0x01,0x03,0x00,		// 0x54, T
		0x01,0x3f,0x41,0x40,0x41,0x3f,0x01,0x00,		// 0x55, U
		0x01,0x0f,0x31,0x40,0x31,0x0f,0x01,0x00,		// 0x56, V
		0x01,0x1f,0x61,0x14,0x61,0x1f,0x01,0x00,		// 0x57, W
		0x41,0x41,0x36,0x08,0x36,0x41,0x41,0x00,		// 0x58, X
		0x01,0x03,0x44,0x78,0x44,0x03,0x01,0x00,		// 0x59, Y
		0x43,0x61,0x51,0x49,0x45,0x43,0x61,0x00,		// 0x5A, Z
		0x00,0x00,0x7f,0x41,0x41,0x00,0x00,0x00,		// 0x5B, [
		0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x00,		// 0x5C,
		0x00,0x00,0x41,0x41,0x7f,0x00,0x00,0x00,		// 0x5D, ]
		0x00,0x04,0x02,0x01,0x01,0x02,0x04,0x00,		// 0x5E, ^
		0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,		// 0x5F, _
		0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00,		// 0x60, `
		0x00,0x34,0x4a,0x4a,0x4a,0x3c,0x40,0x00,		// 0x61, a
		0x00,0x41,0x3f,0x48,0x48,0x48,0x30,0x00,		// 0x62. b
		0x00,0x3c,0x42,0x42,0x42,0x24,0x00,0x00,		// 0x63, c
		0x00,0x30,0x48,0x48,0x49,0x3f,0x40,0x00,		// 0x63, d
		0x00,0x3c,0x4a,0x4a,0x4a,0x2c,0x00,0x00,		// 0x65, e
		0x00,0x00,0x48,0x7e,0x49,0x09,0x00,0x00,		// 0x66, f
		0x00,0x26,0x49,0x49,0x49,0x3f,0x01,0x00,		// 0x67, g
		0x41,0x7f,0x48,0x04,0x44,0x78,0x40,0x00,		// 0x68, h
		0x00,0x00,0x44,0x7d,0x40,0x00,0x00,0x00,		// 0x69, i
		0x00,0x00,0x40,0x44,0x3d,0x00,0x00,0x00,		// 0x6A, j
		0x41,0x7f,0x10,0x18,0x24,0x42,0x42,0x00,		// 0x6B, k
		0x00,0x40,0x41,0x7f,0x40,0x40,0x00,0x00,		// 0x6C, l
		0x42,0x7e,0x02,0x7c,0x02,0x7e,0x40,0x00,		// 0x6D, m
		0x42,0x7e,0x44,0x02,0x42,0x7c,0x40,0x00,		// 0x6E, n
		0x00,0x3c,0x42,0x42,0x42,0x3c,0x00,0x00,		// 0x6F, o
		0x00,0x41,0x7f,0x49,0x09,0x09,0x06,0x00,		// 0x70, p
		0x00,0x06,0x09,0x09,0x49,0x7f,0x41,0x00,		// 0x71, q
		0x00,0x42,0x7e,0x44,0x02,0x02,0x04,0x00,		// 0x72, r
		0x00,0x64,0x4a,0x4a,0x4a,0x36,0x00,0x00,		// 0x73, s
		0x00,0x04,0x3f,0x44,0x44,0x20,0x00,0x00,		// 0x73, t
		0x00,0x02,0x3e,0x40,0x40,0x22,0x7e,0x40,		// 0x75, u
		0x02,0x0e,0x32,0x40,0x32,0x0e,0x02,0x00,		// 0x76, v
		0x02,0x1e,0x62,0x18,0x62,0x1e,0x02,0x00,		// 0x77, w
		0x42,0x62,0x14,0x08,0x14,0x62,0x42,0x00,		// 0x78, x
		0x01,0x43,0x45,0x38,0x05,0x03,0x01,0x00,		// 0x79, y
		0x00,0x46,0x62,0x52,0x4a,0x46,0x62,0x00,		// 0x7A, z
		0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00,		// 0x7B, {
		0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x00,		// 0x7C, |
		0x00,0x00,0x00,0x41,0x36,0x08,0x00,0x00,		// 0x7D, }
		0x00,0x18,0x08,0x08,0x10,0x10,0x18,0x00,		// 0x7E, ~
		0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55			// 0x7F, DEL
	};

u32 g_unSampleSize = 65536;
int g_nSampleRate = 0;


int main()
/**
* \brief       Main() function for Analog Essentials example program.
* \par         Details
*              This function sets up and initializes the FPGA and hardware, displays the root menu via
*              Hyperterminal, then dispatches inidividual demo programs for specific module based on
*              user's keypress selection.
*
* \param       None
*
* \retval      Always TRUE
*/
{
	/
	// Variables for the main() function
	u8 uchInput=0;
	int nMenuState=0;
	int i=0;
	char tempString[256];

	u16 auSamples[1048576];
	u32 unNumberOfSamplesReceived;
/* MTS
	XUartLite uartPortA,uartPortB,uartPortC,uartPortD;
    */ //MTS
	// Xilinx provided utility to initialize the hardware/firmware drivers and enable/disable cache
	init_platform();

	// Clear the Hyperterminal screen by sending printf("\033[2J");
	menu_cls();
    /* MTS
	// Initialize the UARTs on the Zedboard PMOD a..d
	// Note that after this initialization, these variables uartPortA,B,C,D are no longer used
	// All send and receive calls to the UARTS are made directly to their baseaddress
	XUartLite_Initialize(&uartPortA,XPAR_AXI_UARTLITE_0_DEVICE_ID);
	XUartLite_ResetFifos(&uartPortA);
	XUartLite_Initialize(&uartPortB,XPAR_AXI_UARTLITE_1_DEVICE_ID);
	XUartLite_ResetFifos(&uartPortB);
	XUartLite_Initialize(&uartPortC,XPAR_AXI_UARTLITE_2_DEVICE_ID);
	XUartLite_ResetFifos(&uartPortC);
	XUartLite_Initialize(&uartPortD,XPAR_AXI_UARTLITE_3_DEVICE_ID);
	XUartLite_ResetFifos(&uartPortD);
	delay(100);
    */ //MTS
	// Toggle the LEDs so that the user knows the board is awake
	XGpio_Initialize(&g_xGpioLed, XPAR_AXI_GPIO_LED_DEVICE_ID);
	XGpio_SetDataDirection(&g_xGpioLed, 1, 0x00000000);	// Set the LED peripheral to outputs
	led_knight_rider(&g_xGpioLed,2);

	// Initialize the OLED Data structure, the underlying hardware, ...
	// ...and pass a pointer to the active 8x8 pixel font
	initializeOLED(font);

	// Print Welcome Message on OLED
	sprintf(tempString,"MAXIM CAMPBELL");
	printfToOLED(0,0,tempString);
	sprintf(tempString,"REFERENCE DESIGN");
	printfToOLED(0,1,tempString);
	sprintf(tempString, "Revision %02d.%02d\r\n",MAJOR_REVISION,MINOR_REVISION);
	printfToOLED(0,2,tempString);
	sprintf(tempString, "");
	printfToOLED(0,3,tempString);

/* MTS
	// Initialize the GPIO connected to PMOD Ports A,B,C,D
	XGpio_Initialize(&g_xGpioPmodPortA, XPAR_AXI_GPIO_0_DEVICE_ID);
	XGpio_Initialize(&g_xGpioPmodPortB, XPAR_AXI_GPIO_1_DEVICE_ID);
	XGpio_Initialize(&g_xGpioPmodPortC, XPAR_AXI_GPIO_2_DEVICE_ID);
	XGpio_Initialize(&g_xGpioPmodPortD, XPAR_AXI_GPIO_3_DEVICE_ID);
	XGpio_SetDataDirection(&g_xGpioPmodPortA, 1, 0x00000000);	// Set the GPIO1 to all be outputs
	XGpio_SetDataDirection(&g_xGpioPmodPortB, 1, 0x00000000);	// Set the GPIO1 to all be outputs
	XGpio_SetDataDirection(&g_xGpioPmodPortC, 1, 0x00000000);	// Set the GPIO1 to all be outputs
	XGpio_SetDataDirection(&g_xGpioPmodPortD, 1, 0x00000000);	// Set the GPIO1 to all be outputs

	// Inialize the GPIO that drives the mux/select bits on the PMOD port multiplexer
	XGpio_Initialize(&g_xGpioPmodPortMuxIO, XPAR_AXI_GPIO_PMODPORTMUX_DEVICE_ID);
	XGpio_SetDataDirection(&g_xGpioPmodPortMuxIO, 1, 0x00);  // Set the GPIO2 direction to outputs

	// Initialize the ports 0..3 (A..D) with the appropriate technology
	// PMOD_PORT_TYPE_UART, PMOD_PORT_TYPE_SPI, PMOD_PORT_TYPE_GPIO, PMOD_PORT_TYPE_I2C
	g_auchPortType[0] = PMOD_PORT_TYPE_SPI;
	g_auchPortType[1] = PMOD_PORT_TYPE_SPI;
	g_auchPortType[2] = PMOD_PORT_TYPE_SPI;
	g_auchPortType[3] = PMOD_PORT_TYPE_SPI;

	// Configure the PMOD Port Multiplexers for the appropriate PMOD interfaces (ports a,b,c,d)
	max_configure_PMOD_port(g_auchPortType[0],g_auchPortType[1],g_auchPortType[2],g_auchPortType[3]);

	// Clear the Screen, and then display the big Maxim banner for about 2 seconds
	menu_cls();
	menu_print_maxim_banner_big();

	printf("Maxim Campbell (MAXREFDES4#) for the ZED board\r\n");
	printf("Revision %02d.%02d\r\n",MAJOR_REVISION,MINOR_REVISION);


	//printf("Hello World\r\n");
*/
	delay(ABOUT_ONE_SECOND * 3);
	//print_seven_segment_number(0.0f);

	/* The main menu loop runs infinitely to display an output similar to the following:
	 *
	 * Press a number to select sampling mode:
	 * {0} Continuous Sampling
	 * {1} Block Sampling
	 *
		>>

		The main menu is printed to the screen, and then a blocking call to retrieve a single keypress from the UART is issued.
		The result of that keypress is used to select the sampling mode
	*/
/* MTS
	while(1)
	{
		switch(nMenuState)
		{
			case MAIN_MENU:
				menu_cls();
				menu_print_main_menu();
				nMenuState = WAIT_KEYPRESS;
				do{
					uchInput = menu_retrieve_keypress(DEFAULT_HYPERTERMINAL_UART_ADDRESS);
					printf("%c",uchInput);
					if(uchInput<=1)
					{
						if(uchInput==0)
							nMenuState = START_CONTINUOUS_SAMPLING;
						else
							nMenuState = MENU_SAMPLE_SPEED;
					}
				}while(uchInput>1);
				break;
			case MENU_SAMPLE_SPEED:
				menu_cls();
				menu_print_sample_rate_menu();
				do{
					uchInput = menu_retrieve_keypress(DEFAULT_HYPERTERMINAL_UART_ADDRESS);
					printf("%c",uchInput);
					if(uchInput<=3)
					{
						g_nSampleRate=uchInput;
					}
				}while(uchInput>3);
				nMenuState = MENU_SAMPLE_SIZE;
				break;
			case MENU_SAMPLE_SIZE:
				menu_cls();
				menu_print_sample_size_menu();
				do{
					uchInput = menu_retrieve_keypress(DEFAULT_HYPERTERMINAL_UART_ADDRESS);
					printf("%c",uchInput);
					if(uchInput<=3)
					{
						if(uchInput==0)
							g_unSampleSize=65536;
						else if(uchInput==1)
							g_unSampleSize=131072;
						else if(uchInput==2)
							g_unSampleSize=524288;
						else
							g_unSampleSize=1048576;
					}
				}while(uchInput>3);
				nMenuState = START_BLOCK_SAMPLING;
				break;
			case START_CONTINUOUS_SAMPLING:
				menu_cls();
				continuous_sampling();
				nMenuState=MAIN_MENU;
				break;

			case START_BLOCK_SAMPLING:
				menu_cls();
				printf("Press the ESC key to stop sampling\n\n");
				printf("Sampling...\n");
				unNumberOfSamplesReceived=start_sampling(g_unSampleSize, g_nSampleRate, auSamples);

				u16 temp2 = auSamples[24703];
				u16 temp3 = auSamples[24704];
				u16 temp4 = auSamples[24705];
				u16 temp5 = auSamples[24706];
				u16 temp6 = auSamples[24712];
				u16 temp7 = auSamples[65535];


				printf("Done sampling.  Data are stored in the \"Samples\" array\n");
				printf("Do you want to read the sampled data? (Y/N) \n>>");
				do{
					uchInput = menu_retrieve_keypress(DEFAULT_HYPERTERMINAL_UART_ADDRESS);
					printf("%c",uchInput);
					nMenuState=MAIN_MENU;
					if(uchInput=='y' || uchInput=='Y')
					{
						u32 i;
						menu_cls();
						printf("Press the ESC key to stop reading back the data\n\n");
						delay(ABOUT_ONE_SECOND*3);
						printf("Channel 1\n");
						for(i=0; i<unNumberOfSamplesReceived; i++)
						{
							/*
							if(!XUartLite_IsReceiveEmpty(DEFAULT_HYPERTERMINAL_UART_ADDRESS))
								if((u8)XUartLite_ReadReg(DEFAULT_HYPERTERMINAL_UART_ADDRESS, XUL_RX_FIFO_OFFSET)==0x1B)
									break;
							*/ // MTS
/* MTS						u32 temp1 = 0;
							temp1 = Xil_In32(0xE000102C);	// PS7 UART1 channel status register.
							if((temp1 & 0x00000002) == 0)	// if REMPTY bit == 0, there is data in FIFO.
							{
								uchInput = Xil_In32(0xE0001030);	// read the FIFO (only the LSB is valid).
								if(uchInput == 0x1B)
									break;
							}
							printf("%i\n", *(auSamples+i));
						}
						if(i!=unNumberOfSamplesReceived)	//if the Escape key is pressed before the for loop is finished
							break;	//go back to the main menu
						printf("End of samples.  Press any key to go back to the main menu\n");
						nMenuState=MAIN_MENU;
						uchInput=menu_retrieve_keypress(DEFAULT_HYPERTERMINAL_UART_ADDRESS);
						break;
					}
				}while(uchInput!='n' && uchInput!='y' && uchInput!='Y' && uchInput!='N');
				break;

			case MENU_SET_ACTIVE_PMOD:
				menu_cls();
				increment_active_PMOD_Port();
				nMenuState = MAIN_MENU;
				break;
			default:
				printf("Invalid Keypress, please try again\r\n");
				delay(ABOUT_ONE_SECOND * 5);
				nMenuState = MAIN_MENU;
				break;
		}
	}

    cleanup_platform();
    return 0; */ //MTS
}













































