benreg.cpp
来自「基于4个mips核的noc设计」· C++ 代码 · 共 148 行
CPP
148 行
//---------------------------------------------------------------------------
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
#include <stdio.h>
#include <dimesdl.h>
#include "vidime.h"
#include <vector>
#include <math.h>
#include <conio.h>
using namespace std;
char FileName[]="nueping2.bit"; //THIS FILE NAME WILL NEED TO BE CHANGED TO SUIT YOUR MOTHERBOARD
void Exit(DWORD Value);
void DMATest(VIDIME_HANDLE hVIDIME, DIME_HANDLE hCard);
void DMATest2(DIME_HANDLE hCard, unsigned mem);
void RegTest(VIDIME_HANDLE hVIDIME);
void rwreg( DIME_HANDLE hCard, DWORD addr, DWORD data );
int WriteDataFile( char *filename, vector<unsigned>& data, int words=-1 );
int ReadDataFile( char *filename, vector<unsigned>* data );
int WriteMem( DIME_HANDLE hCard, int mem, vector<unsigned>& data );
int ReadMem( DIME_HANDLE hCard, int mem, vector<unsigned>* data, int data_words );
int main(int argc, char* argv[])
{
LOCATE_HANDLE hLocate=NULL;
DWORD ErrorNum,NumOfCards,Cntr,NumModules,LoopCntr,DevCntr;
char ErrorString[1000];
DIME_HANDLE hCard=NULL;
DWORD Result,Cntr2,CurrCount,TotalErrors;
VIDIME_HANDLE hVIDIME;
//Call the function to locate all Nallatech cards on the PCI interface.
if( (hLocate = DIME_LocateCard(dlUSB, mbtALL,NULL,dldrDEFAULT,dlDEFAULT)) == NULL)
{//Error hLocate still NULL Locate handle returned.
//Get the error then terminate the program
DIME_GetError(NULL, &ErrorNum, ErrorString);
printf("Error Number %d\n", ErrorNum);
printf("%s\n",ErrorString);
Exit(1);
}
//Determine how many Nallatech cards have been found.
NumOfCards = DIME_LocateStatus(hLocate,0,dlNUMCARDS);
printf("%d Nallatech card(s) found.\n", NumOfCards);
//Get the details for each card detected.
for (LoopCntr=1; LoopCntr<=NumOfCards; LoopCntr++)
{
printf("Details of card number %d, of %d:\n",LoopCntr,NumOfCards);
printf("\tThe card driver for this card is a %s.\n",(char*)DIME_LocateStatusPtr(hLocate,LoopCntr,dlDESCRIPTION));
printf("\tThe cards motherboard type is %d.\n",DIME_LocateStatus(hLocate,LoopCntr,dlMBTYPE));
}
//At this stage we now have all the information we need to open a card up.
//Open up the first card found.
printf("\nOpening card 1 ...");
hCard = DIME_OpenCard(hLocate, 1, dccOPEN_DEFAULT);
if (hCard == NULL) //check to see if the open worked.
{
DIME_GetError(NULL, &ErrorNum, ErrorString);
printf("Error Number %d\n", ErrorNum);
printf("%s\n",ErrorString);
printf("Card Number One failed to open.\n");
Exit(2);
}
printf(" done\n");
//Get some informtaion about the card and its modules.
printf("\nThis card is a %s.\n",DIME_CardStatusPtr(hCard,dinfDESCRIPTION));
NumModules = DIME_CardStatus(hCard,dinfNUMBERMODULES);
printf("There are %d modules on this card.\nThe Modules are:\n",NumModules);
// List the module Descriptions
for(LoopCntr=0; LoopCntr<NumModules; LoopCntr++)
{
printf("\tModule %d is a %s\n",LoopCntr,DIME_ModuleStatusPtr(hCard,LoopCntr,dinfDESCRIPTION));
for(DevCntr=0; DevCntr<DIME_ModuleStatus(hCard,LoopCntr,dinfNUMDEVICES); DevCntr++ )
printf("\t\tDevice %d is a %s\n",DevCntr,DIME_DeviceStatusPtr(hCard,LoopCntr,DevCntr,dinfDESCRIPTION));
}
DIME_CardResetControl(hCard,drONBOARDFPGA, drENABLE,0);
DIME_CardResetControl(hCard,drSYSTEM, drENABLE,0);
double freq;
DIME_SetOscillatorFrequency( hCard, 1, 20, &freq );
printf("Frequency (1) set to %f\n", freq );
DIME_SetOscillatorFrequency( hCard, 2, 40, &freq );
printf("Frequency (2) set to %f\n", freq );
DIME_CardResetControl(hCard,drONBOARDFPGA, drDISABLE,0);
DIME_CardResetControl(hCard,drINTERFACE, drTOGGLE,0);
DIME_CardResetControl(hCard,drSYSTEM, drDISABLE,0);
bool end = false;
while(!end){
char op[32];
DWORD a, d;
printf("[r/w] <reg> ");
scanf("%s", &op );
switch( op[0] ){
case 'r' :
scanf("%d", &a);
printf( "Reg %d => 0x%x\n", a, viDIME_ReadRegister( hCard, a, 0 ) );
break;
case 'w' :
printf("value? ");
scanf("%d %d", &a, &d );
printf( "Reg %d <= 0x%x\n", a, d );
viDIME_WriteRegister( hCard, a, d, 0 );
break;
default :
end = true;
break;
}
}
DIME_CloseCard(hCard);//Closes down the first card.
//Finally the last thing that should be done is to close down the locate.
DIME_CloseLocate(hLocate);
return 0;
}
void Exit(DWORD Value)
{
printf ("\nPress return to terminate the application.\n");
getchar();
exit(Value);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?