2.5.2.4.1 Library Initialization

The CDC Function Driver instance for a USB device configuration is initialized by the Device Layer when the configuration is set by the host. This process does not require application intervention. Each instance of the CDC Function Driver should be registered with the Device_layer through the Device Layer Function Driver Registration Table. The CDC Function Driver does require a initialization data structure to be defined for each instance of the function driver. This initialization data structure should be of the type USB_DEVICE_CDC_INIT. This data structure specifies the read and write queue sizes. The funcDriverInit member of the function driver registration table entry for the CDC Function Driver instance should be set to point to the corresponding initialization data structure. The USB_DEVICE_CDC_FUNCTION_DRIVER object is a global object provided by the CDC Function Driver and points to the CDC Function Driver - Device Layer interface functions, which are required by the Device Layer. The following code an example of how multiple instances of CDC Function Driver can registered with the Device Layer.

/* This code shows an example of how two CDC function
 * driver instances can be registered with the Device Layer
 * via the Device Layer Function Driver Registration Table.
 * In this case Device Configuration 1 consists of two CDC
 * function driver instances. */

/* Define the CDC initialization data structure for CDC instance 0.
 * Set read queue size to 2 and write queue size to 3 */

const USB_DEVICE_CDC_INIT cdcInit0 = {.queueSizeRead = 2, .queueSizeWrite = 3};

/* Define the CDC initialization data structure for CDC instance 1.
 * Set read queue size to 4 and write queue size to 1 */

const USB_DEVICE_CDC_INIT cdcInit1 = {.queueSizeRead = 4, .queueSizeWrite = 1};
const USB_DEVICE_FUNC_REGISTRATION_TABLE funcRegistrationTable[2] =
{
    /* This is the first instance of the CDC Function Driver */
    {
       .speed = USB_SPEED_FULL|USB_SPEED_HIGH,     // Supported speed
       .configurationValue = 1,                    // To be initialized for Configuration 1
       .interfaceNumber = 0,                       // Starting interface number.
       .numberOfInterfaces = 2,                    // Number of interfaces in this instance
       .funcDriverIndex = 0,                       // Function Driver instance index is 0
       .funcDriverInit = &cdcInit0,                // Function Driver initialization data structure
       .driver = USB_DEVICE_CDC_FUNCTION_DRIVER    // Pointer to Function Driver - Device Layer interface functions
    },
    /* This is the second instance of the CDC Function Driver */
    {
       .speed = USB_SPEED_FULL|USB_SPEED_HIGH,     // Supported speed
       .configurationValue = 1,                    // To be initialized for Configuration 1
       .interfaceNumber = 2,                       // Starting interface number.
       .numberOfInterfaces = 2,                    // Number of interfaces in this instance
       .funcDriverIndex = 1,                       // Function Driver instance index is 1
       .funcDriverInit = &cdcInit1,                // Function Driver initialization data structure
       .driver = USB_DEVICE_CDC_FUNCTION_DRIVER    // Pointer to Function Driver - Device Layer interface functions
    },
};