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

📄 hal_regs.c

📁 epson公司的一个关于s1d13706的低层驱动程序
💻 C
字号:
/*
**===========================================================================
** HAL_REGS.C - Functions to access the registers.
**---------------------------------------------------------------------------
** Copyright (c) 2000, 2001 Epson Research and Development, Inc.
** All Rights Reserved.
**===========================================================================
*/

#include <stdio.h>
#include "hal.h"
#include "nonsefns.h"
#include "assert.h"

/*-----------------------------------------------------------------------*/

/*
** To display register reads and writes, define DISPLAY_REGISTER_READ or
** DISPLAY_REGISTER_WRITE
*/
//#define DISPLAY_REGISTER_WRITE
//#define DISPLAY_REGISTER_READ

/*-----------------------------------------------------------------------*/

static const char Revision[] = "HAL_REGS.C=$Revision: 6 $";

//----------------------------------------------------------------------------
//
// swapbytes
// 
//----------------------------------------------------------------------------

#ifndef INTEL_DOS
void _swapbytes(void *ptr, int size)
	{
	if (size == 2)
		{
		BYTE tmp;
		BYTE *bpt = ptr;

		tmp = bpt[0];
 		bpt[0] = bpt[1];
		bpt[1] = tmp;
		}

	if (size == 4)
		{
		BYTE tmp;
		BYTE *bpt = ptr;

		tmp = bpt[0];
 		bpt[0] = bpt[3];
		bpt[3] = tmp;
		tmp = bpt[1];
 		bpt[1] = bpt[2];
		bpt[2] = tmp;
		}
	}
#endif

/*-------------------------------------------------------------------------*/

/*
** seReadRegByte()
**
** Retrieves the value in the register specified by 'index'.
*/
unsigned seReadRegByte(DWORD index)
{
   unsigned value;

   ASSERT( index <= HIGHEST_REG );

#ifdef LINEAR_ADDRESSES_SUPPORTED
   value =  *((volatile LPBYTE) (_RegLinearAddress + index));
#else
   value = _READXB((unsigned long) (_RegLinearAddress + index));
#endif

#ifdef DISPLAY_REGISTER_READ
   printf("REG[%03lX] > %02X\n", index, value);
#endif

   return value;
}

/*-------------------------------------------------------------------------*/

/*
** seWriteRegByte()
**
** Writes 'value' to the register specified by 'index'.
*/
void seWriteRegByte( DWORD index, unsigned value )
{
   ASSERT( index <= HIGHEST_REG );

#ifdef DISPLAY_REGISTER_WRITE
   printf("REG[%03lX] < %02X\n", index, value);
#endif

#ifdef LINEAR_ADDRESSES_SUPPORTED
   *((LPBYTE) (_RegLinearAddress + index)) = (BYTE) value;
#else
   _WRITEXB(_RegLinearAddress + index, (BYTE) value);
#endif
}

/*-------------------------------------------------------------------------*/

/*
** seReadRegWord()
**
** Retrieves the value in the register specified by 'index'.
*/
unsigned seReadRegWord(DWORD index)
{
   WORD value;
   ASSERT( index <= HIGHEST_REG );

#ifdef LINEAR_ADDRESSES_SUPPORTED
   value = *((volatile LPWORD) (_RegLinearAddress + index));
   if (_EndianReverseRegisterBytes)
      {
      SWAP(value);
      }
#else
   value = _READXW((unsigned long) (_RegLinearAddress + index));
#endif

#ifdef DISPLAY_REGISTER_READ
   printf("REG[%03lX] > %04X\n", index, value);
#endif

   return value;
}

/*-------------------------------------------------------------------------*/

/*
** seWriteRegWord()
**
** Writes 'value' to the register specified by 'index'.
*/
void seWriteRegWord(DWORD index, unsigned value)
{
   ASSERT( index <= HIGHEST_REG );

#ifdef DISPLAY_REGISTER_WRITE
   printf("REG[%03lX] < %04lX\n", index, value);
#endif

#ifdef LINEAR_ADDRESSES_SUPPORTED
   if (_EndianReverseRegisterBytes)
      {
      WORD wvalue = (WORD)value;
      SWAP(wvalue);
      *((LPWORD) (_RegLinearAddress + index)) = wvalue;
      }
   else
      *((LPWORD) (_RegLinearAddress + index)) = (WORD)value;
#else
   _WRITEXW(_RegLinearAddress + index, value);
#endif
}

/*-------------------------------------------------------------------------*/

/*
** seReadRegDword()
**
** Retrieves the value in the register specified by 'index'.
*/
DWORD seReadRegDword(DWORD index)
{
   DWORD value;
   ASSERT( index <= HIGHEST_REG );

#ifdef LCEVBSH3
   value = *((volatile LPBYTE) (_RegLinearAddress + index));
   value |= (*((volatile LPBYTE) (_RegLinearAddress + index + 1)) << 8);
   value |= (*((volatile LPBYTE) (_RegLinearAddress + index + 2)) << 16);
   value |= (*((volatile LPBYTE) (_RegLinearAddress + index + 3)) << 24);

   if (_EndianReverseRegisterBytes)
      {
      SWAP(value);
      }
#elif defined(LINEAR_ADDRESSES_SUPPORTED)
   value = *((volatile LPDWORD) (_RegLinearAddress + index));
   if (_EndianReverseRegisterBytes)
      {
      SWAP(value);
      }          
#else
   value = _READXD((unsigned long) (_RegLinearAddress + index));
#endif

#ifdef DISPLAY_REGISTER_READ
   printf("REG[%03lX] > %08lX\n", index, value);
#endif

   return value;
}

/*-------------------------------------------------------------------------*/

/*
** seWriteRegDword()
**
** Writes 'value' to the register specified by 'index'.
*/
void seWriteRegDword(DWORD index, DWORD value)
{
   ASSERT( index <= HIGHEST_REG );

#ifdef DISPLAY_REGISTER_WRITE
   printf("REG[%03lX] < %08lX\n", index, value);
#endif

#ifdef LCEVBSH3
   if (_EndianReverseRegisterBytes)
      {
      SWAP(value);
      }

   *((LPBYTE) (_RegLinearAddress + index)) = (value & 0xff);
   *((LPBYTE) (_RegLinearAddress + index + 1)) = (value >> 8) & 0xff;
   *((LPBYTE) (_RegLinearAddress + index + 2)) = (value >> 16) & 0xff;
   *((LPBYTE) (_RegLinearAddress + index + 3)) = (value >> 24) & 0xff;
#elif defined(LINEAR_ADDRESSES_SUPPORTED)
   if (_EndianReverseRegisterBytes)
      {
      SWAP(value);
      }

   *((LPDWORD) (_RegLinearAddress + index)) = value;
#else
   _WRITEXD(_RegLinearAddress + index, value);
#endif
}

/*-------------------------------------------------------------------------*/

⌨️ 快捷键说明

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