usb_specific_request.c

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00016 
00017 /* Copyright (c) 2009 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  * 4. This software may only be redistributed and used in connection with an Atmel
00033  * AVR product.
00034  *
00035  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00037  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00038  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00039  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00040  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00041  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00042  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00043  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00044  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00045  */
00046 
00047 
00048 //_____ I N C L U D E S ____________________________________________________
00049 
00050 #include "config.h"
00051 #include "conf_usb.h"
00052 #include "lib_mcu/usb/usb_drv.h"
00053 #include "usb_descriptors.h"
00054 #include "modules/usb/device_chap9/usb_standard_request.h"
00055 #include "usb_specific_request.h"
00056 #include "modules/control_access/ctrl_access.h"
00057 #if ((USB_DEVICE_SN_USE==ENABLE) && (USE_DEVICE_SN_UNIQUE==ENABLE))
00058 #include "lib_mcu/flash/flash_drv.h"
00059 #endif
00060 
00061 //_____ D E F I N I T I O N ________________________________________________
00062 
00063 bit  ms_multiple_drive;
00064 
00065 #ifdef __GNUC__
00066 extern PGM_VOID_P pbuffer;
00067 #else
00068 extern U8   code *pbuffer;
00069 #endif
00070 extern U8   data_to_transfer;
00071 
00072 
00073 //_____ D E C L A R A T I O N ______________________________________________
00074 
00083 Bool usb_user_read_request(U8 type, U8 request)
00084 {
00085    U16   wInterface;
00086    U8    wValue_msb;
00087    U8    wValue_lsb;
00088 
00089    // Read wValue
00090    wValue_lsb = Usb_read_byte();
00091    wValue_msb = Usb_read_byte();
00092 
00093    //** Specific request from Class MassStorage
00094    if( USB_SETUP_SET_CLASS_INTER == type )
00095    {
00096       switch( request )
00097       {
00098          case SETUP_MASS_STORAGE_RESET:
00099          // wValue must be 0
00100          // wIndex = Interface
00101          if( (0!=wValue_lsb) || (0!=wValue_msb) )
00102             break;
00103          LSB(wInterface)=Usb_read_byte();
00104          MSB(wInterface)=Usb_read_byte();
00105          if( INTERFACE_NB != wInterface )
00106             break;
00107          Usb_ack_receive_setup();
00108          Usb_send_control_in();
00109          while(!Is_usb_in_ready());
00110          return TRUE;
00111          break;
00112       }
00113    }
00114    if( USB_SETUP_GET_CLASS_INTER == type )
00115    {
00116       switch( request )
00117       {
00118          case SETUP_MASS_STORAGE_GET_MAX_LUN:
00119          // wValue must be 0
00120          // wIndex = Interface
00121          if( (0!=wValue_lsb) || (0!=wValue_msb) )
00122             break;
00123          LSB(wInterface)=Usb_read_byte();
00124          MSB(wInterface)=Usb_read_byte();
00125          if( INTERFACE_NB != wInterface )
00126             break;
00127          Usb_ack_receive_setup();
00128          Usb_write_byte( (get_nb_lun()-1) );
00129          Usb_send_control_in();
00130          while(!Is_usb_in_ready());
00131          while( !Is_usb_receive_out() );
00132          Usb_ack_receive_out();
00133          ms_multiple_drive = 1;
00134          return TRUE;
00135          break;
00136       }
00137    }
00138    
00139    return FALSE;  // No supported request
00140 }
00141 
00142 
00147 void usb_user_endpoint_init(U8 conf_nb)
00148 {
00149    usb_configure_endpoint(EP_MS_IN,      \
00150                           TYPE_BULK,     \
00151                           DIRECTION_IN,  \
00152                           SIZE_64,       \
00153                           TWO_BANKS,     \
00154                           NYET_ENABLED);
00155    usb_configure_endpoint(EP_MS_OUT,     \
00156                           TYPE_BULK,     \
00157                           DIRECTION_OUT, \
00158                           SIZE_64,       \
00159                           TWO_BANKS,     \
00160                           NYET_ENABLED);
00161 }
00162 
00163 
00170 U8   usb_user_interface_get( U16 wInterface )
00171 {
00172    return 0;  // Only one alternate setting possible for all interface
00173 }
00174 
00175 
00181 void usb_user_interface_reset(U16 wInterface, U8 alternate_setting)
00182 {  
00183    // default setting selected = reset data toggle
00184    if( INTERFACE_NB == wInterface )
00185    {
00186       // Interface Mass Storage
00187       Usb_select_endpoint(EP_MS_IN);
00188       Usb_disable_stall_handshake();
00189       Usb_reset_endpoint(EP_MS_IN);
00190       Usb_reset_data_toggle();
00191       Usb_select_endpoint(EP_MS_OUT);
00192       Usb_disable_stall_handshake();
00193       Usb_reset_endpoint(EP_MS_OUT);
00194       Usb_reset_data_toggle();
00195    }
00196 }
00197 
00198    
00206 Bool usb_user_get_descriptor(U8 type, U8 string)
00207 {
00208    switch(type)
00209    {
00210       case DESCRIPTOR_STRING:
00211       switch (string)
00212       {
00213          case LANG_ID:
00214          data_to_transfer = sizeof (usb_user_language_id);
00215          pbuffer = &(usb_user_language_id.bLength);
00216          return TRUE;
00217          break;
00218         
00219          case MAN_INDEX:
00220          data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00221          pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00222          return TRUE;
00223          break;
00224         
00225          case PROD_INDEX:
00226          data_to_transfer = sizeof (usb_user_product_string_descriptor);
00227          pbuffer = &(usb_user_product_string_descriptor.bLength);
00228          return TRUE;
00229          break;
00230            
00231 #if (USB_DEVICE_SN_USE==ENABLE)              
00232          case SN_INDEX:
00233          data_to_transfer = sizeof (usb_user_serial_number);
00234          pbuffer = &(usb_user_serial_number.bLength);
00235 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00236          f_get_serial_string=TRUE;
00237          data_to_transfer += (SN_LENGTH*4);
00238 #endif
00239          return TRUE;
00240          break;
00241 #endif
00242       }
00243       break;
00244    }
00245    return FALSE;
00246 }
00247 

Generated on Wed Sep 23 09:17:03 2009 for ATMEL by  doxygen 1.5.3