Technical Document #21

Technical Document #21
What is the significance of marking a resource as 'shared' with WinDriver, and how can I verify the 'shared' status of a specific resource on my card?

The "shared" status determines whether the resource is locked for exclusive use.
When a memory, I/O, or interrupt item is defined as non-sharable, the device registration function — WDC_PciDeviceOpen() / WDC_PcmiaDeviceOpen() / WDC_IsaDeviceOpen(), or the low-level WD_Card_Register() function — checks whether the resource is already locked for exclusive use: If it is, the registration fails; otherwise, the resource is locked exclusively, and any subsequent attempt to lock the resource — either from within the same application, or from another WinDriver application — will fail, until the resource is released using WDC_PciDeviceClose() / WDC_PcmiaDeviceClose() / WDC_IsaDeviceClose(), or the low-level WD_Card_Unregister() function.
(Device registers cannot be defined as shared.)

Note that PCI resources, and specifically interrupts, should generally be defined as sharable.
For memory and I/O, the share status defined with WinDriver affects only WinDriver-based applications.
However, for interrupts there is further significance to the share status, since it also determines whether other drivers (not necessarily WinDriver drivers) can lock the same interrupt. For an explanation of how to read the value of the PCI interrupt status register, refer to Technical Document #104.

Use one of the following methods to check whether a resource is defined as sharable:

  1. From your code, print the value of thefNotSharable flag for the memory/IO/interrupt item that you wish to check — deviceInfo.Card.Item[i].fNotSharable when using the WDC API, or cardReg.Card.Item[i].fNotSharable when using the low-level WinDriver API.
    A value of 1 indicates that the resources is not sharable.
    A value of 0 indicates that the resource is sharable.

  2. If you have used the DriverWizard to generate your code, you can run the DriverWizard, open the *.wdp DriverWizard project file, which served as the basis for your application, select the 'Memory', 'I/O', or 'Interrupt' tab (respectively) and click on 'Edit'. Then look to see if the 'Shared' box in the Resource Information window is checked, to signify that the resource is defined as shared for this device.
    Note that this test is only relevant when using the original *.wdp project file for your application code, and assuming your code does not modify the 'shared' status — since any changes made in the *.wdp file, via the DriverWizard, will only affect subsequent code generation, and will not affect the existing application code. Therefore, checking the "shared" values from the code is more accurate.

As a general guideline, avoid locking the same resource twice. It is always recommend to release a previously locked resource before trying to lock it again (either from the same application, or from different applications).
If you need to access the resources from several applications, you can share the handle received from a single call to the device registration function — WDC_PciDeviceOpen() / WDC_PcmiaDeviceOpen() / WDC_IsaDeviceOpen(), or the low-level WD_Card_Register() function — as explained in Technical Document #98.