usb_task.h

Go to the documentation of this file.
00001 
00016 #ifndef _USB_TASK_H_
00017 #define _USB_TASK_H_
00018 
00021 
00022 //_____ I N C L U D E S ____________________________________________________
00023 
00024 
00025 //_____ M A C R O S ________________________________________________________
00026 
00030 #define Usb_send_event(x)               (g_usb_event |= (1<<x))
00031 #define Usb_ack_event(x)                (g_usb_event &= ~(1<<x))
00032 #define Usb_clear_all_event()           (g_usb_event = 0)
00033 #define Is_usb_event(x)                 ((g_usb_event & (1<<x)) ? TRUE : FALSE)
00034 #define Is_not_usb_event(x)             ((g_usb_event & (1<<x)) ? FALSE: TRUE)
00035 
00036 #define Is_host_emergency_exit()        (Is_usb_event(EVT_HOST_DISCONNECTION) || Is_usb_event(EVT_USB_DEVICE_FUNCTION))
00037 #define Is_usb_device()                 (g_usb_mode==USB_MODE_DEVICE ? TRUE : FALSE)
00038 #define Is_usb_host()                   (g_usb_mode==USB_MODE_HOST   ? TRUE : FALSE)
00039 
00040 #define Otg_send_event(x)               (g_otg_event |= (1<<x))
00041 #define Otg_ack_event(x)                (g_otg_event &= ~(1<<x))
00042 #define Otg_clear_all_event()           (g_otg_event = 0)
00043 #define Is_otg_event(x)                 ((g_otg_event & (1<<x)) ? TRUE : FALSE)
00044 #define Is_not_otg_event(x)             ((g_otg_event & (1<<x)) ? FALSE: TRUE)
00045 
00046 #define EVT_USB_POWERED               1         // USB plugged
00047 #define EVT_USB_UNPOWERED             2         // USB un-plugged
00048 #define EVT_USB_DEVICE_FUNCTION       3         // USB in device
00049 #define EVT_USB_HOST_FUNCTION         4         // USB in host
00050 #define EVT_USB_SUSPEND               5         // USB suspend
00051 #define EVT_USB_WAKE_UP               6         // USB wake up
00052 #define EVT_USB_RESUME                7         // USB resume
00053 #define EVT_USB_RESET                 8         // USB reset
00054 #define EVT_HOST_SOF                  9         // Host start of frame sent
00055 #define EVT_HOST_HWUP                 10        // Host wakeup detected
00056 #define EVT_HOST_DISCONNECTION        11        // The target device is disconnected
00057 #define EVT_HOST_REMOTE_WAKEUP        12        // Remote WakeUp has been received (Host)
00058 
00059 #define EVT_OTG_HNP_ERROR             1        // The HNP has failed (A has not responded)
00060 #define EVT_OTG_HNP_SUCCESS           2        // The HNP has succedeed
00061 #define EVT_OTG_SRP_RECEIVED          3        // A-Device received a SRP
00062 #define EVT_OTG_DEV_UNSUPPORTED       4        // An error occured while the device was enumerated
00063 #define EVT_OTG_DEVICE_CONNECTED      5        // B-Device has been configured
00065 
00068    #define GET_STATUS                     0x00
00069    #define GET_DEVICE                     0x01
00070    #define CLEAR_FEATURE                  0x01           
00071    #define GET_STRING                     0x03
00072    #define SET_FEATURE                    0x03           
00073    #define SET_ADDRESS                    0x05
00074    #define GET_DESCRIPTOR                 0x06
00075    #define SET_DESCRIPTOR                 0x07
00076    #define GET_CONFIGURATION              0x08
00077    #define SET_CONFIGURATION              0x09
00078    #define GET_INTERFACE                  0x0A
00079    #define SET_INTERFACE                  0x0B
00080    #define SYNCH_FRAME                    0x0C
00081 
00082    #define GET_DEVICE_DESCRIPTOR             1
00083    #define GET_CONFIGURATION_DESCRIPTOR      4
00084 
00085    #define REQUEST_DEVICE_STATUS          0x80
00086    #define REQUEST_INTERFACE_STATUS       0x81
00087    #define REQUEST_ENDPOINT_STATUS        0x82
00088    #define ZERO_TYPE                      0x00
00089    #define INTERFACE_TYPE                 0x01
00090    #define ENDPOINT_TYPE                  0x02
00091 
00092                      // Descriptor Types
00093    #define DEVICE_DESCRIPTOR                     0x01
00094    #define CONFIGURATION_DESCRIPTOR              0x02
00095    #define STRING_DESCRIPTOR                     0x03
00096    #define INTERFACE_DESCRIPTOR                  0x04
00097    #define ENDPOINT_DESCRIPTOR                   0x05
00098    #define DEVICE_QUALIFIER_DESCRIPTOR           0x06
00099    #define OTHER_SPEED_CONFIGURATION_DESCRIPTOR  0x07
00100    #define OTG_DESCRIPTOR                        0x09
00101 
00102 
00103                     // OTG descriptor
00104    #define OTG_DESCRIPTOR_bLength         0x03
00105    #define HNP_SUPPORT                    0x02
00106    #define SRP_SUPPORT                    0x01
00107 
00108                     // Standard Features
00109    #define FEATURE_DEVICE_REMOTE_WAKEUP   0x01
00110    #define FEATURE_ENDPOINT_HALT          0x00
00111 
00112    #define TEST_J                         0x01
00113    #define TEST_K                         0x02
00114    #define TEST_SEO_NAK                   0x03
00115    #define TEST_PACKET                    0x04
00116    #define TEST_FORCE_ENABLE              0x05
00117 
00118 
00119                      // Device Status
00120    #define BUS_POWERED                       0
00121    #define SELF_POWERED                      1
00122 
00124 
00125 #define USB_MODE_UNDEFINED            0x00
00126 #define USB_MODE_HOST                 0x01
00127 #define USB_MODE_DEVICE               0x02
00128 
00129 
00130 #define   VBUS_PULSE    1
00131 #define   DATA_PULSE    0
00132 
00133 #define   BDEV_HNP_NB_RETRY     3       // number of times that a B-Device retries a HNP with a failure as a result
00134                                         // after "n" failures, the "b_hnp_enable" feature is cancelled
00135 
00136 
00140 #define USER_RQST_SRP           0x01
00141 #define USER_RQST_SUSPEND       0x02
00142 #define USER_RQST_VBUS          0x04    // Vbus TOGGLE
00143 #define USER_RQST_HNP           0x08
00144 #define USER_RQST_RESUME        0x10
00145 #define USER_RQST_RESET         0x20
00146 #define USER_RQST_DISCONNECT    0x40
00147 
00148 // Ask for the B-PERIPH to generate a SRP
00149 #define Is_user_requested_srp()       (((otg_user_request&USER_RQST_SRP) != 0) ? TRUE : FALSE)
00150 #define Set_user_request_srp()        (otg_user_request |= USER_RQST_SRP)
00151 #define Ack_user_request_srp()        (otg_user_request &= ~USER_RQST_SRP)
00152 
00153 // Ask for the A-HOST to enter suspend
00154 #define Is_user_requested_suspend()   (((otg_user_request&USER_RQST_SUSPEND) != 0) ? TRUE : FALSE)
00155 #define Set_user_request_suspend()    (otg_user_request |= USER_RQST_SUSPEND)
00156 #define Ack_user_request_suspend()    (otg_user_request &= ~USER_RQST_SUSPEND)
00157 
00158 // Ask for the A-HOST to toggle Vbus
00159 #define Is_user_requested_vbus()      (((otg_user_request&USER_RQST_VBUS) != 0) ? TRUE : FALSE)
00160 #define Set_user_request_vbus()       (otg_user_request |= USER_RQST_VBUS)
00161 #define Ack_user_request_vbus()       (otg_user_request &= ~USER_RQST_VBUS)
00162 
00163 // Ask for an HNP initiation on both devices
00164 #define Is_user_requested_hnp()       (((otg_user_request&USER_RQST_HNP) != 0) ? TRUE : FALSE)
00165 #define Set_user_request_hnp()        (otg_user_request |= USER_RQST_HNP)
00166 #define Ack_user_request_hnp()        (otg_user_request &= ~USER_RQST_HNP)
00167 
00168 // Ask for the B-PERIPH or the A-PERIPH to disconnect from the bus
00169 #define Is_user_requested_disc()      (((otg_user_request&USER_RQST_DISCONNECT) != 0) ? TRUE : FALSE)
00170 #define Set_user_request_disc()       (otg_user_request |= USER_RQST_DISCONNECT)
00171 #define Ack_user_request_disc()       (otg_user_request &= ~USER_RQST_DISCONNECT)
00172 
00173 /* NOT USED */
00174 /*
00175 // Ask for the A-HOST to resume the bus or the B-PERIPH to send an upstream resume
00176 #define Is_user_requested_resume()    (((otg_user_request&USER_RQST_RESUME) != 0) ? TRUE : FALSE)
00177 #define Set_user_request_resume()     (otg_user_request |= USER_RQST_RESUME)
00178 #define Ack_user_request_resume()     (otg_user_request &= ~USER_RQST_RESUME)
00179 
00180 // Ask for the A-HOST to reset the bus
00181 #define Is_user_requested_reset()     (((otg_user_request&USER_RQST_RESET) != 0) ? TRUE : FALSE)
00182 #define Set_user_request_reset()      (otg_user_request |= USER_RQST_RESET)
00183 #define Ack_user_request_reset()      (otg_user_request &= ~USER_RQST_RESET)
00184 */
00185 
00186 #define Clear_all_user_request()      (otg_user_request = 0)
00187 
00188 
00199 #define Otg_timer_init()              (Timer16_select(OTG_USE_TIMER), Timer16_set_clock(TIMER16_CLKIO_BY_256), \
00200                                        Timer16_set_mode_output_a(TIMER16_COMP_MODE_NORMAL), \
00201                                        Timer16_set_waveform_mode(TIMER16_WGM_CTC_OCR), \
00202                                        Timer16_set_compare_a(62), Timer16_set_counter(0x0000), \
00203                                        Timer16_clear_compare_a_it(), Timer16_compare_a_it_enable())
00204 
00205 //_____ D E C L A R A T I O N S ____________________________________________
00206 
00207 extern volatile U16 g_usb_event;
00208 extern U8 g_usb_mode;
00209 extern U8 remote_wakeup_feature;
00210 
00224 void usb_task_init     (void);
00225 
00236 void usb_task          (void);
00237 
00238 extern volatile U8 private_sof_counter;
00239 
00240 
00248 extern volatile U8 otg_features_supported;
00249 extern U8 otg_user_request;
00250 
00251 extern volatile U16 g_otg_event;
00252 
00253 #if (OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION == ENABLED)
00254   extern U8 id_changed_to_host_event;
00255 #endif
00256 
00257 extern void otg_not_supported_device(void);
00258 
00259 #if (USB_OTG_FEATURE == ENABLED)
00267   #ifndef   OTG_COMPLIANCE_TRICKS
00268     #define OTG_COMPLIANCE_TRICKS                   DISABLED
00269   #endif
00270 
00277   #ifndef   OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION
00278     #define OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION    DISABLED
00279   #endif
00280 
00285   #ifndef   OTG_B_DEVICE_AUTORUN_HNP_IF_REQUIRED
00286     #define OTG_B_DEVICE_AUTORUN_HNP_IF_REQUIRED    ENABLED
00287   #endif
00288 
00292   #ifndef   OTG_RESET_LENGTH
00293     #define OTG_RESET_LENGTH                        1
00294   #endif
00295 #endif
00296 
00297 
00301 
00302 #define   MSG_DISPLAY_NODELAY     0xFFFF
00303 #define   OTG_TEMPO_1SEC          0x01F4  // 500 (x2ms)
00304 #define   OTG_TEMPO_2SEC          0x03E8  // 1000
00305 #define   OTG_TEMPO_3SEC          0x05DC  // 1500
00306 #define   OTG_TEMPO_4SEC          0x07D0  // 2000
00307 #define   OTR_TEMPO_5SEC          0x09C4  // 2500
00308 
00309 // These messages ID numbers must be used with the OTG messaging functions
00310 #define   OTGMSG_SRP_STARTED      1      // Event
00311 #define   OTGMSG_SRP_A_NO_RESP    2      // FAILURE msg
00312 #define   OTGMSG_A_RESPONDED      3      // Event
00313 #define   OTGMSG_CONNECTED_TO_A   4      // Event
00314 #define   OTGMSG_UNSUPPORTED      5      // FAILURE msg
00315 #define   OTGMSG_UNSUPPORTED_HUB  6      // FAILURE msg
00316 #define   OTGMSG_SRP_RECEIVED     7      // Event
00317 #define   OTGMSG_DEVICE_NO_RESP   8      // FAILURE msg
00318 #define   OTGMSG_VBUS_SURCHARGE   9      // Event
00319 
00320 // Messages definitions for OTG library, should not be used directly by user
00321 #define   OTGSTR_SRP_STARTED      "SRP Initiated     "  // Event
00322 #define   OTGSTR_SRP_A_NO_RESP    "A-Dev No Response "  // FAILURE
00323 #define   OTGSTR_A_RESPONDED      "A-Device Responded"  // Event
00324 #define   OTGSTR_CONNECTED_TO_A   "Connected to A-Dev"  // Event
00325 #define   OTGSTR_UNSUPPORTED      "Unsupported Device"  // FAILURE
00326 #define   OTGSTR_UNSUPPORTED_HUB  "Hub Unsuppported  "  // FAILURE
00327 #define   OTGSTR_SRP_RECEIVED     "SRP Received      "  // Event
00328 #define   OTGSTR_DEVICE_NO_RESP   "Device No Response"  // FAILURE
00329 #define   OTGSTR_VBUS_SURCHARGE   "VBUS OverCurrent !"  // Event
00330 
00331 extern U16 otg_msg_event_delay;
00332 extern U16 otg_msg_failure_delay;
00333 
00334 // Output messaging method choice (mode and functions defined in "conf_usb.h")
00335 #define     OTGMSG_NONE     0   // no messages displayed
00336 #define     OTGMSG_FAIL     1   // only failure messages displayed
00337 #define     OTGMSG_ALL      2   // all messages displayed
00338 
00339 #if (OTG_MESSAGING_OUTPUT == OTGMSG_ALL)            // ALL MESSAGES
00340   extern void Otg_messaging_init(void);
00341   extern void Otg_output_event_msg(U8);
00342   extern void Otg_output_failure_msg(U8);
00343   extern void Otg_output_event_clear(void);
00344   extern void Otg_output_failure_clear(void);
00346   #define   Otg_print_new_event_message(str,tm)     (Otg_output_event_msg(str), otg_msg_event_delay = tm)
00347   #define   Otg_clear_event_message()               Otg_output_event_clear()
00348   #define   Get_event_msg_delay()                   (otg_msg_event_delay)
00349   #define   Decrement_event_msg_delay()             (otg_msg_event_delay--)
00351   #define   Otg_print_new_failure_message(str,tm)   (Otg_output_failure_msg(str), otg_msg_failure_delay = tm)
00352   #define   Otg_clear_failure_message()             Otg_output_failure_clear()
00353   #define   Get_failure_msg_delay()                 (otg_msg_failure_delay)
00354   #define   Decrement_failure_msg_delay()           (otg_msg_failure_delay--)
00355 #elif (OTG_MESSAGING_OUTPUT == OTGMSG_FAIL)         // ONLY FAILURE MESSAGES (NEEDED FOR COMPLIANCE)
00356   extern void Otg_messaging_init(void);
00357   extern void Otg_output_failure_msg(U8);
00358   extern void Otg_output_failure_clear(void);
00359   #define   Otg_print_new_event_message(str,tm)     
00360   #define   Otg_clear_event_message()               
00361   #define   Get_event_msg_delay()                   
00362   #define   Decrement_event_msg_delay()             
00363   #define   Otg_print_new_failure_message(str,tm)   (Otg_output_failure_msg(str), otg_msg_failure_delay = tm)
00364   #define   Otg_clear_failure_message()             Otg_output_failure_clear()
00365   #define   Get_failure_msg_delay()                 (otg_msg_failure_delay)
00366   #define   Decrement_failure_msg_delay()           (otg_msg_failure_delay--)
00367 #else                                               // NOT OTG COMPLIANT
00368   #define   Otg_messaging_init()
00369   #define   Otg_print_new_event_message(str,tm)
00370   #define   Otg_clear_event_message()
00371   #define   Get_event_msg_delay()
00372   #define   Decrement_event_msg_delay()
00373   #define   Otg_print_new_failure_message(str,tm)
00374   #define   Otg_clear_failure_message()
00375   #define   Get_failure_msg_delay()
00376   #define   Decrement_failure_msg_delay()
00377 #endif
00379 
00380 #endif /* _USB_TASK_H_ */
00381 

Generated on Mon Feb 19 09:31:47 2007 for Atmel by  doxygen 1.5.1-p1