Allocate Resources for Endpoints

This tutorial shows how to set up the required endpoint resources.

Note: This is an optional step when creating a class driver.

Introduction

Class drivers can allocate resources to endpoints. This allows the PDD PSL to manage DMA resources more efficiently and to enable and disable endpoint resources on particular interface settings.

Note: The functions AllocateEndpointResource(), QueryEndpointResourceUse() and DeAllocateEndpointResource() always refer to the endpoints of the currently active alternate interface setting. Since after interface creation, and before configuration through the host, alternate setting 0 (default) is active, resources for endpoints on other settings of that interface can only be accessed after a successful SetInterface() request from the host that selects the respective alternate setting. See Set the interface.

PDD Support for endpoint resource allocation

The USB Client PDD PSL must explicitly support the allocation of endpoint resources. The PDD will indicate if this is the case by setting the iFeatureWord1 member in the TUsbDeviceCapsV01 structure to the constant KUsbDevCapsFeatureWord1_EndpointResourceAllocV2.

TUsbDeviceCaps caps;
... 
caps().iFeatureWord1 | KUsbDevCapsFeatureWord1_EndpointResourceAllocV2;

This structure is passed to the LDD as part of TUsbcInterfaceInfo at interface (and thus logical endpoint) creation time in the call to SetInterface(). See Define the interface data.

The successful outcome of the SetInterface() call does not depend on the availability of requested resources as the driver does not try to allocate requested endpoint resources at this point. The Physical Device Driver (PDD) PIL passes the resource request information to the PSL only at endpoint configuration time (after a SetInterface() request has been received from the host).

Check that the driver supports endpoint resource allocation for DMA and double buffering with by Getting the Device capabilities for iFeatureWord1.

Allocate endpoint resources

Allocate resources for endpoints with RDevUsbcScClient::AllocateEndpointResource(). Pass the function the endpoint number and a member of TUsbcEndpointResource to indicate the type of resource. The parameter that takes the resource type is not a bitmap and TEndpointResource values should not be combined in the same call to the function.

If more than one resource is to be specified then multiple calls to the function have to be made, each one selecting a single resource.

gPort.AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);

KErrNone is returned if the resource has been successfully allocated, in which case it will be used from when the current bus transfer has been completed. KErrNotSupported will be returned if the endpoint does not support the resource requested and KErrInUse will be returned if the resource is already consumed and cannot be allocated.

Query

There is no direct and immediate feedback as to whether the resources were successfully allocated. The user can find out about the outcome by calling RDevUsbcScClient::QueryEndpointResourceUse() after a configuration or interface alternate setting change notification.

QueryEndpointResourceUse() returns ETrue if the specified resource is in use at the endpoint and EFalse if not.

TBool res = gPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);

A resource may be deallocated by the PDD if:

  • the host selects a different configuration (including zero) than the current one by sending a SET_CONFIGURATION request,

  • the host selects a different alternate interface setting than the current one by sending a SET_INTERFACE request,

  • the user calls RDevUsbcScClient::ReleaseInterface() or Unloads the USB Client LDD.

Deallocate

DeAllocateEndpointResource() de-allocates the use of aResource from some endpoint or ends a specified endpoint behaviour. aResource is typically some rationed hardware resource or possibly specifies a type of endpoint behaviour. aResource is not a bitmap and TEndpointResource values should not be combined. KErrNone is returned if the resource has been successfully de-allocated, in which case it will be removed from when the current bus transfer has been completed. KErrNotSupported will be returned if the endpoint does not support the resource requested.

After you have allocated resources for the endpoints you should force a Re-Enumeration.