usb_task.h

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * 1. Redistributions of source code must retain the above copyright notice,
00020  * this list of conditions and the following disclaimer.
00021  *
00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
00023  * this list of conditions and the following disclaimer in the documentation
00024  * and/or other materials provided with the distribution.
00025  *
00026  * 3. The name of Atmel may not be used to endorse or promote products derived
00027  * from this software without specific prior written permission.
00028  *
00029  * 4. This software may only be redistributed and used in connection with an Atmel
00030  * AVR product.
00031  *
00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00042  */
00043 
00044 #ifndef _USB_TASK_H_
00045 #define _USB_TASK_H_
00046 
00047 #include "modules/usb/usb_commun.h"
00048 
00051 
00052 //_____ I N C L U D E S ____________________________________________________
00053 
00054 
00055 //_____ M A C R O S ________________________________________________________
00056 
00060 #define Usb_send_event(x)               (g_usb_event |= (1<<x))
00061 #define Usb_ack_event(x)                (g_usb_event &= ~(1<<x))
00062 #define Usb_clear_all_event()           (g_usb_event = 0)
00063 #define Is_usb_event(x)                 ((g_usb_event & (1<<x)) ? TRUE : FALSE)
00064 #define Is_not_usb_event(x)             ((g_usb_event & (1<<x)) ? FALSE: TRUE)
00065 #define Is_host_emergency_exit()        (Is_usb_id_device()||(device_state==DEVICE_DISCONNECTED))
00066 #define Is_usb_device()                 (g_usb_mode==USB_MODE_DEVICE ? TRUE : FALSE)
00067 #define Is_usb_host()                   (g_usb_mode==USB_MODE_HOST   ? TRUE : FALSE)
00068 
00069 #define Otg_send_event(x)               (g_otg_event |= (1<<x))
00070 #define Otg_ack_event(x)                (g_otg_event &= ~(1<<x))
00071 #define Otg_clear_all_event()           (g_otg_event = 0)
00072 #define Is_otg_event(x)                 ((g_otg_event & (1<<x)) ? TRUE : FALSE)
00073 #define Is_not_otg_event(x)             ((g_otg_event & (1<<x)) ? FALSE: TRUE)
00074 
00075 #define EVT_USB_POWERED               1         // USB plugged
00076 #define EVT_USB_UNPOWERED             2         // USB un-plugged
00077 #define EVT_USB_DEVICE_FUNCTION       3         // USB in device
00078 #define EVT_USB_HOST_FUNCTION         4         // USB in host
00079 #define EVT_USB_SUSPEND               5         // USB suspend
00080 #define EVT_USB_WAKE_UP               6         // USB wake up
00081 #define EVT_USB_RESUME                7         // USB resume
00082 #define EVT_USB_RESET                 8         // USB reset
00083 #define EVT_HOST_SOF                  9         // Host start of frame sent
00084 #define EVT_HOST_HWUP                 10        // Host wakeup detected
00085 #define EVT_HOST_DISCONNECTION        11        // The target device is disconnected
00086 #define EVT_HOST_REMOTE_WAKEUP        12        // Remote WakeUp has been received (Host)
00087 
00088 #define EVT_OTG_HNP_ERROR             1        // The HNP has failed (A has not responded)
00089 #define EVT_OTG_HNP_SUCCESS           2        // The HNP has succedeed
00090 #define EVT_OTG_SRP_RECEIVED          3        // A-Device received a SRP
00091 #define EVT_OTG_DEV_UNSUPPORTED       4        // An error occured while the device was enumerated
00092 #define EVT_OTG_DEVICE_CONNECTED      5        // B-Device has been configured
00094 
00095 #define USB_MODE_UNDEFINED            0x00
00096 #define USB_MODE_HOST                 0x01
00097 #define USB_MODE_DEVICE               0x02
00098 
00099 
00100 #define   VBUS_PULSE    1
00101 #define   DATA_PULSE    0
00102 
00103 #define   BDEV_HNP_NB_RETRY     3       // number of times that a B-Device retries a HNP with a failure as a result
00104                                         // after "n" failures, the "b_hnp_enable" feature is cancelled
00105 
00106 
00110 #define USER_RQST_SRP           0x01
00111 #define USER_RQST_SUSPEND       0x02
00112 #define USER_RQST_VBUS          0x04    // Vbus TOGGLE
00113 #define USER_RQST_HNP           0x08
00114 #define USER_RQST_RESUME        0x10
00115 #define USER_RQST_RESET         0x20
00116 #define USER_RQST_DISCONNECT    0x40
00117 
00118 // Ask for the B-PERIPH to generate a SRP
00119 #define Is_user_requested_srp()       (((otg_user_request&USER_RQST_SRP) != 0) ? TRUE : FALSE)
00120 #define Set_user_request_srp()        (otg_user_request |= USER_RQST_SRP)
00121 #define Ack_user_request_srp()        (otg_user_request &= ~USER_RQST_SRP)
00122 
00123 // Ask for the A-HOST to enter suspend
00124 #define Is_user_requested_suspend()   (((otg_user_request&USER_RQST_SUSPEND) != 0) ? TRUE : FALSE)
00125 #define Set_user_request_suspend()    (otg_user_request |= USER_RQST_SUSPEND)
00126 #define Ack_user_request_suspend()    (otg_user_request &= ~USER_RQST_SUSPEND)
00127 
00128 // Ask for the A-HOST to toggle Vbus
00129 #define Is_user_requested_vbus()      (((otg_user_request&USER_RQST_VBUS) != 0) ? TRUE : FALSE)
00130 #define Set_user_request_vbus()       (otg_user_request |= USER_RQST_VBUS)
00131 #define Ack_user_request_vbus()       (otg_user_request &= ~USER_RQST_VBUS)
00132 
00133 // Ask for an HNP initiation on both devices
00134 #define Is_user_requested_hnp()       (((otg_user_request&USER_RQST_HNP) != 0) ? TRUE : FALSE)
00135 #define Set_user_request_hnp()        (otg_user_request |= USER_RQST_HNP)
00136 #define Ack_user_request_hnp()        (otg_user_request &= ~USER_RQST_HNP)
00137 
00138 // Ask for the B-PERIPH or the A-PERIPH to disconnect from the bus
00139 #define Is_user_requested_disc()      (((otg_user_request&USER_RQST_DISCONNECT) != 0) ? TRUE : FALSE)
00140 #define Set_user_request_disc()       (otg_user_request |= USER_RQST_DISCONNECT)
00141 #define Ack_user_request_disc()       (otg_user_request &= ~USER_RQST_DISCONNECT)
00142 
00143 /* NOT USED */
00144 /*
00145 // Ask for the A-HOST to resume the bus or the B-PERIPH to send an upstream resume
00146 #define Is_user_requested_resume()    (((otg_user_request&USER_RQST_RESUME) != 0) ? TRUE : FALSE)
00147 #define Set_user_request_resume()     (otg_user_request |= USER_RQST_RESUME)
00148 #define Ack_user_request_resume()     (otg_user_request &= ~USER_RQST_RESUME)
00149 
00150 // Ask for the A-HOST to reset the bus
00151 #define Is_user_requested_reset()     (((otg_user_request&USER_RQST_RESET) != 0) ? TRUE : FALSE)
00152 #define Set_user_request_reset()      (otg_user_request |= USER_RQST_RESET)
00153 #define Ack_user_request_reset()      (otg_user_request &= ~USER_RQST_RESET)
00154 */
00155 
00156 #define Clear_all_user_request()      (otg_user_request = 0)
00157 
00158 
00169 #define Otg_timer_init()              (Timer16_select(OTG_USE_TIMER), Timer16_set_clock(TIMER16_CLKIO_BY_256), \
00170                                        Timer16_set_mode_output_a(TIMER16_COMP_MODE_NORMAL), \
00171                                        Timer16_set_waveform_mode(TIMER16_WGM_CTC_OCR), \
00172                                        Timer16_set_compare_a(62), Timer16_set_counter(0x0000), \
00173                                        Timer16_clear_compare_a_it(), Timer16_compare_a_it_enable())
00174 
00175 //_____ D E C L A R A T I O N S ____________________________________________
00176 
00177 extern volatile U16 g_usb_event;
00178 extern U8 g_usb_mode;
00179 extern U8 remote_wakeup_feature;
00180 
00194 void usb_task_init     (void);
00195 
00206 void usb_task          (void);
00207 
00208 extern volatile U8 private_sof_counter;
00209 
00210 
00218 extern volatile U8 otg_features_supported;
00219 extern U8 otg_user_request;
00220 
00221 extern volatile U16 g_otg_event;
00222 
00223 #if (OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION == ENABLED)
00224   extern U8 id_changed_to_host_event;
00225 #endif
00226 
00227 extern void otg_not_supported_device(void);
00228 
00229 #if (USB_OTG_FEATURE == ENABLED)
00237   #ifndef   OTG_COMPLIANCE_TRICKS
00238     #define OTG_COMPLIANCE_TRICKS                   DISABLED
00239   #endif
00240 
00247   #ifndef   OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION
00248     #define OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION    DISABLED
00249   #endif
00250 
00255   #ifndef   OTG_B_DEVICE_AUTORUN_HNP_IF_REQUIRED
00256     #define OTG_B_DEVICE_AUTORUN_HNP_IF_REQUIRED    ENABLED
00257   #endif
00258 
00262   #ifndef   OTG_RESET_LENGTH
00263     #define OTG_RESET_LENGTH                        1
00264   #endif
00265 #endif
00266 
00267 
00271 
00272 #define   MSG_DISPLAY_NODELAY     0xFFFF
00273 #define   OTG_TEMPO_1SEC          0x01F4  // 500 (x2ms)
00274 #define   OTG_TEMPO_2SEC          0x03E8  // 1000
00275 #define   OTG_TEMPO_3SEC          0x05DC  // 1500
00276 #define   OTG_TEMPO_4SEC          0x07D0  // 2000
00277 #define   OTR_TEMPO_5SEC          0x09C4  // 2500
00278 
00279 // These messages ID numbers must be used with the OTG messaging functions
00280 #define   OTGMSG_SRP_STARTED      1      // Event
00281 #define   OTGMSG_SRP_A_NO_RESP    2      // FAILURE msg
00282 #define   OTGMSG_A_RESPONDED      3      // Event
00283 #define   OTGMSG_CONNECTED_TO_A   4      // Event
00284 #define   OTGMSG_UNSUPPORTED      5      // FAILURE msg
00285 #define   OTGMSG_UNSUPPORTED_HUB  6      // FAILURE msg
00286 #define   OTGMSG_SRP_RECEIVED     7      // Event
00287 #define   OTGMSG_DEVICE_NO_RESP   8      // FAILURE msg
00288 #define   OTGMSG_VBUS_SURCHARGE   9      // Event
00289 
00290 // Messages definitions for OTG library, should not be used directly by user
00291 #define   OTGSTR_SRP_STARTED      "SRP Initiated     "  // Event
00292 #define   OTGSTR_SRP_A_NO_RESP    "A-Dev No Response "  // FAILURE
00293 #define   OTGSTR_A_RESPONDED      "A-Device Responded"  // Event
00294 #define   OTGSTR_CONNECTED_TO_A   "Connected to A-Dev"  // Event
00295 #define   OTGSTR_UNSUPPORTED      "Unsupported Device"  // FAILURE
00296 #define   OTGSTR_UNSUPPORTED_HUB  "Hub Unsuppported  "  // FAILURE
00297 #define   OTGSTR_SRP_RECEIVED     "SRP Received      "  // Event
00298 #define   OTGSTR_DEVICE_NO_RESP   "Device No Response"  // FAILURE
00299 #define   OTGSTR_VBUS_SURCHARGE   "VBUS OverCurrent !"  // Event
00300 
00301 extern U16 otg_msg_event_delay;
00302 extern U16 otg_msg_failure_delay;
00303 
00304 // Output messaging method choice (mode and functions defined in "conf_usb.h")
00305 #define     OTGMSG_NONE     0   // no messages displayed
00306 #define     OTGMSG_FAIL     1   // only failure messages displayed
00307 #define     OTGMSG_ALL      2   // all messages displayed
00308 
00309 #if (OTG_MESSAGING_OUTPUT == OTGMSG_ALL)            // ALL MESSAGES
00310   extern void Otg_messaging_init(void);
00311   extern void Otg_output_event_msg(U8);
00312   extern void Otg_output_failure_msg(U8);
00313   extern void Otg_output_event_clear(void);
00314   extern void Otg_output_failure_clear(void);
00316   #define   Otg_print_new_event_message(str,tm)     (Otg_output_event_msg(str), otg_msg_event_delay = tm)
00317   #define   Otg_clear_event_message()               Otg_output_event_clear()
00318   #define   Get_event_msg_delay()                   (otg_msg_event_delay)
00319   #define   Decrement_event_msg_delay()             (otg_msg_event_delay--)
00321   #define   Otg_print_new_failure_message(str,tm)   (Otg_output_failure_msg(str), otg_msg_failure_delay = tm)
00322   #define   Otg_clear_failure_message()             Otg_output_failure_clear()
00323   #define   Get_failure_msg_delay()                 (otg_msg_failure_delay)
00324   #define   Decrement_failure_msg_delay()           (otg_msg_failure_delay--)
00325 #elif (OTG_MESSAGING_OUTPUT == OTGMSG_FAIL)         // ONLY FAILURE MESSAGES (NEEDED FOR COMPLIANCE)
00326   extern void Otg_messaging_init(void);
00327   extern void Otg_output_failure_msg(U8);
00328   extern void Otg_output_failure_clear(void);
00329   #define   Otg_print_new_event_message(str,tm)     
00330   #define   Otg_clear_event_message()               
00331   #define   Get_event_msg_delay()                   
00332   #define   Decrement_event_msg_delay()             
00333   #define   Otg_print_new_failure_message(str,tm)   (Otg_output_failure_msg(str), otg_msg_failure_delay = tm)
00334   #define   Otg_clear_failure_message()             Otg_output_failure_clear()
00335   #define   Get_failure_msg_delay()                 (otg_msg_failure_delay)
00336   #define   Decrement_failure_msg_delay()           (otg_msg_failure_delay--)
00337 #else                                               // NOT OTG COMPLIANT
00338   #define   Otg_messaging_init()
00339   #define   Otg_print_new_event_message(str,tm)
00340   #define   Otg_clear_event_message()
00341   #define   Get_event_msg_delay()
00342   #define   Decrement_event_msg_delay()
00343   #define   Otg_print_new_failure_message(str,tm)
00344   #define   Otg_clear_failure_message()
00345   #define   Get_failure_msg_delay()
00346   #define   Decrement_failure_msg_delay()
00347 #endif
00349 
00350 #endif /* _USB_TASK_H_ */
00351 

Generated on Mon Sep 14 13:24:11 2009 for ATMEL by  doxygen 1.5.3