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 96 of file usb_task.h.
Referenced by usb_general_interrupt(), usb_task(), and usb_task_init().
#define USB_MODE_DEVICE 0x02 |
Definition at line 97 of file usb_task.h.
Referenced by usb_general_interrupt(), usb_task(), and usb_task_init().
#define VBUS_PULSE 1 |
Definition at line 100 of file usb_task.h.
#define DATA_PULSE 0 |
Definition at line 101 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 110 of file usb_task.h.
#define USER_RQST_SUSPEND 0x02 |
Definition at line 111 of file usb_task.h.
#define USER_RQST_VBUS 0x04 |
Definition at line 112 of file usb_task.h.
#define USER_RQST_HNP 0x08 |
Definition at line 113 of file usb_task.h.
#define USER_RQST_RESUME 0x10 |
Definition at line 114 of file usb_task.h.
#define USER_RQST_RESET 0x20 |
Definition at line 115 of file usb_task.h.
#define USER_RQST_DISCONNECT 0x40 |
Definition at line 116 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 120 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 125 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 129 of file usb_task.h.
#define Set_user_request_vbus | ( | ) | (otg_user_request |= USER_RQST_VBUS) |
Definition at line 130 of file usb_task.h.
#define Ack_user_request_vbus | ( | ) | (otg_user_request &= ~USER_RQST_VBUS) |
Definition at line 131 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 135 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 140 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 169 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 238 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 248 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 256 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 263 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 272 of file usb_task.h.
#define OTG_TEMPO_1SEC 0x01F4 |
Definition at line 273 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 277 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 284 of file usb_task.h.
#define OTGMSG_UNSUPPORTED_HUB 6 |
Definition at line 285 of file usb_task.h.
#define OTGMSG_SRP_RECEIVED 7 |
Definition at line 286 of file usb_task.h.
#define OTGMSG_DEVICE_NO_RESP 8 |
#define OTGMSG_VBUS_SURCHARGE 9 |
Definition at line 288 of file usb_task.h.
#define OTGSTR_SRP_STARTED "SRP Initiated " |
Definition at line 291 of file usb_task.h.
#define OTGSTR_SRP_A_NO_RESP "A-Dev No Response " |
Definition at line 292 of file usb_task.h.
#define OTGSTR_A_RESPONDED "A-Device Responded" |
Definition at line 293 of file usb_task.h.
#define OTGSTR_CONNECTED_TO_A "Connected to A-Dev" |
Definition at line 294 of file usb_task.h.
#define OTGSTR_UNSUPPORTED "Unsupported Device" |
Definition at line 295 of file usb_task.h.
#define OTGSTR_UNSUPPORTED_HUB "Hub Unsuppported " |
Definition at line 296 of file usb_task.h.
#define OTGSTR_SRP_RECEIVED "SRP Received " |
Definition at line 297 of file usb_task.h.
#define OTGSTR_DEVICE_NO_RESP "Device No Response" |
Definition at line 298 of file usb_task.h.
#define OTGSTR_VBUS_SURCHARGE "VBUS OverCurrent !" |
Definition at line 299 of file usb_task.h.
#define OTGMSG_NONE 0 |
Definition at line 305 of file usb_task.h.
#define OTGMSG_FAIL 1 |
Definition at line 306 of file usb_task.h.
#define OTGMSG_ALL 2 |
Definition at line 307 of file usb_task.h.
#define Otg_messaging_init | ( | ) |
Definition at line 338 of file usb_task.h.
#define Otg_print_new_event_message | ( | str, | |||
tm | ) |
#define Otg_clear_event_message | ( | ) |
Definition at line 340 of file usb_task.h.
#define Get_event_msg_delay | ( | ) |
Definition at line 341 of file usb_task.h.
#define Decrement_event_msg_delay | ( | ) |
Definition at line 342 of file usb_task.h.
#define Otg_print_new_failure_message | ( | str, | |||
tm | ) |
#define Otg_clear_failure_message | ( | ) |
Definition at line 344 of file usb_task.h.
#define Get_failure_msg_delay | ( | ) |
Definition at line 345 of file usb_task.h.
#define Decrement_failure_msg_delay | ( | ) |
Definition at line 346 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 180 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_MODE_DEVICE, USB_MODE_HOST, and USB_MODE_UNDEFINED.
00181 { 00182 #if (USB_HOST_FEATURE == ENABLED && USB_DEVICE_FEATURE == ENABLED) 00183 U8 delay; 00184 #endif 00185 00186 #if (USE_USB_PADS_REGULATOR==ENABLE) // Otherwise assume USB PADs regulator is not used 00187 Usb_enable_regulator(); 00188 #endif 00189 00190 // ---- DUAL ROLE DEVICE USB MODE --------------------------------------------- 00191 #if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED)) 00192 Usb_enable_uid_pin(); 00193 delay=PORTA; 00194 g_usb_mode=USB_MODE_UNDEFINED; 00195 if(Is_usb_id_device()) 00196 { 00197 g_usb_mode=USB_MODE_DEVICE; 00198 usb_device_task_init(); 00199 } 00200 else 00201 { 00202 g_usb_mode=USB_MODE_HOST; 00203 Usb_ack_id_transition(); // REQUIRED !!! Startup with ID=0, Ack ID pin transistion (default hwd start up is device mode) 00204 #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE) 00205 Usb_enable_id_interrupt(); 00206 #endif 00207 Enable_interrupt(); 00208 usb_host_task_init(); 00209 } 00210 g_old_usb_mode=g_usb_mode; // Store current usb mode, for mode change detection 00211 // ----------------------------------------------------------------------------- 00212 00213 // ---- DEVICE ONLY USB MODE --------------------------------------------------- 00214 #elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE)) 00215 Usb_force_device_mode(); 00216 usb_device_task_init(); 00217 // ----------------------------------------------------------------------------- 00218 00219 // ---- REDUCED HOST ONLY USB MODE --------------------------------------------- 00220 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED)) 00221 Usb_force_host_mode(); 00222 usb_host_task_init(); 00223 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE)) 00224 #error at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled 00225 #endif 00226 // ----------------------------------------------------------------------------- 00227 00228 00229 }
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 241 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_MODE_DEVICE, USB_MODE_HOST, USB_MODE_UNDEFINED, wdtdrv_enable(), and WDTO_16MS.
00242 { 00243 // ---- DUAL ROLE DEVICE USB MODE --------------------------------------------- 00244 #if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED)) 00245 if(Is_usb_id_device()) 00246 { g_usb_mode=USB_MODE_DEVICE;} 00247 else 00248 { g_usb_mode=USB_MODE_HOST;} 00249 00250 if( g_old_usb_mode != g_usb_mode ) 00251 { 00252 // ID pin hot state change 00253 #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE) 00254 // Hot ID transition generates wdt reset 00255 wdtdrv_enable(WDTO_16MS); 00256 while(1); 00257 #else 00258 // Hot ID transition reset USB mode 00259 Usb_ack_id_transition(); // REQUIRED 00260 if (Is_usb_id_host()) 00261 { 00262 Usb_disable_resume_interrupt(); 00263 Usb_disable_wake_up_interrupt(); 00264 Usb_disable_suspend_interrupt(); 00265 Usb_disable_reset_interrupt(); 00266 Usb_detach(); 00267 Usb_disable(); 00268 usb_host_task_init(); 00269 } 00270 else 00271 { 00272 Host_disable_device_disconnection_interrupt(); 00273 Host_disable_sof_interrupt(); 00274 Host_disable_sof(); 00275 Usb_disable_vbus(); 00276 Usb_disable_manual_vbus(); 00277 Usb_freeze_clock(); 00278 Usb_disable(); 00279 usb_device_task_init(); 00280 } 00281 #endif 00282 } 00283 00284 // Store current usb mode, for mode change detection 00285 g_old_usb_mode=g_usb_mode; 00286 00287 // Depending on current usb mode, launch the correct usb task (device or host) 00288 switch(g_usb_mode) 00289 { 00290 case USB_MODE_DEVICE: 00291 usb_device_task(); 00292 break; 00293 00294 case USB_MODE_HOST: 00295 usb_host_task(); 00296 break; 00297 00298 case USB_MODE_UNDEFINED: // No break ! 00299 default: 00300 break; 00301 } 00302 // ----------------------------------------------------------------------------- 00303 00304 // ---- DEVICE ONLY USB MODE --------------------------------------------------- 00305 #elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE)) 00306 usb_device_task(); 00307 // ----------------------------------------------------------------------------- 00308 00309 // ---- REDUCED HOST ONLY USB MODE --------------------------------------------- 00310 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED)) 00311 usb_host_task(); 00312 // ----------------------------------------------------------------------------- 00313 00315 #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE)) 00316 #error at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled 00317 #error otherwise the usb task has nothing to do ... 00318 #endif 00319 // ----------------------------------------------------------------------------- 00320 00321 }
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 106 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 164 of file usb_task.c.
Public : (U8) remote_wakeup_feature Store a host request for remote wake up (set feature received) /.
Definition at line 101 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 146 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 |