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

📄 cm1_funcs.c

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

	cm1_funcs.c

	This file contains the HMI interface routines for the CM-1.

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

#include <stdlib.h>
#include <stdio.h>
#include <intrpt.h>
#include <8051.h>
#include <string.h>
#include "command.h"
#include "test.h"
#include "serial.h"
#include "error.h"
#include "hostport.h"
#include "mystrings.h"
#include "cm1_funcs.h"

// These are timeout parameters. The estimate is approximate.
#define ONE_MS                ( ( unsigned short )( 1000.0*33/( 28*12 ) ) )
#define TO_HF2_HIGH           ( 5*ONE_MS )
#define TO_HF2_LOW            ( 100*ONE_MS )
#define TO_RXDF_HIGH          ( 5*ONE_MS )
#define TO_TXDE_HIGH          ( 5*ONE_MS )
#define TO_TRDY_READ					( 100*ONE_MS )

extern near long gPeekPointer;
extern near long gPokePointer;
extern near long gLast_hackTranslation;

unsigned char Host_HF2_High( void );
unsigned char Host_HF2_Low( void );

/************************************************************************/
/*                           Code starts here                           */
/************************************************************************/
//this routine prints a description of the error when given an error #.

//define error codes and error messages here 
#define cERR_HOST_TRDY					1
#define cERR_HOST_HF2High				2
#define cERR_HOST_HF2Low				3
#define cERR_HOST_RXDF					4
#define cERR_HOST_TXDE					5
#define cERR_HOST_TRDY_READ			6

extern code char * get_CM1host_error( unsigned char err_num )	{
	static code char * code host_error_ptr[] = {
		noErrorStr,
		err_CM1_str1,
		err_CM1_str2,
		err_CM1_str3,
		err_CM1_str4,
		err_CM1_str5,
		err_CM1_str6
	};

  return( host_error_ptr[ err_num ] );
}

//read/write the various host registers on the CM1,
//see DSP56303 manual for more information about these
//registers.
unsigned char read_icr() {
  char * iHost_ptr = ( char * ) cHOST_ICR_ptr;

  return( *( iHost_ptr ) );
}

void write_icr( unsigned char value ) {
  char * iHost_ptr = ( char * ) cHOST_ICR_ptr;

  *( iHost_ptr ) = value;
}

unsigned char read_cvr() {
  char * iHost_ptr = ( char * ) cHOST_CVR_ptr;

  return( *( iHost_ptr ) );
}

void write_cvr( unsigned char value ) {
  char * iHost_ptr = ( char * ) cHOST_CVR_ptr;

  *( iHost_ptr ) = value;
}

unsigned char read_isr() {
  char * iHost_ptr = ( char * ) cHOST_ISR_ptr;

  return( *( iHost_ptr ) );
}

unsigned char read_ivr() {
  char * iHost_ptr = ( char * ) cHOST_IVR_ptr;

  return( *( iHost_ptr ) );
}

void write_ivr( unsigned char value ) {
  char * iHost_ptr = ( char * ) cHOST_IVR_ptr;

  *( iHost_ptr ) = value;
}

unsigned char read_drh() {
  char * iHost_ptr = ( char * ) cHOST_DRH_ptr;

  return( *( iHost_ptr ) );
}

void write_drh( unsigned char value ) {
  char * iHost_ptr = ( char * ) cHOST_DRH_ptr;

  *( iHost_ptr ) = value;
}

unsigned char read_drm() {
  char * iHost_ptr = ( char * ) cHOST_DRM_ptr;

  return( *( iHost_ptr ) );
}

void write_drm( unsigned char value ) {
  char * iHost_ptr = ( char * ) cHOST_DRM_ptr;

  *( iHost_ptr ) = value;
}

unsigned char read_drl() {
  char * iHost_ptr = ( char * ) cHOST_DRL_ptr;

  return( *( iHost_ptr ) );
}

void write_drl( unsigned char value ) {
  char * iHost_ptr = ( char * )cHOST_DRL_ptr;

  *( iHost_ptr ) = value;
}

//If the module discovered is a CM-1 then the following routines are used.
//see Hostport.c for assignment routines. Similar ones exist for the CM-2.
extern unsigned char Host_Translate_Address_CM1( unsigned long address ) {
  write_cvr( cMSG_TRANSLATE_ADDRESS );	// initiate Translate Address

	if ( Host_HF2_High() )	{
		write_host_long_CM1( address );
		if ( !( Host_HF2_Low() ) )
			return( cERR_HOST_HF2Low );
  }
	else
		return( cERR_HOST_HF2High );
	return( cERR_NO_ERROR );
}

extern void Host_Interrupt_Ack_CM1( void )	{
	write_cvr ( cMSG_INTERRUPT_ACK );
}

extern unsigned char Host_Multiplex_OP_CM1 ( unsigned char mux_op )	{
  write_cvr( cMSG_MULTIPLEX_OP );
	if ( Host_HF2_High() )	{
		write_drl( mux_op );
		if ( !( Host_HF2_Low() ) )
			return( cERR_HOST_HF2Low );
	}
	else
		return( cERR_HOST_HF2High );
	return( cERR_NO_ERROR );
}

extern unsigned char write_host_long_CM1( unsigned long the_data )	{
  unsigned short count = 0;

	while( !( read_isr() & cISR_TXDE ) && ( count++ < TO_TXDE_HIGH ) )
		;
	if ( count < TO_TXDE_HIGH )	{
		write_drh( the_data >> 16 );
		write_drm( the_data >> 8 );
		write_drl( the_data );
		count = 0;
		while( !( read_isr() & cISR_TRDY ) && ( count++ < TO_TRDY_READ ) )
			;
		if ( !( count < TO_TRDY_READ ) )
			return( cERR_HOST_TRDY_READ );
		else
			return( cERR_NO_ERROR );
	}
	else
		return( cERR_HOST_RXDF );

	return( cERR_NO_ERROR );	//shouldn't reach this code.
}

extern unsigned long read_host_long_CM1( unsigned char * error_code_ptr )	{
	unsigned long temp_long = 0;
  unsigned short count = 0;

	*error_code_ptr = cERR_NO_ERROR;

	while( !( read_isr() & cISR_RXDF ) && ( count++ < TO_RXDF_HIGH ) )
		;
	if ( count < TO_RXDF_HIGH )	{
	  temp_long = read_drh();
		temp_long = ( temp_long << 8 ) | read_drm();
		temp_long = ( temp_long << 8 ) | read_drl();
	}
	else
		*error_code_ptr = cERR_HOST_RXDF;
	return( temp_long );
}

unsigned char Host_HF2_High( void )	{
//this routine waits for HF2 to go high or times out and returns error
  unsigned short count = 0;

  while ( !( read_isr() & cISR_HF2 )  && ( count++ < TO_HF2_HIGH ) )
		;        // waiting for HF2 == High
	return ( ( count < TO_HF2_HIGH ) );
}

unsigned char Host_HF2_Low( void )	{
//this routine waits for HF2 to go low or times out and returns error
  unsigned short count = 0;

	while ( ( read_isr() & cISR_HF2 ) && ( count++ < TO_HF2_LOW ) )
		;         // waiting for HF2 == low
	return ( ( count < TO_HF2_LOW ) );
}

extern void Host_Garbage_Read_CM1()	{
	read_drl();
}

⌨️ 快捷键说明

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