dmatest.cpp

来自「基于4个mips核的noc设计」· C++ 代码 · 共 166 行

CPP
166
字号
#define BLOCKSIZE 256
#define LOOPSIZE 1

void DMATest(VIDIME_HANDLE hVIDIME, DIME_HANDLE hCard)
{
  DWORD DataW[2048],DataR[2048];
  long WriteStart,WriteEnd,WriteTotal;
  long ReadStart,ReadEnd,ReadTotal;
  long StartTime;
  long time;
  DWORD Result,Cntr2,CurrCount,TotalErrors;

  printf("Blocksize:%d\n",BLOCKSIZE);
  printf("Loopsize:%d\n",LOOPSIZE);

  StartTime=GetTickCount();
  WriteTotal=ReadTotal=0;

  for(int Cntr=0;Cntr<LOOPSIZE;Cntr++)
    {

      // Fill the Data array
      for(Cntr2=0;Cntr2<BLOCKSIZE;Cntr2++)
        DataW[Cntr2]=Cntr*256+Cntr2;

      CurrCount=0;
      //Transfer the Data
      WriteStart=GetTickCount();

      viDIME_WriteRegister( hCard, 2, 0, 0 );
      printf("Reg2 = %d\n", viDIME_ReadRegister( hCard, 2, 0 ) );
      if((Result=viDIME_DMAWrite(hCard,DataW,BLOCKSIZE,1,NULL, &CurrCount, 5000))!=0)
        printf("Loop %d: Write Result = %d and count is %d\n",Cntr,Result,CurrCount);

      WriteEnd=GetTickCount();
      WriteTotal+=(WriteEnd-WriteStart);
      printf("Reg2 = %d\n", viDIME_ReadRegister( hCard, 2, 0 ) );

      viDIME_WriteRegister( hCard, 2, 0, 0 );
      printf("Reg2 = %d\n", viDIME_ReadRegister( hCard, 2, 0 ) );
      // Read the data Back
      ReadStart=GetTickCount();
      if((Result=viDIME_DMARead(hCard,DataR,BLOCKSIZE,1,NULL, &CurrCount, 5000))!=0)
        printf("Loop %d: Read Result = %d and Count is %d\n",Cntr,Result,CurrCount);

      ReadEnd=GetTickCount();
      ReadTotal+=(ReadEnd-ReadStart);
      printf("Reg2 = %d\n", viDIME_ReadRegister( hCard, 2, 0 ) );

      CurrCount=0;

      // Compare the data
      TotalErrors=0;
      for(Cntr2=0;Cntr2<BLOCKSIZE;Cntr2++)
        {
          if( DataW[Cntr2] != DataR[Cntr2] )
            {
              TotalErrors++;
              printf ("0x%x: PC:%08x, VIRTEX(s):%08x\n",Cntr2, DataW[Cntr2], DataR[Cntr2]);
            }
        }

      // Print status
      if (TotalErrors != 0)
        printf("Loop %d had %d errors\n",Cntr,TotalErrors);
    }

  time=GetTickCount()-StartTime;

  printf("time : %ld MilliSeconds\n",time);

  printf("Total: Throughput : %f Words/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 2 * 1000 * 2) / (double)time);
  printf("Total: Throughput : %f kByte/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 2 * 4 * 2) / (double)time);
  printf("Card Write: Throughput : %f Words/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 1000) / (double)WriteTotal);
  printf("Card Write: Throughput : %f kByte/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 4) / (double)WriteTotal);
  printf("Card Read : Throughput : %f Words/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 1000) / (double)ReadTotal);
  printf("Card Read : Throughput : %f kByte/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 4) / (double)ReadTotal);

}


void DMATest2(DIME_HANDLE hCard, unsigned mem)
{
  DWORD DataW[2048],DataR[2048];
  long WriteStart,WriteEnd,WriteTotal;
  long ReadStart,ReadEnd,ReadTotal;
  long StartTime;
  long time;
  DWORD Result,Cntr2,CurrCount,TotalErrors;

  printf("Blocksize:%d\n",BLOCKSIZE);
  printf("Loopsize:%d\n",LOOPSIZE);

  StartTime=GetTickCount();
  WriteTotal=ReadTotal=0;

  for(int Cntr=0;Cntr<LOOPSIZE;Cntr++)
    {

      // Fill the Data array
      for(Cntr2=0;Cntr2<BLOCKSIZE;Cntr2++)
        DataW[Cntr2]=Cntr*256+Cntr2;

      CurrCount=0;
      //Transfer the Data

      viDIME_WriteRegister( hCard, 4, mem, 0 );
      printf("Reg4 = %d\n", viDIME_ReadRegister( hCard, 4, 0 ) );

      viDIME_WriteRegister( hCard, 2, 0, 0 );
      printf("Reg2 = %d\n", viDIME_ReadRegister( hCard, 2, 0 ) );

      WriteStart=GetTickCount();
      for(Cntr2=0;Cntr2<BLOCKSIZE;Cntr2++)
        viDIME_WriteRegister( hCard, 6, DataW[Cntr2], 0 );
      WriteEnd=GetTickCount();
      WriteTotal += (WriteEnd-WriteStart);

      printf("Reg2 = %d\n", viDIME_ReadRegister( hCard, 2, 0 ) );

      viDIME_WriteRegister( hCard, 2, 0, 0 );
      printf("Reg2 = %d\n", viDIME_ReadRegister( hCard, 2, 0 ) );
      // Read the data Back
      ReadStart=GetTickCount();
      for(Cntr2=0;Cntr2<BLOCKSIZE;Cntr2++)
        DataR[Cntr2] = viDIME_ReadRegister( hCard, 6, 0 );

      ReadEnd=GetTickCount();
      ReadTotal+=(ReadEnd-ReadStart);
      printf("Reg2 = %d\n", viDIME_ReadRegister( hCard, 2, 0 ) );

      CurrCount=0;

      viDIME_WriteRegister( hCard, 4, 0, 0 );
      printf("Reg4 = %d\n", viDIME_ReadRegister( hCard, 4, 0 ) );

      // Compare the data
      TotalErrors=0;
      for(Cntr2=0;Cntr2<BLOCKSIZE;Cntr2++)
        {
          if( DataW[Cntr2] != DataR[Cntr2] )
            {
              TotalErrors++;
              printf ("0x%x: PC:%08x, VIRTEX(s):%08x\n",Cntr2, DataW[Cntr2], DataR[Cntr2]);
            }
        }

      // Print status
      if (TotalErrors != 0)
        printf("Loop %d had %d errors\n",Cntr,TotalErrors);
    }

  time=GetTickCount()-StartTime;

  printf("time : %ld MilliSeconds\n",time);

  printf("Total: Throughput : %f Words/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 2 * 1000 * 2) / (double)time);
  printf("Total: Throughput : %f kByte/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 2 * 4 * 2) / (double)time);
  printf("Card Write: Throughput : %f Words/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 1000) / (double)WriteTotal);
  printf("Card Write: Throughput : %f kByte/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 4) / (double)WriteTotal);
  printf("Card Read : Throughput : %f Words/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 1000) / (double)ReadTotal);
  printf("Card Read : Throughput : %f kByte/Second\n", (double)((double)LOOPSIZE * BLOCKSIZE * 4) / (double)ReadTotal);

}

⌨️ 快捷键说明

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