/***********************************************************************************/
/*                                                                                 */
/*   sis330x Ram test 1                                                             */
/*   write with A32DMA_D32  pattern                                                */
/*   read with BLT32, MBLT64 and 2EVME                                             */
/*   check data                                                                    */
/*                                                                                 */
/*                                                                                 */
/***********************************************************************************/


#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>




#include "dev/pci/sis1100_var.h"
#include "sis3100_vme_calls.h"




/*===========================================================================*/
/* Globals					  			     */
/*===========================================================================*/

#define MAX_NUMBER_OF_PRINTS 0x10
#define MAX_NUMBER_LWORDS 0x1000000       /* 64MByte */

u_int32_t wblt_data[MAX_NUMBER_LWORDS] ;
u_int32_t rblt_data[MAX_NUMBER_LWORDS] ;

u_int32_t test1_data[16] ;




/*===========================================================================*/
/* Prototypes					  			     */
/*===========================================================================*/

int vme_sis330x_ram_test(int ip, u_int32_t vme_start_addr, u_int32_t no_of_lwords) ;


/****************************************************************************/
int main(int argc, char* argv[])
{


int p;
u_int32_t addr ;
u_int32_t no_of_lwords ;

int return_code ;

int i;




test1_data[0]   =   0x12345678 ;
test1_data[1]   =   0x87654321 ;
test1_data[2]   =   0x11224488 ;
test1_data[3]   =   0x88442211 ;
test1_data[4]   =   0xAA559966 ;
test1_data[5]   =   0x66AA5599 ;
test1_data[6]   =   0x9966AA55 ;
test1_data[7]   =   0x559966AA ;
test1_data[8]   =   0xffffffff ;
test1_data[9]   =   0x00000000 ;
test1_data[10]  =   0xFF00FF00 ;
test1_data[11]  =   0x00FF00FF ;
test1_data[12]  =   0xFFFF0000 ;
test1_data[13]  =   0x0000FFFF ;
test1_data[14]  =   0xF0F0F0F0 ;
test1_data[15]  =   0x0F0F0F0F ;


/* open VME */
   if ((p=open("/tmp/sis1100", O_RDWR, 0))<0) {
     printf("error on opening VME environment\n");
     return -1;
   }

if (argc<3)
  {
   printf("usage:  VME_START_ADDRESS  NO_OF_LWORDS  \n");
  return -1;
  }

addr         = strtoul(argv[1],NULL,0);
no_of_lwords = strtoul(argv[2],NULL,0) ;




/******************************************************************/
/*                                                                */
/* Test VME RAM from PCI                    */
/*                                                                */
/******************************************************************/




for (i=0;i<20;i++)    {
    return_code = vme_sis330x_ram_test(p, addr, no_of_lwords) ;
    if (return_code != 0)  {
        printf("Error in VME_SIS330x Ram Test1:  start_addr = 0x%08x   no_of_lwords = 0x%08x\n", addr, no_of_lwords );
        return -1 ;
       }
    printf("Test VME_SIS330x Ram Test1                                                        OK\n");
 }



close(p);
return 0 ;
}








/***************************************************/
      


int vme_sis330x_ram_test(int ip, u_int32_t vme_start_addr, u_int32_t no_of_lwords)
{
/*
#define MAX_NUMBER_OF_PRINTS 0x10      
#define MAX_NUMBER_LWORDS 0x400000        
u_int32_t wblt_data[MAX_NUMBER_LWORDS] ;
u_int32_t rblt_data[MAX_NUMBER_LWORDS] ;
*/
u_int32_t addr ;
u_int32_t get_lwords ;
u_int32_t put_lwords ;

int i;
int error_cnt ;
int return_code ;



if (no_of_lwords > MAX_NUMBER_LWORDS)  {
     printf("no_of_lwords (0x%08x) must be lower then MAX_NUMBER_LWORDS (0x%08x)\n",no_of_lwords, MAX_NUMBER_LWORDS);
     return -1;
   }

if (no_of_lwords == 0)  {
     printf("no_of_lwords (0x%08x) must be higher then 1 \n",no_of_lwords);
     return -1;
   }
/* check address if 4,8, bzw 8,10 */


/******************************************************************/
/*                                                                */
/* step 1:   write increment pattern                              */
/*                                                                */
/******************************************************************/
    /* prepare data */
    for (i=0;i<no_of_lwords;i++)    { wblt_data[i] = i ;  }


    /* VME write data */
    addr =  vme_start_addr ;
           return_code =   vme_A32DMA_D32_write(ip, addr, wblt_data, no_of_lwords, &put_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32DMA_D32_write:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != put_lwords) {
              printf("length Error vme_A32DMA_D32_write:   must length = 0x%08x  written length = 0x%08x\n", no_of_lwords, put_lwords );
              return -1 ;
             }


  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with vme_A32DMA_D32_read */
    addr =  vme_start_addr ;
           return_code =   vme_A32DMA_D32_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32DMA_D32_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32DMA_D32_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)   {
          if (wblt_data[i] != rblt_data[i])  {
             printf(" Error0 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with  vme_A32BLT32_read */
           return_code =   vme_A32BLT32_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32BLT32_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32BLT32_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)
       {
          if (wblt_data[i] != rblt_data[i])
           {
             printf(" Error (read BLT32) at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with  vme_A32MBLT64_read */
           return_code =   vme_A32MBLT64_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32MBLT64_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32MBLT64_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }

     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)
       {
          if (wblt_data[i] != rblt_data[i])
           {
             printf(" Error (read MBLT64) at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }
  /* read data with  vme_A32_2EVME_read */
           return_code =   vme_A32_2EVME_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32_2EVME_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32_2EVME_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }

     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)
       {
          if (wblt_data[i] != rblt_data[i])
           {
             printf(" Error3 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }





/******************************************************************/
/*                                                                */
/* step 2:   bit shift pattern                                    */
/*                                                                */
/******************************************************************/
    /* prepare data */
    for (i=0;i<no_of_lwords;i++)    { wblt_data[i] = (0x1 << (i&0x1f)) ;  }
/*   for (i=0;i<no_of_lwords;i++)    { printf("w = 0x%08x \n", wblt_data[i]);  } */

    /* VME write data */
    addr =  vme_start_addr ;
           return_code =   vme_A32DMA_D32_write(ip, addr, wblt_data, no_of_lwords, &put_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32DMA_D32_write:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != put_lwords) {
              printf("length Error vme_A32DMA_D32_write:   must length = 0x%08x  written length = 0x%08x\n", no_of_lwords, put_lwords );
              return -1 ;
             }


   /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with vme_A32DMA_D32_read */
    addr =  vme_start_addr ;
           return_code =   vme_A32DMA_D32_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32DMA_D32_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32DMA_D32_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)   {
          if (wblt_data[i] != rblt_data[i])       {
             printf(" Error0 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with  vme_A32BLT32_read */
           return_code =   vme_A32BLT32_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32BLT32_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32BLT32_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)   {
          if (wblt_data[i] != rblt_data[i])       {
             printf(" Error1 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with  vme_A32MBLT64_read */
           return_code =   vme_A32MBLT64_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32MBLT64_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32MBLT64_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)   {
          if (wblt_data[i] != rblt_data[i])       {
             printf(" Error2 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }




  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }
  /* read data with  vme_A32_2EVME_read */
           return_code =   vme_A32_2EVME_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32_2EVME_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32_2EVME_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }

     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)   {
          if (wblt_data[i] != rblt_data[i])       {
             printf(" Error3 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }


/******************************************************************/
/*                                                                */
/* step 3:    pattern                                             */
/*                                                                */
/******************************************************************/
    /* prepare data */
    for (i=0;i<no_of_lwords;i++)    { wblt_data[i] =  test1_data[i&0xf] ;  }
/*    for (i=0;i<no_of_lwords;i++)    { printf("w = 0x%08x \n", wblt_data[i]);  }  */

    /* VME write data */
    addr =  vme_start_addr ;
           return_code =   vme_A32DMA_D32_write(ip, addr, wblt_data, no_of_lwords, &put_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32DMA_D32_write:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != put_lwords) {
              printf("length Error vme_A32DMA_D32_write:   must length = 0x%08x  written length = 0x%08x\n", no_of_lwords, put_lwords );
              return -1 ;
             }


   /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with vme_A32DMA_D32_read */
    addr =  vme_start_addr ;
           return_code =   vme_A32DMA_D32_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32DMA_D32_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32DMA_D32_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)  {
          if (wblt_data[i] != rblt_data[i])   {
             printf(" Error0 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with  vme_A32BLT32_read */
           return_code =   vme_A32BLT32_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32BLT32_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32BLT32_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)  {
          if (wblt_data[i] != rblt_data[i])   {
             printf(" Error1 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with  vme_A32MBLT64_read */
           return_code =   vme_A32MBLT64_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32MBLT64_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32MBLT64_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)  {
          if (wblt_data[i] != rblt_data[i])   {
             printf(" Error2 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }




  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }
  /* read data with  vme_A32_2EVME_read */
           return_code =   vme_A32_2EVME_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32_2EVME_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32_2EVME_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }


     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)  {
          if (wblt_data[i] != rblt_data[i])   {
             printf(" Error3 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }




/******************************************************************/
/*                                                                */
/* step 4:    random                                              */
/*                                                                */
/******************************************************************/
    /* prepare data */
    for (i=0;i<no_of_lwords;i++)    { wblt_data[i] =  random() ;  }
/*    for (i=0;i<no_of_lwords;i++)    { printf("w = 0x%08x \n", wblt_data[i]);  }   */


    /* VME write data */
    addr =  vme_start_addr ;
           return_code =   vme_A32DMA_D32_write(ip, addr, wblt_data, no_of_lwords, &put_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32DMA_D32_write:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != put_lwords) {
              printf("length Error vme_A32DMA_D32_write:   must length = 0x%08x  written length = 0x%08x\n", no_of_lwords, put_lwords );
              return -1 ;
             }



   /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with vme_A32DMA_D32_read */
    addr =  vme_start_addr ;
           return_code =   vme_A32DMA_D32_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32DMA_D32_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32DMA_D32_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)      {
          if (wblt_data[i] != rblt_data[i])      {
             printf(" Error0 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with  vme_A32BLT32_read */
           return_code =   vme_A32BLT32_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32BLT32_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32BLT32_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)      {
          if (wblt_data[i] != rblt_data[i])      {
             printf(" Error1 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }



  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }

  /* read data with  vme_A32MBLT64_read */
           return_code =   vme_A32MBLT64_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32MBLT64_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error vme_A32MBLT64_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }
     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)      {
          if (wblt_data[i] != rblt_data[i])      {
             printf(" Error2 at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }




  /* clear read pattern */
    for (i=0;i<no_of_lwords;i++)    { rblt_data[i] = 0 ;  }
  /* read data with  vme_A32_2EVME_read */
           return_code =   vme_A32_2EVME_read(ip, addr, rblt_data, no_of_lwords, &get_lwords) ;
           if(return_code != 0) {
              printf("return Error vme_A32_2EVME_read:   return_code = 0x%08x  at address = 0x%08x\n", return_code, addr );
              return -1 ;
             }
           if(no_of_lwords != get_lwords) {
              printf("length Error3 vme_A32_2EVME_read:   must length = 0x%08x  read length = 0x%08x\n", no_of_lwords, get_lwords );
              return -1 ;
             }


     /* check data */
     error_cnt =  0 ;
     for (i=0;(i)<no_of_lwords;i++)      {
          if (wblt_data[i] != rblt_data[i])      {
             printf(" Error at i = : 0x%08x    written = : 0x%08x   read = : 0x%08x\n", i, wblt_data[i], rblt_data[i]);
             error_cnt = error_cnt + 1;
             if (error_cnt > MAX_NUMBER_OF_PRINTS) return -1 ;
           }
       }


  if (error_cnt == 0) {
     return 0 ; }
    else {
     return -1 ;}

}


































