SAMV71 Xplained Ultra Software Package 1.4

MSDDriver.c

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         ATMEL Microcontroller Software Support
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2008, 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  *  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     if (cfgnum) {
00088         pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
00089         MSDFunction_Configure((USBGenericDescriptor*)pDesc,
00090                               pDesc->wTotalLength);
00091     }
00092 }
00093 
00094 /**
00095  * Handler for incoming SETUP requests on default Control endpoint 0.
00096  *
00097  * Standard requests are forwarded to the USBDDriver_RequestHandler
00098  * method.
00099  * \param  pMsdDriver  Pointer to MSDDriver instance.
00100  * \param  request Pointer to a USBGenericRequest instance
00101  */
00102 void MSDDriver_RequestHandler(
00103     const USBGenericRequest *request)
00104 {
00105     USBDDriver *pUsbd = USBD_GetDriver();
00106     TRACE_INFO_WP("NewReq ");
00107     if (MSDFunction_RequestHandler(request)) {
00108         USBDDriver_RequestHandler(pUsbd, request);
00109     }
00110 }
00111 
00112 /**@}*/
00113 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines