SAMV71 Xplained Ultra Software Package 1.5

USBDDriverDescriptors.c

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