📄 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
WORD N0,N1;
DWORD FIFO0, FIFO1, Edge;
// 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 ******************
if(!EnablePortAccess())
{
AfxMessageBox("Giveio.sys couldn't be opened");
}
_outpw(base+0xC,0x0101);
Sleep(1);
_outpw(base+0xC,0x0000);
// *********************** Your Code ********************************************************
// ****************** Setup ***************************
// _LSB ___Address
// | | _____MSB
// ...| ||..
_outpw(base+0x0, 0x00fb);_outpw(base+0x2, 0x0000);//Reg 0, Start ring oscillator, enable & falling rising edges
_outpw(base+0x0, 0x0700);_outpw(base+0x2, 0x1707);//Reg 1, Channel adjust
_outpw(base+0x0, 0x0001);_outpw(base+0x2, 0x2007);//Reg 2, G-Mode
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x3800);//Reg 3, use TTL inputs
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x4600);//Reg 4, MTimer begins with Start, EF high-Z
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x5020);//Reg 5, Stop disable before Start
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x6000);//Reg 6, Switch off ECL inputs
_outpw(base+0x0, 0x1fb4);_outpw(base+0x2, 0x7014);//Reg 7, Resolution = 41.1523ps, MTimer = 1祍
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0xB400);//Reg 11,PLL not locked -> Err
_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0xC200);//Reg 12,MTimer -> Int
//******************** Measurement ********************q
_outpw(base+0x0,0x0000);_outpw(base+0x2,0x4640);//TDC-GPX MasterReset
printf("TDC resetted");
do
{
while(!(_inpw(base+0x8) & 0x0020)); // Check Interrupt flag
_outpw(base+0x4,0x000B); //Read register 11, get number of hits per channel
N0 = _inpw(base+0x0);
N1 = ((N0 & 0xFF00)>>8)*2; // *2 only if rising and falling edge is selected
N0 = (N0 & 0xFF)*2; // *2 only if rising and falling edge is selected
printf("\nN0 %X\tN1 %X\n",N0,N1);
i=0;
while(i<N0)
{
_outpw(base+0x4,0x0008); //Read TDC-GPX IFIFO1
FIFO0 = _inpd(base+0x0)&0x7FFFFF;
Edge = (FIFO0 & 0x400000)>>22;
FIFO0 = FIFO0 & 0x3FFFFF;
printf("ch1 hit# %d Edge %d \t%5.3fns\n",i+1, Edge,(FIFO0-150)*41.1523/1000);
i++;
}
i=0;
while(i<N1)
{
_outpw(base+0x4,0x0009); //Read TDC-GPX IFIFO2
FIFO1 = _inpd(base+0x0)&0x7FFFFF;
Edge = (FIFO1 & 0x400000)>>22;
FIFO1 = FIFO1 & 0x3FFFFF;
printf("ch2 hit# %d Edge %d \t%5.3fps\n",i+1, Edge,(FIFO1-260)*41.1523/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;
}
}
_outpw(base+0x0,0x0000);_outpw(base+0x2,0x4640);//TDC-GPX MasterReset
} while ( !quit );
// ********************************* End of Your code *****************************************
return nRetCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -