驅動程式可以使用 CONNECT_FULLY_SPECIFIED 版本的 IoConnectInterruptEx 來註冊特定中斷的 InterruptService 例程。 從 Windows Vista 開始,驅動程式可以使用 CONNECT_FULLY_SPECIFIED 版本。 藉由連結至 Iointex.lib 連結庫,驅動程式可以使用 Windows 2000、Windows XP 和 Windows Server 2003 中的CONNECT_FULLY_SPECIFIED版本。 如需詳細資訊,請參閱 在 Windows Vista 之前使用 IoConnectInterruptEx。
驅動程式會指定 Parameters-Version> 的 CONNECT_FULLY_SPECIFIED 值,並使用 Parameters-FullySpecified> 的成員來指定作業的其他參數:
參數->FullySpecified.PhysicalDeviceObject 指定 ISR 為裝置提供服務的 PDO。
Parameters->FullySpecified.ServiceRoutine 指向 InterruptService 例程,而 Parameters->FullySpecified.ServiceContext 指定系統傳遞給 InterruptService 作為 ServiceContext 參數的值。 驅動程式可以使用這個 來傳遞內容資訊。 如需傳遞內容資訊的詳細資訊,請參閱 提供ISR內容資訊。
驅動程式提供Parameters-FullySpecified.InterruptObject> 中PKINTERRUPT變數的指標。 IoConnectInterruptEx 例程會將此變數設定為指向中斷物件的中斷物件,此物件可在移除 ISR 時使用。
驅動程式可以選擇性地在Parameters-FullySpecified.SpinLock>中指定微調鎖定,讓系統在與ISR同步處理時使用。 大部分的驅動程式都可以指定 NULL,讓系統為驅動程式分配自旋鎖。 如需與 ISR 同步存取裝置資料的詳細資訊,請參閱 同步存取裝置資料。
驅動程式必須在 Parameters-FullySpecified> 的其他成員中指定中斷的索引鍵屬性。 當系統將IRP_MN_START_DEVICE IRP 傳送至驅動程式時,系統會在CM_PARTIAL_RESOURCE_DESCRIPTOR結構數位中提供必要的資訊。
系統會為每個中斷提供類型成員等於CmResourceTypeInterrupt的CM_PARTIAL_RESOURCE_DESCRIPTOR結構。 針對訊息訊號中斷,會將 Flags 成員的 CM_RESOURCE_INTERRUPT_MESSAGE 位設定為 1;否則,會將其清除。
CM_PARTIAL_RESOURCE_DESCRIPTOR的 u.Interrupt 成員包含以行為基礎的中斷描述,而 u.MessageInterrupt.Translated 成員則包含訊息訊號中斷的描述。 下表顯示在CM_PARTIAL_RESOURCE_DESCRIPTOR 結構中,提供設置Parameters-FullySpecified成員所需資訊的位置,以用於兩種類型的中斷。 如需詳細資訊,請參閱數據表後面的程式代碼範例。
會員 | 以線路為基礎的中斷 | 訊息訊號中斷 |
---|---|---|
ShareVector |
ShareDisposition |
ShareDisposition |
向量 |
u.Interrupt.Vector |
u.MessageInterrupt.Translated.Vector |
Irql |
u.Interrupt.Level |
u.MessageInterrupt.Translated.Level |
中斷模式 |
旗標 和CM_RESOURCE_INTERRUPT_LATCHED |
旗標 和CM_RESOURCE_INTERRUPT_LATCHED |
處理器啟用遮罩 |
u.Interrupt.Affinity |
u.MessageInterrupt.Translated.Affinity |
驅動程式只會在 Windows Vista 及更高版本的 Windows 上,接收用於訊號訊息中斷的 CM_PARTIAL_RESOURCE_DESCRIPTOR 結構。
下列程式代碼範例示範如何使用 CONNECT_FULLY_SPECIFIED 註冊 InterruptService 例程。
IO_CONNECT_INTERRUPT_PARAMETERS params;
// deviceExtension is a pointer to the driver's device extension.
// deviceExtension->IntObj is a PKINTERRUPT.
// deviceInterruptService is a pointer to the driver's InterruptService routine.
// IntResource is a CM_PARTIAL_RESOURCE_DESCRIPTOR structure of either type CmResourceTypeInterrupt or CmResourceTypeMessageInterrupt.
// PhysicalDeviceObject is a pointer to the device's PDO.
// ServiceContext is a pointer to driver-specified context for the ISR.
RtlZeroMemory( ¶ms, sizeof(IO_CONNECT_INTERRUPT_PARAMETERS) );
params.Version = CONNECT_FULLY_SPECIFIED;
params.FullySpecified.PhysicalDeviceObject = PhysicalDeviceObject;
params.FullySpecified.InterruptObject = &devExt->IntObj;
params.FullySpecified.ServiceRoutine = deviceInterruptService;
params.FullySpecified.ServiceContext = ServiceContext;
params.FullySpecified.FloatingSave = FALSE;
params.FullySpecified.SpinLock = NULL;
if (IntResource->Flags & CM_RESOURCE_INTERRUPT_MESSAGE) {
// The resource is for a message-signaled interrupt. Use the u.MessageInterrupt.Translated member of IntResource.
params.FullySpecified.Vector = IntResource->u.MessageInterrupt.Translated.Vector;
params.FullySpecified.Irql = (KIRQL)IntResource->u.MessageInterrupt.Translated.Level;
params.FullySpecified.SynchronizeIrql = (KIRQL)IntResource->u.MessageInterrupt.Translated.Level;
params.FullySpecified.ProcessorEnableMask = IntResource->u.MessageInterrupt.Translated.Affinity;
} else {
// The resource is for a line-based interrupt. Use the u.Interrupt member of IntResource.
params.FullySpecified.Vector = IntResource->u.Interrupt.Vector;
params.FullySpecified.Irql = (KIRQL)IntResource->u.Interrupt.Level;
params.FullySpecified.SynchronizeIrql = (KIRQL)IntResource->u.Interrupt.Level;
params.FullySpecified.ProcessorEnableMask = IntResource->u.Interrupt.Affinity;
}
params.FullySpecified.InterruptMode = (IntResource->Flags & CM_RESOURCE_INTERRUPT_LATCHED ? Latched : LevelSensitive);
params.FullySpecified.ShareVector = (BOOLEAN)(IntResource->ShareDisposition == CmResourceShareShared);
status = IoConnectInterruptEx(¶ms);
if (!NT_SUCCESS(status)) {
...
}