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

📄 hardware.c

📁 在对存储空间要求非常严格的嵌入式系统中用CPU下载CPLD的代码
💻 C
字号:
#include "opcode.h"

#ifdef VME_WINDOWS
#include <windows.h>
#include <mmsystem.h>
#include <time.h>
#include <conio.h>
#include "windriver.h"
#endif /* VME_WINDOWS */

#ifdef VME_DEBUG
#include <stdio.h>
#endif /* VME_DEBUG */

#ifdef VME_WINDOWS
#endif /* VME_WINDOWS */

/*************************************************************
*                                                            *
* EXTERNAL VARIABLE                                          *
*                                                            *
*************************************************************/

extern short int g_siIspPins;

/*************************************************************
*                                                            *
* EXTERNAL FUNCTION                                          *
*                                                            *
*************************************************************/

extern void ispVMStateMachine( char a_cNextState );

/*************************************************************
*                                                            *
* READPORT                                                   *
*                                                            *
* INPUT:                                                     *
*     None.                                                  *
*                                                            *
* RETURN:                                                    *
*     Returns the bit read back from the device.             *
*                                                            *
* DESCRIPTION:                                               *
*     This function is used to read the TDO pin from the     *
*     input port.                                            *
*                                                            *
*     NOTE: This function should be modified in an embedded  *
*     system!                                                *
*                                                            *
*************************************************************/

unsigned char readPort()
{
	unsigned char ucRet = 0;

#ifdef VME_WINDOWS
	if ( _inp( 0x379 ) & pinTDO ) {
		ucRet = 0x01;
	}
	else {
		ucRet = 0x00;
	}
#endif /* VME_WINDOWS */

	return ( ucRet );
} 

/*************************************************************
*                                                            *
* WRITEPORT                                                  *
*                                                            *
* INPUT:                                                     *
*     a_ucPins: a byte to indicate which pin will be         *
*     depending on the value.                                *
*                                                            *
*     a_ucValue: the value to determine of the pin above     *
*     will be written out or not.                            *
*                                                            *
* RETURN:                                                    *
*     None.                                                  *
*                                                            *
* DESCRIPTION:                                               *
*     To apply the specified value to the pins indicated.    *
*     This routine will likely be modified for specific      *
*     systems. As an example, this code is for the PC, as    *
*     described below.                                       *
*                                                            *
*     This routine uses the IBM-PC standard Parallel port,   *
*     along with the schematic shown in Lattice              *
*     documentation, to apply the signals to the programming *
*     loop.                                                  *
*                                                            *
*     NOTE: This function should be modified in an embedded  *
*     system!                                                *
*                                                            *
*************************************************************/

void writePort( unsigned char a_ucPins, unsigned char a_ucValue )
{
	if ( a_ucValue ) {
		g_siIspPins = a_ucPins | g_siIspPins;
	}
	else {
		g_siIspPins = ~a_ucPins & g_siIspPins;
	}

#ifdef VME_WINDOWS
	_outp( 0x378, g_siIspPins );
#endif /* VME_WINDOWS */
}

/*************************************************************
*                                                            *
* ISPVMDELAY                                                 *
*                                                            *
* INPUT:                                                     *
*     a_uiDelay: number of clocks to apply.                  *
*                                                            *
* RETURN:                                                    *
*     None.                                                  *
*                                                            *
* DESCRIPTION:                                               *
*     Users must devise their own timing procedures to       *
*     ensure the specified minimum delay is observed when    *
*     using different platform.  The timing function used    *
*     here is for PC only by hocking the clock chip.         *
*                                                            *
*     NOTE: This function should be modified in an embedded  *
*     system!                                                *
*                                                            *
*************************************************************/

void ispVMDelay( unsigned int a_uiDelay )
{	
	int iCurrentTime = 0;
	int iStartTime = 0;

#ifdef VME_DEBUG
	printf( "%d\n", a_uiDelay );
#endif /* VME_DEBUG */

#ifdef VME_WINDOWS
	if ( a_uiDelay > 0 ) {
		iStartTime = time( NULL );
		timeBeginPeriod( 1 );
		iCurrentTime = timeGetTime();    
		while ( ( iStartTime = timeGetTime() - iCurrentTime ) < a_uiDelay ) {
			
		}
		timeEndPeriod( 1 );
	}
	else{
		for ( iStartTime = 1; iStartTime <= 10; iStartTime++ ) {
			iCurrentTime++;
		}
	}
#endif /* VME_WINDOWS */
}

/*************************************************************
*                                                            *
* ENABLEHARDWARE                                             *
*                                                            *
* INPUT:                                                     *
*     None.                                                  *
*                                                            *
* RETURN:                                                    *
*     None.                                                  *
*                                                            *
* DESCRIPTION:                                               *
*     This function is called to enable the hardware.        *
*                                                            *
*     NOTE: This function should be modified in an embedded  *
*     system!                                                *
*                                                            *
*************************************************************/

void EnableHardware()
{
#ifdef VME_WINDOWS
	writePort( pinCE, 0x01 );
	ispVMStateMachine( RESET );
#endif /* VME_WINDOWS */
}

/*************************************************************
*                                                            *
* DISABLEHARDWARE                                            *
*                                                            *
* INPUT:                                                     *
*     None.                                                  *
*                                                            *
* RETURN:                                                    *
*     None.                                                  *
*                                                            *
* DESCRIPTION:                                               *
*     This function is called to disable the hardware.       *
*                                                            *
*     NOTE: This function should be modified in an embedded  *
*     system!                                                *
*                                                            *
*************************************************************/

void DisableHardware()
{
#ifdef VME_WINDOWS
	ispVMStateMachine( RESET );
	ispVMDelay( 1 );
	writePort( pinCE,0x00 );
#endif /* VME_WINDOWS */
}


⌨️ 快捷键说明

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