//**************************************************************************
//
// Copyright (c) 2001 IAG Software Team,
//
// BeiJing R&D Center
//
// Advantech Co., Ltd.
//
// PCI-1716 example for MS-DOS
//
// This is An Unpublished Work Containing Confidential And Proprietary
// Information Which Is The Property Of Advantech Automation Corp.
//
// Any Disclosure, Use, Or Reproduction, Without Written Authorization From
// Advantech Automation Corp., Is Strictly Prohibit.
//
//
//*****************************************************************************
//
// Program : Aififoint.C
// Revision: 1.0
// Author : Changping
// Date : 09/20/01
//
// Description:Perform pacer trigger analog input with FIFO half full
// interrupt of PCI-1716/HG.
//
//-----------------------------------------------------------------------------
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include "PCI.C"
// Global variable declare
dword gdwBaseAddr; //Base address
dword addr1_9054;
int giIrqNum; //IRQ number
int giIrqSourceBit; //indecate the interrupt source
int giComplete; //AI conversion complete flag
int giIntCount; //Interrupt occurs times
word giDataNumber; //AI conversion data count
word *gpwDataBuf; //Interrupt transfer data buffer
int counter=0;
// Local fucntion declare
void interrupt IrqHandler ();
byte InitInterrupt (
int iIrqNum,
void interrupt ( *pIsrHandler )(),
void interrupt ( **pOldIsr )() );
int GetFifoSize ( dword dwBaseAddr );
void ResetAi ( dword dwBaseAddr );
void RestoreOldIsr (
int iIrqNum,
byte ucIrqMask,
void interrupt ( *pOldIsr )() );
int SetPacer (
dword dwBaseAddr,
float fFrequency,
float fSourceFreq );
void StopPacer ( dword dwBaseAddr );
void main()
{
word wVendorId, wDeviceId, wIndex;
int iErrCode;
byte ucBusNumber, ucDevAndFunc;
dword dwData;
int iChannel, iStartChannel, iStopChannel;
byte ucGain, ucUniPolar, ucDifferential; //Base+2,
//channel range setting
byte ucTrigSrc, ucIrqEn, ucFh, ucCnt0; //Base+6, Control register
int iFifoSize, i;
byte ucIrqMask;
void interrupt ( *pOldIsr )();
word wRawData;
float fVoltage, fHiVolt, fLoVolt;
byte ucStatus;
wVendorId = 0x13fe;
wDeviceId = 0x1716;
wIndex = 0;
iStartChannel = 0; //Select analog input start channel
iStopChannel = 15; //Select analog input stop channel
giDataNumber = 100; //Conversion 100 data
gpwDataBuf = ( word* )malloc( giDataNumber * sizeof( word ) );
clrscr();
gotoxy( 10, 5 );
printf( "------------------ PCI-1716 AIINT.C -----------------------" );
printf( "\n\tThis program get voltage from channel %d to %d. ",
iStartChannel,
iStopChannel );
//==========================================================================
// Get 1716's resource
//==========================================================================
//
// Search PCI-1716
//
iErrCode = find_pci_device(
wDeviceId,
wVendorId,
wIndex,
&ucBusNumber,
&ucDevAndFunc );
if ( iErrCode == NOT_SUCCESSFUL )
{
printf( "\n\tPCI-1716 search fail.\n" );
exit( 1 );
}
//
//Get 9054 address, from PCI base address range 1
//
iErrCode = read_configuration_dword(
ucBusNumber,
ucDevAndFunc,
PCI_CS_BASE_ADDRESS_1,
&addr1_9054 );
if ( !iErrCode )
{
if ( addr1_9054 & 0x01 )
{
addr1_9054 &= 0xfffffffc;
printf( "\n\t9054 address=%lx ", addr1_9054 );
}
else
{
addr1_9054 &= 0xfffffff0;
printf( "\n\tPCI9054 MEMORY 9054=%lx ", addr1_9054 );
}
}
//
//Get base address, from PCI base address range 2
//
iErrCode = read_configuration_dword(
ucBusNumber,
ucDevAndFunc,
PCI_CS_BASE_ADDRESS_2,
&dwData );
if ( iErrCode == NOT_SUCCESSFUL )
{
printf( "\n\tPCI-1716 gets base address fail.\n" );
exit( 1 );
}
else
{
gdwBaseAddr = dwData & 0xfffffffc;
}
//
//Get Interrupt line
//
iErrCode = read_configuration_dword(
ucBusNumber,
ucDevAndFunc,
PCI_CS_INTERRUPT_LINE,
&dwData );
if ( iErrCode == NOT_SUCCESSFUL )
{
printf( "\n\tPCI-1716 gets interrupt line fail.\n" );
exit( 1 );
}
else
{
giIrqNum = dwData & 0xf;
}
printf( "\n\tPCI-1716/HG Base Address: %lx", gdwBaseAddr );
printf( "\n\tPCI-1716/HG Interrupt: %d", giIrqNum );
//Get FIFO size
iFifoSize = GetFifoSize( gdwBaseAddr );
printf( "\n\n\tPress any key to start conversion..." );
outport( addr1_9054 + 0x68, 0x0900 ); //INTCSR
//==========================================================================
// Reset AI function of PCI-1716/HG by clearing previous setting
//==========================================================================
ResetAi( gdwBaseAddr );
//==========================================================================
// Install ISR
//==========================================================================
ucIrqMask = InitInterrupt( giIrqNum, IrqHandler, &pOldIsr );
//==========================================================================
// Config PCI-1716 to pacer trigger, interrupt generate.
//==========================================================================
//Set pacer to 20Hz, source crystal is 1MHz
//Note, different gain code has different max. conversion rate.
StopPacer( gdwBaseAddr );
SetPacer( gdwBaseAddr, 10, 1000 );
//
//Set voltage input range (base+2)
// Bit# 7 6 5 4 3 2 1 0
// S/D B/U G2 G1 G0
// S/D: 0 = single ended, 1 = differential
// B/U: 0 = Bipolar, 1 = uniopolar
// G2,G1,G0 : Gain code
//
// B/U N/A G2 G1 G0 Voltage range PCI-1710, PCI-1710HG
// 0 0 0 0 -5V to 5V -5V to +5V
// 0 0 0 1 -2.5V to 2.5V -0.5V to 0.5V
// 0 0 1 0 -1.25V to 1.25V -0.05V to 0.05V
// 0 0 1 1 -0.625V to 0.625V -0.005V to 0.005V
// 0 1 0 0 -10V to 10V -10V to 10V
// 0 1 0 1 -1V to 1V
// 0 1 1 0 -0.1V to 0.1V
// 0 1 1 1 -0.01V to 0.01V
// 1 0 0 0 0V to 10V 0V to 10V
// 1 0 0 1 0V to 5V 0V to 1V
// 1 0 1 0 0V to 2.5V 0V to 0.1V
// 1 0 1 1 0V to 1.25V 0V to 0.01V
//
fLoVolt = -5.0; //Voltage -5V to + 5V
fHiVolt = 5.0;
ucGain = 0 ; //Gain code 0
ucUniPolar = 0; //Bipolar
ucDifferential = 0; //Single ended
ucGain = ucGain | ucUniPolar | ucDifferential;
for ( iChannel = iStartChannel; iChannel <= iStopChannel; iChannel++ )
{
outportb( gd