compword.c

来自「详细介绍了一篇关于pci开发的接口芯片」· C语言 代码 · 共 138 行

C
138
字号
/* compword.c

   wcompare -> addr1 & addr2 increment
   wcompare_1 -> addr1 stays same, addr2

   All have same...

   Entry:
   Exit: <> if OK.

*/

#include <stdtypes.h>
#include <clib1.h>
#include <string.h>
#include <stdio.h>

int wcompare(LONG length, VOID *addr1, VOID *addr2, \
    CHAR *err_string, WORD max_err_length)

/* Word compare both addresses increment.
*/
{
   register VWORD *sptr = addr1, *dptr = addr2;
   register LONG counter = length/2;
   CHAR local_str[80];

   while( counter )
   {
      if ( *dptr++ != *sptr++ )
      {
         sprintf( local_str, "WORD miscompare offset $%8.8lx bytes.\n", length - (counter * 2) );
         strmcat( err_string, max_err_length, local_str );
         sprintf( local_str, "SB: $%4x, WS: $%4x.\n", *(sptr - 1), *(dptr - 1) );
         strmcat( err_string, max_err_length, local_str );
         return(0);
      }

      counter--;
   }

   return(1);
}


int wcompare_1( LONG length, VOID *addr1, VOID *addr2, \
    CHAR *err_string, WORD max_err_length)

/* Word compare, addr1 does not increment.
*/
{
   register VWORD *sptr = addr1, *dptr = addr2;
   register LONG counter = length/2;
   register WORD data;
   CHAR local_str[80];

   while( counter )
   {
      data = *sptr;
      if ( data != *dptr++ )
      {
         sprintf( local_str, "WORD miscompare offset $%8.8lx bytes.\n", length - (counter * 2) );
         strmcat( err_string, max_err_length, local_str );
         sprintf( local_str, "SB: $%4x, WS: $%4x.\n", *(dptr - 1), data );
         strmcat( err_string, max_err_length, local_str );
         return(0);
      }

      counter--;
   }

   return(1);
}



int physical_wcompare(LONG length, UINT32 addr1, UINT32 addr2, \
    CHAR *err_string, WORD max_err_length)

/* Word compare both addresses increment.
*/
{
   	register LONG counter = length/2;
	register UINT16 sbdata, wsdata;
   	CHAR local_str[80];

   while( counter )
   {
		sbdata = xpeek16( addr1 );
		addr1 += 2;
		wsdata = xpeek16( addr2 );
		addr2 += 2;
      if ( sbdata != wsdata )
      {
         sprintf( local_str, "WORD miscompare offset $%8.8lx bytes.\n", length - (counter * 2) );
         strmcat( err_string, max_err_length, local_str );
         sprintf( local_str, "SB: $%4x, WS: $%4x.\n", sbdata, wsdata );
         strmcat( err_string, max_err_length, local_str );
         return(0);
      }

      counter--;
   }

   return(1);
}


int physical_wcompare_1( LONG length, UINT32 addr1, UINT32 addr2, \
    CHAR *err_string, WORD max_err_length)

/* Word compare, addr1 does not increment.
*/
{
	register LONG counter = length/2;
	register UINT16 sbdata, wsdata;
   	CHAR local_str[80];

   	while( counter )
   	{
		sbdata = xpeek16( addr1 );
		wsdata = xpeek16( addr2 );
		addr2 += 2;
      	if ( sbdata != wsdata )
      	{
         	sprintf( local_str, "WORD miscompare offset $%8.8lx bytes.\n", length - (counter * 2) );
         	strmcat( err_string, max_err_length, local_str );
         	sprintf( local_str, "SB: $%4x, WS: $%4x.\n", sbdata, wsdata );
         	strmcat( err_string, max_err_length, local_str );
         	return(0);
      	}

      	counter--;
   	}

	return(1);
}

⌨️ 快捷键说明

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