Multiple Unit Support

This document describes how to support multiple units of hardware with a single device driver.

Supporting multiple units

An LDD can support more than one device by providing a separate channel to each device.

There can be more than one PDD associated with a given LDD, where each PDD supports a different variation of a similar device.

Alternatively, a single PDD can be designed to support multiple instances of an identical device by supporting more than one channel. For example, a platform that contains two identical UARTS could support these by providing a PDD that can open a channel on either (or both) UARTs.

Where a driver supports multiple devices on a platform, then it uses a unit number to distinguish between each instance of the device. Clients open a channel to the driver for a particular unit. The following shows an example of this, and the example driver function that creates the channel:

// User application opens the driver for unit1
RExDriverChannel ldd;
r = ldd.Open(KUnit1);
test(r==KErrNone);
// User side wrapper function to driver API
inline TInt RExDriverChannel::Open(TInt aUnit)
    {    
    return DoCreate(KDriverName,VersionRequired(),
                aUnit,NULL,NULL,EOwnerThread);    
    }

System information

The driver must inform the framework that it supports the use of unit numbers. A driver can use unit numbers to ensure that it only opens on one unit. This is done by setting the DLogicalDevice::iParseMask bitmask with the KDeviceAllowUnit flag.

// Logical Channel Second stage constructor
DExDriverLogicalDevice:: DExDriverLogicalDevice ()
    {
    iParseMask = KDeviceAllowPhysicalDevice | KDeviceAllowUnit;
    ...
    }

Unit number validation

The device driver framework validates if the driver supports unit numbers. In the following example, the PDD checks if the unit number passed is valid.

TInt DExH4PhysicalDevice::Validate(TInt aUnit, const TDesC8* 
/*aInfo*/, const TVersion& aVer)
    {    
    ...        
    if (aUnit<0 || aUnit>=KNumUarts)
        return KErrNotSupported;
    }