lib/sw_apps/zynq_dram_test/src/test01.c
int memtest(int start, int size, int mode, int loop)
{
  int i, rd, addr, data, ref, mod16, imaski;
  int merr = 0;   // per test word errors
  int randval;
  int lerrcnt[4];  // local errcnt per test


  for (i=0; i<4; i++)
    lerrcnt[i] = 0;
  if (memtest_stat)
    REG_WRITE(MAILBOX_STAT, 100+mode);

  timer_init();

  // write then read memory
  for (rd=0; rd<2; rd++)
  {  // 0=wr, 1=rd
    randval = 0x12345678 + loop + 19*mode;

    for (i=0; i<size; i+=4)
    {
      mod16 = (i >> 2) & 0x0f;
      imaski = (i >> 6) & 0x07;  // invert mask index
      addr = start + i;
      if (mode == 0)
        ref = addr & qmask;
      else if (mode == 1)
        ref = 0;
      else if (mode == 2)
        ref = 0xffffffff;
      else if (mode == 3)
        ref = 0xAAAAAAAA;
      else if (mode == 4)
        ref = 0x55555555;
      else if (mode == 5)
        ref = (i & 4) ? 0xffffffff : 0;
      else if (mode == 6)
        ref = (i & 4) ? 0 : 0xffffffff;
      else if (mode == 7)
        ref = (i & 4) ? 0xaaaaaaaa : 0x55555555;
      else if (mode == 8)
        ref = (i & 4) ? 0x55555555 : 0xaaaaaaaa;
      else if (mode == 9)
        ref = pattern1[mod16];
      else if (mode == 10)
        ref = pattern1[mod16] ^ invertmask[imaski];
      else
      {
        // random
        randval = calc_value(randval);
        ref = randval;
      }

      if (rd == 0)
      {
        REG_WRITE(addr, ref);
        //progress bar, print dot every 32MB if the total size > 32MB
        if((i%0x2000000==0) && (size>0x2000000))
        {
          fflush(stdout);
          printf(".");
        }
      }
      else // read and compare
      {
        //progress bar, print dot every 32MB if the total size > 32MB
        if((i%0x2000000==0) && (size>0x2000000))
        {
          fflush(stdout);
          printf(".");
        }
        data = REG_READ(addr);
        if (data != ref)
        {
          werr++;
          merr++;
          if ((data & 0x000000ff) != (ref & 0x000000ff))
            lerrcnt[0]++;
          if ((data & 0x0000ff00) != (ref & 0x0000ff00))
            lerrcnt[1]++;
          if ((data & 0x00ff0000) != (ref & 0x00ff0000))
            lerrcnt[2]++;
          if ((data & 0xff000000) != (ref & 0xff000000))
            lerrcnt[3]++;

          if ((verbose & 8) && (merr <= 10))
            printf("\rMemtest_0 ERROR: addr=0x%X rd/ref/xor = 0x%08X 0x%08X 0x%08X \r\n", addr, data, ref, data ^ ref);

          error_info(addr, ref, data);
        }

        if ((lerrcnt[0] > 1000) && (lerrcnt[1] > 1000) && (lerrcnt[2] > 1000) && (lerrcnt[3] > 1000))
          break;  // to save time when there are lots of errors
      } // read and compare
    } // i
    DCacheInvalidate();
  }  // rd

  i = timer_read();
  test_time = timer_value(i, pclk);
  total_test_time += test_time;

  if (verbose & 1)
  {
    printf("\rMemtest_0 (%3d:%2d)      %d         [%8d] [%8d] [%8d] [%8d]    %g\n",
        loop,mode, merr, lerrcnt[0], lerrcnt[1], lerrcnt[2], lerrcnt[3],
        test_time);
  }

  // add local to global
  for (i=0; i<4; i++)
    errcnt[i] += lerrcnt[i];
  if (merr > 0)
    epp += 1 << mode;
  return 0;
}
/****************************************************************************
 * Function: memtest
 * Description: Do a simple memory test
        start and size are in bytes
 ****************************************************************************/
memtest
Description: Do a simple memory test
start and size are in bytes
memtest Description : Do a simple memory test start and size are in bytes
int memtest(int start, int size, int mode, int loop)
{
  int i, rd, addr, data, ref, mod16, imaski;
  int merr = 0;   
  int randval;
  int lerrcnt[4];  
  for (i=0; i<4; i++)
    lerrcnt[i] = 0;
  if (memtest_stat)
    REG_WRITE(MAILBOX_STAT, 100+mode);
  timer_init();
  for (rd=0; rd<2; rd++)
  {  
    randval = 0x12345678 + loop + 19*mode;
    for (i=0; i<size; i+=4)
    {
      mod16 = (i >> 2) & 0x0f;
      imaski = (i >> 6) & 0x07;  
      addr = start + i;
      if (mode == 0)
        ref = addr & qmask;
      else if (mode == 1)
        ref = 0;
      else if (mode == 2)
        ref = 0xffffffff;
      else if (mode == 3)
        ref = 0xAAAAAAAA;
      else if (mode == 4)
        ref = 0x55555555;
      else if (mode == 5)
        ref = (i & 4) ? 0xffffffff : 0;
      else if (mode == 6)
        ref = (i & 4) ? 0 : 0xffffffff;
      else if (mode == 7)
        ref = (i & 4) ? 0xaaaaaaaa : 0x55555555;
      else if (mode == 8)
        ref = (i & 4) ? 0x55555555 : 0xaaaaaaaa;
      else if (mode == 9)
        ref = pattern1[mod16];
      else if (mode == 10)
        ref = pattern1[mod16] ^ invertmask[imaski];
      else
      {
        randval = calc_value(randval);
        ref = randval;
      }
      if (rd == 0)
      {
        REG_WRITE(addr, ref);
        if((i%0x2000000==0) && (size>0x2000000))
        {
          fflush(stdout);
          printf(".");
        }
      }
      else 
      {
        if((i%0x2000000==0) && (size>0x2000000))
        {
          fflush(stdout);
          printf(".");
        }
        data = REG_READ(addr);
        if (data != ref)
        {
          werr++;
          merr++;
          if ((data & 0x000000ff) != (ref & 0x000000ff))
            lerrcnt[0]++;
          if ((data & 0x0000ff00) != (ref & 0x0000ff00))
            lerrcnt[1]++;
          if ((data & 0x00ff0000) != (ref & 0x00ff0000))
            lerrcnt[2]++;
          if ((data & 0xff000000) != (ref & 0xff000000))
            lerrcnt[3]++;
          if ((verbose & 8) && (merr <= 10))
            printf("\rMemtest_0 ERROR: addr=0x%X rd/ref/xor = 0x%08X 0x%08X 0x%08X \r\n", addr, data, ref, data ^ ref);
          error_info(addr, ref, data);
        }
        if ((lerrcnt[0] > 1000) && (lerrcnt[1] > 1000) && (lerrcnt[2] > 1000) && (lerrcnt[3] > 1000))
          break;  
      } 
    } 
    DCacheInvalidate();
  }  
  i = timer_read();
  test_time = timer_value(i, pclk);
  total_test_time += test_time;
  if (verbose & 1)
  {
    printf("\rMemtest_0 (%3d:%2d)      %d         [%8d] [%8d] [%8d] [%8d]    %g\n",
        loop,mode, merr, lerrcnt[0], lerrcnt[1], lerrcnt[2], lerrcnt[3],
        test_time);
  }
  for (i=0; i<4; i++)
    errcnt[i] += lerrcnt[i];
  if (merr > 0)
    epp += 1 << mode;
  return 0;
}
int memtest ( int start , int size , int mode , int loop ) { int i , rd , addr , data , ref , mod16 , imaski ; int merr = 0 ; int randval ; int lerrcnt [ 4 ] ; for ( i = 0 ; i < 4 ; i ++ ) lerrcnt [ i ] = 0 ; if ( memtest_stat ) REG_WRITE ( MAILBOX_STAT , 100 + mode ) ; timer_init ( ) ; for ( rd = 0 ; rd < 2 ; rd ++ ) { randval = 0x12345678 + loop + 19 * mode ; for ( i = 0 ; i < size ; i += 4 ) { mod16 = ( i >> 2 ) & 0x0f ; imaski = ( i >> 6 ) & 0x07 ; addr = start + i ; if ( mode == 0 ) ref = addr & qmask ; else if ( mode == 1 ) ref = 0 ; else if ( mode == 2 ) ref = 0xffffffff ; else if ( mode == 3 ) ref = 0xAAAAAAAA ; else if ( mode == 4 ) ref = 0x55555555 ; else if ( mode == 5 ) ref = ( i & 4 ) ? 0xffffffff : 0 ; else if ( mode == 6 ) ref = ( i & 4 ) ? 0 : 0xffffffff ; else if ( mode == 7 ) ref = ( i & 4 ) ? 0xaaaaaaaa : 0x55555555 ; else if ( mode == 8 ) ref = ( i & 4 ) ? 0x55555555 : 0xaaaaaaaa ; else if ( mode == 9 ) ref = pattern1 [ mod16 ] ; else if ( mode == 10 ) ref = pattern1 [ mod16 ] ^ invertmask [ imaski ] ; else { randval = calc_value ( randval ) ; ref = randval ; } if ( rd == 0 ) { REG_WRITE ( addr , ref ) ; if ( ( i % 0x2000000 == 0 ) && ( size > 0x2000000 ) ) { fflush ( stdout ) ; printf ( " " ) ; } } else { if ( ( i % 0x2000000 == 0 ) && ( size > 0x2000000 ) ) { fflush ( stdout ) ; printf ( " " ) ; } data = REG_READ ( addr ) ; if ( data != ref ) { werr ++ ; merr ++ ; if ( ( data & 0x000000ff ) != ( ref & 0x000000ff ) ) lerrcnt [ 0 ] ++ ; if ( ( data & 0x0000ff00 ) != ( ref & 0x0000ff00 ) ) lerrcnt [ 1 ] ++ ; if ( ( data & 0x00ff0000 ) != ( ref & 0x00ff0000 ) ) lerrcnt [ 2 ] ++ ; if ( ( data & 0xff000000 ) != ( ref & 0xff000000 ) ) lerrcnt [ 3 ] ++ ; if ( ( verbose & 8 ) && ( merr <= 10 ) ) printf ( " \r \r \n " , addr , data , ref , data ^ ref ) ; error_info ( addr , ref , data ) ; } if ( ( lerrcnt [ 0 ] > 1000 ) && ( lerrcnt [ 1 ] > 1000 ) && ( lerrcnt [ 2 ] > 1000 ) && ( lerrcnt [ 3 ] > 1000 ) ) break ; } } DCacheInvalidate ( ) ; } i = timer_read ( ) ; test_time = timer_value ( i , pclk ) ; total_test_time += test_time ; if ( verbose & 1 ) { printf ( " \r \n " , loop , mode , merr , lerrcnt [ 0 ] , lerrcnt [ 1 ] , lerrcnt [ 2 ] , lerrcnt [ 3 ] , test_time ) ; } for ( i = 0 ; i < 4 ; i ++ ) errcnt [ i ] += lerrcnt [ i ] ; if ( merr > 0 ) epp += 1 << mode ; return 0 ; }
Function: memtest
 Description: Do a simple memory test
start and size are in bytes
Function : memtest Description : Do a simple memory test start and size are in bytes
// per test word errors // local errcnt per test // write then read memory // 0=wr, 1=rd // invert mask index // random //progress bar, print dot every 32MB if the total size > 32MB // read and compare //progress bar, print dot every 32MB if the total size > 32MB // to save time when there are lots of errors // read and compare // i // rd // add local to global