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

📄 sampleappguidlg.cpp

📁 pci驱动程序,用于PLX9052的开发.安装后会生成文档和函数库.
💻 CPP
字号:
/******************************************************************************
 *
 * File Name:
 *
 *      SampleAppGUIDlg.cpp
 *
 * Description:
 *
 *      Sample GUI application to demonstrate how to use the 6350 detection algorithm.
 *
 * Revision History:
 *
 *      01-01-07 : PLX SDK v5.00
 *
 ******************************************************************************/


#include "stdafx.h"
#include "SampleAppGUI.h"
#include "SampleAppGUIDlg.h"
#include "PlxApi.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif




/**********************************************
 *               Globals
 *********************************************/
CSampleAppGUIDlg *Gbl_pMainDlg = NULL;




BEGIN_MESSAGE_MAP(CSampleAppGUIDlg, CDialog)
    //{{AFX_MSG_MAP(CSampleAppGUIDlg)
    ON_BN_CLICKED(IDOK, OnButtonSelect)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()




/*****************************************************************************************
 *
 * Function   :
 *
 * Description: 
 *
 ****************************************************************************************/
CSampleAppGUIDlg::CSampleAppGUIDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CSampleAppGUIDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CSampleAppGUIDlg)
	m_SendStr = _T("");
	m_DisplayStr = _T("");
	//}}AFX_DATA_INIT

    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}




/*****************************************************************************************
 *
 * Function   :
 *
 * Description: 
 *
 ****************************************************************************************/
void CSampleAppGUIDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);

    //{{AFX_DATA_MAP(CSampleAppGUIDlg)
	DDX_Control(pDX, IDC_DISPLAYSTR, m_Control_DISPLAYSTR);
    DDX_Control(pDX, IDC_LOG_STATUS, m_LogMessages);
    DDX_Control(pDX, IDC_LIST_SELECT_DEVICE, m_List_Devices);
	DDX_Text(pDX, IDC_SENDSTR, m_SendStr);
	DDX_Text(pDX, IDC_DISPLAYSTR, m_DisplayStr);
	//}}AFX_DATA_MAP
}





/*****************************************************************************************
 *
 * Function   :
 *
 * Description: 
 *
 ****************************************************************************************/
BOOL CSampleAppGUIDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    SetIcon(m_hIcon, TRUE);         // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    // Set global dialog pointer
    Gbl_pMainDlg = this;

    // Enable highlight of an entire row
    m_List_Devices.SetExtendedStyle(
        LVS_EX_FULLROWSELECT
        );

    // Increase height of items in list box
    m_LogMessages.SetItemHeight(
        0,
        m_LogMessages.GetItemHeight(0) + 1
        );
    
    // Display devices found
    DisplayList();

    // Display initial message
    m_LogMessages.AddString(
        ""
        );

    if (m_List_Devices.GetItemCount() == 0)
    {
        // Disable device list
        m_List_Devices.EnableWindow(FALSE);

        // Disable verify button
        GetDlgItem(IDOK)->EnableWindow(FALSE);

        m_LogMessages.AddString(
            "ERROR: No PCI devices found or PLX"
            );

        m_LogMessages.AddString(
            "driver not loaded."
            );
    }
    else
    {
        m_LogMessages.AddString(
            "Please select a device to open..."
            );
    }

    return TRUE;
}




/*****************************************************************************************
 *
 * Function   :
 *
 * Description: 
 *
 ****************************************************************************************/
void CSampleAppGUIDlg::DisplayList(void)
{
    U8              i;
    U8              DeviceNum;
    char           *Col[] = {"Bus", "Slot", "Fn", "Dev ID", "Ven ID", ""};
    CString         StrTmp;
    LVCOLUMN        Column;
    RETURN_CODE     rc;
    PLX_DEVICE_KEY  Key;


    // Setup columns
    i = 0;
    while (Col[i][0] != '\0')
    {
        m_List_Devices.InsertColumn(
            i,
            Col[i],
            LVCFMT_CENTER,
			m_List_Devices.GetStringWidth(Col[i]) + 20,
            i
            );

        i++;
    }

    // Make sure first column is centered
    Column.mask = LVCF_FMT;
    Column.fmt  = LVCFMT_CENTER;

    m_List_Devices.SetColumn(
        0,
        &Column
        );

    // Find all devices
    DeviceNum = 0;
    do
    {
        // Clear device structure
        Key.bus         = PCI_FIELD_IGNORE;
        Key.slot        = PCI_FIELD_IGNORE;
        Key.function    = PCI_FIELD_IGNORE;
        Key.DeviceId    = PCI_FIELD_IGNORE;
        Key.VendorId    = PCI_FIELD_IGNORE;
        Key.SubDeviceId = PCI_FIELD_IGNORE;
        Key.SubVendorId = PCI_FIELD_IGNORE;
        Key.Revision    = PCI_FIELD_IGNORE;

        rc =
            PlxPci_DeviceFind(
                &Key,
                DeviceNum
                );

        // Check if all devices have been found
        if (rc != ApiSuccess)
        {
            break;
        }

        // Add device to list box
        i = m_List_Devices.GetItemCount();

        // Insert new entry
        m_List_Devices.InsertItem(
            i,
            ""
            );

        // Set item data to PCI location
        m_List_Devices.SetItemData(
            i,
            ((U32)Key.bus << 16) | (Key.slot << 8) | Key.function
            );

        // Display bus number
        StrTmp.Format("%02X", Key.bus);
        m_List_Devices.SetItemText(
            i,
            0,
            StrTmp
            );

        // Display slot number
        StrTmp.Format("%02X", Key.slot);
        m_List_Devices.SetItemText(
            i,
            1,
            StrTmp
            );

        // Display function number
        StrTmp.Format("%02X", Key.function);
        m_List_Devices.SetItemText(
            i,
            2,
            StrTmp
            );

        // Display device ID
        StrTmp.Format("%04X", Key.DeviceId);
        m_List_Devices.SetItemText(
            i,
            3,
            StrTmp
            );

        // Display vendor ID
        StrTmp.Format("%04X", Key.VendorId);
        m_List_Devices.SetItemText(
            i,
            4,
            StrTmp
            );

        // Increment to next device
        DeviceNum++;
    }
    while (1);

    // A hack to make sure the entire list is visible
    m_List_Devices.EnsureVisible(
        m_List_Devices.GetItemCount(),
        TRUE                // Partial visibility ok
        );

    m_List_Devices.EnsureVisible(
        0,
        TRUE                // Partial visibility ok
		);
}




/*****************************************************************************************
 *
 * Function   :  OnButtonSelect
 *
 * Description:  Attempts to select a device
 *
 ****************************************************************************************/
void CSampleAppGUIDlg::OnButtonSelect()
{
    int               i;
    U32               TmpValue;
    U32               ChipType;
    U8                Revision;
    CString           StrTmp;
    RETURN_CODE       rc;
    PLX_DEVICE_KEY    Key;
    PLX_DEVICE_OBJECT Device;

	//char WriteBuffer[]={0x42,0x42,0x42,0x42,0x00};

	

	U8	WriteBuffer[1]={0x49};
	U8    WriteBuffer1[1];


    // Get selected device
    i = m_List_Devices.GetSelectionMark();

    if (i == -1)
    {
        AfxMessageBox(
            "Please select a device to open."
            );

        return;
    }

    // Get PCI location of device
    TmpValue =
        m_List_Devices.GetItemData(
            i
            );

    // Build device information
    Key.bus         = (U8)(TmpValue >> 16);
    Key.slot        = (U8)(TmpValue >>  8);
    Key.function    = (U8)(TmpValue >>  0);
    Key.DeviceId    = PCI_FIELD_IGNORE;
    Key.VendorId    = PCI_FIELD_IGNORE;
    Key.SubDeviceId = PCI_FIELD_IGNORE;
    Key.SubVendorId = PCI_FIELD_IGNORE;
    Key.Revision    = PCI_FIELD_IGNORE;


    /************************************
    *        Open the device
    ************************************/
    m_LogMessages.AddString(
        ""
        );

    StrTmp.Format(
        "Opening device [b:%02x  s:%02x  f:%02x]...",
        Key.bus, Key.slot, Key.function
        );

    m_LogMessages.AddString(
        StrTmp
        );


    /*********************************************
     *              Open Device
     ********************************************/
    rc =
        PlxPci_DeviceOpen(
            &Key,
            &Device
            );

    if (rc != ApiSuccess)
    {
        StrTmp.Format(
            "  Device open..... Failed (rc=%03Xh)",
            rc
            );

        m_LogMessages.AddString(
            StrTmp
            );

        goto __Exit_OnButtonSelect;
    }

    m_LogMessages.AddString(
        "  Device open..... Ok"
        );



    /*********************************************
     *           Call an API function
     ********************************************/
    rc =
        PlxPci_ChipTypeGet(
            &Device,
            &ChipType,
            &Revision
            );

    if (rc != ApiSuccess)
    {
        StrTmp.Format(
            "  Device type..... Failed (rc=%03Xh)",
            rc
            );

        m_LogMessages.AddString(
            StrTmp
            );
    }
    else
    {
        StrTmp.Format(
            "  Device type..... Ok (%04X rev %02X)",
            ChipType, Revision
            );

        m_LogMessages.AddString(
            StrTmp
            );
    }

	//写8255控制寄存器 
	WriteBuffer[0]=0x89;
	rc =
		PlxPci_IoPortWrite(
		&Device,
		0xd886, // Specify I/O port base
		WriteBuffer,
		1, // Number of bytes to read
		BitSize8 // Perform 8-bit reads
		);
	if(rc != ApiSuccess)
	{
		StrTmp.Format(
			"A3......Failed");
		m_LogMessages.AddString(
			StrTmp);
	}



	//写C口后用示波器检测
 	WriteBuffer1[0]=0xff;
	rc =
		PlxPci_IoPortWrite(
		&Device,
		0xd880, // Specify I/O port base
		WriteBuffer1,
		1, // Number of bytes to read
		BitSize8 // Perform 8-bit reads
		);
	if(rc != ApiSuccess)
	{
		StrTmp.Format(
			"A3......Failed");
		m_LogMessages.AddString(
			StrTmp);
	}


    /*********************************************
     *              Close Device
     ********************************************/
    rc =
        PlxPci_DeviceClose(
            &Device
            );

    if (rc != ApiSuccess)
    {
        StrTmp.Format(
            "  Device close.... Failed (rc=%03Xh)",
            rc
            );

        m_LogMessages.AddString(
            StrTmp
            );
    }
    else
    {
        m_LogMessages.AddString(
            "  Device close.... Ok"
            );
    }


__Exit_OnButtonSelect:
    m_LogMessages.AddString(
        "      ______________________"
        );

    // Display initial message
    m_LogMessages.AddString(
        ""
        );

    m_LogMessages.AddString(
        "Please select a device to open..."
        );

    // Scroll the list if necessary
    m_LogMessages.SetTopIndex(
        m_LogMessages.GetCount() - 1
        );
}

//DEL void CSampleAppGUIDlg::OnClickListSelectDevice(NMHDR* pNMHDR, LRESULT* pResult) 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 	
//DEL 	*pResult = 0;
//DEL }

⌨️ 快捷键说明

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