📄 cm2_funcs.c
字号:
/*************************************************************************
cm2_funcs.c
This file specifies the routines to interface to the Host port on the
CM-2 CobraNet Module.
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 "cm2_funcs.h"
extern near long gPeekPointer;
extern near long gPokePointer;
extern near long gLast_hackTranslation;
/************************************************************************/
/* Code starts here */
/************************************************************************/
//read and write the host registers.
//see CS18101 manual for more information about these registers.
void write_message_reg( unsigned char which_reg, unsigned char the_message ) {
char * iHost_ptr = ( char * ) ( cHOST_MESSAGE_ptr + which_reg );
*( iHost_ptr ) = the_message;
}
unsigned char read_data_reg( unsigned char which_reg ) {
char * iHost_ptr = ( char * ) ( cHOST_DATA_ptr + which_reg );
return( *( iHost_ptr ) );
}
void write_data_reg( unsigned char which_reg, unsigned char the_data ) {
char * iHost_ptr = ( char * ) ( cHOST_DATA_ptr + which_reg );
*( iHost_ptr ) = the_data;
}
//If the module discovered is a CM-2 then the following routines are used.
//see Hostport.c for assignment routines. Similar ones exist for the CM-1.
extern unsigned char Host_Translate_Address_CM2( unsigned long address ) {
write_message_reg( cHOST_REG_C, address );
write_message_reg( cHOST_REG_B, address >>= 8 );
write_message_reg( cHOST_REG_A, address >>= 8 );
write_message_reg( cHOST_REG_D, cMSG_TRANSLATE_ADDRESS );
return( cERR_NO_ERROR );
}
extern void Host_Interrupt_Ack_CM2 ( void ) {
write_message_reg( cHOST_REG_D, cMSG_INTERRUPT_ACK );
}
unsigned char Host_Multiplex_OP_CM2 ( unsigned char mux_op ) {
write_message_reg( cHOST_REG_C, mux_op );
write_message_reg( cHOST_REG_D, cMSG_MULTIPLEX_OP );
return( cERR_NO_ERROR );
}
extern unsigned char write_host_long_CM2( unsigned long the_data ) {
unsigned char temp_char = the_data;
write_data_reg( cHOST_REG_C, the_data >>= 8 );
write_data_reg( cHOST_REG_B, the_data >>= 8 );
write_data_reg( cHOST_REG_A, the_data >>= 8 );
write_data_reg( cHOST_REG_D, temp_char );
return( cERR_NO_ERROR );
}
extern unsigned long read_host_long_CM2( unsigned char * error_code_ptr ) {
unsigned long temp_long = 0;
*error_code_ptr = cERR_NO_ERROR;
temp_long = read_data_reg( cHOST_REG_A );
temp_long = ( temp_long << 8 ) | read_data_reg( cHOST_REG_B );
temp_long = ( temp_long << 8 ) | read_data_reg( cHOST_REG_C );
temp_long = ( temp_long << 8 ) | read_data_reg( cHOST_REG_D );
return( temp_long );
}
void Host_Garbage_Read_CM2() {
read_data_reg( cHOST_REG_D );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -