I created a WDF driver that talks to a device over an I2C bus. I need to lock the bus to prevent simultaneous access to it. I cannot use a spinlock since the transaction takes several milliseconds (and many 10s of milliseconds if communication times out). I cannot use a spinlock because it should not be used for that length of time. So I am trying to use a fast mutex. When I use the following code to create the lock in EvtDeviceAdd(), I get ntstatus error 0xC0200211.
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = fdoData->WdfDevice;
attributes.ExecutionLevel = WdfExecutionLevelPassive; // force lock to be a fast mutex
status = WdfWaitLockCreate(&attributes, &I2cLock);
When I comment out the line “attributes.ExecutionLevel = WdfExecutionLevelPassive” I do not get the error. According to the documentation for WdfObjectAcquireLock, it says that “If the driver specified WdfExecutionLevelPassive for the ExecutionLevel member of the specified object’s WDF_OBJECT_ATTRIBUTES structure…WdfObjectAcquireLock acquires a fast mutex…” and “If the driver did not specify WdfExecutionLevelPassive for the ExecutionLevel member of the specified object’s WDF_OBJECT_ATTRIBUTES structure…WdfObjectAcquireLock acquires a spin lock…”
I am trying to use a fast mutex so I think I need WdfExecutionLevelPassive for this object. Please help, thanks.