usb_task.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00002 
00003 
00004 /*! \file usb_task.h *********************************************************************
00005  *
00006  * \brief
00007  *      This file manages the USB task either device/host or both.
00008  *
00009  *      The USB task selects the correct USB task (usb_device task or usb_host task
00010  *      to be executed depending on the current mode available.
00011  *
00012  *      According to USB_DEVICE_FEATURE and USB_HOST_FEATURE value (located in conf_usb.h file)
00013  *      The usb_task can be configured to support USB DEVICE mode or USB Host mode or both
00014  *      for a dual role device application.
00015  *
00016  *      This module also contains the general USB interrupt subroutine. This subroutine is used
00017  *      to detect asynchronous USB events.
00018  *
00019  *      Note:
00020  *        - The usb_task belongs to the scheduler, the usb_device_task and usb_host do not, they are called
00021  *          from the general usb_task
00022  *        - See conf_usb.h file for more details about the configuration of this module
00023  *
00024  * \addtogroup usbstick
00025  *
00026  * \author
00027  *      Atmel Corporation: http://www.atmel.com \n
00028  *      Support email: avr@atmel.com
00029  *
00030  ******************************************************************************/
00031 /* Copyright (c) 2008  ATMEL Corporation
00032    All rights reserved.
00033 
00034    Redistribution and use in source and binary forms, with or without
00035    modification, are permitted provided that the following conditions are met:
00036 
00037    * Redistributions of source code must retain the above copyright
00038      notice, this list of conditions and the following disclaimer.
00039    * Redistributions in binary form must reproduce the above copyright
00040      notice, this list of conditions and the following disclaimer in
00041      the documentation and/or other materials provided with the
00042      distribution.
00043    * Neither the name of the copyright holders nor the names of
00044      contributors may be used to endorse or promote products derived
00045      from this software without specific prior written permission.
00046 
00047   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00048   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00049   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00050   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00051   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00052   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00053   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00054   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00055   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00056   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00057   POSSIBILITY OF SUCH DAMAGE.
00058 */
00059 
00060 #ifndef _USB_TASK_H_
00061 #define _USB_TASK_H_
00062 
00063 /**
00064    \ingroup usbstick
00065    \defgroup usbdriver USB Driver
00066    @{
00067 */
00068 
00069 //_____ I N C L U D E S ____________________________________________________
00070 
00071 
00072 //_____ M A C R O S ________________________________________________________
00073 
00074 //! \name USB Events
00075 //! @{
00076 
00077 //! Send event
00078 #define Usb_send_event(x)               (g_usb_event |= (1<<x))
00079 //! Ack event processed
00080 #define Usb_ack_event(x)                (g_usb_event &= ~(1<<x))
00081 //! Clear all events
00082 #define Usb_clear_all_event()           (g_usb_event = 0)
00083 //! Check for USB event
00084 #define Is_usb_event(x)                 ((g_usb_event & (1<<x)) ? TRUE : FALSE)
00085 //! Check for USB event NOT occuring
00086 #define Is_not_usb_event(x)             ((g_usb_event & (1<<x)) ? FALSE: TRUE)
00087 //! Check if USB is device
00088 #define Is_usb_device()                 (g_usb_mode==USB_MODE_DEVICE ? TRUE : FALSE)
00089 
00090 
00091 //! USB Event: USB plugged
00092 #define EVT_USB_POWERED               1         
00093 //! USB Event: USB un-plugged
00094 #define EVT_USB_UNPOWERED             2         
00095 //! USB Event: USB in device
00096 #define EVT_USB_DEVICE_FUNCTION       3         
00097 //! USB Event: USB in host
00098 #define EVT_USB_HOST_FUNCTION         4         
00099 //! USB Event: USB suspend
00100 #define EVT_USB_SUSPEND               5         
00101 //! USB Event: USB wake up
00102 #define EVT_USB_WAKE_UP               6         
00103 //! USB Event: USB resume
00104 #define EVT_USB_RESUME                7         
00105 //! USB Event: USB reset
00106 #define EVT_USB_RESET                 8         
00107 //! USB Event: USB setup received
00108 #define EVT_USB_SETUP_RX              9         
00109 //! @}
00110 
00111 //! \name Standard requests defines
00112 //! @{
00113 
00114    #define GET_STATUS                     0x00
00115    #define GET_DEVICE                     0x01
00116    #define CLEAR_FEATURE                  0x01           //!< see FEATURES below
00117    #define GET_STRING                     0x03
00118    #define SET_FEATURE                    0x03           //!< see FEATURES below
00119    #define SET_ADDRESS                    0x05
00120    #define GET_DESCRIPTOR                 0x06
00121    #define SET_DESCRIPTOR                 0x07
00122    #define GET_CONFIGURATION              0x08
00123    #define SET_CONFIGURATION              0x09
00124    #define GET_INTERFACE                  0x0A
00125    #define SET_INTERFACE                  0x0B
00126    #define SYNCH_FRAME                    0x0C
00127 
00128    #define GET_DEVICE_DESCRIPTOR             1
00129    #define GET_CONFIGURATION_DESCRIPTOR      4
00130 
00131    #define REQUEST_DEVICE_STATUS          0x80
00132    #define REQUEST_INTERFACE_STATUS       0x81
00133    #define REQUEST_ENDPOINT_STATUS        0x82
00134    #define ZERO_TYPE                      0x00
00135    #define INTERFACE_TYPE                 0x01
00136    #define ENDPOINT_TYPE                  0x02
00137 
00138                      // Descriptor Types
00139    #define DEVICE_DESCRIPTOR                     0x01
00140    #define CONFIGURATION_DESCRIPTOR              0x02
00141    #define STRING_DESCRIPTOR                     0x03
00142    #define INTERFACE_DESCRIPTOR                  0x04
00143    #define ENDPOINT_DESCRIPTOR                   0x05
00144    #define DEVICE_QUALIFIER_DESCRIPTOR           0x06
00145    #define OTHER_SPEED_CONFIGURATION_DESCRIPTOR  0x07
00146 
00147 
00148 
00149                     // Standard Features
00150    #define FEATURE_DEVICE_REMOTE_WAKEUP   0x01
00151    #define FEATURE_ENDPOINT_HALT          0x00
00152 
00153    #define TEST_J                         0x01
00154    #define TEST_K                         0x02
00155    #define TEST_SEO_NAK                   0x03
00156    #define TEST_PACKET                    0x04
00157    #define TEST_FORCE_ENABLE              0x05
00158 
00159 
00160                      // Device Status
00161    #define BUS_POWERED                       0
00162    #define SELF_POWERED                      1
00163 
00164    //! @}
00165 
00166 #define USB_MODE_UNDEFINED            0x00
00167 #define USB_MODE_HOST                 0x01
00168 #define USB_MODE_DEVICE               0x02
00169 
00170 
00171 typedef enum {
00172         rndis_only,
00173         rndis_debug,
00174         mass_storage,
00175         eem
00176 } usb_mode_t;
00177 
00178 //_____ D E C L A R A T I O N S ____________________________________________
00179 
00180 extern volatile uint16_t g_usb_event;
00181 extern uint8_t g_usb_mode;
00182 
00183 
00184 PROCESS_NAME(usb_process);
00185 
00186 extern volatile uint8_t private_sof_counter;
00187 
00188 void usb_start_device  (void);
00189 void usb_device_task   (void);
00190 
00191 
00192 //! @}
00193 
00194 #endif /* _USB_TASK_H_ */
00195 
00196 /** @} */

Generated on Mon Apr 11 14:23:36 2011 for Contiki 2.5 by  doxygen 1.6.1