PCI9052在多功能CAN適配卡中的應(yīng)用研究
NTSTATUS PCIDriverDevice::DeviceControl(KIrp I)
{
NTSTATUS status;
switch (I.IoctlCode())
{
………………………………………
case IOCTL_HIL100_READ_IO_DATA:
status = IOCTL_HIL100_READ_IO_DATA _Handler(I);
case IOCTL_HIL100_WRITE_IO_DATA:
status = IOCTL_HIL100_WRITE_IO_DATA _Handler(I);
case IOCTL_HIL100_WRITE_DA_DATA:
status = IOCTL_HIL100_WRITE_DA_DATA _Handler(I);
case IOCTL_HIL100_READ_AD_DATA:
status = IOCTL_HIL100_READ_AD_DATA _Handler(I);
default:
status = STATUS_INVALID_PARAMETER;
break;
}
………………………….
}
在該函數(shù)進(jìn)行驅(qū)動中相應(yīng)的數(shù)據(jù)處理與傳遞,包括從內(nèi)存中讀上層應(yīng)用程序發(fā)送下來的數(shù)據(jù)或?qū)D、CAN等外設(shè)傳遞上來的數(shù)據(jù)送到上層應(yīng)用程序。
API函數(shù)主要提供了PCI卡的開關(guān),A/D、D/A、I/O的讀寫函數(shù),CAN的設(shè)置、讀寫,中斷事件消息函數(shù)等。API函數(shù)與以上控制代碼相關(guān)聯(lián),傳遞數(shù)據(jù)和控制參數(shù)。如下程序所示:
bool WriteDataToIO(unsigned char data) //寫數(shù)據(jù)到IO口
{
……
ULONG BytesReturned;
if (!DeviceIoControl(hHIL100, IOCTL_HIL100_WRITE_IO_DATA, data, 1,
NULL, 0, BytesReturned, NULL))
……
}
bool ReadDataFromIO(unsigned char *data) //從IO口讀數(shù)據(jù)
{
……
ULONG BytesReturned;
if (!DeviceIoControl(hHIL100, IOCTL_HIL100_READ_IO_DATA, data, 1,
data, 1, BytesReturned, NULL))
……
}
bool WriteDataToDA(unsigned short control,unsigned short freq[4])//寫數(shù)據(jù)到AD
{
……
ULONG BytesReturned;
unsigned short pData[16];
pData[0]=control;
pData[1]=freq[0];
pData[2]=freq[1];
pData[3]=freq[2];
pData[4]=freq[3];
if (!DeviceIoControl(hHIL100, IOCTL_HIL100_WRITE_DA_DATA, pData, 10,
NULL, 0, BytesReturned, NULL))
……
}
bool ReadDataFromAD(unsigned short address[8],unsigned short data[8])
{ //從AD讀數(shù)據(jù)
……
ULONG BytesReturned;
if (!DeviceIoControl(hHIL100, IOCTL_HIL100_READ_AD_DATA,address,16,
data,16, BytesReturned, NULL))
……
}
bool ReadDataFromDA (unsigned char address,unsigned short *data)//從DA讀數(shù)據(jù)
{
……
ULONG BytesReturned;
if (!DeviceIoControl(hHIL100, IOCTL_HIL100_READ_DA1_DATA,address,1,
data, 2, BytesReturned, NULL))
……
}
將這些接口函數(shù)生成動態(tài)鏈接庫的形式,供上層應(yīng)用程序調(diào)用。
3 結(jié)束語
由于PCI總線的高速特性,使其被廣泛應(yīng)用于高速數(shù)據(jù)采集系統(tǒng)和數(shù)據(jù)傳輸通信系統(tǒng)中,有效地解決了實時采集、實時傳輸和實時存儲等問題。而PCI總線控制器專用芯片的出現(xiàn)則縮短了PCI總線硬件設(shè)備的開發(fā)周期,使得硬件設(shè)備的可靠性和穩(wěn)定性都有了較大的提高。在開發(fā)過程中,尤其對于高速采樣及實時嚴(yán)格的系統(tǒng),我們實現(xiàn)了對該系統(tǒng)高效率的操作特性,該研究有效的解決了高速實時采集、實時傳輸和實時存儲等的驅(qū)動問題。同時該PCI多功能CAN適配卡既實現(xiàn)了CAN總線通信功能,同時也實現(xiàn)了多路通道的數(shù)據(jù)采集和相應(yīng)控制。
3 本文的創(chuàng)新觀點
1) 本文將API函數(shù)與控制代碼建立起關(guān)聯(lián)
2) 本文將應(yīng)用程序集成到對應(yīng)的API函數(shù)里本文引用地址:http://www.ex-cimer.com/article/173838.htm
評論