usb_specific_request.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00016 
00017 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
00018  *
00019  * Redistribution and use in source and binary forms, with or without
00020  * modification, are permitted provided that the following conditions are met:
00021  *
00022  * 1. Redistributions of source code must retain the above copyright notice,
00023  * this list of conditions and the following disclaimer.
00024  *
00025  * 2. Redistributions in binary form must reproduce the above copyright notice,
00026  * this list of conditions and the following disclaimer in the documentation
00027  * and/or other materials provided with the distribution.
00028  *
00029  * 3. The name of ATMEL may not be used to endorse or promote products derived
00030  * from this software without specific prior written permission.
00031  *
00032  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00034  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00042  */
00043 
00044 
00045 //_____ I N C L U D E S ____________________________________________________
00046 
00047 #include "config.h"
00048 #include "conf_usb.h"
00049 #include "lib_mcu/usb/usb_drv.h"
00050 #include "usb_descriptors.h"
00051 #include "modules/usb/device_chap9/usb_standard_request.h"
00052 #include "usb_specific_request.h"
00053 #include "modules/control_access/ctrl_access.h"
00054 #if ((USB_DEVICE_SN_USE==ENABLE) && (USE_DEVICE_SN_UNIQUE==ENABLE))
00055 #include "lib_mcu/flash/flash_drv.h"
00056 #endif
00057 
00058 //_____ D E F I N I T I O N ________________________________________________
00059 
00060 bit  ms_multiple_drive;
00061 
00062 #ifdef __GNUC__
00063 extern PGM_VOID_P pbuffer;
00064 #else
00065 extern U8   code *pbuffer;
00066 #endif
00067 extern U8   data_to_transfer;
00068 
00069 
00070 //_____ D E C L A R A T I O N ______________________________________________
00071 
00080 Bool usb_user_read_request(U8 type, U8 request)
00081 {
00082    U16   wInterface;
00083    U8    wValue_msb;
00084    U8    wValue_lsb;
00085 
00086    // Read wValue
00087    wValue_lsb = Usb_read_byte();
00088    wValue_msb = Usb_read_byte();
00089 
00090    //** Specific request from Class MassStorage
00091    if( USB_SETUP_SET_CLASS_INTER == type )
00092    {
00093       switch( request )
00094       {
00095          case SETUP_MASS_STORAGE_RESET:
00096          // wValue must be 0
00097          // wIndex = Interface
00098          if( (0!=wValue_lsb) || (0!=wValue_msb) )
00099             break;
00100          LSB(wInterface)=Usb_read_byte();
00101          MSB(wInterface)=Usb_read_byte();
00102          if( INTERFACE_NB != wInterface )
00103             break;
00104          Usb_ack_receive_setup();
00105          Usb_send_control_in();
00106          return TRUE;
00107          break;
00108       }
00109    }
00110    if( USB_SETUP_GET_CLASS_INTER == type )
00111    {
00112       switch( request )
00113       {
00114          case SETUP_MASS_STORAGE_GET_MAX_LUN:
00115          // wValue must be 0
00116          // wIndex = Interface
00117          if( (0!=wValue_lsb) || (0!=wValue_msb) )
00118             break;
00119          LSB(wInterface)=Usb_read_byte();
00120          MSB(wInterface)=Usb_read_byte();
00121          if( INTERFACE_NB != wInterface )
00122             break;
00123          Usb_ack_receive_setup();
00124          Usb_write_byte( (get_nb_lun()-1) );
00125          Usb_send_control_in();
00126          ms_multiple_drive = 1;
00127          return TRUE;
00128          break;
00129       }
00130    }
00131    
00132    return FALSE;  // No supported request
00133 }
00134 
00135 
00140 void usb_user_endpoint_init(U8 conf_nb)
00141 {
00142    usb_configure_endpoint(EP_MS_IN,      \
00143                           TYPE_BULK,     \
00144                           DIRECTION_IN,  \
00145                           SIZE_64,       \
00146                           TWO_BANKS,     \
00147                           NYET_ENABLED);
00148    usb_configure_endpoint(EP_MS_OUT,     \
00149                           TYPE_BULK,     \
00150                           DIRECTION_OUT, \
00151                           SIZE_64,       \
00152                           TWO_BANKS,     \
00153                           NYET_ENABLED);
00154 }
00155 
00156 
00163 U8   usb_user_interface_get( U16 wInterface )
00164 {
00165    return 0;  // Only one alternate setting possible for all interface
00166 }
00167 
00168 
00174 void usb_user_interface_reset(U16 wInterface, U8 alternate_setting)
00175 {  
00176    // default setting selected = reset data toggle
00177    if( INTERFACE_NB == wInterface )
00178    {
00179       // Interface Mass Storage
00180       Usb_select_endpoint(EP_MS_IN);
00181       Usb_disable_stall_handshake();
00182       Usb_reset_endpoint(EP_MS_IN);
00183       Usb_reset_data_toggle();
00184       Usb_select_endpoint(EP_MS_OUT);
00185       Usb_disable_stall_handshake();
00186       Usb_reset_endpoint(EP_MS_OUT);
00187       Usb_reset_data_toggle();
00188    }
00189 }
00190 
00191    
00199 Bool usb_user_get_descriptor(U8 type, U8 string)
00200 {
00201    switch(type)
00202    {
00203       case DESCRIPTOR_STRING:
00204       switch (string)
00205       {
00206          case LANG_ID:
00207          data_to_transfer = sizeof (usb_user_language_id);
00208          pbuffer = &(usb_user_language_id.bLength);
00209          return TRUE;
00210          break;
00211         
00212          case MAN_INDEX:
00213          data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00214          pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00215          return TRUE;
00216          break;
00217         
00218          case PROD_INDEX:
00219          data_to_transfer = sizeof (usb_user_product_string_descriptor);
00220          pbuffer = &(usb_user_product_string_descriptor.bLength);
00221          return TRUE;
00222          break;
00223            
00224 #if (USB_DEVICE_SN_USE==ENABLE)              
00225          case SN_INDEX:
00226          data_to_transfer = sizeof (usb_user_serial_number);
00227          pbuffer = &(usb_user_serial_number.bLength);
00228 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00229          f_get_serial_string=TRUE;
00230          data_to_transfer += (SN_LENGTH*4);
00231 #endif
00232          return TRUE;
00233          break;
00234 #endif
00235       }
00236       break;
00237    }
00238    return FALSE;
00239 }
00240 

Generated on Fri Oct 31 15:08:58 2008 for ATMEL by  doxygen 1.5.3