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

📄 host_reg.c

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

	host_reg.c

	This file contains the host register read and write line commands.

	Consult the respective technical documentation for the CM-1 and CM-2
	for a description of the host registers.

	Line commands supported: READ, WRITE

	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 "cm1_funcs.h"
#include "mib.h"
#include "mystrings.h"
#include "host_reg.h"

void read( char * com_arg_ptr[] );
void write( char * com_arg_ptr[] );

void read_help( unsigned char detailed );
void write_help( unsigned char detailed );

extern unsigned char gWHICH_MODULE;
void read_execute( unsigned char the_argument, char * the_str );

//CS18101 registers
#define cREG_MSG			0
#define cREG_DATA			1
#define cREG_MSGA			2
#define cREG_MSGB			3
#define cREG_MSGC			4
#define cREG_MSGD			5
#define cREG_DATAA		6
#define cREG_DATAB		7
#define cREG_DATAC		8
#define cREG_DATAD		9

//DSP56303 registers.
#define cREG_ICR			10
#define cREG_CVR			11
#define cREG_ISR			12
#define cREG_IVR			13
#define cREG_UNUSED		14
#define cREG_DRH			15
#define cREG_DRM			16
#define cREG_DRL			17

//more CS18101 registers.
#define cREG_CONTROL	18
#define cREG_STATUS		19

/*************************************************************************
*																READ COMMAND							    					 *
*************************************************************************/
//read returns the value of a given host register.
code struct command_item_t read_command = {
	( code char * ) str_Com_read,
	( code command_function_t ) read
};

void read( char * com_arg_ptr[] )	{
	unsigned char read_char;

	if ( com_arg_ptr[ 1 ] == NULL )	//look for the command without arguments
		read_help( cHELP_SHORT );
	else	{
		if ( *com_arg_ptr[ 1 ] == '?' )
			read_help( cHELP_LONG );
		else	{
			read_char = 0;
			while ( ( strCodecmp( reg_arguments[ read_char ], 
								com_arg_ptr[ 1 ] ) ) && 
							( reg_arguments[ read_char ] != NULL ) )
				read_char++;
			if ( reg_arguments[ read_char ] == NULL )
				printErrString( get_error_string( cERR_ARGUMENT ) );
			else
				read_execute( read_char, com_arg_ptr[ 0 ] );
		}
	}
}

unsigned char read_host_reg( unsigned char the_reg )	{
  char * iHost_ptr = ( char * ) cHOST_PORT_ptr;

	return( *( iHost_ptr + the_reg ) );
}

void read_execute( unsigned char the_argument, char * the_str )	{
	unsigned char the_reg;

	switch( the_argument )	{
		case cREG_MSG:
		case cREG_DATA:
			the_argument *= 4;
			*the_str = cASCII_NULL;
			for ( the_reg = the_argument; the_reg < ( the_argument + 4 ); 
						the_reg++ )
				strcat( the_str, byte2str( read_host_reg( the_reg ) ) );
			break;
		case cREG_ICR:
		case cREG_CVR:
		case cREG_ISR:
		case cREG_IVR:
		case cREG_UNUSED:
		case cREG_DRH:
		case cREG_DRM:
		case cREG_DRL:
			the_argument -= 8;
		case cREG_MSGA:
		case cREG_MSGB:
		case cREG_MSGC:
		case cREG_MSGD:
		case cREG_DATAA:
		case cREG_DATAB:
		case cREG_DATAC:
		case cREG_DATAD:
			strcpy( the_str, byte2str( read_host_reg( the_argument - 2 ) ) );
			break;
		case cREG_CONTROL:
			strcpy( the_str, byte2str( read_host_reg( cHOST_CONTROL_REG ) ) );
			break;
		case cREG_STATUS:
			strcpy( the_str, byte2str( read_host_reg( cHOST_STATUS_REG ) ) );
			break;
		default:
			break;
	};	//switch
	printStrCode( str_HexPrefix );
	printStrC( the_str );
}

void read_help( unsigned char detailed )	{
	printStrCodeC( regrd_str_help1 );
	if ( detailed )
		printStrCodeC( regrd_str_help2 );
}

/*************************************************************************
*																WRITE COMMAND   												 *
*************************************************************************/
//write writes a given value to a given host register.
void write_execute( unsigned char the_argument, char * the_data_str );

code struct command_item_t write_command = {
	( code char * ) str_Com_write,
	( code command_function_t ) write
};

void write( char * com_arg_ptr[] )	{
	unsigned char write_char;
	unsigned char cerr = cERR_NO_ERROR;

	if ( com_arg_ptr[ 1 ] == NULL )	//look for the command without arguments
		write_help( cHELP_SHORT );
	else	{
		if ( *com_arg_ptr[ 1 ] == '?' )
			write_help( cHELP_LONG );
		else	{
			write_char = 0;
			while ( ( strCodecmp( reg_arguments[ write_char ], 
								com_arg_ptr[ 1 ] ) ) && 
							( reg_arguments[ write_char ] != NULL ) )
				write_char++;
			if ( reg_arguments[ write_char ] == NULL )
				printErrString( get_error_string( cERR_ARGUMENT ) );
			else
				if ( com_arg_ptr[ 2 ] == NULL )
					printErrString( get_error_string( cERR_MISSING_ARG ) );
				else	{
					if (  cerr = validate_hex_string( com_arg_ptr[ 2 ], 
								c8_HEX_CHAR ) )
						printTwoErrorString( get_error_string( cERR_ADDR_HEX_NOT ),
																	 get_error_string( cerr ) );
					else
						write_execute( write_char, com_arg_ptr[ 2 ] );
				}
		}
	}
}

void write_host_reg( unsigned char the_reg, unsigned char the_data )	{
  char * iHost_ptr = ( char * ) cHOST_PORT_ptr;

	*( iHost_ptr + the_reg ) = the_data;
}

void write_execute( unsigned char the_argument, char * the_data_str )	{
	unsigned char the_reg;
	unsigned long temp_long;
	unsigned char temp_char;

	temp_long = str2Long( the_data_str + 2 );	//skip 0x part

	switch( the_argument )	{
		case cREG_MSG:
		case cREG_DATA:
			the_argument *= 4;
			temp_char = ( unsigned char ) temp_long;
			temp_long >>= 8;
			for ( the_reg = 0; the_reg < 3; the_reg++ )	{
				write_host_reg( 2 - the_reg + the_argument, 
												( unsigned char ) temp_long );
				temp_long >>= 8;
			}
			write_host_reg( 3 + the_argument, temp_char );
			break;
		case cREG_ICR:
		case cREG_CVR:
		case cREG_ISR:
		case cREG_IVR:
		case cREG_UNUSED:
		case cREG_DRH:
		case cREG_DRM:
		case cREG_DRL:
				the_argument -= 8;
		case cREG_MSGA:
		case cREG_MSGB:
		case cREG_MSGC:
		case cREG_MSGD:
		case cREG_DATAA:
		case cREG_DATAB:
		case cREG_DATAC:
		case cREG_DATAD:
				write_host_reg( the_argument - 2, ( unsigned char ) temp_long );
			break;
		default:
			break;
	};	//switch
}

void write_help( unsigned char detailed )	{
	printStrCodeC( regwr_str_help1 );
	if ( detailed )
		printStrCodeC( regwr_str_help2 );
}

⌨️ 快捷键说明

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