usb_host_enum.h

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00017 
00018 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00019  *
00020  * Redistribution and use in source and binary forms, with or without
00021  * modification, are permitted provided that the following conditions are met:
00022  *
00023  * 1. Redistributions of source code must retain the above copyright notice,
00024  * this list of conditions and the following disclaimer.
00025  *
00026  * 2. Redistributions in binary form must reproduce the above copyright notice,
00027  * this list of conditions and the following disclaimer in the documentation
00028  * and/or other materials provided with the distribution.
00029  *
00030  * 3. The name of Atmel may not be used to endorse or promote products derived
00031  * from this software without specific prior written permission.
00032  *
00033  * 4. This software may only be redistributed and used in connection with an Atmel
00034  * AVR product.
00035  *
00036  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00038  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00039  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00040  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00041  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00042  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00044  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00045  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00046  */
00047 
00048 #ifndef _USB_HOST_ENUM_H_
00049 #define _USB_HOST_ENUM_H_
00050 
00051 //_____ I N C L U D E S ____________________________________________________
00052 
00053 
00054 #include "modules/usb/usb_task.h"
00055 
00056 //_____ M A C R O S ________________________________________________________
00057 
00058 #ifndef SIZEOF_DATA_STAGE
00059    #error SIZEOF_DATA_STAGE should be defined in conf_usb.h
00060 #endif
00061 
00062 #if (SIZEOF_DATA_STAGE<0xFF)     
00063    #define T_DESC_OFFSET   U8    
00064 #else
00065    #define T_DESC_OFFSET   U16   
00066 #endif
00067 
00068 #ifndef MAX_EP_PER_INTERFACE
00069    #define MAX_EP_PER_INTERFACE 4
00070 #endif
00071 
00072 
00073 //_____ S T A N D A R D    D E F I N I T I O N S ___________________________
00074 
00077 
00079 typedef struct
00080 {
00081    U8      bmRequestType;        
00082    U8      bRequest;             
00083    U16     wValue;               
00084    U16     wIndex;               
00085    U16     wLength;              
00086    U8      uncomplete_read;      
00087 }  S_usb_setup_data;
00088 
00089 typedef struct
00090 {
00091    U8 ep_addr;
00092    U8 pipe_number;
00093    U8 ep_size;
00094    U8 ep_type;
00095 } S_usb_endpoint;
00096 
00097 typedef struct
00098 {
00099    U8  interface_nb;
00100    U8  altset_nb;
00101    U16 class;
00102    U16 subclass;
00103    U16 protocol;
00104    U8  nb_ep;
00105    S_usb_endpoint ep[MAX_EP_PER_INTERFACE];
00106 } S_usb_interface;
00107 
00108 typedef struct
00109 {
00110    U8 device_address;
00111    U8 ep_ctrl_size;
00112    U8 hub_port_nb;
00113    U8 parent_hub_number;
00114    U8 nb_interface;
00115    U16 pid;
00116    U16 vid;
00117    U8 bmattributes;
00118    U8 maxpower;
00119    S_usb_interface interface[MAX_INTERFACE_FOR_DEVICE];
00120 } S_usb_device;
00121 
00122 typedef struct
00123 {
00124    U8 nb_device;
00125    S_usb_device device[MAX_DEVICE_IN_USB_TREE];
00126 } S_usb_tree;
00127 
00128 
00129 #if (USB_HUB_SUPPORT==ENABLE)
00130 extern U8 user_periodic_pipe;
00131 #endif
00132 extern  S_usb_tree usb_tree;
00133 extern  S_usb_setup_data usb_request;
00134 extern  U8 data_stage[SIZEOF_DATA_STAGE];
00135 extern  U8 device_status;
00136 
00137 #define REQUEST_TYPE_POS         0
00138 #define REQUEST_POS              1
00139 #define VALUE_HIGH_POS           2
00140 #define VALUE_LOW_POS            3
00141 #define INDEX_HIGH_POS           4
00142 #define INDEX_LOW_POS            5
00143 #define LENGTH_HIGH_POS          6
00144 #define LENGTH_LOW_POS           7
00145 #define UNCOMPLETE_READ_POS      8
00146 #define DATA_ADDR_HIGH_POS       9
00147 #define DATA_ADDR_LOW_POS       10
00148 
00149 #define CONTROL_GOOD             0
00150 #define CONTROL_DATA_TOGGLE   0x01
00151 #define CONTROL_DATA_PID      0x02
00152 #define CONTROL_PID           0x04
00153 #define CONTROL_TIMEOUT       0x08
00154 #define CONTROL_CRC16         0x10
00155 #define CONTROL_STALL         0x20
00156 #define CONTROL_NO_DEVICE     0x40
00157 
00158 
00160 #define OFFSET_FIELD_MAXPACKETSIZE     7
00161 #define OFFSET_FIELD_MSB_VID           9
00162 #define OFFSET_FIELD_LSB_VID           8
00163 #define OFFSET_FIELD_MSB_PID           11
00164 #define OFFSET_FIELD_LSB_PID           10
00165 
00166 #define OFFSET_DESCRIPTOR_LENGHT       0
00167 #define OFFSET_FIELD_DESCRIPTOR_TYPE   1
00168 #define OFFSET_FIELD_TOTAL_LENGHT      2
00169 #define OFFSET_FIELD_BMATTRIBUTES      7
00170 #define OFFSET_FIELD_MAXPOWER          8
00171 
00172 
00173 
00175 #define OFFSET_FIELD_NB_INTERFACE      4
00176 #define OFFSET_FIELD_CLASS             5
00177 #define OFFSET_FIELD_SUB_CLASS         6
00178 #define OFFSET_FIELD_PROTOCOL          7
00179 
00180 #define OFFSET_FIELD_INTERFACE_NB      2
00181 #define OFFSET_FIELD_ALT               3
00182 #define OFFSET_FIELS_NB_OF_EP          4
00183 
00184 #define OFFSET_FIELD_EP_ADDR           2
00185 #define OFFSET_FIELD_EP_TYPE           3
00186 #define OFFSET_FIELD_EP_SIZE           4
00187 #define OFFSET_FIELD_EP_INTERVAL       6
00188 
00189 #define HOST_FALSE                     0
00190 #define HOST_TRUE                      1
00191 
00192 U8 host_send_control(U8*);
00193 
00203 #define host_clear_endpoint_feature(ep)   (usb_request.bmRequestType = USB_SETUP_SET_STAND_ENDPOINT,\
00204                                            usb_request.bRequest      = SETUP_CLEAR_FEATURE,\
00205                                            usb_request.wValue        = FEATURE_ENDPOINT_HALT << 8,\
00206                                            usb_request.wIndex        = ep,\
00207                                            usb_request.wLength       = 0,\
00208                                            usb_request.uncomplete_read = FALSE,\
00209                                            host_send_control(data_stage))
00210 
00219 #define host_get_configuration()          (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00220                                            usb_request.bRequest      = SETUP_GET_CONFIGURATION,\
00221                                            usb_request.wValue        = 0,\
00222                                            usb_request.wIndex        = 0,\
00223                                            usb_request.wLength       = 1,\
00224                                            usb_request.uncomplete_read = FALSE,\
00225                                            host_send_control(data_stage))
00226 
00235 #define host_set_configuration(cfg_nb)    (usb_request.bmRequestType = USB_SETUP_SET_STAND_DEVICE,\
00236                                            usb_request.bRequest      = SETUP_SET_CONFIGURATION,\
00237                                            usb_request.wValue        = cfg_nb,\
00238                                            usb_request.wIndex        = 0,\
00239                                            usb_request.wLength       = 0,\
00240                                            usb_request.uncomplete_read = FALSE,\
00241                                            host_send_control(data_stage))
00242 
00253 #define host_set_interface(interface_nb,alt_setting)        (usb_request.bmRequestType = USB_SETUP_SET_STAND_DEVICE,\
00254                                            usb_request.bRequest      = USB_SETUP_SET_STAND_INTERFACE,\
00255                                            usb_request.wValue        = alt_setting,\
00256                                            usb_request.wIndex        = interface_nb,\
00257                                            usb_request.wLength       = 0,\
00258                                            usb_request.uncomplete_read = FALSE,\
00259                                            host_send_control(data_stage))
00260 
00274 #define host_get_device_descriptor_uncomplete()  (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00275                                            usb_request.bRequest      = SETUP_GET_DESCRIPTOR,\
00276                                            usb_request.wValue        = DESCRIPTOR_DEVICE << 8,\
00277                                            usb_request.wIndex        = 0,\
00278                                            usb_request.wLength       = 64,\
00279                                            usb_request.uncomplete_read = TRUE,\
00280                                            host_send_control(data_stage))
00281 
00294 #define host_get_device_descriptor()      (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00295                                            usb_request.bRequest      = SETUP_GET_DESCRIPTOR,\
00296                                            usb_request.wValue        = DESCRIPTOR_DEVICE << 8,\
00297                                            usb_request.wIndex        = 0,\
00298                                            usb_request.wLength       = 18,\
00299                                            usb_request.uncomplete_read = FALSE,\
00300                                            host_send_control(data_stage))
00301 
00313 #define host_get_configuration_descriptor()  (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00314                                            usb_request.bRequest      = SETUP_GET_DESCRIPTOR,\
00315                                            usb_request.wValue        = DESCRIPTOR_CONFIGURATION << 8,\
00316                                            usb_request.wIndex        = 0,\
00317                                            usb_request.wLength       = 255,\
00318                                            usb_request.uncomplete_read = FALSE,\
00319                                            host_send_control(data_stage))
00320 
00321 #define host_get_descriptor_uncomplete()  (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00322                                            usb_request.bRequest      = SETUP_GET_DESCRIPTOR,\
00323                                            usb_request.wValue        = 0,\
00324                                            usb_request.wIndex        = 0,\
00325                                            usb_request.wLength       = 64,\
00326                                            usb_request.uncomplete_read = FALSE,\
00327                                            host_send_control(data_stage))
00328 
00339 #define host_set_address(addr)            (usb_request.bmRequestType = USB_SETUP_SET_STAND_DEVICE,\
00340                                            usb_request.bRequest      = SETUP_SET_ADDRESS,\
00341                                            usb_request.wValue        = (U16)addr,\
00342                                            usb_request.wIndex        = 0,\
00343                                            usb_request.wLength       = 0,\
00344                                            usb_request.uncomplete_read = FALSE,\
00345                                            host_send_control(data_stage))
00346 
00356 #define host_set_feature_remote_wakeup()   (usb_request.bmRequestType = USB_SETUP_SET_STAND_DEVICE,\
00357                                            usb_request.bRequest      = SETUP_SET_FEATURE,\
00358                                            usb_request.wValue        = 1,\
00359                                            usb_request.wIndex        = 1,\
00360                                            usb_request.wLength       = 0,\
00361                                            usb_request.uncomplete_read = FALSE,\
00362                                            host_send_control(data_stage))
00363 
00375 #define host_ms_get_max_lun()             (usb_request.bmRequestType = USB_SETUP_GET_CLASS_INTER,\
00376                                            usb_request.bRequest      = SETUP_MASS_STORAGE_GET_MAX_LUN,\
00377                                            usb_request.wValue        = 0,\
00378                                            usb_request.wIndex        = 0,\
00379                                            usb_request.wLength       = 1,\
00380                                            usb_request.uncomplete_read = FALSE,\
00381                                            host_send_control(data_stage))
00382 
00393 #define Get_VID()      (usb_tree.device[selected_device].vid)
00394 
00405 #define Get_PID()      (usb_tree.device[selected_device].pid)
00406 
00417 #define Get_ep0_size()      (usb_tree.device[selected_device].ep_ctrl_size)
00418 
00429 #define Get_maxpower()      (usb_tree.device[selected_device].maxpower)
00430 
00438 #define Get_class(s_interface)      (usb_tree.device[selected_device].interface[s_interface].class)
00439 
00447 #define Get_subclass(s_interface)      (usb_tree.device[selected_device].interface[s_interface].subclass)
00448 
00456 #define Get_protocol(s_interface)      (usb_tree.device[selected_device].interface[s_interface].protocol)
00457 
00467 #define Get_ep_addr(s_interface,n_ep)      (usb_tree.device[selected_device].interface[s_interface].ep[n_ep].ep_addr)
00468 
00477 #define Get_nb_ep(s_interface)      (usb_tree.device[selected_device].interface[s_interface].nb_ep)
00478 
00487 #define Get_alts_s(s_interface)      (usb_tree.device[selected_device].interface[s_interface].altset_nb)
00488 
00497 #define Get_interface_number(s_interface)      (usb_tree.device[selected_device].interface[s_interface].interface_nb)
00498 
00506 #define Get_nb_supported_interface()      (usb_tree.device[selected_device].nb_interface)
00507 
00515 #define Is_device_self_powered()      ((usb_tree.device[selected_device].bmattributes & USB_CONFIG_ATTRIBUTES_SELFPOWERED) ? TRUE : FALSE)
00516 
00524 #define Get_nb_device()      (usb_tree.nb_device)
00525 
00533 #define Is_device_supports_remote_wakeup()  ((usb_tree.device[selected_device].bmattributes & USB_CONFIG_ATTRIBUTES_REMOTEWAKEUP) ? TRUE : FALSE)
00534 
00535 #if (USB_HUB_SUPPORT==ENABLE && USER_PERIODIC_PIPE==ENABLE)
00536    #define Host_select_device(i)   (host_select_device(i))
00537 #else
00538    #define Host_select_device(i)   (selected_device=i, Host_configure_address(usb_tree.device[i].device_address))
00539 #endif
00540 
00541 #define Host_get_nb_device()    ((U16)(usb_tree.nb_device))
00542 
00543 
00544 extern U8 selected_device;
00545 extern U8 ctrl_pipe_size;
00546 
00547 U8 host_check_VID_PID(void);
00548 U8 host_check_class  (void);
00549 U8 host_auto_configure_endpoint();
00550 T_DESC_OFFSET get_interface_descriptor_offset(U8 interface, U8 alt);
00551 U8 host_get_hwd_pipe_nb(U8 ep_addr);
00552 void init_usb_tree(void);
00553 void remove_device_entry(U8 device_index);
00554 void host_select_device(U8 i);
00555 
00556 #if (USB_HUB_SUPPORT==ENABLE && USER_PERIODIC_PIPE==ENABLE)
00557 void freeze_user_periodic_pipe(void);
00558 void unfreeze_user_periodic_pipe(void);
00559 #endif
00560 
00562 
00563 #endif  // _USB_HOST_ENUM_H_
00564 

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