⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evif.c

📁 PEAKAUDIO用于EV2板的MCU控制源码
💻 C
字号:
/*************************************************************************

	evif.c

	This file contains the line commands to read and write the EV memory.
	Only data memory reads and writes are supported at this time.

	Supported line commands: PEEKEV, POKEEV

	Copyright (C) 2001-2004 by Cirrus Logic Inc. All Rights Reserved
*************************************************************************/

#include <8051.h>
#include <intrpt.h>
#include <conio.h>
#include <string.h>
#include "serial.h"
#include "command.h"
#include "error.h"
#include "hostport.h"
#include "cnmutil.h"
#include "test.h"
#include "mib.h"
#include "mystrings.h"
#include "evif.h"

void peekev( char * com_arg_ptr[] );
void pokeev( char * com_arg_ptr[] );

void peekev_help( unsigned char detailed );
void pokeev_help( unsigned char detailed );

extern unsigned char gWHICH_MODULE;

#define cERR_BAD_ADDR				1
#define cERR_BAD_VALUE			2

code char * get_evif_error_string( char error_number )	{
	static code char * code cmnd_arg_error[] = {
		noErrorStr,
		str_err_BadAddr,
		str_err_BadValue
	};

	return( cmnd_arg_error[ error_number ] );
}

/*************************************************************************
*																peekev COMMAND													 *
*************************************************************************/

code struct command_item_t peekev_command = {
	( code char * ) str_Com_peekev,
	( code command_function_t ) peekev
};

void peekev( char * com_arg_ptr[] )	{
//peekev returns the value of a given memory location.
  unsigned char error_code = cERR_NO_ERROR;
	unsigned char temp_char;
	unsigned char count = 1;
	unsigned char i,j;
	unsigned char * addr;
	char * local_ptr;


	if ( com_arg_ptr[ 1 ] == NULL )	//look for the command without arguments
		peekev_help( cHELP_SHORT );
	else	{
		if ( *com_arg_ptr[ 1 ] == '?' )
			peekev_help( cHELP_LONG );
		else	{
			if ( error_code = validate_hex_string( com_arg_ptr[ 1 ], 
						c4_HEX_CHAR ) )
					printTwoErrorString( get_evif_error_string( cERR_BAD_ADDR ),
															 get_error_string( error_code ) );
			else	{
				if ( com_arg_ptr[ 2 ] != NULL )	{
					if ( error_code = validate_hex_string( com_arg_ptr[ 2 ], 
								c2_HEX_CHAR ) )	{
						printTwoErrorString( get_evif_error_string( cERR_BAD_VALUE ),
																 get_error_string( error_code ) );
						return;
					}
					else
						count = ( unsigned char ) str2Long( com_arg_ptr[ 2 ] + 2 );
				}
				local_ptr = com_arg_ptr[ 0 ];		//use this area as scratch pad
				addr = ( unsigned char * ) str2Long( com_arg_ptr[ 1 ] + 2 );
				//this prints out the data in hex and ascii format
				for ( i = 0; i < count; i++ )	{
					temp_char = *( addr++ );
					printStr( byte2str( temp_char ) );
					printStrCode( str_Space );
					if ( temp_char < ' ' )	
						temp_char = 0x2E;			//make control chars a period.
					*local_ptr++ = temp_char;
					if ( !( ( i ^ 0x0F ) & 0x0F ) || ( ( i + 1 ) == count ) )	{
						if ( ( i + 1 ) == count )
							for ( j = 0; j < ( 15 - ( i & 0x0F ) ); j++ )
									printStrCode( str_Space3 );
						printStrCode( str_Space3 );
						printStrCode( str_Space3 );
						*local_ptr = cASCII_NULL;
						printStrC( com_arg_ptr[ 0 ] );
						local_ptr = com_arg_ptr[ 0 ];
						waiting( mMSECOND10 );
					}
				}
			}
		}
	}
}

void peekev_help( unsigned char detailed )	{
	printStrCodeC( peekev_str_help1 );
	if ( detailed )
		printStrCodeC( peekev_str_help2 );
}

/*************************************************************************
*															pokeev COMMAND														 *
*************************************************************************/

code struct command_item_t pokeev_command = {
	( code char * ) str_Com_pokeev,
	( code command_function_t ) pokeev
};

void pokeev( char * com_arg_ptr[] )	{
//pokeev writes a given value to a given memory location.
	unsigned char * local_ptr;
  unsigned char error_code = cERR_NO_ERROR;

	if ( com_arg_ptr[ 1 ] == NULL )	//look for the command without arguments
		pokeev_help( cHELP_SHORT );
	else	{
		if ( *com_arg_ptr[ 1 ] == '?' )
			pokeev_help( cHELP_LONG );
		else	{
			if ( error_code = validate_hex_string( com_arg_ptr[ 1 ], 
						c4_HEX_CHAR ) )
						printTwoErrorString( get_evif_error_string( cERR_BAD_ADDR ),
																 get_error_string( error_code ) );
			else	{
				if ( com_arg_ptr[ 2 ] == NULL )
					printErrString( get_error_string( cERR_MISSING_ARG ) );
				else	{
					if ( error_code = validate_hex_string( com_arg_ptr[ 2 ], 
								c2_HEX_CHAR ) )
						printTwoErrorString( get_evif_error_string( cERR_BAD_VALUE ),
																 get_error_string( error_code ) );
					else	{
						local_ptr = ( unsigned char * ) str2Long( com_arg_ptr[ 1 ] + 2 );
						*local_ptr = ( unsigned char ) str2Long( com_arg_ptr[ 2 ] + 2 );
					}
				}
			}
		}
	}
}

void pokeev_help( unsigned char detailed )	{
	printStrCodeC( pokeev_str_help1 );
	if ( detailed )
		printStrCodeC( pokeev_str_help2 );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -