SAMV71 Xplained Ultra Software Package 1.5

MSDDriver.h

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  * \section Purpose
00032  * 
00033  * Mass storage %device driver implementation.
00034  * 
00035  * \section Usage
00036  * 
00037  * -# Enable and setup USB related pins (see pio & board.h).
00038  * -# Configure the memory interfaces used for Mass Storage LUNs
00039  *    (see memories, MSDLun.h).
00040  * -# Instance the USB device configure descriptor as
00041  *    MSDConfigurationDescriptors or MSDConfigurationDescriptorsOTG defined.
00042  *    Interface number should be 0.
00043  * -# Configure the USB MSD %driver using MSDDriver_Initialize.
00044  * -# Invoke MSDDriver_StateMachine in main loop to handle all Mass Storage
00045  *    operations.
00046  */
00047 
00048 #ifndef MSDDRIVER_H
00049 #define MSDDRIVER_H
00050 
00051 /** \addtogroup usbd_msd 
00052  *@{
00053  */
00054  
00055 /*------------------------------------------------------------------------------
00056  *         Headers
00057  *------------------------------------------------------------------------------*/
00058 
00059 #include <stdint.h>
00060 
00061 #include <MSDLun.h>
00062 #include <MSD.h>
00063 #include <MSDDStateMachine.h>
00064 #include <MSDFunction.h>
00065 
00066 /*------------------------------------------------------------------------------
00067  *         Types
00068  *------------------------------------------------------------------------------*/
00069 #pragma pack(1)
00070 #if defined   ( __CC_ARM   ) /* Keil ¦̀Vision 4 */
00071 #elif defined ( __ICCARM__ ) /* IAR Ewarm */
00072 #define __attribute__(...)
00073 #define __packed__  packed
00074 #elif defined (  __GNUC__  ) /* GCC CS3 */
00075 #define __packed__  aligned(1)
00076 #endif
00077 /**
00078  * \typedef MSDConfigurationDescriptors
00079  * \brief List of configuration descriptors used by a Mass Storage device driver.
00080  */
00081 typedef struct _MSDConfigurationDescriptors {
00082 
00083     /** Standard configuration descriptor. */
00084     USBConfigurationDescriptor configuration;
00085     /** Mass storage interface descriptor. */
00086     USBInterfaceDescriptor interface;
00087     /** Bulk-out endpoint descriptor. */
00088     USBEndpointDescriptor bulkOut;
00089     /** Bulk-in endpoint descriptor. */
00090     USBEndpointDescriptor bulkIn;
00091 
00092 } __attribute__ ((__packed__)) MSDConfigurationDescriptors;
00093 
00094 /**
00095  * \typedef MSDConfigurationDescriptorsOTG
00096  * \brief List of configuration descriptors used by a
00097  *        Mass Storage device driver, with OTG support.
00098  */
00099 typedef struct _MSDConfigurationDescriptorsOTG {
00100 
00101     /** Standard configuration descriptor. */
00102     USBConfigurationDescriptor configuration;
00103     /* OTG descriptor */
00104     USBOtgDescriptor otgDescriptor;
00105     /** Mass storage interface descriptor. */
00106     USBInterfaceDescriptor interface;
00107     /** Bulk-out endpoint descriptor. */
00108     USBEndpointDescriptor bulkOut;
00109     /** Bulk-in endpoint descriptor. */
00110     USBEndpointDescriptor bulkIn;
00111 
00112 } __attribute__ ((__packed__)) MSDConfigurationDescriptorsOTG;
00113 
00114 #pragma pack()
00115 
00116 /*------------------------------------------------------------------------------
00117  *      Global functions
00118  *------------------------------------------------------------------------------*/
00119 
00120 extern void MSDDriver_Initialize(
00121     const USBDDriverDescriptors *pDescriptors,
00122     MSDLun *luns, uint8_t numLuns);
00123 
00124 extern void MSDDriver_RequestHandler(
00125     const USBGenericRequest *request);
00126 
00127 extern void MSDDriver_ConfigurationChangeHandler(
00128     uint8_t cfgnum);
00129 
00130 /**
00131  * State machine for the MSD driver
00132  * \param  pMsdDriver  Pointer to MSDDriver instance.
00133  */
00134 static inline void MSDDriver_StateMachine(void) {
00135     MSDFunction_StateMachine();
00136 }
00137 
00138 /**@}*/
00139 
00140 #endif /* #ifndef MSDDRIVER_H */
00141 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines