📄 console_pci2.cpp
字号:
// console_pci2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "atmd_pci.h"
#include "conio.h"
#include "console_pci2.h"
#include "math.h"
#include "winbase.h"
#include "stdio.h"
void writeRegQuiet ( WORD, int, DWORD);
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int mc(WORD);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode;
int i,iBoardCount;
char ch;
WORD atmd_pci_base_address[10],base;
BOOL AtmdOK = FALSE, quit = FALSE;
DWORD dwTemp;
// Your variables
DWORD FIFO0, FIFO1, Edge,Chan;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// ****************************************************************
// ************* Start of application code ************************
// detect ATMD PCI (call GetATMDPCIBoardCount() to detect number of ATMD-PCI boards)
iBoardCount = GetATMDPCIBoardCount();
printf("No. of ATMD PCI boards found = %d\n",iBoardCount);
i=0;
while((!AtmdOK) || (i>4))
{
AtmdOK = GetATMDPCIBaseAddr(i,dwTemp);
atmd_pci_base_address[i] = (WORD) dwTemp;
i++;
}
if (AtmdOK)
{
printf("ATMD PCI Board found on 0x%x\n",atmd_pci_base_address[i-1]);
base = atmd_pci_base_address[i-1]; // base = base address
if(!EnablePortAccess())
{
AfxMessageBox("Giveio.sys couldn't be opened");
}
}
else
{
AfxMessageBox("ATMD-PCI interface not found");
}
}
// ******************** board-reset ******************
_outpw(base+0xC,0x0101); //ATMD-specific
Sleep(1);
_outpw(base+0xC,0x0000); //ATMD-specific
// *********************** Your Code ********************************************************
// ****************** Setup ***************************
// _LSB ___Address
// | | _____MSB
// ...| ||..
_outpw(base+0x0, 0xfc81);_outpw(base+0x2, 0x0007);//Reg 0, 0x007fc81 Start ring oscillator, enable rising edges
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x1000);//Reg 1, 0x0000000 Channel adjust
_outpw(base+0x0, 0x0002);_outpw(base+0x2, 0x2000);//Reg 2, 0x0000002 I-Mode
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x3000);//Reg 3, 0x0000000 not relevant in I-Mode
_outpw(base+0x0, 0x0001);_outpw(base+0x2, 0x4200);//Reg 4, 0x2000001 EF high-Z, StartTimer = 1 for external start retrigger
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x5800);//Reg 5, 0x8000000 Start retrigger, Stop disable until first Start
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x6000);//Reg 6, 0x0000000 Switch off ECL inputs
_outpw(base+0x0, 0x1fb4);_outpw(base+0x2, 0x7000);//Reg 7, 0x0001fb4 Resolution = 82.3045 ps
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0xB400);//Reg 11,0x4000000 PLL not locked -> Err
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0xC000);//Reg 12,0x0000000 No interrupt (Start retrigger)
//******************** Measurement ********************
_outpw(base+0x0,0x0001);_outpw(base+0x2,0x4240);//TDC-GPX MasterReset
printf("TDC resetted");
do
{
//while(!(_inpw(base+0x8) & 0x0020)); // Check Interrupt flag
i=0;
while(!(_inpd(base+0x8)&0x800)) //while IFIFO1 not empty
{
_outpw(base+0x4,0x0008); //Read from address 8, TDC-GPX IFIFO1
FIFO0 = _inpd(base+0x0);
Edge = (FIFO0 & 0x020000)>>17; //select edge bit
Chan = (FIFO0 & 0xc000000)>>26; //select channel number bits
FIFO0 = FIFO0 & 0x1FFFF;
printf("ch %d hit# %d Edge %d \t%5.3fns\n\n",Chan+1, i+1,Edge,(FIFO0)*82.3045/1000);
i++;
}
i=0;
while(!(_inpd(base+0x8)&0x1000)) //while IFIFO2 not empty
{
_outpw(base+0x4,0x0009); //Read address 9, TDC-GPX IFIFO2
FIFO1 = _inpd(base+0x0);
Edge = (FIFO1 & 0x020000)>>17; //select edge bit
Chan = (FIFO1& 0xc000000)>>26 ; //select channel number bits
FIFO1 = FIFO1 & 0x1FFFF;
printf("ch %d hit# %d Edge %d \t%5.3fns\n\n",Chan+5, i+1,Edge,(FIFO1)*82.3045/1000);
i++;
}
// Keyboard: "i" = interrupt measurement, "q" = quit measurement
if(kbhit())
{
ch=getch();
if(ch=='q')
quit=true;
if(ch=='i')
{
while(!kbhit());
quit=false;
}
}
} while ( !quit );
// ********************************* End of Your code *****************************************
return nRetCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -