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

📄 sgl.c

📁 pci卡驱动开发程序.该程序采用DMA方式传输
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 * Copyright (c) 1997 - 1998 PLX Technology, Inc.
 * 
 * PLX Technology Inc. licenses this software under specific terms and
 * conditions.  Use of any of the software or derviatives thereof in any
 * product without a PLX Technology chip is strictly prohibited. 
 * 
 * PLX Technology, Inc. provides this software AS IS, WITHOUT ANY WARRANTY,
 * EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  PLX makes no guarantee
 * or representations regarding the use of, or the results of the use of,
 * the software and documentation in terms of correctness, accuracy,
 * reliability, currentness, or otherwise; and you rely on the software,
 * documentation and results solely at your own risk.
 * 
 * IN NO EVENT SHALL PLX BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
 * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
 * OF ANY KIND.  IN NO EVENT SHALL PLX'S TOTAL LIABILITY EXCEED THE SUM
 * PAID TO PLX FOR THE PRODUCT LICENSED HEREUNDER.
 * 
 *****************************************************************************/

/******************************************************************************
 *
 * File Name: Sgl.c
 *
 * Module Name: 
 *
 * Description: This file contains an example of how to use the SGL DMA APIs.
 *
 * The project uses the following Preprocessor defines:
 *     NDEBUG, WIN32, PCI_CODE, LITTLE_ENDIAN.
 *
 *  The project options are: /nologo /MT /W3 /GX /O2 /I "..\..\..\inc"
 *                           /D "NDEBUG" /D "WIN32" /D  
 *                           /D "PCI_CODE" /D "LITTLE_ENDIAN" 
 *                           /Fp" .\Release/Sgl.pch" 
 *                           /YX /Fo".\Release/" /Fd".\Release/" /FD /c 
 * 
 * Revision:
 *     11-23-98 : Release 2.1 PCI SDK  (Vitana Corp.)
 *
 *****************************************************************************/

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "pcitypes.h"
#include "plxtypes.h"
#include "plx.h"
#include "pciapi.h"

#include <winioctl.h>
#include "ioctl.h"

/*++++++ Developer Data Section  ++++++++++++++++++++++++++++++++++++++++++++*/

/*  INSERT YOUR CONSTANTS HERE                                               */
/*  INSERT YOUR TYPEDEFS HERE                                                */
/*  INSERT YOUR GLOBAL DATA HERE                                             */
/*  INSERT YOUR MODULE GLOBAL DATA HERE                                      */
/*  INSERT YOUR MACROS HERE                                                  */

/*------ End Of Developer Data Section --------------------------------------*/


/*++++++ Developer Public Functions +++++++++++++++++++++++++++++++++++++++++*/

VOID SglTest(HANDLE drvHandle, DMA_CHANNEL dmaChannel);
VOID DescribeErrorCode(RETURN_CODE rc, FILE *fp);


/******************************************************************************
 *
 * Function Name: main()
 *
 * Description:
 *     This is the entry point for a developers application.
 *
 ******************************************************************************/
void 
main(
    int argc, 
    char * argv[]
){
    DEVICE_LOCATION device;
	HANDLE myPlxDevice;
    RETURN_CODE rc;
    U32 c;
    U32 plxDeviceCount, i, j;

    /*This tests the SGL DMA functions of the PLX PCI SDK API*/
    device.BusNumber  = MINUS_ONE_LONG;
    device.SlotNumber = MINUS_ONE_LONG;
    device.DeviceId   = MINUS_ONE_LONG;
    device.VendorId   = MINUS_ONE_LONG;
    device.SerialNumber[0] = '\0';

    /* Get the total number of supported devices */
    plxDeviceCount = FIND_AMOUNT_MATCHED;
    rc = PlxPciDeviceFind(&device, &plxDeviceCount);

    if ((rc != ApiSuccess) || (plxDeviceCount == 0))
    {
        printf("\nError in scanning for devices:\n");
        printf("No devices found\n");
        printf ("Press any key to exit.....");
        getch();
        return;
    }

    /* Check the number of devices found */
    if (plxDeviceCount > 1)
    {
        /* Display device information for each one */
        printf("\nMore than one PLX device found!!\n");
        printf("Available devices are:\n\n");
        printf("#  Bus Slot VendorId DeviceId\n");
        printf("-----------------------------\n");
        for (i=0; i < plxDeviceCount; i++)
        {
            device.BusNumber  = MINUS_ONE_LONG;
            device.SlotNumber = MINUS_ONE_LONG;
            device.DeviceId   = MINUS_ONE_LONG;
            device.VendorId   = MINUS_ONE_LONG;
            device.SerialNumber[0] = '\0';
            j = i;
            rc = PlxPciDeviceFind(&device, &j);
            if (rc != ApiSuccess)
            {
                printf("\nSCANNING ERROR\n");
                printf("Press any key to exit\n");
                getch();
                return;
            }

            printf("%d  %d   0x%02x %04x     %04x\n", 
                                    i, 
                                    device.BusNumber, 
                                    device.SlotNumber, 
                                    device.VendorId, 
                                    device.DeviceId);
        }

        printf("\nPlease select a device:");
        scanf("%d", &i);

        device.BusNumber  = MINUS_ONE_LONG;
        device.SlotNumber = MINUS_ONE_LONG;
        device.DeviceId   = MINUS_ONE_LONG;
        device.VendorId   = MINUS_ONE_LONG;
        device.SerialNumber[0] = '\0';

        /* Select the correct device */
        rc = PlxPciDeviceFind(&device, &i);

        if (rc != ApiSuccess)
        {
            printf("\nInvalid device selected\n");
            printf("Press any key to exit\n");
            getch();
            return;
        }
    }
    else
    {
        printf("\nOnly one PLX device found\n");
    }

    printf ("Opening device...\n");

    rc = PlxPciDeviceOpen (&device, &myPlxDevice);
    /*Open a handle to a PLX device,*/
    if (rc != ApiSuccess)
    {
        printf ("\n\nError in opening device.\n");
        printf ("Returned code %d\n",rc);
        printf("Trying 9054...\n");

        device.BusNumber  = MINUS_ONE_LONG;
        device.SlotNumber = MINUS_ONE_LONG;
        device.DeviceId   = MINUS_ONE_LONG;
        device.VendorId   = MINUS_ONE_LONG;
        strcpy (device.SerialNumber, "pci9054-0");

        rc = PlxPciDeviceOpen (&device, &myPlxDevice);
        /*Open a handle to a PLX device,*/
        if (rc != ApiSuccess)
        {
            printf ("\n\nError in opening device.\n");
            DescribeErrorCode(rc, stdout);
            printf("Press any thing to exit\n");
            getch();
            return;
        }
    }

    printf("\n\nDevice information.");
	printf("\nBus = 0x%x, Slot = 0x%x, Vendor ID = 0x%x, Device ID = 0x%x.\n\n", 
				device.BusNumber,
				device.SlotNumber,
				device.VendorId,
				device.DeviceId);

    printf("\nPlease select a DMA channel to use\n");
    printf("1. Sgl test with DMA channel 0\n");
    printf("2. Sgl test with DMA channel 1\n");
    printf("Anything else exits\n");
    printf("Selection:");
    scanf("%d",&c);
    if (c == 1)
    {
        SglTest(myPlxDevice, PrimaryPciChannel0);
    }
    else if (c == 2)
    {
        SglTest(myPlxDevice, PrimaryPciChannel1);
    }
    else
    {
        printf("Invalid choice, exiting\n");
    }

    printf("Press any key to exit\n");
    getch();

    PlxPciDeviceClose(myPlxDevice);

   
    return;
}/* end main */


/******************************************************************************
 * Function: SglTest
 *
 * Description: Perform the SGL test
 *
 ******************************************************************************/
VOID
SglTest(HANDLE drvHandle, DMA_CHANNEL dmaChannel)
{
    DMA_CHANNEL_DESC desc;
    DMA_TRANSFER_ELEMENT dmaData;
    RETURN_CODE rc;
    U32 localStartOffset;
    U32 totalSize;
    U32 *bufFrom = NULL;
    U32 *bufTo = NULL;
    U32 *buf = NULL;
    U32 count;
    U32 value;
    DWORD startTime, transferTime;

    /* Setup DMA configuration structure */
    desc.EnableReadyInput = 1;

⌨️ 快捷键说明

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