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 * Implement a single interface device with single MS function in. 00034 */ 00035 00036 /*------------------------------------------------------------------------------ 00037 * Includes 00038 *------------------------------------------------------------------------------*/ 00039 00040 #include <MSDDriver.h> 00041 #include <MSDFunction.h> 00042 #include <USBLib_Trace.h> 00043 #include "USBD.h" 00044 #include <USBD_HAL.h> 00045 #include <USBDDriver.h> 00046 00047 /*----------------------------------------------------------------------------- 00048 * Internal variables 00049 *-----------------------------------------------------------------------------*/ 00050 00051 /*----------------------------------------------------------------------------- 00052 * Internal functions 00053 *-----------------------------------------------------------------------------*/ 00054 00055 /*----------------------------------------------------------------------------- 00056 * Exported functions 00057 *-----------------------------------------------------------------------------*/ 00058 00059 /** 00060 * Initializes the MSD driver and the associated USB driver. 00061 * \param pDescriptors Pointer to Descriptors list for MSD Device. 00062 * \param pLuns Pointer to a list of LUNs 00063 * \param numLuns Number of LUN in list 00064 * \see MSDLun 00065 */ 00066 void MSDDriver_Initialize( 00067 const USBDDriverDescriptors *pDescriptors, 00068 MSDLun *pLuns, unsigned char numLuns) 00069 { 00070 USBDDriver *pUsbd = USBD_GetDriver(); 00071 USBDDriver_Initialize(pUsbd, pDescriptors, 0); 00072 MSDFunction_Initialize(pUsbd, 0, pLuns, numLuns); 00073 USBD_Init(); 00074 } 00075 00076 /** 00077 * Invoked when the configuration of the device changes. Resets the mass 00078 * storage driver. 00079 * \param pMsdDriver Pointer to MSDDriver instance. 00080 * \param cfgnum New configuration number. 00081 */ 00082 void MSDDriver_ConfigurationChangeHandler( 00083 uint8_t cfgnum) 00084 { 00085 USBDDriver *pUsbd = USBD_GetDriver(); 00086 USBConfigurationDescriptor *pDesc; 00087 00088 if (cfgnum) { 00089 pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum); 00090 MSDFunction_Configure((USBGenericDescriptor *)pDesc, 00091 pDesc->wTotalLength); 00092 } 00093 } 00094 00095 /** 00096 * Handler for incoming SETUP requests on default Control endpoint 0. 00097 * 00098 * Standard requests are forwarded to the USBDDriver_RequestHandler 00099 * method. 00100 * \param pMsdDriver Pointer to MSDDriver instance. 00101 * \param request Pointer to a USBGenericRequest instance 00102 */ 00103 void MSDDriver_RequestHandler( 00104 const USBGenericRequest *request) 00105 { 00106 USBDDriver *pUsbd = USBD_GetDriver(); 00107 TRACE_INFO_WP("NewReq "); 00108 00109 if (MSDFunction_RequestHandler(request)) 00110 USBDDriver_RequestHandler(pUsbd, request); 00111 } 00112 00113 /**@}*/ 00114