/**HEADER********************************************************************
* 
* Copyright (c) 2010 Avnet Japan Co.,Ltd (NIKE Borad Project.)
* All Rights Reserved
*
*************************************************************************** 
*
* $FileName: NIKE_demo_Shell_Commands.c$
* $Version : 3.0.8.0$
* $Date    : Dec-5-2008$
*
* Comments:
*
*   
*
*END************************************************************************/


#include "NIKE_demo.h"
#include <string.h>
#include <shell.h>
#include <P5Q_spi.h>

//#include "hvac_public.h"
#include "NIKE_demo_Shell_Commands.h"
#include "Signal_Task.h"


/* ------------------------------------------------------------------ 
   --- macro definition                                           --- 
   ------------------------------------------------------------------ */

#define E_OK	0

/* ------------------------------------------------------------------ 
   --- structure body definition                                  --- 
   ------------------------------------------------------------------ */


/* ------------------------------------------------------------------ 
   --- variable definition                                        --- 
   ------------------------------------------------------------------ */

static	pointer 	pcm_fh_ptr;

uchar send_buffer[16];
uchar recv_buffer[16];
uint_32		shell_pcmaddr;
uchar 		shell_pcmdata[16];

extern  FILE_PTR                   pcm_dev_handle1;

/* ------------------------------------------------------------------ 
   --- prototype declaration                                      --- 
   ------------------------------------------------------------------ */

extern _mqx_int SignalEvent_Set_StartSignal(void);
int_32  get_hex_string(char *in );
void printf_dump_byte(int_32 addr, int_32 size );
void printf_dump_word(int_32 addr, int_32 size );
void printf_dump_dword(int_32 addr, int_32 size );




#if DEMOCFG_ENABLE_USB_FILESYSTEM

/*FUNCTION*-------------------------------------------------------------
*
*  Function Name :  Shell_log
*  Returned Value:  none
*  Comments  :  SHELL utility to type a file
*
*END*-----------------------------------------------------------------*/

int_32  Shell_log(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   FILE_PTR             fd;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc == 1)  {
         
         fd = fopen(LOG_FILE, "r");
         if (fd)  {
            while (!feof(fd) ) {
               fputc(fgetc(fd), stdout);
            } 
            fclose(fd);
            printf("\n");
         } else  {
            printf("Error, unable to open file %s.\n", LOG_FILE );
            return_code = SHELL_EXIT_ERROR;
         }
      } else  {
         printf("Error, %s invoked with incorrect number of arguments\n", argv[0]);
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s \n", argv[0]);
      } else  {
         printf("Usage: %s \n", argv[0]);
      }
   }
   return return_code;
} /* Endbody */

#endif


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_AdcTes
* Returned Value   :  int_32 error code
* Comments  :  ADC/DAC 動作開始
*
*END*---------------------------------------------------------------------*/

int_32  Shell_AdcTest(int_32 argc, char_ptr argv[] )
{
	boolean           	print_usage, shorthelp = FALSE;
	int_32            	return_code = SHELL_EXIT_SUCCESS;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );
	if (!print_usage)  {
		SignalEvent_Set_StartSignal();
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s \n", argv[0]);
		}
		else  {
			printf("Usage: %s \n", argv[0]);
		}
	}

	return return_code;
} 


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_recode_rec
* Returned Value   :  int_32 error code
* Comments  :  REC要求
*
*END*---------------------------------------------------------------------*/

int_32  Shell_recode_rec(int_32 argc, char_ptr argv[] )
{
	boolean           	print_usage, shorthelp = FALSE;
	int_32            	return_code = SHELL_EXIT_SUCCESS;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );
	if (!print_usage)  {
		printf("REC \n");
		SignalEvent_Set_RECODE_REC();
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s \n", argv[0]);
		}
		else  {
			printf("Usage: %s \n", argv[0]);
		}
	}

	return return_code;
}


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_recode_play
* Returned Value   :  int_32 error code
* Comments  :  記録信号 再生要求
*
*END*---------------------------------------------------------------------*/

int_32  Shell_recode_play(int_32 argc, char_ptr argv[] )
{
	boolean           	print_usage, shorthelp = FALSE;
	int_32            	return_code = SHELL_EXIT_SUCCESS;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );
	if (!print_usage)  {
		printf("PLAY \n");
		SignalEvent_Set_RECODE_PLAY();
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s \n", argv[0]);
		}
		else  {
			printf("Usage: %s \n", argv[0]);
		}
	}

   return return_code;
} 


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   get_hex_string
* Returned Value   :  HEX code
* Comments  :  文字（HEX）をHEX情報に変換する。
*
*END*---------------------------------------------------------------------*/

int_32  get_hex_string(char *in )
{
	int	i;
	int len;
	int hex;
	int c;

	hex = 0;

	len = strlen(in);

	for(i=0;i<len;i++){
		c = 0;

		hex = hex * 16;

		if ((in[i] >= '0') && (in[i] <= '9')){
			c = in[i] & 0x0f;
		}
		else if (in[i] >= 'a' && in[i] <= 'f'){
			c = 9 + (in[i] & 0x0f);
		}
		else if (in[i] >= 'A' && in[i] <= 'F'){
			c = 9 + (in[i] & 0x0f);
		}
		hex = hex + c;
	}

	return hex;
}


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  printf_dump_byte
* Returned Value   :  void
* Comments  :  DATA DUMP PRINT処理（BYTE）
*
*END*---------------------------------------------------------------------*/

void printf_dump_byte(int_32 addr, int_32 size )
{
	unsigned char *pdmup;
	int i;

	pdmup = (unsigned char*)addr;

	for ( i=0; i<size; i++ ){
		if ( (i%16) == 0 ){
			printf("%08x:", &pdmup[i]);
		}

		printf("%02x ", pdmup[i]);

		if ((i%16) == 15){
			printf(";\n");
		}
	}
}


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  printf_dump_word
* Returned Value   :  void
* Comments  :  DATA DUMP PRINT処理（WORD）
*
*END*---------------------------------------------------------------------*/

void printf_dump_word(int_32 addr, int_32 size )
{
	uint_16 *pdmup;
	int i;

	pdmup = (uint_16 *)addr;

	for ( i=0; i<(size/2); i++ ){
		if ( (i%8) == 0 ){
			printf("%08x:", &pdmup[i]);
		}

		printf("%04x ", pdmup[i]);

		if ((i%8) == 7){
			printf(";\n");
		}
	}
}


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  printf_dump_dword
* Returned Value   :  void
* Comments  :  DATA DUMP PRINT処理（DWORD）
*
*END*---------------------------------------------------------------------*/

void printf_dump_dword(int_32 addr, int_32 size )
{
	uint_32 *pdmup;
	int i;

	pdmup = (uint_32 *)addr;

	for ( i=0; i<(size/4); i++ ){
		if ( (i%4) == 0 ){
			printf("%08x:", &pdmup[i]);
		}

		printf("%08x ", pdmup[i]);

		if ((i%4) == 3){
			printf(";\n");
		}
	}
}



/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_mem_dump_byte
* Returned Value   :  int_32 error code
* Comments  :  Memory Byte dump.
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_dump_byte(int_32 argc, char_ptr argv[] )
{
	boolean           print_usage, shorthelp = FALSE;
	int_32            return_code = SHELL_EXIT_SUCCESS;
	uint_32           inHex1;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		if (argc > 2) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 1) {
			inHex1 = get_hex_string((char*)argv[1]);
			printf_dump_byte(inHex1, 256);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = Dump memory address\n");
		}
	}

	return return_code;
} 



/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  Shell_mem_dump_word
* Returned Value   :  int_32 error code
* Comments  :  Memory Word dump.
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_dump_word(int_32 argc, char_ptr argv[] )
{
	boolean           print_usage, shorthelp = FALSE;
	int_32            return_code = SHELL_EXIT_SUCCESS;
	uint_32           inHex1;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {

		if (argc > 2) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 1) {
			inHex1 = get_hex_string((char*)argv[1]);
			printf_dump_word(inHex1, 256);
		}
	}
	
	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
      	else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = Dump memory address\n");
		}
	}

	return return_code;
} 

/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  Shell_mem_dump_dword
* Returned Value   :  int_32 error code
* Comments  :  Memory DWord dump.
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_dump_dword(int_32 argc, char_ptr argv[] )
{
	boolean           print_usage, shorthelp = FALSE;
	int_32            return_code = SHELL_EXIT_SUCCESS;
	uint_32           inHex1;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {

		if (argc > 2) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 1) {
			inHex1 = get_hex_string((char*)argv[1]);
			printf_dump_dword(inHex1, 256);
		}
	}
	
	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = Dump memory address\n");
		}
	}

	return return_code;
}



/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  Shell_mem_read_byte
* Returned Value   :  int_32 error code
* Comments  :  memry read(BYTE)
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_read_byte(int_32 argc, char_ptr argv[] )
{
	boolean		print_usage, shorthelp = FALSE;
	int_32		return_code = SHELL_EXIT_SUCCESS;
	uint_32		inHex1;
	char		*pmem;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		if (argc > 2) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 1) {
			inHex1 = get_hex_string((char*)argv[1]);
			pmem = (char*)inHex1;
			printf("READ %08x : %02x \n", pmem, *pmem);
		}
	}
	
	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = Read memory address\n");
		}
   }
   return return_code;
} 


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  Shell_mem_read_word
* Returned Value   :  int_32 error code
* Comments  :  memry read(WORD)
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_read_word(int_32 argc, char_ptr argv[] )
{
	boolean		print_usage, shorthelp = FALSE;
	int_32		return_code = SHELL_EXIT_SUCCESS;
	uint_32		inHex1;
	uint_16		*pmem;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		if (argc > 2) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 1) {
			inHex1 = get_hex_string((char*)argv[1]);
			pmem = (uint_16*)inHex1;
			printf("READ %08x : %04x \n", pmem, *pmem);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = Read memory address\n");
		}
	}

	return return_code;
} 


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_mem_read_dword
* Returned Value   :  int_32 error code
* Comments  :  memry read(DWORD)
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_read_dword(int_32 argc, char_ptr argv[] )
{
	boolean		print_usage, shorthelp = FALSE;
	int_32		return_code = SHELL_EXIT_SUCCESS;
	uint_32		inHex1;
	uint_32		*pmem;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		if (argc > 2) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 1) {
			inHex1 = get_hex_string((char*)argv[1]);
			pmem = (uint_32*)inHex1;
			printf("READ %08x : %08x \n", pmem, *pmem);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = Read memory address\n");
		}
	}

	return return_code;
}




/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_mem_write_byte
* Returned Value   :  int_32 error code
* Comments  :  memry write(BYTE)
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_write_byte(int_32 argc, char_ptr argv[] )
{
	boolean		print_usage, shorthelp = FALSE;
	int_32		return_code = SHELL_EXIT_SUCCESS;
	uint_32		inHex1;
	uint_32		inHex2;
	char		*pmem;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		if (argc > 3) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 2) {
			inHex1 = get_hex_string((char*)argv[1]);
			inHex2 = get_hex_string((char*)argv[2]);

			pmem = (char*)inHex1;
			*pmem = (char)inHex2;

			printf("WRITE %08x : %02x \n", inHex1, inHex2);
			printf("READ  %08x : %02x \n", pmem, *pmem);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr] [data]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr] [data]\n", argv[0]);
			printf("   Addr = Write memory address\n");
			printf("   data = Write data\n");
		}
	}

	return return_code;
} 


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  Shell_mem_write_word
* Returned Value   :  int_32 error code
* Comments  :  memry write(WORD)
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_write_word(int_32 argc, char_ptr argv[] )
{
	boolean		print_usage, shorthelp = FALSE;
	int_32		return_code = SHELL_EXIT_SUCCESS;
	uint_32		inHex1;
	uint_32		inHex2;
	uint_16		*pmem;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		if (argc > 3) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 2) {
			inHex1 = get_hex_string((char*)argv[1]);
			inHex2 = get_hex_string((char*)argv[2]);

			pmem = (uint_16*)inHex1;
			*pmem = (uint_16)inHex2;

			printf("WRITE %08x : %04x \n", inHex1, inHex2);
			printf("READ  %08x : %04x \n", pmem, *pmem);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr] [data]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr] [data]\n", argv[0]);
			printf("   Addr = Write memory address\n");
			printf("   data = Write data\n");
		}
	}

	return return_code;
} 


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  Shell_mem_write_dword
* Returned Value   :  int_32 error code
* Comments  :  memry write(DWORD)
*
*END*---------------------------------------------------------------------*/

int_32  Shell_mem_write_dword(int_32 argc, char_ptr argv[] )
{
	boolean		print_usage, shorthelp = FALSE;
	int_32		return_code = SHELL_EXIT_SUCCESS;
	uint_32		inHex1;
	uint_32		inHex2;
	uint_32		*pmem;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		if (argc > 3) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 2) {
			inHex1 = get_hex_string((char*)argv[1]);
			inHex2 = get_hex_string((char*)argv[2]);

			pmem = (uint_32*)inHex1;
			*pmem = (uint_32)inHex2;

			printf("WRITE %08x : %08x \n", inHex1, inHex2);
			printf("READ %08x  : %08x \n", pmem, *pmem);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr] [data]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr] [data]\n", argv[0]);
			printf("   Addr = Write memory address\n");
			printf("   data = Write data\n");
		}
	}

	return return_code;
} 



/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  Shell_PCM_mem_read_dump
* Returned Value   :  int_32 error code
* Comments  :  PCM Memory dump.
*
*END*---------------------------------------------------------------------*/

int_32  Shell_PCM_mem_read_dump(int_32 argc, char_ptr argv[] )
{
	boolean           print_usage, shorthelp = FALSE;
	int_32            return_code = SHELL_EXIT_SUCCESS;
	uint_32           inHex1;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {

		if (argc > 2) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 1) {
			inHex1 = get_hex_string((char*)argv[1]);
			{
				int_32 addr;
				int_32 size;
				static uchar  get_data[512];
				int i;
				static PCM_SPI_MAMORY_IO	pcm_mem;

				addr = inHex1;
				size = 512;

				pcm_mem.addr = inHex1;
				pcm_mem.data = &get_data[0];
				pcm_mem.size = 512;

				ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_BLOCK_GET_MEM, (pointer)&pcm_mem);

				for ( i=0; i<size; i++ ){
					if ( (i%16) == 0 ){
						printf("%08x:", (addr+i));
					}

					printf("%02x ", get_data[i]);

					if ((i%16) == 15){
						printf(";\n");
					}
				}
			}
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = Dump PCM memory address\n");
		}
	}

	return return_code;
} 


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_PCM_sec_erase
* Returned Value   :  int_32 error code
* Comments  :  PCM memory erase.
*
*END*---------------------------------------------------------------------*/
int_32  Shell_PCM_sec_erase(int_32 argc, char_ptr argv[] )
{
	boolean           print_usage, shorthelp = FALSE;
	int_32            return_code = SHELL_EXIT_SUCCESS;
	uint_32           inHex1;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {

		if (argc > 2) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 1) {
			inHex1 = get_hex_string((char*)argv[1]);
			shell_pcmaddr = inHex1;
			printf("SCTOR ERASE %08x \n", shell_pcmaddr);
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SCTOR_ERASE, (pointer)&shell_pcmaddr);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = PCM Erase memory address\n");
		}
	}

	return return_code;
}

/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_PCM_sec_erase
* Returned Value   :  int_32 error code
* Comments  :  PCM memory erase.
*
*END*---------------------------------------------------------------------*/
int_32  Shell_PCM_blk_erase(int_32 argc, char_ptr argv[] )
{
	boolean           print_usage, shorthelp = FALSE;
	int_32            return_code = SHELL_EXIT_SUCCESS;
//	uint_32           inHex1;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {

		if (argc > 1) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else{
			printf("BLOCK ERASE \n");
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_BLOCK_ERASE, (pointer)&shell_pcmaddr);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr]\n", argv[0]);
			printf("   Addr = PCM Erase memory address\n");
		}
	}

	return return_code;
}


/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :   Shell_PCM_baw_write
* Returned Value   :  int_32 error code
* Comments  :  PCM memory write.
*
*END*---------------------------------------------------------------------*/

int_32  Shell_PCM_baw_write(int_32 argc, char_ptr argv[] )
{
	boolean           print_usage, shorthelp = FALSE;
	int_32            return_code = SHELL_EXIT_SUCCESS;
	uint_32           inHex1;
	uint_32           inHex2;
//	int_32 				addr;

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		if (argc > 3) {
			printf("Error, invalid number of parameters\n");
			return_code = SHELL_EXIT_ERROR;
			print_usage=TRUE;
		}
		else if (argc > 2) {
			inHex1 = get_hex_string((char*)argv[1]);
			inHex2 = get_hex_string((char*)argv[2]);

			shell_pcmaddr = inHex1;
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SET_ADDR, (pointer)&shell_pcmaddr);
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_GET_ADDR, (pointer)&shell_pcmaddr);

			shell_pcmdata[0] = inHex2;
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SET_MEM, (pointer)shell_pcmdata);
			printf("WRITE %08x : %02x\n", shell_pcmaddr, inHex2);

			shell_pcmaddr = inHex1;
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_GET_MEM, (pointer)shell_pcmdata);
			printf("READ %08x : %02x\n", shell_pcmaddr, shell_pcmdata[0]);
		}
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s [Addr]\n", argv[0]);
		}
		else  {
			printf("Usage: %s [Addr] [data]\n", argv[0]);
			printf("   Addr = Write PCM memory address\n");
			printf("   data = Write PCM data\n");
		}
	}

	return return_code;
} 

#if 0

#if 0
uchar test_ptn0[256] = {
	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
	0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
	0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
	0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xba, 0xb7, 0xbc, 0xbd, 0xbb, 0xbe, 0xbf,
	0x50, 0x52, 0x54, 0x51, 0x55, 0x56, 0x53, 0x58, 0x59, 0x5a, 0x57, 0x5c, 0x5d, 0x5b, 0x5e, 0x5f,
	0xc0, 0xc2, 0xc4, 0xc1, 0xc5, 0xc6, 0xc3, 0xc8, 0xc9, 0xca, 0xc7, 0xcc, 0xcd, 0xcb, 0xce, 0xcf,
	0xe0, 0xe2, 0xe4, 0xe1, 0xe5, 0xe6, 0xe3, 0xe8, 0xe9, 0xea, 0xe7, 0xec, 0xed, 0xeb, 0xee, 0xef,
	0x80, 0x82, 0x84, 0x81, 0x85, 0x86, 0x83, 0x88, 0x89, 0x8a, 0x87, 0x8c, 0x8d, 0x8b, 0x8e, 0x8f,
	0xf0, 0xf2, 0xf4, 0xf1, 0xf5, 0xf6, 0xf3, 0xf8, 0xf9, 0xfa, 0xf7, 0xfc, 0xfd, 0xfb, 0xfe, 0xff
};




/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    :  Shell_PCM_test
* Returned Value   :  int_32 error code
* Comments  :  PCM Memory test.
*
*END*---------------------------------------------------------------------*/

int_32  Shell_PCM_test(int_32 argc, char_ptr argv[] )
{
	boolean           print_usage, shorthelp = FALSE;
	int_32            return_code = SHELL_EXIT_SUCCESS;
	int i;
	int test_err;
	static PCM_SPI_MAMORY_IO	pcm_mem;
	static uchar  test_pcm_data[256];

	print_usage = Shell_check_help_request(argc, argv, &shorthelp );

	if (!print_usage)  {
		test_err = 0;

		pcm_mem.addr = 0x5000;
		pcm_mem.data = &test_ptn1[0];
		pcm_mem.size = 256;
		ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_BLOCK_SET_MEM, (pointer)&pcm_mem);

		pcm_mem.addr = 0x5000;
		pcm_mem.data = &test_pcm_data[0];
		pcm_mem.size = 256;
		ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_BLOCK_GET_MEM, (pointer)&pcm_mem);

		for (i=0; i<256; i++){
			if (test_pcm_data[i] !=test_ptn1[i] ){
				test_err = 1;
			}
		}

		for(i=0; i<256; i++){
			shell_pcmaddr = 0x6000+i;
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SET_ADDR, (pointer)&shell_pcmaddr);

			shell_pcmdata[0] = test_ptn1[i];
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SET_MEM, (pointer)shell_pcmdata);
		}

		for (i=0; i<256; i++){
			shell_pcmaddr = 0x6000+i;
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SET_ADDR, (pointer)&shell_pcmaddr);
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_GET_MEM, (pointer)shell_pcmdata);

			if (shell_pcmdata[0] !=test_ptn1[i] ){
				test_err = 1;
			}
		}

		for(i=0; i<256; i++){
			shell_pcmaddr = 0x7000+i;
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SET_ADDR, (pointer)&shell_pcmaddr);

			shell_pcmdata[0] = test_ptn1[i];
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SET_MEM, (pointer)shell_pcmdata);
		}

		for (i=0; i<256; i++){
			shell_pcmaddr = 0x7000+i;
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_SET_ADDR, (pointer)&shell_pcmaddr);
			ioctl(pcm_dev_handle1, IO_IOCTL_QSPI_GET_MEM, (pointer)shell_pcmdata);

			if (shell_pcmdata[0] !=test_ptn1[i] ){
				test_err = 1;
			}
		}

		printf("PCM Test %s \n", ((test_err==0)?"OK":"NG"));
	}

	if (print_usage)  {
		if (shorthelp)  {
			printf("%s \n", argv[0]);
		}
		 else  {
			printf("Usage: %s \n", argv[0]);
		}
	}

	return return_code;
} 

#endif


/* EOF*/