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

📄 test.c

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

	test.c

	This is the line command to test the eval board and the CobraNet module.

	Line command supported: TESTEV

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

#include <stdio.h>
#include <intrpt.h>
#include <8051.h>
#include <string.h>
#include "hostport.h"
#include "cnmutil.h"
#include "command.h"
#include "query.h"
#include "led.h"
#include "serial.h"
#include "mib.h"
#include "hostport.h"
#include "error.h"
#include "mystrings.h"
#include "test.h"


#define cTEST_STR_LEN 60

//EV-2 test defines
#define cTESTEV_MEMORY	0
#define cTESTEV_DOG			1
#define cTESTEV_HOST		2
#define cTESTEV_RESETCN 3

//error codes
#define cERR_TEST_MUTE			1
#define cERR_TEST_DAWG			2
#define cERR_TEST_HOST			3
#define cERR_TEST_MEMORY		4

near unsigned char pattern_mem[16];

//the following globals are used for the memory test.
unsigned near short asm_errors;
near unsigned char * near pattern_ptr = pattern_mem;
near unsigned char write_value;
near unsigned char read_value;

extern unsigned char init_cm( unsigned char do_reset );
void testev_execute( unsigned char testev_selection, char * string_ptr );
void testev_help( unsigned char detailed );

code char * get_testev_error_string( unsigned char error_number )	{
	//error statements for line commands
	static code char * code cmnd_arg_error[] = {
		noErrorStr,
		err_Test_str1,
		err_Test_str2,
		err_Test_str3,
		err_Test_str4
	};

	return( cmnd_arg_error[ error_number ] );
}

void testev( char * com_arg_ptr[] );

code struct command_item_t testev_command = {
	( code char * ) str_Com_testev,
	( code command_function_t ) testev
};

void testev( char * com_arg_ptr[] )	{
	unsigned char testev_ch;

	if ( com_arg_ptr[ 1 ] == NULL )	//look for the command without arguments
		testev_help( cHELP_SHORT );
	else	{
		if ( *com_arg_ptr[ 1 ] == '?' )	//look for detailed help argument
			testev_help( cHELP_LONG );
		else	{
			testev_ch = 0;
			while ( ( strCodecmp( testev_arguments[ testev_ch ], 
								com_arg_ptr[ 1 ] ) ) && 
							( testev_arguments[ testev_ch ] != NULL ) )
				testev_ch++;
			if ( testev_arguments[ testev_ch ] == NULL )
				printErr( cERR_ARGUMENT );
			else
				testev_execute( testev_ch, com_arg_ptr[ 0 ] );
		}
	}
}

void testev_execute( unsigned char testev_selection, char * string_ptr ) {
	unsigned short dawg_poo;
  unsigned char error_code = cERR_NO_ERROR;

	switch( testev_selection )	{
		case cTESTEV_MEMORY:
			dawg_poo = testMemory();
			if ( dawg_poo )	{
				printStrCode( str_Fail );
				printStr( long2ascii( ( long ) dawg_poo ) );
				printStrCode( str_Read );
				printStr( long2ascii( ( long ) &read_value ) );
				printStrCode( str_Wrote );
				printStrC( long2ascii( ( long ) &read_value ) );
			}
			else
				printStrCodeC( str_Pass );
			break;
		case cTESTEV_DOG:
			error_code = testWatchDawg( &dawg_poo );
			if ( error_code )
				printStrCode( str_Fail );
			else
				printStrCode( str_Pass );
			printStrC( long2ascii( ( long ) dawg_poo ) );
			break;
		case cTESTEV_HOST:
			error_code = testHost( 0 );
			if ( error_code )	{
				printStrCodeC( str_Fail );
				error_code = testHost( 1 );
			}
			else
				printStrCodeC( str_Pass );
			break;
		case cTESTEV_RESETCN:
			error_code = init_cm( cRESET );
			break;
		default:
			break;
	};	//switch
}

extern unsigned char testWatchDawg( unsigned short * dawg_count )	{
		//counts watchdawg pulses for approx one second and compares
		//the count to an acceptable range. Watchdawg should be
		//about 375 Hz.
   TL0 = 0;				//initialize counter 0 to zero
   TH0 = 0;
   TMOD = 0x15;		//set to 16 bit counter
   TR0 = 1;				//start counter
   waiting( cWAIT_ONE_SECOND ); 	//wait approx. 1 sec.
   TR0 = 0;		//stop counter
	 *dawg_count = TL0 + TH0*256;
   if ( ( TH0 = cDAWG_UPPER ) && ( TL0 > cDAWG_MIN ) && 
				( TL0 < cDAWG_MAX ) )
      return( cERR_NO_ERROR );
   else
      return( cERR_TEST_DAWG );
}

extern unsigned char testHost( unsigned char get_details )	{
		//Power On Host Test.  
		//tests interface by writing a pattern to the sysContact location
		//in the CobraNet module memory
	near static unsigned char error_flag;		//flags any errors
  unsigned char count = cTEST_STR_LEN;
	static char read_str[ cTEST_STR_LEN + 1 ];	//test string length + null
	code char * char_ptr;						//used to point to next set of
	char * read_ptr;								//characters to be written
	
	if ( get_details )	{
		printStrCodeC( str_sales );
		printStrC( read_str );
	}
	else	{	//write a test pattern to the sysContact location
		read_ptr = read_str;
		char_ptr = str_sales;
		for ( count = 0; count < cTEST_STR_LEN; count++ )
			*read_ptr++ = *char_ptr++;	//copy test string to data memory
		*read_ptr = cASCII_NULL;
		put_display_string( sysCONTACT_ptr, read_str );

			//test the pattern

		char_ptr = str_sales;
		read_ptr = read_str;

		get_display_string( sysCONTACT_ptr, read_str );
		error_flag = 0;
		for ( count = 0; count < cTEST_STR_LEN; count++ )
			if ( *read_ptr++ != *char_ptr++ )
				error_flag = 1;
	}
	return( error_flag );
}

extern unsigned near unsigned short testMemory(){
		//Tests external MCU memory.  Assumes internal SRAM is good.
	asm_errors = 0;
	read_value = 0;
	write_value = 0;

	for ( read_value = 0; read_value < 16; read_value++ )
		pattern_mem[ read_value ] = pattern_memCode[ read_value ];
	read_value = 0;
#asm
		clr		EA										;disable interrupts
		mov		dpl,#0								;pointer to external sram
    mov		dph,#3
		mov		r3,#0x7D							;outer loop counter here
		mov		r0,#0									;this will point to temp memory in ERAM

  x1:
		mov		r2,#0									;use this as an 8-bit counter
	x2:
		movx	a,@dptr								;save contents of external SRAM
		movx	@r0,a									;save value in temp buffer in ERAM
		inc		r0
		inc		dptr
		djnz	r2,x2

		dec		dph
	x3:
		mov		a,r2
		anl		a,#0xf								;only sixteen locations valid
		jnz		z1
		mov		r0,_pattern_ptr
	z1:
		mov		a,@r0
		movx	@dptr,a								;copy pattern to memory
		inc		dptr
		inc		r0
		djnz	r2,x3

		dec		dph
	x4:
		mov		a,r2
		anl		a,#0xf								;only sixteen locations valid
		jnz		z2
		mov		r0,_pattern_ptr
	z2:														;compare pattern to written pattern
		movx	a,@dptr
		mov		r5,a									;save in case of error
		xrl		a,@r0
		jz		x5
		mov		_read_value,r5
		mov		_write_value,a
		inc		_asm_errors+1					;keep a count of errors encountered.
		mov		a,_asm_errors+1
		jnz		x5
		inc		_asm_errors
	x5:
		inc		dptr
		inc		r0
		djnz	r2,x4

		mov		r0,#0									;this will point to temp memory in ERAM
		dec		dph
	x6:														;restore contents to external SRAM
		movx	a,@r0
		movx	@dptr,a
		inc		r0
		inc		dptr
		djnz	r2,x6

		djnz	r3,x1
		setb	EA								;enable interrupts
#endasm

		return ( asm_errors );
}

void testev_help( unsigned char detailed )	{
	printStrCodeC( test_str_help1 );
	if ( detailed )
		printStrCodeC( test_str_help2 );
}

⌨️ 快捷键说明

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