SAMV71 Xplained Ultra Software Package 1.4

USBDDriverDescriptors.c

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /** \file
00031  * \addtogroup usbd_msd
00032  *@{
00033  */
00034 
00035 /*------------------------------------------------------------------------------
00036  *         Headers
00037  *----------------------------------------------------------------------------*/
00038 
00039 #include "board.h"
00040 #include "USBD_Config.h"
00041 #include "MSDDriver.h"
00042 #include "MSDescriptors.h"
00043 
00044 /*------------------------------------------------------------------------------
00045  *         Internal definitions
00046  *----------------------------------------------------------------------------*/
00047 
00048 
00049 
00050 /** \addtogroup usbd_msd_device_descriptor_ids MSD Device Descriptor IDs
00051  *      @{
00052  * \section IDs
00053  * - MSDDriverDescriptors_VENDORID
00054  * - MSDDriverDescriptors_PRODUCTID
00055  * - MSDDriverDescriptors_RELEASE
00056  */
00057 
00058 /** Vendor ID for the Mass Storage device driver. */
00059 #define MSDDriverDescriptors_VENDORID       USBD_VID_ATMEL
00060 /** Product ID for the Mass Storage device driver. */
00061 #define MSDDriverDescriptors_PRODUCTID      USBD_PID_MSD
00062 /** Device release number for the Mass Storage device driver. */
00063 #define MSDDriverDescriptors_RELEASE        USBD_RELEASE_1_00
00064 /*---------------------------------------------------------------------------- */
00065 
00066 /**      @}*/
00067 
00068 /*------------------------------------------------------------------------------
00069  *         Macros
00070  *----------------------------------------------------------------------------*/
00071 
00072 /** Returns the minimum between two values. */
00073 #define MIN(a, b)       ((a < b) ? a : b)
00074 
00075 /*------------------------------------------------------------------------------
00076  *         Local variables
00077  *----------------------------------------------------------------------------*/
00078 
00079 /** Mass storage driver device descriptor. */
00080 static const USBDeviceDescriptor deviceDescriptor = {
00081 
00082     sizeof(USBDeviceDescriptor),
00083     USBGenericDescriptor_DEVICE,
00084     USBDeviceDescriptor_USB2_00,
00085     MSDeviceDescriptor_CLASS,
00086     MSDeviceDescriptor_SUBCLASS,
00087     MSDeviceDescriptor_PROTOCOL,
00088     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
00089     MSDDriverDescriptors_VENDORID,
00090     MSDDriverDescriptors_PRODUCTID,
00091     MSDDriverDescriptors_RELEASE,
00092     1, /* Manufacturer string descriptor index. */
00093     2, /* Product string descriptor index. */
00094     3, /* Serial number string descriptor index. */
00095     1  /* Device has one possible configuration. */
00096 };
00097 
00098 /** Device qualifier descriptor (Necessary to pass USB test). */
00099 static const USBDeviceQualifierDescriptor qualifierDescriptor = {
00100 
00101     sizeof(USBDeviceQualifierDescriptor),
00102     USBGenericDescriptor_DEVICEQUALIFIER,
00103     USBDeviceDescriptor_USB2_00,
00104     MSDeviceDescriptor_CLASS,
00105     MSDeviceDescriptor_SUBCLASS,
00106     MSDeviceDescriptor_PROTOCOL,
00107     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
00108     1, // Device has one possible configuration.
00109     0x00
00110 };
00111 
00112 /** Full-speed configuration descriptor. */
00113 static const MSDConfigurationDescriptors configurationDescriptorsFS = {
00114 
00115     /* Standard configuration descriptor. */
00116     {
00117         sizeof(USBConfigurationDescriptor),
00118         USBGenericDescriptor_CONFIGURATION,
00119         sizeof(MSDConfigurationDescriptors),
00120         1, /* Configuration has one interface. */
00121         1, /* This is configuration #1. */
00122         0, /* No string descriptor for configuration. */
00123         USBD_BMATTRIBUTES,
00124         USBConfigurationDescriptor_POWER(100)
00125     },
00126     /* Mass Storage interface descriptor. */
00127     {
00128         sizeof(USBInterfaceDescriptor),
00129         USBGenericDescriptor_INTERFACE,
00130         0, /* This is interface #0. */
00131         0, /* This is alternate setting #0. */
00132         2, /* Interface uses two endpoints. */
00133         MSInterfaceDescriptor_CLASS,
00134         MSInterfaceDescriptor_SCSI,
00135         MSInterfaceDescriptor_BULKONLY,
00136         0 /* No string descriptor for interface. */
00137     },
00138     /* Bulk-OUT endpoint descriptor */
00139     {
00140         sizeof(USBEndpointDescriptor),
00141         USBGenericDescriptor_ENDPOINT,
00142         USBEndpointDescriptor_ADDRESS(
00143             USBEndpointDescriptor_OUT,
00144             MSDDriverDescriptors_BULKOUT),
00145         USBEndpointDescriptor_BULK,
00146         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
00147             USBEndpointDescriptor_MAXBULKSIZE_FS),
00148         0 /* Must be 0 for full-speed Bulk endpoints. */
00149     },
00150     /* Bulk-IN endpoint descriptor */
00151     {
00152         sizeof(USBEndpointDescriptor),
00153         USBGenericDescriptor_ENDPOINT,
00154         USBEndpointDescriptor_ADDRESS(
00155             USBEndpointDescriptor_IN,
00156             MSDDriverDescriptors_BULKIN),
00157         USBEndpointDescriptor_BULK,
00158         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
00159             USBEndpointDescriptor_MAXBULKSIZE_FS),
00160         0 /* Must be 0 for full-speed Bulk endpoints. */
00161 
00162     }
00163 };
00164 
00165 /** Full-speed other speed configuration descriptor. */
00166 static const MSDConfigurationDescriptors otherSpeedDescriptorsFS = {
00167 
00168     /* Standard configuration descriptor. */
00169     {
00170         sizeof(USBConfigurationDescriptor),
00171         USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
00172         sizeof(MSDConfigurationDescriptors),
00173         1, /* Configuration has one interface. */
00174         1, /* This is configuration #1. */
00175         0, /* No string descriptor for configuration. */
00176         BOARD_USB_BMATTRIBUTES,
00177         USBConfigurationDescriptor_POWER(100)
00178     },
00179     /* Mass Storage interface descriptor. */
00180     {
00181         sizeof(USBInterfaceDescriptor),
00182         USBGenericDescriptor_INTERFACE,
00183         0, /* This is interface #0. */
00184         0, /* This is alternate setting #0. */
00185         2, /* Interface uses two endpoints. */
00186         MSInterfaceDescriptor_CLASS,            
00187         MSInterfaceDescriptor_SCSI,                 
00188         MSInterfaceDescriptor_BULKONLY,            
00189         0 /* No string descriptor for interface. */
00190     },
00191     /* Bulk-OUT endpoint descriptor */
00192     {
00193         sizeof(USBEndpointDescriptor), 
00194         USBGenericDescriptor_ENDPOINT,
00195         USBEndpointDescriptor_ADDRESS(
00196             USBEndpointDescriptor_OUT,
00197             MSDDriverDescriptors_BULKOUT),
00198         USBEndpointDescriptor_BULK,
00199         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
00200             USBEndpointDescriptor_MAXBULKSIZE_HS),
00201         0 /* No string descriptor for endpoint. */
00202     },
00203     /* Bulk-IN endpoint descriptor */
00204     {
00205         sizeof(USBEndpointDescriptor),
00206         USBGenericDescriptor_ENDPOINT,
00207         USBEndpointDescriptor_ADDRESS(
00208             USBEndpointDescriptor_IN,
00209             MSDDriverDescriptors_BULKIN),
00210         USBEndpointDescriptor_BULK,
00211         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
00212             USBEndpointDescriptor_MAXBULKSIZE_HS),
00213         0 /* No string descriptor for endpoint. */
00214     }
00215 };
00216 
00217 /** High-speed configuration descriptor. */
00218 static const MSDConfigurationDescriptors configurationDescriptorsHS = {
00219 
00220     /* Standard configuration descriptor. */
00221     {
00222         sizeof(USBConfigurationDescriptor),
00223         USBGenericDescriptor_CONFIGURATION,
00224         sizeof(MSDConfigurationDescriptors),
00225         1, /* Configuration has one interface. */
00226         1, /* This is configuration #1. */
00227         0, /* No string descriptor for configuration. */
00228         BOARD_USB_BMATTRIBUTES,
00229         USBConfigurationDescriptor_POWER(100)
00230     },
00231     /* Mass Storage interface descriptor. */
00232     {
00233         sizeof(USBInterfaceDescriptor),
00234         USBGenericDescriptor_INTERFACE,
00235         0, /* This is interface #0. */
00236         0, /* This is alternate setting #0. */
00237         2, /* Interface uses two endpoints. */
00238         MSInterfaceDescriptor_CLASS,
00239         MSInterfaceDescriptor_SCSI,
00240         MSInterfaceDescriptor_BULKONLY,
00241         0 /* No string descriptor for interface. */
00242     },
00243     /* Bulk-OUT endpoint descriptor */
00244     {
00245         sizeof(USBEndpointDescriptor), 
00246         USBGenericDescriptor_ENDPOINT,
00247         USBEndpointDescriptor_ADDRESS(
00248             USBEndpointDescriptor_OUT,
00249             MSDDriverDescriptors_BULKOUT),
00250         USBEndpointDescriptor_BULK,
00251         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
00252             USBEndpointDescriptor_MAXBULKSIZE_HS),
00253         0 /* No string descriptor for endpoint. */
00254     },
00255     /* Bulk-IN endpoint descriptor */
00256     {
00257         sizeof(USBEndpointDescriptor),
00258         USBGenericDescriptor_ENDPOINT,
00259         USBEndpointDescriptor_ADDRESS(
00260             USBEndpointDescriptor_IN,
00261             MSDDriverDescriptors_BULKIN),
00262         USBEndpointDescriptor_BULK,
00263         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
00264             USBEndpointDescriptor_MAXBULKSIZE_HS),
00265         0 /* No string descriptor for endpoint. */
00266     }
00267 };
00268 
00269 /** High-speed other speed configuration descriptor. */
00270 static const MSDConfigurationDescriptors otherSpeedDescriptorsHS = {
00271 
00272     /* Standard configuration descriptor. */
00273     {
00274         sizeof(USBConfigurationDescriptor),
00275         USBGenericDescriptor_OTHERSPEEDCONFIGURATION,
00276         sizeof(MSDConfigurationDescriptors),
00277         1, /* Configuration has one interface. */
00278         1, /* This is configuration #1. */
00279         0, /* No string descriptor for configuration. */
00280         BOARD_USB_BMATTRIBUTES,
00281         USBConfigurationDescriptor_POWER(100)
00282     },
00283     /* Mass Storage interface descriptor. */
00284     {
00285         sizeof(USBInterfaceDescriptor),
00286         USBGenericDescriptor_INTERFACE,
00287         0, /* This is interface #0. */
00288         0, /* This is alternate setting #0. */
00289         2, /* Interface uses two endpoints. */
00290         MSInterfaceDescriptor_CLASS,
00291         MSInterfaceDescriptor_SCSI,
00292         MSInterfaceDescriptor_BULKONLY,
00293         0 /* No string descriptor for interface. */
00294     },
00295     /* Bulk-OUT endpoint descriptor */
00296     {
00297         sizeof(USBEndpointDescriptor), 
00298         USBGenericDescriptor_ENDPOINT,
00299         USBEndpointDescriptor_ADDRESS(
00300             USBEndpointDescriptor_OUT,
00301             MSDDriverDescriptors_BULKOUT),
00302         USBEndpointDescriptor_BULK,
00303         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKOUT),
00304             USBEndpointDescriptor_MAXBULKSIZE_FS),
00305         0 /* No string descriptor for endpoint. */
00306     },
00307     /* Bulk-IN endpoint descriptor */
00308     {
00309         sizeof(USBEndpointDescriptor),
00310         USBGenericDescriptor_ENDPOINT,
00311         USBEndpointDescriptor_ADDRESS(
00312             USBEndpointDescriptor_IN,
00313             MSDDriverDescriptors_BULKIN),
00314         USBEndpointDescriptor_BULK,
00315         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDDriverDescriptors_BULKIN),
00316             USBEndpointDescriptor_MAXBULKSIZE_FS),
00317         0 /* No string descriptor for endpoint. */
00318     }
00319 };
00320 
00321 /** Language ID string descriptor. */
00322 static const unsigned char languageIdDescriptor[] = {
00323 
00324     USBStringDescriptor_LENGTH(1),
00325     USBGenericDescriptor_STRING,
00326     USBStringDescriptor_ENGLISH_US
00327 };
00328 
00329 /** Manufacturer string descriptor. */
00330 static const unsigned char manufacturerDescriptor[] = {
00331 
00332     USBStringDescriptor_LENGTH(5),
00333     USBGenericDescriptor_STRING,
00334     USBStringDescriptor_UNICODE('A'),
00335     USBStringDescriptor_UNICODE('T'),
00336     USBStringDescriptor_UNICODE('M'),
00337     USBStringDescriptor_UNICODE('E'),
00338     USBStringDescriptor_UNICODE('L')
00339 };
00340 
00341 /** Product string descriptor. */
00342 static const unsigned char productDescriptor[] = {
00343 
00344     USBStringDescriptor_LENGTH(14),
00345     USBGenericDescriptor_STRING,
00346     USBStringDescriptor_UNICODE('A'),
00347     USBStringDescriptor_UNICODE('T'),
00348     USBStringDescriptor_UNICODE('M'),
00349     USBStringDescriptor_UNICODE('E'),
00350     USBStringDescriptor_UNICODE('L'),
00351     USBStringDescriptor_UNICODE(' '),
00352     USBStringDescriptor_UNICODE('A'),
00353     USBStringDescriptor_UNICODE('T'),
00354     USBStringDescriptor_UNICODE('9'),
00355     USBStringDescriptor_UNICODE('1'),
00356     USBStringDescriptor_UNICODE(' '),
00357     USBStringDescriptor_UNICODE('M'),
00358     USBStringDescriptor_UNICODE('S'),
00359     USBStringDescriptor_UNICODE('D')
00360 };
00361 
00362 /** Serial number string descriptor. The serial number must be at least 12 */
00363 /** characters long and made up of only letters & numbers to be compliant with */
00364 /** the MSD specification. */
00365 static const unsigned char serialNumberDescriptor[] = {
00366 
00367     USBStringDescriptor_LENGTH(12),
00368     USBGenericDescriptor_STRING,
00369     USBStringDescriptor_UNICODE('0'),
00370     USBStringDescriptor_UNICODE('1'),
00371     USBStringDescriptor_UNICODE('2'),
00372     USBStringDescriptor_UNICODE('3'),
00373     USBStringDescriptor_UNICODE('4'),
00374     USBStringDescriptor_UNICODE('5'),
00375     USBStringDescriptor_UNICODE('6'),
00376     USBStringDescriptor_UNICODE('7'),
00377     USBStringDescriptor_UNICODE('8'),
00378     USBStringDescriptor_UNICODE('9'),
00379     USBStringDescriptor_UNICODE('A'),
00380     USBStringDescriptor_UNICODE('B')
00381 };
00382 
00383 /** List of all string descriptors used. */
00384 static const unsigned char *stringDescriptors[] = {
00385 
00386     languageIdDescriptor,
00387     manufacturerDescriptor,
00388     productDescriptor,
00389     serialNumberDescriptor
00390 };
00391 
00392 /*--------------------------------------------------------------------------- */
00393 /*         Global variables */
00394 /*--------------------------------------------------------------------------- */
00395 
00396 
00397 /** List of the standard descriptors used by the Mass Storage driver. */
00398 const USBDDriverDescriptors msdDriverDescriptors = {
00399 
00400     &deviceDescriptor,
00401     (USBConfigurationDescriptor *) &configurationDescriptorsFS,
00402     &qualifierDescriptor,
00403     (USBConfigurationDescriptor *) &otherSpeedDescriptorsFS,
00404     0, /* No high-speed device descriptor (uses FS one) */
00405     (USBConfigurationDescriptor *) &configurationDescriptorsHS,
00406     &qualifierDescriptor,
00407     (USBConfigurationDescriptor *) &otherSpeedDescriptorsHS,
00408     stringDescriptors,
00409     4 /* Four string descriptors in array */
00410 };
00411 
00412 /**@}*/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines