Jump to main content

##

# Initializing the Device Layer

With the USB Device Master Descriptor and the Function Driver Registration Table available, the application can now create the Device Layer Initialization Data structure. This data structure is a USB_DEVICE_INIT type and contains the information need to initialize the Device Layer. The actual initialization is performed by calling the USB_DEVICE_Initialize function. This function returns a Device Layer System Module Object which must be used by the System Module to access this Device Layer context while calling the Device Layer task routine.

The following code shows an example of initializing the Device Layer.

    /*************************************************
     * USB Device Layer Initialization.
     **************************************************/

    USB_DEVICE_INIT usbDevInitData =
    {
        /* Number of function drivers registered to this instance of the
         * USB device layer */
        .registeredFuncCount = 2,

        /* Function driver table registered to this instance of the USB device layer*/
        .registeredFunctions = (USB_DEVICE_FUNCTION_REGISTRATION_TABLE*)funcRegistrationTable,

        /* Pointer to USB Descriptor structure */
        .usbMasterDescriptor = (USB_DEVICE_MASTER_DESCRIPTOR*)&usbMasterDescriptor,

        /* USB Device Speed */
        .deviceSpeed = USB_SPEED_HIGH,

        /* Pointer to the USB Driver Interface */
        .usbDriverInterface = DRV_USBHSV1_DEVICE_INTERFACE
    };

    /****************************************
     * System Initialization Routine
     ****************************************/
    void SYS_Initialize ( void * data )
    {

        /* Initialize the USB device layer */
        sysObjects.usbDevObject = USB_DEVICE_Initialize (USB_DEVICE_INDEX_0,( SYS_MODULE_INIT* ) & usbDevInitData);

        /* Initialize the Application */
        APP_Initialize ( );

    }