⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pci.all

📁 在dos下读写pci卡
💻 ALL
📖 第 1 页 / 共 3 页
字号:
}//Main




//
//PCI.C
//
#include <dos.h>
#include <stddef.h>

/*---PCI Functions---*/
#define PCI_BIOS_PRESENT          0x01
#define FIND_PCI_DEVICE           0x02
#define READ_CONFIG_DWORD         0x0a
#define PCI_FUNCTION_ID           0xb1

/*---Return Code ---*/
#define SUCCESSFUL               0x00
#define NOT_SUCCESSFUL           0x01

/*---PCI Configuration Space Registers---*/

#define PCI_CS_VENDOR_ID         0x00
#define PCI_CS_DEVICE_ID         0x02
#define PCI_CS_COMMAND           0x04
#define PCI_CS_STATUS            0x06
#define PCI_CS_REVISION_ID       0x08
#define PCI_CS_CLASS_CODE        0x09
#define PCI_CS_CACHE_LINE_SIZE   0x0c
#define PCI_CS_MASTER_LATENCY    0x0d
#define PCI_CS_HEADER_TYPE       0x0e
#define PCI_CS_BIST              0x0f
#define PCI_CS_BASE_ADDRESS_0    0x10
#define PCI_CS_BASE_ADDRESS_1    0x14
#define PCI_CS_BASE_ADDRESS_2    0x18
#define PCI_CS_BASE_ADDRESS_3    0x1c
#define PCI_CS_BASE_ADDRESS_4    0x20
#define PCI_CS_BASE_ADDRESS_5    0x24
#define PCI_CS_SUBSYSTEM_ID      0x2c
#define PCI_CS_EXPANSION_ROM     0x30
#define PCI_CS_INTERRUPT_LINE    0x3c
#define PCI_CS_INTERRUPT_PIN     0x3d

/*---Define macros to obtain individual bytes from a word register---*/
#define TRUE    1
#define FALSE   0
#define HIGH_BYTE(ax) (ax >> 8)
#define LOW_BYTE(ax) (ax & 0xff)
#define CARRY_FLAG 0x01         /* 80x86 Flags Register Carry Flag bit */

typedef unsigned char byte;     /* byte data type */
typedef unsigned short word;    /* word data type */
typedef unsigned long dword;    /* double word data type */

/* Function Prototypes */
static int read_configuration_area(byte function, byte bus_number,
                                   byte device_and_function,
                                   byte register_number, dword *data);

int find_pci_device(word device_id, word vendor_id, word index,
                    byte *bus_number, byte *device_and_function);

int read_configuration_dword(byte bus_number, byte device_and_function,
                             byte register_number, dword *dword_read);

/* Function source code */
int find_pci_device(word device_id,
                    word vendor_id,
                    word index,
                    byte *bus_number,
                    byte *device_and_function)
{
   int ret_status;
   word ax, bx, flags;

   /* Set registers for PCI BIOS call */
   _CX = device_id;
   _DX = vendor_id;
   _SI = index;
   _AH = PCI_FUNCTION_ID;
   _AL = FIND_PCI_DEVICE;

   /* Call PCI BIOS Int 1Ah */
   geninterrupt(0x1a);

   ax = _AX;
   bx = _BX;
   flags = _FLAGS;

   /* if carry flag set, error has occurred */
   if ((flags & CARRY_FLAG) == 0)
     {
       /* Get Return code from BIOS */
       ret_status = HIGH_BYTE(ax);

       if (ret_status == SUCCESSFUL)
        {
          /* Assign Bus Number, Device & Function if successful */
          if (bus_number != NULL)
            { *bus_number = HIGH_BYTE(bx); }

          if (device_and_function != NULL)
            { *device_and_function = LOW_BYTE(bx); }
        }
     }
    else
     { ret_status = NOT_SUCCESSFUL; }

   return (ret_status);
}

int read_configuration_dword(byte bus_number, byte device_and_function,
                             byte register_number, dword *dword_read)
{
   int ret_status;
   dword data;

   /* Read PCI configuration register data */
   ret_status = read_configuration_area(READ_CONFIG_DWORD, bus_number,
                                        device_and_function,
                                        register_number, &data);
   if (ret_status == SUCCESSFUL)
     { *dword_read = data; }

   return (ret_status);
}

static int read_configuration_area(byte function, byte bus_number,
                                   byte device_and_function,
                                   byte register_number, dword *data)
{
   int ret_status;
   word ax, flags;
   dword ecx;

   /* Load entry registers for PCI BIOS */
   _BH = bus_number;
   _BL = device_and_function;
   _DI = register_number;
   _AH = PCI_FUNCTION_ID;
   _AL = function;

   /* Call PCI BIOS Int 1Ah interface */
   geninterrupt(0x1a);

   ecx = _ECX;
   ax = _AX;
   flags = _FLAGS;

   /* if carry flag Set, error has occurred */
   if ((flags & CARRY_FLAG) == 0)
     {
       /* Get Return code from BIOS */
       ret_status = HIGH_BYTE(ax);

       /* If successful, return data */
       if (ret_status == SUCCESSFUL)
         { *data = ecx; }
     }
    else
     { ret_status = NOT_SUCCESSFUL; }

   return (ret_status);
}




/*
   '**********************************************************************
   '*  Program  : Pulse.c                                                *
   '*  Revision : 1.00                                                   *
   '*  Date     : 6/24/2002                     Arbor Technology Corp.   *
   '*====================================================================*
   '*                                                                    *
   '*  This program demonstrates the Pulse out funciton of pDAQ-722.     *
   '*  pDAQ-722 counter 0 supports this feature.                         *
   '*                                                                    *
   '**********************************************************************
*/
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include "PCI.C"
#include "pDAQ722.h"

#define  TIME_BASE     4*1000000      //4Mhz chrystral
#define  FREQ_MIN      ((TIME_BASE+65535) / 65536)
#define  FREQ_MAX      4000
#define  STR_FREQ_OUT  "Pulse out frequency: "

void main(void)
{
  word  wVendorId, wDeviceId, wIndex;
  int   iScanKey, iErrCode, iFreqVal;

  byte  ucBusNumber, ucDevAndFunc;
  dword dwData, dwBaseAddr;
  word  wCount;

  wVendorId = VENDOR_ID;
  wDeviceId = DEVICE_ID;

  // Description, Pulse out funciton Jumper setting and pins position
  clrscr();
  printf("Arbor Technology Corp.\n\n");
  printf("Pulse Out demo program.\n");
  printf("The isolation pulse out use %dKHz clock base, and\n", (int)(TIME_BASE / 1000));
  printf("generates %d - %d Hz pulse.\n\n", (int)FREQ_MIN, (int)FREQ_MAX);

  printf("Before running this program you should:\n");
  printf("1. Check pDAQ-722 JP9 pin2,3 shorted.\n");
  printf("2. Pulse out signal presents on TOUT_L0 (pin 33) and TOUT_H0(pin15).\n\n");

 /***************************
  * Get pDAQ-72x's resource
  ***************************/
  //
  // Search pDAQ-72x
  //
  for( wIndex=0; wIndex < 32; wIndex++)
  {
    iErrCode = find_pci_device(
                  wDeviceId,
                  wVendorId,
                  wIndex,
                  &ucBusNumber,
                  &ucDevAndFunc );
    if (iErrCode == NOT_SUCCESSFUL )
    {
       printf("\n pDAQ-720/722 search fail.\n");
       exit(1);
    }
    iErrCode = read_configuration_dword(
                  ucBusNumber,
                  ucDevAndFunc,
                  PCI_CS_SUBSYSTEM_ID,
                  &dwData);
    if(dwData == SUBSYSTEM_ID)
      break;
  }

  //
  //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("\npDAQ-72x gets base address failure.\n");
    exit(1);
  }
  else
    dwBaseAddr = dwData & 0xfffffffc;

 /*******************
  * Counter 0 setting
  *******************/
 /******************************
  * Config counter to start event counting function.
  *
  * Base + 0xb, control register, standard mode
  * bit#  7   6   5   4   3   2   1   0
  * value SC1 SC2 RW1 RW0 M2  M1  M0  BCD
  *
  *   SC1 SC0 Select Counter     |  RW1 RW2 Select R/W operation
  *    0   0           0         |   0   0  Counter latch
  *    0   1           1         |   0   1  Read/write LSB
  *    1   0           2         |   1   0  Read/write MSB
  *    1   1  Read-back comand   |   1   1  R/W LSB first then MSB
  *
  *   M2 M1 M0 Mode
  *   0  0  0  0  Stop on terminal count
  *   0  0  1  1  Programable one shot
  *   0  1  0  2  Rate generate
  *   0  1  1  3  Square wave generator
  *   1  0  0  4  Software triggered strobe
  *   1  0  1  5  Hardware triggered strobe
  ******************************/
  outportb(dwBaseAddr+0xb, 0x36);      // Counter 0, R/W LSB first then MSB,
                                       // Rate generate, Binary.

  iFreqVal = (FREQ_MAX+FREQ_MIN) / 2;  // default pulse frequency
  wCount = TIME_BASE / iFreqVal;

  outportb(dwBaseAddr+0x8, wCount & 0xff);         //LSB first
  outportb(dwBaseAddr+0x8, (wCount >> 8) & 0xff);  //MSB next

 /***************
  * Cyclic change current pulse frequency
  ***************/
  printf("Press Up, down, Left, Reiht arrow keys to change pulse out frequency.\n");
  printf("Press other keys to stop program.\n\n");
  printf(STR_FREQ_OUT);
  printf("%dHz", iFreqVal);

  iScanKey = 1;
  while(iScanKey)
  {
    if(kbhit())
    {
      if( getch() == 0)
      {
        iScanKey = getch();
        switch(iScanKey)
        {
        case 0x48:
          iFreqVal += 10;
          break;
        case 0x4d:
          iFreqVal += 1;
          break;
        case 0x4b:
          iFreqVal -= 1;
          break;
        case 0x50:
          iFreqVal -= 10;
          break;
        }
        if(iFreqVal > FREQ_MAX)
          iFreqVal = FREQ_MAX;
        else if(iFreqVal < FREQ_MIN)
          iFreqVal = FREQ_MIN;

        //Write new value to counter 0
        wCount = TIME_BASE / iFreqVal;
        outportb(dwBaseAddr+0x8, wCount & 0xff);         //LSB first
        outportb(dwBaseAddr+0x8, (wCount >> 8) & 0xff);  //MSB next

        // Display on screen
        gotoxy( sizeof(STR_FREQ_OUT), wherey());
        printf("%dHz  ", iFreqVal);
      }
      else
        iScanKey = 0;
    }
  }
}//Main


//
//PDAQ722.H
//
#define ESC 0x1b
#define PCI_CS_SUBSYSTEM_ID 0x2c

#define VENDOR_ID    0x10b5
#define DEVICE_ID    0x9050
#define SUBSYSTEM_ID 0x72509999

⌨️ 快捷键说明

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