usb_host_enum.h

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00017 
00018 /* Copyright (c) 2007, 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  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00034  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00035  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00036  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00037  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00038  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00039  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00040  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00041  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00042  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00043  */
00044 
00045 #ifndef _USB_HOST_ENUM_H_
00046 #define _USB_HOST_ENUM_H_
00047 
00048 //_____ I N C L U D E S ____________________________________________________
00049 
00050 
00051 #include "modules/usb/usb_task.h"
00052 
00053 //_____ M A C R O S ________________________________________________________
00054 
00055 #ifndef SIZEOF_DATA_STAGE
00056    #error SIZEOF_DATA_STAGE should be defined in conf_usb.h
00057 #endif
00058 
00059 #if (SIZEOF_DATA_STAGE<0xFF)     
00060    #define T_DESC_OFFSET   U8    
00061 #else
00062    #define T_DESC_OFFSET   U16   
00063 #endif
00064 
00065 #ifndef MAX_EP_PER_INTERFACE
00066    #define MAX_EP_PER_INTERFACE 4
00067 #endif
00068 
00069 
00070 //_____ S T A N D A R D    D E F I N I T I O N S ___________________________
00071 
00074 
00076 typedef struct
00077 {
00078    U8      bmRequestType;        
00079    U8      bRequest;             
00080    U16     wValue;               
00081    U16     wIndex;               
00082    U16     wLength;              
00083    U8      uncomplete_read;      
00084 }  S_usb_setup_data;
00085 
00086 typedef struct
00087 {
00088    U8 ep_addr;
00089    U8 pipe_number;
00090    U8 ep_size;
00091    U8 ep_type;
00092 } S_usb_endpoint;
00093 
00094 typedef struct
00095 {
00096    U8  interface_nb;
00097    U8  altset_nb;
00098    U16 class;
00099    U16 subclass;
00100    U16 protocol;
00101    U8  nb_ep;
00102    S_usb_endpoint ep[MAX_EP_PER_INTERFACE];
00103 } S_usb_interface;
00104 
00105 typedef struct
00106 {
00107    U8 device_address;
00108    U8 ep_ctrl_size;
00109    U8 hub_port_nb;
00110    U8 parent_hub_number;
00111    U8 nb_interface;
00112    U16 pid;
00113    U16 vid;
00114    U8 bmattributes;
00115    U8 maxpower;
00116    S_usb_interface interface[MAX_INTERFACE_FOR_DEVICE];
00117 } S_usb_device;
00118 
00119 typedef struct
00120 {
00121    U8 nb_device;
00122    S_usb_device device[MAX_DEVICE_IN_USB_TREE];
00123 } S_usb_tree;
00124 
00125 
00126 #if (USB_HUB_SUPPORT==ENABLE)
00127 extern U8 user_periodic_pipe;
00128 #endif
00129 extern  S_usb_tree usb_tree;
00130 extern  S_usb_setup_data usb_request;
00131 extern  U8 data_stage[SIZEOF_DATA_STAGE];
00132 extern  U8 device_status;
00133 
00134 #define REQUEST_TYPE_POS         0
00135 #define REQUEST_POS              1
00136 #define VALUE_HIGH_POS           2
00137 #define VALUE_LOW_POS            3
00138 #define INDEX_HIGH_POS           4
00139 #define INDEX_LOW_POS            5
00140 #define LENGTH_HIGH_POS          6
00141 #define LENGTH_LOW_POS           7
00142 #define UNCOMPLETE_READ_POS      8
00143 #define DATA_ADDR_HIGH_POS       9
00144 #define DATA_ADDR_LOW_POS       10
00145 
00146 #define CONTROL_GOOD             0
00147 #define CONTROL_DATA_TOGGLE   0x01
00148 #define CONTROL_DATA_PID      0x02
00149 #define CONTROL_PID           0x04
00150 #define CONTROL_TIMEOUT       0x08
00151 #define CONTROL_CRC16         0x10
00152 #define CONTROL_STALL         0x20
00153 #define CONTROL_NO_DEVICE     0x40
00154 
00155 
00157 #define OFFSET_FIELD_MAXPACKETSIZE     7
00158 #define OFFSET_FIELD_MSB_VID           9
00159 #define OFFSET_FIELD_LSB_VID           8
00160 #define OFFSET_FIELD_MSB_PID           11
00161 #define OFFSET_FIELD_LSB_PID           10
00162 
00163 #define OFFSET_DESCRIPTOR_LENGHT       0
00164 #define OFFSET_FIELD_DESCRIPTOR_TYPE   1
00165 #define OFFSET_FIELD_TOTAL_LENGHT      2
00166 #define OFFSET_FIELD_BMATTRIBUTES      7
00167 #define OFFSET_FIELD_MAXPOWER          8
00168 
00169 
00170 
00172 #define OFFSET_FIELD_NB_INTERFACE      4
00173 #define OFFSET_FIELD_CLASS             5
00174 #define OFFSET_FIELD_SUB_CLASS         6
00175 #define OFFSET_FIELD_PROTOCOL          7
00176 
00177 #define OFFSET_FIELD_INTERFACE_NB      2
00178 #define OFFSET_FIELD_ALT               3
00179 #define OFFSET_FIELS_NB_OF_EP          4
00180 
00181 #define OFFSET_FIELD_EP_ADDR           2
00182 #define OFFSET_FIELD_EP_TYPE           3
00183 #define OFFSET_FIELD_EP_SIZE           4
00184 #define OFFSET_FIELD_EP_INTERVAL       6
00185 
00186 #define HOST_FALSE                     0
00187 #define HOST_TRUE                      1
00188 
00189 U8 host_send_control(U8*);
00190 
00200 #define host_clear_endpoint_feature(ep)   (usb_request.bmRequestType = USB_SETUP_SET_STAND_ENDPOINT,\
00201                                            usb_request.bRequest      = SETUP_CLEAR_FEATURE,\
00202                                            usb_request.wValue        = FEATURE_ENDPOINT_HALT << 8,\
00203                                            usb_request.wIndex        = ep,\
00204                                            usb_request.wLength       = 0,\
00205                                            usb_request.uncomplete_read = FALSE,\
00206                                            host_send_control(data_stage))
00207 
00216 #define host_get_configuration()          (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00217                                            usb_request.bRequest      = SETUP_GET_CONFIGURATION,\
00218                                            usb_request.wValue        = 0,\
00219                                            usb_request.wIndex        = 0,\
00220                                            usb_request.wLength       = 1,\
00221                                            usb_request.uncomplete_read = FALSE,\
00222                                            host_send_control(data_stage))
00223 
00232 #define host_set_configuration(cfg_nb)    (usb_request.bmRequestType = USB_SETUP_SET_STAND_DEVICE,\
00233                                            usb_request.bRequest      = SETUP_SET_CONFIGURATION,\
00234                                            usb_request.wValue        = cfg_nb,\
00235                                            usb_request.wIndex        = 0,\
00236                                            usb_request.wLength       = 0,\
00237                                            usb_request.uncomplete_read = FALSE,\
00238                                            host_send_control(data_stage))
00239 
00250 #define host_set_interface(interface_nb,alt_setting)        (usb_request.bmRequestType = USB_SETUP_SET_STAND_DEVICE,\
00251                                            usb_request.bRequest      = USB_SETUP_SET_STAND_INTERFACE,\
00252                                            usb_request.wValue        = alt_setting,\
00253                                            usb_request.wIndex        = interface_nb,\
00254                                            usb_request.wLength       = 0,\
00255                                            usb_request.uncomplete_read = FALSE,\
00256                                            host_send_control(data_stage))
00257 
00271 #define host_get_device_descriptor_uncomplete()  (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00272                                            usb_request.bRequest      = SETUP_GET_DESCRIPTOR,\
00273                                            usb_request.wValue        = DESCRIPTOR_DEVICE << 8,\
00274                                            usb_request.wIndex        = 0,\
00275                                            usb_request.wLength       = 64,\
00276                                            usb_request.uncomplete_read = TRUE,\
00277                                            host_send_control(data_stage))
00278 
00291 #define host_get_device_descriptor()      (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00292                                            usb_request.bRequest      = SETUP_GET_DESCRIPTOR,\
00293                                            usb_request.wValue        = DESCRIPTOR_DEVICE << 8,\
00294                                            usb_request.wIndex        = 0,\
00295                                            usb_request.wLength       = 18,\
00296                                            usb_request.uncomplete_read = FALSE,\
00297                                            host_send_control(data_stage))
00298 
00310 #define host_get_configuration_descriptor()  (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00311                                            usb_request.bRequest      = SETUP_GET_DESCRIPTOR,\
00312                                            usb_request.wValue        = DESCRIPTOR_CONFIGURATION << 8,\
00313                                            usb_request.wIndex        = 0,\
00314                                            usb_request.wLength       = 255,\
00315                                            usb_request.uncomplete_read = FALSE,\
00316                                            host_send_control(data_stage))
00317 
00318 #define host_get_descriptor_uncomplete()  (usb_request.bmRequestType = USB_SETUP_GET_STAND_DEVICE,\
00319                                            usb_request.bRequest      = SETUP_GET_DESCRIPTOR,\
00320                                            usb_request.wValue        = 0,\
00321                                            usb_request.wIndex        = 0,\
00322                                            usb_request.wLength       = 64,\
00323                                            usb_request.uncomplete_read = FALSE,\
00324                                            host_send_control(data_stage))
00325 
00336 #define host_set_address(addr)            (usb_request.bmRequestType = USB_SETUP_SET_STAND_DEVICE,\
00337                                            usb_request.bRequest      = SETUP_SET_ADDRESS,\
00338                                            usb_request.wValue        = (U16)addr,\
00339                                            usb_request.wIndex        = 0,\
00340                                            usb_request.wLength       = 0,\
00341                                            usb_request.uncomplete_read = FALSE,\
00342                                            host_send_control(data_stage))
00343 
00353 #define host_set_feature_remote_wakeup()   (usb_request.bmRequestType = USB_SETUP_SET_STAND_DEVICE,\
00354                                            usb_request.bRequest      = SETUP_SET_FEATURE,\
00355                                            usb_request.wValue        = 1,\
00356                                            usb_request.wIndex        = 1,\
00357                                            usb_request.wLength       = 0,\
00358                                            usb_request.uncomplete_read = FALSE,\
00359                                            host_send_control(data_stage))
00360 
00372 #define host_ms_get_max_lun()             (usb_request.bmRequestType = USB_SETUP_GET_CLASS_INTER,\
00373                                            usb_request.bRequest      = SETUP_MASS_STORAGE_GET_MAX_LUN,\
00374                                            usb_request.wValue        = 0,\
00375                                            usb_request.wIndex        = 0,\
00376                                            usb_request.wLength       = 1,\
00377                                            usb_request.uncomplete_read = FALSE,\
00378                                            host_send_control(data_stage))
00379 
00390 #define Get_VID()      (usb_tree.device[selected_device].vid)
00391 
00402 #define Get_PID()      (usb_tree.device[selected_device].pid)
00403 
00414 #define Get_ep0_size()      (usb_tree.device[selected_device].ep_ctrl_size)
00415 
00426 #define Get_maxpower()      (usb_tree.device[selected_device].maxpower)
00427 
00435 #define Get_class(s_interface)      (usb_tree.device[selected_device].interface[s_interface].class)
00436 
00444 #define Get_subclass(s_interface)      (usb_tree.device[selected_device].interface[s_interface].subclass)
00445 
00453 #define Get_protocol(s_interface)      (usb_tree.device[selected_device].interface[s_interface].protocol)
00454 
00464 #define Get_ep_addr(s_interface,n_ep)      (usb_tree.device[selected_device].interface[s_interface].ep[n_ep].ep_addr)
00465 
00474 #define Get_nb_ep(s_interface)      (usb_tree.device[selected_device].interface[s_interface].nb_ep)
00475 
00484 #define Get_alts_s(s_interface)      (usb_tree.device[selected_device].interface[s_interface].altset_nb)
00485 
00494 #define Get_interface_number(s_interface)      (usb_tree.device[selected_device].interface[s_interface].interface_nb)
00495 
00503 #define Get_nb_supported_interface()      (usb_tree.device[selected_device].nb_interface)
00504 
00512 #define Is_device_self_powered()      ((usb_tree.device[selected_device].bmattributes & USB_CONFIG_ATTRIBUTES_SELFPOWERED) ? TRUE : FALSE)
00513 
00521 #define Get_nb_device()      (usb_tree.nb_device)
00522 
00530 #define Is_device_supports_remote_wakeup()  ((usb_tree.device[selected_device].bmattributes & USB_CONFIG_ATTRIBUTES_REMOTEWAKEUP) ? TRUE : FALSE)
00531 
00532 #if (USB_HUB_SUPPORT==ENABLE && USER_PERIODIC_PIPE==ENABLE)
00533    #define Host_select_device(i)   (host_select_device(i))
00534 #else
00535    #define Host_select_device(i)   (selected_device=i, Host_configure_address(usb_tree.device[i].device_address))
00536 #endif
00537 
00538 #define Host_get_nb_device()    ((U16)(usb_tree.nb_device))
00539 
00540 
00541 extern U8 selected_device;
00542 extern U8 ctrl_pipe_size;
00543 
00544 U8 host_check_VID_PID(void);
00545 U8 host_check_class  (void);
00546 U8 host_auto_configure_endpoint();
00547 T_DESC_OFFSET get_interface_descriptor_offset(U8 interface, U8 alt);
00548 U8 host_get_hwd_pipe_nb(U8 ep_addr);
00549 void init_usb_tree(void);
00550 void remove_device_entry(U8 device_index);
00551 void host_select_device(U8 i);
00552 
00553 #if (USB_HUB_SUPPORT==ENABLE && USER_PERIODIC_PIPE==ENABLE)
00554 void freeze_user_periodic_pipe(void);
00555 void unfreeze_user_periodic_pipe(void);
00556 #endif
00557 
00559 
00560 #endif  // _USB_HOST_ENUM_H_
00561 

Generated on Mon Nov 3 10:08:24 2008 for ATMEL by  doxygen 1.5.3