Modules | |
USB software Events Management | |
Macros to manage USB events detected under interrupt. | |
Defines | |
#define | USB_MODE_UNDEFINED 0x00 |
#define | USB_MODE_HOST 0x01 |
#define | USB_MODE_DEVICE 0x02 |
#define | VBUS_PULSE 1 |
#define | DATA_PULSE 0 |
#define | BDEV_HNP_NB_RETRY 3 |
#define | USER_RQST_SRP 0x01 |
#define | USER_RQST_SUSPEND 0x02 |
#define | USER_RQST_VBUS 0x04 |
#define | USER_RQST_HNP 0x08 |
#define | USER_RQST_RESUME 0x10 |
#define | USER_RQST_RESET 0x20 |
#define | USER_RQST_DISCONNECT 0x40 |
#define | Is_user_requested_srp() (((otg_user_request&USER_RQST_SRP) != 0) ? TRUE : FALSE) |
#define | Set_user_request_srp() (otg_user_request |= USER_RQST_SRP) |
#define | Ack_user_request_srp() (otg_user_request &= ~USER_RQST_SRP) |
#define | Is_user_requested_suspend() (((otg_user_request&USER_RQST_SUSPEND) != 0) ? TRUE : FALSE) |
#define | Set_user_request_suspend() (otg_user_request |= USER_RQST_SUSPEND) |
#define | Ack_user_request_suspend() (otg_user_request &= ~USER_RQST_SUSPEND) |
#define | Is_user_requested_vbus() (((otg_user_request&USER_RQST_VBUS) != 0) ? TRUE : FALSE) |
#define | Set_user_request_vbus() (otg_user_request |= USER_RQST_VBUS) |
#define | Ack_user_request_vbus() (otg_user_request &= ~USER_RQST_VBUS) |
#define | Is_user_requested_hnp() (((otg_user_request&USER_RQST_HNP) != 0) ? TRUE : FALSE) |
#define | Set_user_request_hnp() (otg_user_request |= USER_RQST_HNP) |
#define | Ack_user_request_hnp() (otg_user_request &= ~USER_RQST_HNP) |
#define | Is_user_requested_disc() (((otg_user_request&USER_RQST_DISCONNECT) != 0) ? TRUE : FALSE) |
#define | Set_user_request_disc() (otg_user_request |= USER_RQST_DISCONNECT) |
#define | Ack_user_request_disc() (otg_user_request &= ~USER_RQST_DISCONNECT) |
#define | Clear_all_user_request() (otg_user_request = 0) |
#define | Otg_timer_init() |
#define | OTG_COMPLIANCE_TRICKS DISABLED |
#define | OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION DISABLED |
#define | OTG_B_DEVICE_AUTORUN_HNP_IF_REQUIRED ENABLED |
#define | OTG_RESET_LENGTH 1 |
#define | MSG_DISPLAY_NODELAY 0xFFFF |
#define | OTG_TEMPO_1SEC 0x01F4 |
#define | OTG_TEMPO_2SEC 0x03E8 |
#define | OTG_TEMPO_3SEC 0x05DC |
#define | OTG_TEMPO_4SEC 0x07D0 |
#define | OTR_TEMPO_5SEC 0x09C4 |
#define | OTGMSG_SRP_STARTED 1 |
#define | OTGMSG_SRP_A_NO_RESP 2 |
#define | OTGMSG_A_RESPONDED 3 |
#define | OTGMSG_CONNECTED_TO_A 4 |
#define | OTGMSG_UNSUPPORTED 5 |
#define | OTGMSG_UNSUPPORTED_HUB 6 |
#define | OTGMSG_SRP_RECEIVED 7 |
#define | OTGMSG_DEVICE_NO_RESP 8 |
#define | OTGMSG_VBUS_SURCHARGE 9 |
#define | OTGSTR_SRP_STARTED "SRP Initiated " |
#define | OTGSTR_SRP_A_NO_RESP "A-Dev No Response " |
#define | OTGSTR_A_RESPONDED "A-Device Responded" |
#define | OTGSTR_CONNECTED_TO_A "Connected to A-Dev" |
#define | OTGSTR_UNSUPPORTED "Unsupported Device" |
#define | OTGSTR_UNSUPPORTED_HUB "Hub Unsuppported " |
#define | OTGSTR_SRP_RECEIVED "SRP Received " |
#define | OTGSTR_DEVICE_NO_RESP "Device No Response" |
#define | OTGSTR_VBUS_SURCHARGE "VBUS OverCurrent !" |
#define | OTGMSG_NONE 0 |
#define | OTGMSG_FAIL 1 |
#define | OTGMSG_ALL 2 |
#define | Otg_messaging_init() |
#define | Otg_print_new_event_message(str, tm) |
#define | Otg_clear_event_message() |
#define | Get_event_msg_delay() |
#define | Decrement_event_msg_delay() |
#define | Otg_print_new_failure_message(str, tm) |
#define | Otg_clear_failure_message() |
#define | Get_failure_msg_delay() |
#define | Decrement_failure_msg_delay() |
Functions | |
void | usb_task_init (void) |
void | usb_task (void) |
void | otg_not_supported_device (void) |
Variables | |
volatile U16 | g_usb_event |
Public : U16 g_usb_event usb_connected is used to store USB events detected upon USB general interrupt subroutine Its value is managed by the following macros (See usb_task.h file) Usb_send_event(x) Usb_ack_event(x) Usb_clear_all_event() Is_usb_event(x) Is_not_usb_event(x). | |
U8 | g_usb_mode |
Public : (U8) g_usb_mode Used in dual role application (both device/host) to store the current mode the usb controller is operating /. | |
U8 | remote_wakeup_feature |
Public : (U8) remote_wakeup_feature Store a host request for remote wake up (set feature received) /. | |
volatile U8 | private_sof_counter |
Private : (U8) private_sof_counter Incremented by host SOF interrupt subroutime This counter is used to detect timeout in host requests. | |
volatile U8 | otg_features_supported |
U8 | otg_user_request |
volatile U16 | g_otg_event |
U8 | id_changed_to_host_event |
U16 | otg_msg_event_delay |
U16 | otg_msg_failure_delay |
#define USB_MODE_UNDEFINED 0x00 |
#define USB_MODE_HOST 0x01 |
Definition at line 93 of file usb_task.h.
Referenced by usb_general_interrupt(), usb_task(), and usb_task_init().
#define USB_MODE_DEVICE 0x02 |
Definition at line 94 of file usb_task.h.
Referenced by usb_general_interrupt(), usb_task(), and usb_task_init().
#define VBUS_PULSE 1 |
Definition at line 97 of file usb_task.h.
#define DATA_PULSE 0 |
Definition at line 98 of file usb_task.h.
#define BDEV_HNP_NB_RETRY 3 |
#define USER_RQST_SRP 0x01 |
Definitions of OTG user requests (user software requests)
Definition at line 107 of file usb_task.h.
#define USER_RQST_SUSPEND 0x02 |
Definition at line 108 of file usb_task.h.
#define USER_RQST_VBUS 0x04 |
Definition at line 109 of file usb_task.h.
#define USER_RQST_HNP 0x08 |
Definition at line 110 of file usb_task.h.
#define USER_RQST_RESUME 0x10 |
Definition at line 111 of file usb_task.h.
#define USER_RQST_RESET 0x20 |
Definition at line 112 of file usb_task.h.
#define USER_RQST_DISCONNECT 0x40 |
Definition at line 113 of file usb_task.h.
#define Is_user_requested_srp | ( | ) | (((otg_user_request&USER_RQST_SRP) != 0) ? TRUE : FALSE) |
#define Set_user_request_srp | ( | ) | (otg_user_request |= USER_RQST_SRP) |
Definition at line 117 of file usb_task.h.
#define Ack_user_request_srp | ( | ) | (otg_user_request &= ~USER_RQST_SRP) |
#define Is_user_requested_suspend | ( | ) | (((otg_user_request&USER_RQST_SUSPEND) != 0) ? TRUE : FALSE) |
#define Set_user_request_suspend | ( | ) | (otg_user_request |= USER_RQST_SUSPEND) |
Definition at line 122 of file usb_task.h.
#define Ack_user_request_suspend | ( | ) | (otg_user_request &= ~USER_RQST_SUSPEND) |
#define Is_user_requested_vbus | ( | ) | (((otg_user_request&USER_RQST_VBUS) != 0) ? TRUE : FALSE) |
Definition at line 126 of file usb_task.h.
#define Set_user_request_vbus | ( | ) | (otg_user_request |= USER_RQST_VBUS) |
Definition at line 127 of file usb_task.h.
#define Ack_user_request_vbus | ( | ) | (otg_user_request &= ~USER_RQST_VBUS) |
Definition at line 128 of file usb_task.h.
#define Is_user_requested_hnp | ( | ) | (((otg_user_request&USER_RQST_HNP) != 0) ? TRUE : FALSE) |
#define Set_user_request_hnp | ( | ) | (otg_user_request |= USER_RQST_HNP) |
Definition at line 132 of file usb_task.h.
#define Ack_user_request_hnp | ( | ) | (otg_user_request &= ~USER_RQST_HNP) |
#define Is_user_requested_disc | ( | ) | (((otg_user_request&USER_RQST_DISCONNECT) != 0) ? TRUE : FALSE) |
#define Set_user_request_disc | ( | ) | (otg_user_request |= USER_RQST_DISCONNECT) |
Definition at line 137 of file usb_task.h.
#define Ack_user_request_disc | ( | ) | (otg_user_request &= ~USER_RQST_DISCONNECT) |
#define Clear_all_user_request | ( | ) | (otg_user_request = 0) |
#define Otg_timer_init | ( | ) |
Value:
(Timer16_select(OTG_USE_TIMER), Timer16_set_clock(TIMER16_CLKIO_BY_256), \ Timer16_set_mode_output_a(TIMER16_COMP_MODE_NORMAL), \ Timer16_set_waveform_mode(TIMER16_WGM_CTC_OCR), \ Timer16_set_compare_a(62), Timer16_set_counter(0x0000), \ Timer16_clear_compare_a_it(), Timer16_compare_a_it_enable())
none |
Definition at line 166 of file usb_task.h.
#define OTG_COMPLIANCE_TRICKS DISABLED |
Enable some additionnal feature to pass compliance plan This feature must be ENABLED to pass the OTG compliance program (FS-A-UUT tests TD4.5-2.9ms and TD4.6) Possible values are : ENABLE to add a special feature to OTG firmware : the problem comes from the disconnection delay of A-PERIPH once it has detected a Suspend condition. This delay is 3ms, but compliance test is not enough precise. This feature waits 500µs freezing clock when it notices that SOF are missing DISABLE to disable this feature (that may lead to malfunction in original cases)
Definition at line 235 of file usb_task.h.
#define OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION DISABLED |
Selects a Vbus delivery option This feature must be ENABLED to pass the OTG compliance program (Checklist OTG Protocol P23/P24) Possible values are : ENABLE to make the application initiate a session (like an answer to SRP) once A-plug inserted DISABLE to disable this feature This feature is compatible with OTG_VBUS_AUTO_WHEN_A_PLUG feature disabled
Definition at line 245 of file usb_task.h.
#define OTG_B_DEVICE_AUTORUN_HNP_IF_REQUIRED ENABLED |
ENABLE to make the B-Device run a HNP automatically if a SetFeature(b_hnp_enable) is received and Suspend detected This feature must be ENABLED to pass the OTG compliance program Possible values ENABLE or DISABLE
Definition at line 253 of file usb_task.h.
#define OTG_RESET_LENGTH 1 |
Selects the Reset Length (x11ms) This value is the number of consecutives Reset sent by the Host
Definition at line 260 of file usb_task.h.
#define MSG_DISPLAY_NODELAY 0xFFFF |
OTG Messaging definitions "No Silent Failure" rule makes any OTG compliant device handle messaging functions Differents means are supported : LCD display, LEDs, etc.
Definition at line 269 of file usb_task.h.
#define OTG_TEMPO_1SEC 0x01F4 |
Definition at line 270 of file usb_task.h.
#define OTG_TEMPO_2SEC 0x03E8 |
#define OTG_TEMPO_3SEC 0x05DC |
#define OTG_TEMPO_4SEC 0x07D0 |
#define OTR_TEMPO_5SEC 0x09C4 |
Definition at line 274 of file usb_task.h.
#define OTGMSG_SRP_STARTED 1 |
#define OTGMSG_SRP_A_NO_RESP 2 |
#define OTGMSG_A_RESPONDED 3 |
#define OTGMSG_CONNECTED_TO_A 4 |
#define OTGMSG_UNSUPPORTED 5 |
Definition at line 281 of file usb_task.h.
#define OTGMSG_UNSUPPORTED_HUB 6 |
Definition at line 282 of file usb_task.h.
#define OTGMSG_SRP_RECEIVED 7 |
Definition at line 283 of file usb_task.h.
#define OTGMSG_DEVICE_NO_RESP 8 |
#define OTGMSG_VBUS_SURCHARGE 9 |
Definition at line 285 of file usb_task.h.
#define OTGSTR_SRP_STARTED "SRP Initiated " |
Definition at line 288 of file usb_task.h.
#define OTGSTR_SRP_A_NO_RESP "A-Dev No Response " |
Definition at line 289 of file usb_task.h.
#define OTGSTR_A_RESPONDED "A-Device Responded" |
Definition at line 290 of file usb_task.h.
#define OTGSTR_CONNECTED_TO_A "Connected to A-Dev" |
Definition at line 291 of file usb_task.h.
#define OTGSTR_UNSUPPORTED "Unsupported Device" |
Definition at line 292 of file usb_task.h.
#define OTGSTR_UNSUPPORTED_HUB "Hub Unsuppported " |
Definition at line 293 of file usb_task.h.
#define OTGSTR_SRP_RECEIVED "SRP Received " |
Definition at line 294 of file usb_task.h.
#define OTGSTR_DEVICE_NO_RESP "Device No Response" |
Definition at line 295 of file usb_task.h.
#define OTGSTR_VBUS_SURCHARGE "VBUS OverCurrent !" |
Definition at line 296 of file usb_task.h.
#define OTGMSG_NONE 0 |
Definition at line 302 of file usb_task.h.
#define OTGMSG_FAIL 1 |
Definition at line 303 of file usb_task.h.
#define OTGMSG_ALL 2 |
Definition at line 304 of file usb_task.h.
#define Otg_messaging_init | ( | ) |
Definition at line 335 of file usb_task.h.
#define Otg_print_new_event_message | ( | str, | |||
tm | ) |
#define Otg_clear_event_message | ( | ) |
Definition at line 337 of file usb_task.h.
#define Get_event_msg_delay | ( | ) |
Definition at line 338 of file usb_task.h.
#define Decrement_event_msg_delay | ( | ) |
Definition at line 339 of file usb_task.h.
#define Otg_print_new_failure_message | ( | str, | |||
tm | ) |
#define Otg_clear_failure_message | ( | ) |
Definition at line 341 of file usb_task.h.
#define Get_failure_msg_delay | ( | ) |
Definition at line 342 of file usb_task.h.
#define Decrement_failure_msg_delay | ( | ) |
Definition at line 343 of file usb_task.h.
void usb_task_init | ( | void | ) |
This function initializes the USB proces.
This function enables the USB controller and init the USB interrupts. The aim is to allow the USB connection detection in order to send the appropriate USB event to the operating mode manager. Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the corespong usb mode initialization function
none |
Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the coresponding usb mode initialization function
none |
Definition at line 177 of file usb_task.c.
References g_old_usb_mode, g_usb_mode, Is_usb_id_device, Usb_ack_id_transition, usb_device_task_init(), Usb_enable_id_interrupt, Usb_enable_regulator, Usb_enable_uid_pin, Usb_force_device_mode, Usb_force_host_mode, usb_host_task_init(), USB_MODE_DEVICE, USB_MODE_HOST, and USB_MODE_UNDEFINED.
00178 { 00179 #if (USB_HOST_FEATURE == ENABLED && USB_DEVICE_FEATURE == ENABLED) 00180 U8 delay; 00181 #endif 00182 00183 #if (USE_USB_PADS_REGULATOR==ENABLE) // Otherwise assume USB PADs regulator is not used 00184 Usb_enable_regulator(); 00185 #endif 00186 00187 // ---- DUAL ROLE DEVICE USB MODE --------------------------------------------- 00188 #if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED)) 00189 Usb_enable_uid_pin(); 00190 delay=PORTA; 00191 g_usb_mode=USB_MODE_UNDEFINED; 00192 if(Is_usb_id_device()) 00193 { 00194 g_usb_mode=USB_MODE_DEVICE; 00195 usb_device_task_init(); 00196 } 00197 else 00198 { 00199 g_usb_mode=USB_MODE_HOST; 00200 Usb_ack_id_transition(); // REQUIRED !!! Startup with ID=0, Ack ID pin transistion (default hwd start up is device mode) 00201 #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE) 00202 Usb_enable_id_interrupt(); 00203 #endif 00204 Enable_interrupt(); 00205 usb_host_task_init(); 00206 } 00207 g_old_usb_mode=g_usb_mode; // Store current usb mode, for mode change detection 00208 // ----------------------------------------------------------------------------- 00209 00210 // ---- DEVICE ONLY USB MODE --------------------------------------------------- 00211 #elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE)) 00212 Usb_force_device_mode(); 00213 usb_device_task_init(); 00214 // ----------------------------------------------------------------------------- 00215 00216 // ---- REDUCED HOST ONLY USB MODE --------------------------------------------- 00217 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED)) 00218 Usb_force_host_mode(); 00219 usb_host_task_init(); 00220 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE)) 00221 #error at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled 00222 #endif 00223 // ----------------------------------------------------------------------------- 00224 00225 00226 }
void usb_task | ( | void | ) |
Entry point of the USB mamnagement Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the corespong usb management function
none |
none |
Definition at line 238 of file usb_task.c.
References g_old_usb_mode, g_usb_mode, Host_disable_device_disconnection_interrupt, Host_disable_sof, Host_disable_sof_interrupt, Is_usb_id_device, Is_usb_id_host, Usb_ack_id_transition, Usb_detach, usb_device_task(), usb_device_task_init(), Usb_disable, Usb_disable_manual_vbus, Usb_disable_reset_interrupt, Usb_disable_resume_interrupt, Usb_disable_suspend_interrupt, Usb_disable_vbus, Usb_disable_wake_up_interrupt, Usb_freeze_clock, usb_host_task(), usb_host_task_init(), USB_MODE_DEVICE, USB_MODE_HOST, USB_MODE_UNDEFINED, wdtdrv_enable(), and WDTO_16MS.
00239 { 00240 // ---- DUAL ROLE DEVICE USB MODE --------------------------------------------- 00241 #if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED)) 00242 if(Is_usb_id_device()) 00243 { g_usb_mode=USB_MODE_DEVICE;} 00244 else 00245 { g_usb_mode=USB_MODE_HOST;} 00246 00247 if( g_old_usb_mode != g_usb_mode ) 00248 { 00249 // ID pin hot state change 00250 #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE) 00251 // Hot ID transition generates wdt reset 00252 wdtdrv_enable(WDTO_16MS); 00253 while(1); 00254 #else 00255 // Hot ID transition reset USB mode 00256 Usb_ack_id_transition(); // REQUIRED 00257 if (Is_usb_id_host()) 00258 { 00259 Usb_disable_resume_interrupt(); 00260 Usb_disable_wake_up_interrupt(); 00261 Usb_disable_suspend_interrupt(); 00262 Usb_disable_reset_interrupt(); 00263 Usb_detach(); 00264 Usb_disable(); 00265 usb_host_task_init(); 00266 } 00267 else 00268 { 00269 Host_disable_device_disconnection_interrupt(); 00270 Host_disable_sof_interrupt(); 00271 Host_disable_sof(); 00272 Usb_disable_vbus(); 00273 Usb_disable_manual_vbus(); 00274 Usb_freeze_clock(); 00275 Usb_disable(); 00276 usb_device_task_init(); 00277 } 00278 #endif 00279 } 00280 00281 // Store current usb mode, for mode change detection 00282 g_old_usb_mode=g_usb_mode; 00283 00284 // Depending on current usb mode, launch the correct usb task (device or host) 00285 switch(g_usb_mode) 00286 { 00287 case USB_MODE_DEVICE: 00288 usb_device_task(); 00289 break; 00290 00291 case USB_MODE_HOST: 00292 usb_host_task(); 00293 break; 00294 00295 case USB_MODE_UNDEFINED: // No break ! 00296 default: 00297 break; 00298 } 00299 // ----------------------------------------------------------------------------- 00300 00301 // ---- DEVICE ONLY USB MODE --------------------------------------------------- 00302 #elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE)) 00303 usb_device_task(); 00304 // ----------------------------------------------------------------------------- 00305 00306 // ---- REDUCED HOST ONLY USB MODE --------------------------------------------- 00307 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED)) 00308 usb_host_task(); 00309 // ----------------------------------------------------------------------------- 00310 00312 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE)) 00313 #error at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled 00314 #error otherwise the usb task has nothing to do ... 00315 #endif 00316 // ----------------------------------------------------------------------------- 00317 00318 }
void otg_not_supported_device | ( | void | ) |
volatile U16 g_usb_event |
Public : U16 g_usb_event usb_connected is used to store USB events detected upon USB general interrupt subroutine Its value is managed by the following macros (See usb_task.h file) Usb_send_event(x) Usb_ack_event(x) Usb_clear_all_event() Is_usb_event(x) Is_not_usb_event(x).
Definition at line 103 of file usb_task.c.
Public : (U8) g_usb_mode Used in dual role application (both device/host) to store the current mode the usb controller is operating /.
Definition at line 161 of file usb_task.c.
Public : (U8) remote_wakeup_feature Store a host request for remote wake up (set feature received) /.
Definition at line 98 of file usb_standard_request.c.
volatile U8 private_sof_counter |
Private : (U8) private_sof_counter Incremented by host SOF interrupt subroutime This counter is used to detect timeout in host requests.
It must not be modified by the user application tasks. /
Definition at line 143 of file usb_task.c.
volatile U8 otg_features_supported |
External public declarations for OTG features
none |
Referenced by usb_set_feature().
volatile U16 g_otg_event |