SAMV71 Xplained Ultra Software Package 1.4

MSD.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, 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  * \section Purpose
00032  *
00033  * Mass Storage class definitions.
00034  *
00035  * See
00036  * - <a
00037  * href="http://www.usb.org/developers/devclass_docs/usb_msc_overview_1.2.pdf"> 
00038  * USB Mass Storage Class Spec. Overview</a>
00039  * - <a href="http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf"> 
00040  * USB Mass Storage Class Bulk-Only Transport</a>
00041  *
00042  * \section Usage
00043  *
00044  * -# Uses "MSD Requests" to check incoming requests from USB Host.
00045  * -# Uses "MSD Subclass Codes" and "MSD Protocol Codes" to fill %device
00046  *    interface descriptors for a MSD %device.
00047  * -# Handle the incoming Bulk data with "MSD CBW Definitions" and MSCbw
00048  *    structure.
00049  * -# Prepare the outgoing Bulk data with "MSD CSW Definitions" and MSCsw
00050  *    structure.
00051  */
00052 
00053 #ifndef MSD_H
00054 #define MSD_H
00055 
00056 /** \addtogroup usbd_msd
00057  *@{
00058  */
00059 
00060 /*------------------------------------------------------------------------------
00061  *      Includes
00062  *------------------------------------------------------------------------------*/
00063 
00064 #include <stdint.h>
00065 
00066 /*------------------------------------------------------------------------------
00067  *      Definitions
00068  *------------------------------------------------------------------------------*/
00069 
00070 /*
00071  * MSD Requests
00072  * This section lists MSD-specific requests ( Actually for Bulk-only protocol ).
00073  *
00074  * \section Requests
00075  * - MSD_BULK_ONLY_RESET
00076  * - MSD_GET_MAX_LUN
00077  */
00078 
00079 /** Reset the mass storage %device and its associated interface. */
00080 #define MSD_BULK_ONLY_RESET                     0xFF
00081 /** Return the maximum LUN number supported by the %device. */
00082 #define MSD_GET_MAX_LUN                         0xFE
00083 
00084 /** \addtogroup usbd_msd_subclass MSD Subclass Codes
00085  *      @{
00086  * This page lists the Subclass Codes for bInterfaceSubClass field.
00087  * (Table 2.1, USB Mass Storage Class Spec. Overview)
00088  *
00089  * \section SubClasses
00090  * - MSD_SUBCLASS_RBC
00091  * - MSD_SUBCLASS_SFF_MCC
00092  * - MSD_SUBCLASS_QIC
00093  * - MSD_SUBCLASS_UFI
00094  * - MSD_SUBCLASS_SFF
00095  * - MSD_SUBCLASS_SCSI
00096  */
00097 
00098 /** Reduced Block Commands (RBC) T10 */
00099 #define MSD_SUBCLASS_RBC                        0x01
00100 /** C/DVD devices */
00101 #define MSD_SUBCLASS_SFF_MCC                    0x02
00102 /** Tape device */
00103 #define MSD_SUBCLASS_QIC                        0x03
00104 /** Floppy disk drive (FDD) device */
00105 #define MSD_SUBCLASS_UFI                        0x04
00106 /** Floppy disk drive (FDD) device */
00107 #define MSD_SUBCLASS_SFF                        0x05
00108 /** SCSI transparent command set */
00109 #define MSD_SUBCLASS_SCSI                       0x06
00110 /**      @} */
00111 
00112 
00113 /** \addtogroup usbd_msd_protocol_codes MSD Protocol Codes
00114  *      @{
00115  * This page lists the Transport Protocol codes for MSD.
00116  * (Table 3.1, USB Mass Storage Class Spec. Overview)
00117  *
00118  * \section Protocols
00119  * - MSD_PROTOCOL_CBI_COMPLETION
00120  * - MSD_PROTOCOL_CBI
00121  * - MSD_PROTOCOL_BULK_ONLY
00122  */
00123 
00124 /** Control/Bulk/Interrupt (CBI) Transport (with command complete interrupt) */
00125 #define MSD_PROTOCOL_CBI_COMPLETION             0x00
00126 /** Control/Bulk/Interrupt (CBI) Transport (no command complete interrupt) */
00127 #define MSD_PROTOCOL_CBI                        0x01
00128 /** Bulk-Only Transport */
00129 #define MSD_PROTOCOL_BULK_ONLY                  0x50
00130 /**      @}*/
00131 
00132 /** \addtogroup usbd_msd_cbw_def MSD CBW Definitions
00133  *      @{
00134  * This page lists the Command Block Wrapper (CBW) definitions.
00135  *
00136  * \section Constants
00137  * - MSD_CBW_SIZE
00138  * - MSD_CBW_SIGNATURE
00139  *
00140  * \section Fields
00141  * - MSD_CBW_DEVICE_TO_HOST
00142  */
00143 
00144 /** Command Block Wrapper Size */
00145 #define MSD_CBW_SIZE                            31
00146 /** 'USBC' 0x43425355 */
00147 #define MSD_CBW_SIGNATURE                       0x43425355
00148 
00149 /** CBW bmCBWFlags field */
00150 #define MSD_CBW_DEVICE_TO_HOST                  (1 << 7)
00151 #define MSD_CBW_DEVICE_TO_DEVICE                (0 << 7)
00152 /**      @}*/
00153 
00154 /** \addtogroup usbd_msd_csw_def MSD CSW Definitions
00155  *      @{
00156  * This page lists the Command Status Wrapper (CSW) definitions.
00157  *
00158  * \section Constants
00159  * - MSD_CSW_SIZE
00160  * - MSD_CSW_SIGNATURE
00161  *
00162  * \section Command Block Status Values
00163  * (Table 5.3 , USB Mass Storage Class Bulk-Only Transport)
00164  * - MSD_CSW_COMMAND_PASSED
00165  * - MSD_CSW_COMMAND_FAILED
00166  * - MSD_CSW_PHASE_ERROR
00167  */
00168 
00169 /** Command Status Wrapper Size */
00170 #define MSD_CSW_SIZE                            13
00171 /** 'USBS' 0x53425355 */
00172 #define MSD_CSW_SIGNATURE                       0x53425355
00173 
00174 /** Command Passed (good status) */
00175 #define MSD_CSW_COMMAND_PASSED                  0
00176 /** Command Failed */
00177 #define MSD_CSW_COMMAND_FAILED                  1
00178 /** Phase Error */
00179 #define MSD_CSW_PHASE_ERROR                     2
00180 /**      @}*/
00181 
00182 
00183 /*------------------------------------------------------------------------------
00184  *      Structures
00185  *------------------------------------------------------------------------------*/
00186 COMPILER_PACK_SET(1)
00187 /*------------------------------------------------------------------------------
00188  * Command Block Wrapper (CBW),
00189  * See Table 5.1, USB Mass Storage Class Bulk-Only Transport.
00190  *
00191  * The CBW shall start on a packet boundary and shall end as a
00192  * short packet with exactly 31 (1Fh) bytes transferred.
00193  *------------------------------------------------------------------------------*/
00194 typedef struct {
00195 
00196     /** 'USBC' 0x43425355 (little endian) */
00197     uint32_t  dCBWSignature;
00198     /** Must be the same as dCSWTag */
00199     uint32_t  dCBWTag;
00200     /** Number of bytes transfer */
00201     uint32_t  dCBWDataTransferLength;
00202     /** Indicates the directin of the transfer:
00203      *  - 0x80=IN=device-to-host;
00204      *  - 0x00=OUT=host-to-device
00205      */
00206     uint8_t bmCBWFlags;
00207     /** bits 0->3: bCBWLUN */
00208     uint8_t bCBWLUN   :4,
00209             bReserved1:4;           /** reserved */
00210     /** bits 0->4: bCBWCBLength */
00211     uint8_t bCBWCBLength:5,
00212             bReserved2  :3;         /** reserved */
00213     /** Command block */
00214     uint8_t pCommand[16];
00215 
00216 } MSCbw;
00217 
00218 /*------------------------------------------------------------------------------
00219  * Command Status Wrapper (CSW),
00220  * See Table 5.2, USB Mass Storage Class Bulk-Only Transport.
00221  *------------------------------------------------------------------------------*/
00222 typedef struct
00223 {
00224     /** 'USBS' 0x53425355 (little endian) */
00225     uint32_t  dCSWSignature;
00226     /** Must be the same as dCBWTag */
00227     uint32_t  dCSWTag;
00228     /**
00229      * For Data-Out the device shall report in the dCSWDataResidue the
00230      * difference between the amount of data expected as stated in the
00231      * dCBWDataTransferLength, and the actual amount of data processed by
00232      * the device. For Data-In the device shall report in the dCSWDataResidue
00233      * the difference between the amount of data expected as stated in the
00234      * dCBWDataTransferLength and the actual amount of relevant data sent by
00235      * the device. The dCSWDataResidue shall not exceed the value sent in the
00236      * dCBWDataTransferLength.
00237      */
00238     uint32_t  dCSWDataResidue;
00239     /** Indicates the success or failure of the command. */
00240     uint8_t bCSWStatus;
00241 
00242 } MSCsw;
00243 
00244 COMPILER_PACK_RESET()
00245 /**@}*/
00246 #endif /*#ifndef MSD_H */
00247 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines