#include "config.h"
#include "conf_usb.h"
#include "lib_mcu/timer/timer16_drv.h"
#include "usb_task.h"
#include "lib_mcu/usb/usb_drv.h"
#include "usb_descriptors.h"
#include "lib_mcu/power/power_drv.h"
#include "lib_mcu/wdt/wdt_drv.h"
#include "lib_mcu/pll/pll_drv.h"
#include "modules/usb/host_chap9/usb_host_task.h"
#include "modules/usb/device_chap9/usb_device_task.h"
Include dependency graph for usb_task.c:

Go to the source code of this file.
Defines | |
| #define | Is_vbus_overcurrent() (FALSE) |
| VBUS Overload management. | |
Functions | |
| void | Otg_message_task_init (void) |
| Private function prototypes Tasks for OTG Messaging features. | |
| void | Otg_message_task (void) |
| OTG Messaging main task. | |
| void | usb_task_init (void) |
| This function initializes the USB proces. | |
| void | usb_task (void) |
| Entry point of the USB mamnagement. | |
| __interrupt void | usb_general_interrupt () |
| USB interrupt subroutine. | |
| __interrupt void | otg_timer_interrupt () |
| OTG TIMER interrupt subroutine. | |
| void | suspend_action (void) |
| void | host_suspend_action (void) |
| void | otg_not_supported_device (void) |
Variables | |
| U8 | g_sav_int_sof_enable |
| U8 code | log_device_disconnect [] = "Device Disconnected" |
| U8 code | log_id_change [] = "Pin Id Change" |
| volatile U16 | g_usb_event = 0 |
| 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). | |
| bit | usb_connected |
| Public : (bit) usb_connected usb_connected is set to TRUE when VBUS has been detected usb_connected is set to FALSE otherwise Used with USB_DEVICE_FEATURE == ENABLED only /. | |
| U8 | usb_configuration_nb |
| Public : (U8) usb_configuration_nb Store the number of the USB configuration used by the USB device when its value is different from zero, it means the device mode is enumerated Used with USB_DEVICE_FEATURE == ENABLED only /. | |
| 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 = 0 |
| Private : (U8) private_sof_counter Incremented by host SOF interrupt subroutime This counter is used to detect timeout in host requests. | |
| volatile S_pipe_int | it_pipe_str [MAX_EP_NB] |
| U8 | g_usb_mode = 0x00 |
| Public : (U8) g_usb_mode Used in dual role application (both device/host) to store the current mode the usb controller is operating /. | |
| U8 | g_old_usb_mode |
| volatile U8 | otg_features_supported |
| External public declarations for OTG features. | |
| U8 | otg_user_request |
| Public : (U8) otg_user_request; Store the last request of the user (see usb_device_task.h). | |
| U16 | otg_msg_event_delay |
| Public : (U16) otg_msg_event_delay; Contains the current display duration of the OTG event message. | |
| U16 | otg_msg_failure_delay |
| Public : (U16) otg_msg_failure_delay; Contains the current display duration of the OTG failure message. | |
| volatile U16 | g_otg_event |
| Public : (U16) g_otg_event; Contains several bits corresponding to differents OTG events (similar to g_usb_event). | |
| U8 | otg_device_nb_hnp_retry |
| Public : (U8) otg_device_nb_hnp_retry; Counts the number of times a HNP fails, before aborting the operations. | |
| U8 | id_changed_to_host_event |
| volatile U8 | otg_last_sof_received |
| volatile U8 | otg_last_sof_stored |
| volatile U8 | reset_received |
Copyright (c) 2006 Atmel.
Please read file license.txt for copyright notice.
The USB task selects the correct USB task (usb_device task or usb_host task to be executed depending on the current mode available.
According to USB_DEVICE_FEATURE and USB_HOST_FEATURE value (located in conf_usb.h file) The usb_task can be configured to support USB DEVICE mode or USB Host mode or both for a dual role device application.
This module also contains the general USB interrupt subroutine. This subroutine is used to detect asynchronous USB events.
Note:
Definition in file usb_task.c.
| #define Is_vbus_overcurrent | ( | ) | (FALSE) |
VBUS Overload management.
Nothing to do ! If the condition is not defined in the board driver file (i.e. if the board does not support Vbus overcurrent detection), the macro is defined to false for firmware compatibility
Definition at line 188 of file usb_task.c.
Referenced by usb_task().
| void Otg_message_task_init | ( | void | ) |
Private function prototypes Tasks for OTG Messaging features.
Initializes variables and screen to prepare next messages to be handled First version of this function works on SPIDER Board and needs for the 3 lower lines of the LCD
| none |
Definition at line 1003 of file usb_task.c.
References Otg_messaging_init, otg_msg_event_delay, and otg_msg_failure_delay.
Referenced by usb_task_init().
01004 { 01005 Otg_messaging_init(); 01006 otg_msg_event_delay = 0; 01007 otg_msg_failure_delay = 0; 01008 }
| void Otg_message_task | ( | void | ) |
OTG Messaging main task.
OTG specifies that user must be kept informed of several events This task allows user to display two kinds of messages : EVENT or FAILURE For each new message, it can specify if the message remains displayed all the time or only during a specified delay
| none |
Definition at line 1020 of file usb_task.c.
References Get_event_msg_delay, Get_failure_msg_delay, Otg_clear_event_message, and Otg_clear_failure_message.
Referenced by usb_task().
01021 { 01022 // Check if an OTG message must be erased (if it was set up for a specified delay) 01023 #if ((OTG_MESSAGING_OUTPUT == OTGMSG_ALL) || (OTG_MESSAGING_OUTPUT == OTGMSG_FAIL)) 01024 if (Get_failure_msg_delay() == 0) { Otg_clear_failure_message(); } 01025 #if (OTG_MESSAGING_OUTPUT == OTGMSG_ALL) 01026 if (Get_event_msg_delay() == 0) { Otg_clear_event_message(); } 01027 #endif 01028 #endif 01029 }
| __interrupt void usb_general_interrupt | ( | ) |
USB interrupt subroutine.
This function is called each time a USB interrupt occurs. The following USB DEVICE events are taken in charge:
The following USB HOST events are taken in charge:
The following USB HOST events are taken in charge:
For each event, the user can launch an action by completing the associate define (See conf_usb.h file to add action upon events)
Note: Only interrupts events that are enabled are processed
| none |
Definition at line 411 of file usb_task.c.
References A_END_HNP_WAIT_VFALL, A_PERIPHERAL, Ack_user_request_hnp, B_END_HNP_SUSPEND, B_HOST, B_IDLE, B_PERIPHERAL, Clear_all_user_request, Clear_otg_features_from_host, DEVICE_ATTACHED, DEVICE_DISCONNECTED, device_state, DEVICE_UNATTACHED, DIRECTION_OUT, DISABLE, DISABLED, S_pipe_int::enable, ENABLE, ENABLED, End_session_with_srp, EP_CONTROL, EVT_HOST_DISCONNECTION, EVT_HOST_HWUP, EVT_HOST_REMOTE_WAKEUP, EVT_HOST_SOF, EVT_OTG_HNP_ERROR, EVT_OTG_HNP_SUCCESS, EVT_USB_DEVICE_FUNCTION, EVT_USB_HOST_FUNCTION, EVT_USB_POWERED, EVT_USB_RESET, EVT_USB_RESUME, EVT_USB_SUSPEND, EVT_USB_UNPOWERED, EVT_USB_WAKE_UP, FALSE, g_old_usb_mode, g_sav_int_sof_enable, g_usb_mode, S_pipe_int::handle, Host_ack_device_connection, Host_ack_device_disconnection, Host_ack_hwup, Host_ack_remote_wakeup, Host_ack_reset, Host_ack_sof, Host_device_connection_action, Host_device_disconnection_action, host_disable_all_pipe(), Host_disable_hwup_interrupt, Host_disable_remote_wakeup_interrupt, Host_disable_reset_interrupt, Host_disable_sof_interrupt, Host_enable_sof, Host_get_pipe_type, Host_get_selected_pipe, Host_hwup_action, Host_is_reset, Host_select_pipe, Host_send_reset, Host_send_resume, Host_sof_action, Host_stop_pipe_interrupt, id_changed_to_host_event, is_any_interrupt_pipe_active(), Is_device_connection, Is_device_disconnection, Is_hnp_error_interrupt_enabled, Is_host_device_connection_interrupt_enabled, Is_host_device_disconnection_interrupt_enabled, Is_host_hwup, Is_host_hwup_interrupt_enabled, Is_host_remote_wakeup, Is_host_remote_wakeup_interrupt_enabled, Is_host_requested_hnp, Is_host_sof, Is_host_sof_interrupt_enabled, Is_reset_interrupt_enabled, Is_resume_interrupt_enabled, Is_role_exchange_interrupt_enabled, Is_session_started_with_srp, Is_sof_interrupt_enabled, Is_suspend_interrupt_enabled, Is_swake_up_interrupt_enabled, Is_usb_hnp, Is_usb_hnp_error_interrupt, Is_usb_id_device, Is_usb_id_host, Is_usb_id_interrupt_enabled, Is_usb_id_transition, Is_usb_reset, Is_usb_resume, Is_usb_role_exchange_interrupt, Is_usb_sof, Is_usb_suspend, Is_usb_vbus_high, Is_usb_vbus_interrupt_enabled, Is_usb_vbus_transition, Is_usb_wake_up, Is_user_requested_hnp, it_pipe_str, log_device_disconnect, log_id_change, LOG_STR_CODE, MAX_EP_NB, NYET_DISABLED, ONE_BANK, OTG_B_DEVICE_AUTORUN_HNP_IF_REQUIRED, otg_b_device_state, OTG_B_HNP_ENABLE, otg_device_nb_hnp_retry, otg_features_supported, otg_last_sof_received, otg_last_sof_stored, Otg_send_event, OTG_USE_TIMER, PIPE_DELAY_TIMEOUT, private_sof_counter, remote_wakeup_feature, reset_received, SIZE_8, sof_seen_in_session, S_pipe_int::status, TIMEOUT_DELAY, Timer16_get_counter_low, Timer16_select, Timer16_set_counter, TRUE, TYPE_CONTROL, TYPE_INTERRUPT, Usb_ack_hnp_error_interrupt, Usb_ack_id_transition, Usb_ack_reset, Usb_ack_resume, Usb_ack_role_exchange_interrupt, Usb_ack_sof, Usb_ack_suspend, Usb_ack_vbus_transition, Usb_ack_wake_up, Usb_attach, usb_configuration_nb, usb_configure_endpoint, usb_connected, Usb_detach, Usb_device_initiate_hnp, Usb_device_stop_hnp, Usb_disable_hnp_error_interrupt, Usb_disable_resume_interrupt, Usb_disable_role_exchange_interrupt, Usb_disable_sof_interrupt, Usb_disable_suspend_interrupt, Usb_disable_wake_up_interrupt, Usb_enable_hnp_error_interrupt, Usb_enable_reset_interrupt, Usb_enable_role_exchange_interrupt, Usb_enable_sof_interrupt, Usb_enable_suspend_interrupt, Usb_enable_wake_up_interrupt, Usb_freeze_clock, Usb_id_transition_action, usb_init_device(), USB_MODE_DEVICE, USB_MODE_HOST, Usb_reset_action, Usb_resume_action, Usb_select_device, Usb_select_host, Usb_send_event, Usb_sof_action, usb_start_device(), Usb_suspend_action, Usb_unfreeze_clock, Usb_vbus_off_action, Usb_vbus_on_action, Usb_wake_up_action, Wait_pll_ready, Wdt_change_16ms, and Wdt_change_enable.
00413 { 00414 #if (USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE) 00415 U8 i; 00416 U8 save_pipe_nb; 00417 #endif 00418 00419 // ---------- DEVICE events management ----------------------------------- 00420 // ----------------------------------------------------------------------- 00421 #if ((USB_DEVICE_FEATURE == ENABLED) || (USB_OTG_FEATURE == ENABLED)) 00422 //- VBUS state detection 00423 if (Is_usb_vbus_transition() && Is_usb_vbus_interrupt_enabled() && Is_usb_id_device()) 00424 { 00425 Usb_ack_vbus_transition(); 00426 if (Is_usb_vbus_high()) 00427 { 00428 usb_connected = TRUE; 00429 Usb_vbus_on_action(); 00430 Usb_send_event(EVT_USB_POWERED); 00431 Usb_enable_reset_interrupt(); 00432 usb_start_device(); 00433 Usb_attach(); 00434 } 00435 else 00436 { 00437 Usb_detach(); 00438 #if (USB_OTG_FEATURE == ENABLED) 00439 Usb_device_stop_hnp(); 00440 Usb_select_device(); 00441 Clear_all_user_request(); 00442 #endif 00443 Usb_vbus_off_action(); 00444 usb_connected = FALSE; 00445 usb_configuration_nb = 0; 00446 Usb_send_event(EVT_USB_UNPOWERED); 00447 } 00448 } 00449 // - Device start of frame received 00450 if (Is_usb_sof() && Is_sof_interrupt_enabled()) 00451 { 00452 Usb_ack_sof(); 00453 Usb_sof_action(); 00454 #if (USB_OTG_FEATURE == ENABLED) 00455 sof_seen_in_session = TRUE; 00456 #if (OTG_COMPLIANCE_TRICKS == ENABLED) 00457 otg_last_sof_received = UDFNUML; // store last frame number received 00458 #endif 00459 #endif 00460 } 00461 // - Device Suspend event (no more USB activity detected) 00462 if (Is_usb_suspend() && Is_suspend_interrupt_enabled()) 00463 { 00464 #if (USB_OTG_FEATURE == ENABLED) 00465 // 1st : B-PERIPH mode ? 00466 if (Is_usb_id_device()) 00467 { 00468 // HNP Handler 00469 if (Is_host_requested_hnp() // "b_hnp_enable" feature received 00470 && (Is_session_started_with_srp() || Is_user_requested_hnp() || (OTG_B_DEVICE_AUTORUN_HNP_IF_REQUIRED == ENABLED))) 00471 { 00472 if (otg_device_nb_hnp_retry == 0) 00473 { 00474 otg_features_supported &= ~OTG_B_HNP_ENABLE; 00475 } 00476 else 00477 { 00478 Ack_user_request_hnp(); 00479 Usb_ack_hnp_error_interrupt(); 00480 Usb_ack_role_exchange_interrupt(); 00481 Usb_enable_role_exchange_interrupt(); 00482 Usb_enable_hnp_error_interrupt(); 00483 Usb_device_initiate_hnp(); 00484 otg_device_nb_hnp_retry--; 00485 } 00486 Usb_ack_suspend(); 00487 } 00488 else 00489 { 00490 // Remote wake-up handler 00491 if ((remote_wakeup_feature == ENABLED) && (usb_configuration_nb != 0)) 00492 { 00493 00494 Usb_disable_suspend_interrupt(); 00495 Usb_ack_wake_up(); 00496 Usb_enable_wake_up_interrupt(); 00497 // After that user can execute "Usb_initiate_remote_wake_up()" to initiate a remote wake-up 00498 // Note that the suspend interrupt flag SUSPI must still be set to enable upstream resume 00499 // So the SUSPE enable bit must be cleared to avoid redundant interrupt 00500 // **************** 00501 // Please note also that is Vbus is lost during an upstream resume (Host disconnection), 00502 // the RMWKUP bit (used to initiate remote wake up and that is normally cleared by hardware when sent) 00503 // remains set after the event, so that a good way to handle this feature is : 00504 // Usb_initiate_remote_wake_up(); 00505 // while (Is_usb_pending_remote_wake_up()) 00506 // { 00507 // if (Is_usb_vbus_low()) 00508 // { 00509 // // Emergency action (reset macro, etc.) if Vbus lost during resuming 00510 // break; 00511 // } 00512 // } 00513 // Usb_ack_remote_wake_up_start(); 00514 // **************** 00515 } 00516 else 00517 { 00518 // No remote wake-up supported 00519 Usb_send_event(EVT_USB_SUSPEND); 00520 Usb_suspend_action(); 00521 Usb_ack_suspend(); 00522 Usb_ack_wake_up(); // clear wake up to detect next event 00523 Usb_enable_wake_up_interrupt(); 00524 Usb_freeze_clock(); 00525 } 00526 } 00527 } 00528 else 00529 { 00530 // A-PERIPH mode (will cause a session end, handled in usb_host_task.c) 00531 Usb_send_event(EVT_USB_SUSPEND); 00532 Usb_suspend_action(); 00533 Usb_ack_suspend(); 00534 } 00535 #else 00536 // Remote wake-up handler 00537 if ((remote_wakeup_feature == ENABLED) && (usb_configuration_nb != 0)) 00538 { 00539 Usb_disable_suspend_interrupt(); 00540 Usb_ack_wake_up(); 00541 Usb_enable_wake_up_interrupt(); 00542 Usb_suspend_action(); 00543 Usb_freeze_clock(); 00544 // After that user can execute "Usb_initiate_remote_wake_up()" to initiate a remote wake-up 00545 // Note that the suspend interrupt flag SUSPI must still be set to enable upstream resume 00546 // So the SUSPE enable bit must be cleared to avoid redundant interrupt 00547 // **************** 00548 // Please note also that is Vbus is lost during an upstream resume (Host disconnection), 00549 // the RMWKUP bit (used to initiate remote wake up and that is normally cleared by hardware when sent) 00550 // remains set after the event, so that a good way to handle this feature is : 00551 // Usb_unfreeze_clock(); 00552 // Usb_initiate_remote_wake_up(); 00553 // while (Is_usb_pending_remote_wake_up()) 00554 // { 00555 // if (Is_usb_vbus_low()) 00556 // { 00557 // // Emergency action (reset macro, etc.) if Vbus lost during resuming 00558 // break; 00559 // } 00560 // } 00561 // Usb_ack_remote_wake_up_start(); 00562 // **************** 00563 } 00564 else 00565 { 00566 // No remote wake-up supported 00567 Usb_send_event(EVT_USB_SUSPEND); 00568 Usb_suspend_action(); 00569 Usb_ack_suspend(); 00570 Usb_ack_wake_up(); // clear wake up to detect next event 00571 Usb_enable_wake_up_interrupt(); 00572 Usb_freeze_clock(); 00573 } 00574 #endif 00575 } 00576 00577 // - Wake up event (USB activity detected): Used to resume 00578 if (Is_usb_wake_up() && Is_swake_up_interrupt_enabled()) 00579 { 00580 Usb_unfreeze_clock(); 00581 Usb_ack_wake_up(); 00582 Usb_disable_wake_up_interrupt(); 00583 Usb_ack_suspend(); 00584 Usb_enable_suspend_interrupt(); 00585 Usb_wake_up_action(); 00586 Usb_send_event(EVT_USB_WAKE_UP); 00587 } 00588 // - Resume state bus detection 00589 if (Is_usb_resume() && Is_resume_interrupt_enabled()) 00590 { 00591 Usb_disable_wake_up_interrupt(); 00592 Usb_ack_resume(); 00593 Usb_disable_resume_interrupt(); 00594 Usb_resume_action(); 00595 Usb_send_event(EVT_USB_RESUME); 00596 } 00597 // - USB bus reset detection 00598 if (Is_usb_reset()&& Is_reset_interrupt_enabled()) 00599 { 00600 Usb_ack_reset(); 00601 usb_init_device(); 00602 #if (USB_OTG_FEATURE == ENABLED) 00603 if (Is_usb_id_host()) 00604 { 00605 usb_configure_endpoint(EP_CONTROL, \ 00606 TYPE_CONTROL, \ 00607 DIRECTION_OUT, \ 00608 SIZE_8, \ 00609 ONE_BANK, \ 00610 NYET_DISABLED); 00611 } 00612 #if (OTG_COMPLIANCE_TRICKS == ENABLED) 00613 // First initialization is important to be synchronized 00614 // A reset must first have been received 00615 if (device_state == A_PERIPHERAL) 00616 { 00617 otg_last_sof_received = UDFNUML; 00618 otg_last_sof_stored = UDFNUML; 00619 Usb_ack_sof(); 00620 Usb_enable_sof_interrupt(); 00621 reset_received = TRUE; 00622 Timer16_select(OTG_USE_TIMER); // reinitialize timer 00623 Timer16_set_counter(0); 00624 } 00625 #endif 00626 #endif 00627 Usb_reset_action(); 00628 Usb_send_event(EVT_USB_RESET); 00629 } 00630 00631 // ---------- OTG events management ------------------------------------ 00632 // --------------------------------------------------------------------- 00633 #if (USB_OTG_FEATURE == ENABLED) 00634 // - OTG HNP Success detection 00635 if (Is_usb_role_exchange_interrupt() && Is_role_exchange_interrupt_enabled()) 00636 { 00637 Usb_ack_role_exchange_interrupt(); 00638 Host_ack_device_connection(); 00639 Host_ack_device_disconnection(); 00640 Otg_send_event(EVT_OTG_HNP_SUCCESS); 00641 End_session_with_srp(); 00642 Clear_otg_features_from_host(); 00643 if (Is_usb_id_host()) 00644 { 00645 // HOST (A- or B-) mode 00646 if ((device_state != A_PERIPHERAL) && (device_state != A_END_HNP_WAIT_VFALL)) 00647 { 00648 // Current mode is A-HOST, device will take the A-PERIPHERAL role 00649 otg_b_device_state = B_PERIPHERAL; 00650 device_state = A_PERIPHERAL; 00651 usb_connected = FALSE; 00652 usb_configuration_nb = 0; 00653 Usb_select_device(); 00654 Usb_attach(); 00655 Usb_unfreeze_clock(); 00656 Usb_disable_role_exchange_interrupt(); 00657 Usb_disable_hnp_error_interrupt(); 00658 Usb_device_stop_hnp(); 00659 Usb_ack_suspend(); 00660 Usb_ack_reset(); 00661 #if (OTG_COMPLIANCE_TRICKS == ENABLED) 00662 Timer16_select(OTG_USE_TIMER); // 4 first lines compensating test error TD4.5-2,9ms 00663 Timer16_set_counter(0); 00664 Usb_freeze_clock(); // USB clock can be freezed to slow down events and condition detection 00665 while (Timer16_get_counter_low() != 20); 00666 Usb_unfreeze_clock(); 00667 reset_received = FALSE; 00668 Usb_disable_sof_interrupt(); // will be set in the next OTG Timer IT (mandatory) 00669 #endif 00670 Usb_enable_suspend_interrupt(); 00671 Usb_enable_reset_interrupt(); 00672 usb_configure_endpoint(EP_CONTROL, \ 00673 TYPE_CONTROL, \ 00674 DIRECTION_OUT, \ 00675 SIZE_8, \ 00676 ONE_BANK, \ 00677 NYET_DISABLED); 00678 } 00679 } 00680 else 00681 { // In B_HOST mode, the HNPREQ bit must not be cleared because it releases the bus in suspend mode (and sof can't start) 00682 if ((otg_b_device_state != B_HOST) && (otg_b_device_state != B_END_HNP_SUSPEND)) 00683 { 00684 // Current mode is B-PERIPHERAL, device will go into B-HOST role 00685 End_session_with_srp(); 00686 Clear_otg_features_from_host(); 00687 otg_b_device_state = B_HOST; 00688 device_state = DEVICE_ATTACHED; 00689 usb_connected = FALSE; 00690 usb_configuration_nb = 0; 00691 Usb_select_host(); 00692 Host_enable_sof(); // start Host (sof) 00693 Host_send_reset(); // send the first RESET 00694 Host_disable_reset_interrupt(); 00695 while (Host_is_reset()); 00696 i = 2; 00697 while (i != 1) 00698 { 00699 i++; 00700 }; 00701 while (i < 5) // generates 4 others RESET 00702 { 00703 while (Host_is_reset()); 00704 Host_send_reset(); 00705 Host_ack_reset(); 00706 i++; 00707 } 00708 00709 Usb_disable_role_exchange_interrupt(); 00710 Usb_disable_hnp_error_interrupt(); 00711 Clear_all_user_request(); 00712 } 00713 } 00714 } 00715 // - OTG HNP Failure detection 00716 if (Is_usb_hnp() && Is_usb_hnp_error_interrupt()&& Is_hnp_error_interrupt_enabled()) 00717 { 00718 Usb_device_stop_hnp(); 00719 Usb_disable_role_exchange_interrupt(); 00720 Usb_disable_hnp_error_interrupt(); 00721 Usb_ack_hnp_error_interrupt(); 00722 if (Is_usb_id_device()) 00723 { 00724 Otg_send_event(EVT_OTG_HNP_ERROR); 00725 Clear_all_user_request(); 00726 } 00727 } 00728 #endif 00729 #endif// End DEVICE FEATURE MODE 00730 00731 // ---------- HOST events management ----------------------------------- 00732 // --------------------------------------------------------------------- 00733 #if ((USB_HOST_FEATURE == ENABLED && USB_DEVICE_FEATURE == ENABLED) || (USB_OTG_FEATURE == ENABLED)) 00734 // - ID pin change detection 00735 if(Is_usb_id_transition()&&Is_usb_id_interrupt_enabled()) 00736 { 00737 Usb_device_stop_hnp(); 00738 #if (USB_OTG_FEATURE == ENABLED) 00739 Clear_all_user_request(); 00740 #endif 00741 if(Is_usb_id_device()) 00742 { g_usb_mode=USB_MODE_DEVICE;} 00743 else 00744 { g_usb_mode=USB_MODE_HOST;} 00745 Usb_ack_id_transition(); 00746 if( g_usb_mode != g_old_usb_mode) // Basic Debounce 00747 { 00748 if(Is_usb_id_device()) // Going into device mode 00749 { 00750 Usb_send_event(EVT_USB_DEVICE_FUNCTION); 00751 #if (USB_OTG_FEATURE == ENABLED) 00752 otg_b_device_state = B_IDLE; 00753 #endif 00754 device_state = DEVICE_UNATTACHED; 00755 #if ((OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION == ENABLED) && (USB_OTG_FEATURE == ENABLED)) 00756 id_changed_to_host_event = DISABLED; 00757 #endif 00758 } 00759 else // Going into host mode 00760 { 00761 #if (USB_OTG_FEATURE == ENABLED) 00762 otg_b_device_state = B_IDLE; 00763 #endif 00764 device_state = DEVICE_UNATTACHED; 00765 Usb_send_event(EVT_USB_HOST_FUNCTION); 00766 #if ((OTG_VBUS_AUTO_AFTER_A_PLUG_INSERTION == ENABLED) && (USB_OTG_FEATURE == ENABLED)) 00767 id_changed_to_host_event = ENABLED; 00768 #endif 00769 } 00770 Usb_id_transition_action(); 00771 LOG_STR_CODE(log_id_change); 00772 #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE) 00773 // Hot ID transition generates wdt reset 00774 #ifndef AVRGCC 00775 Wdt_change_16ms(); while(1); 00776 #else 00777 Wdt_change_enable(); while(1); 00778 #endif 00779 #endif 00780 } 00781 } 00782 #endif 00783 #if ((USB_HOST_FEATURE == ENABLED) || (USB_OTG_FEATURE == ENABLED)) 00784 // - The device has been disconnected 00785 if(Is_device_disconnection() && Is_host_device_disconnection_interrupt_enabled()) 00786 { 00787 host_disable_all_pipe(); 00788 Host_ack_device_disconnection(); 00789 device_state=DEVICE_DISCONNECTED; 00790 Usb_send_event(EVT_HOST_DISCONNECTION); 00791 LOG_STR_CODE(log_device_disconnect); 00792 Host_device_disconnection_action(); 00793 #if (USB_OTG_FEATURE == ENABLED) 00794 Clear_all_user_request(); 00795 #endif 00796 } 00797 // - Device connection 00798 if(Is_device_connection() && Is_host_device_connection_interrupt_enabled()) 00799 { 00800 Host_ack_device_connection(); 00801 host_disable_all_pipe(); 00802 Host_device_connection_action(); 00803 } 00804 // - Host Start of frame has been sent 00805 if (Is_host_sof() && Is_host_sof_interrupt_enabled()) 00806 { 00807 Host_ack_sof(); 00808 Usb_send_event(EVT_HOST_SOF); 00809 private_sof_counter++; 00810 00811 // delay timeout management for interrupt tranfer mode in host mode 00812 #if ((USB_HOST_PIPE_INTERRUPT_TRANSFER==ENABLE) && (TIMEOUT_DELAY_ENABLE==ENABLE)) 00813 if (private_sof_counter>=250) // Count 1/4 sec 00814 { 00815 private_sof_counter=0; 00816 for(i=0;i<MAX_EP_NB;i++) 00817 { 00818 if(it_pipe_str[i].enable==ENABLE) 00819 { 00820 save_pipe_nb=Host_get_selected_pipe(); 00821 Host_select_pipe(i); 00822 if((++it_pipe_str[i].timeout>TIMEOUT_DELAY) && (Host_get_pipe_type()!=TYPE_INTERRUPT)) 00823 { 00824 it_pipe_str[i].enable=DISABLE; 00825 it_pipe_str[i].status=PIPE_DELAY_TIMEOUT; 00826 Host_stop_pipe_interrupt(i); 00827 if (is_any_interrupt_pipe_active()==FALSE) // If no more transfer is armed 00828 { 00829 if (g_sav_int_sof_enable==FALSE) 00830 { 00831 Host_disable_sof_interrupt(); 00832 } 00833 } 00834 it_pipe_str[i].handle(PIPE_DELAY_TIMEOUT,it_pipe_str[i].nb_byte_processed); 00835 } 00836 Host_select_pipe(save_pipe_nb); 00837 } 00838 } 00839 } 00840 #endif // (USB_HOST_PIPE_INTERRUPT_TRANSFER==ENABLE) && (TIMEOUT_DELAY_ENABLE==ENABLE)) 00841 Host_sof_action(); 00842 } 00843 // - Host Wake-up has been received 00844 if (Is_host_hwup() && Is_host_hwup_interrupt_enabled()) 00845 { 00846 Host_disable_hwup_interrupt(); // Wake up interrupt should be disable host is now wake up ! 00847 Host_disable_remote_wakeup_interrupt(); 00848 // CAUTION HWUP can be cleared only when USB clock is active (not frozen)! 00849 Pll_start_auto(); // First Restart the PLL for USB operation 00850 Wait_pll_ready(); // Get sure pll is lock 00851 Usb_unfreeze_clock(); // Enable clock on USB interface 00852 Host_enable_sof(); // start sending SOF 00853 Host_ack_hwup(); // Clear HWUP interrupt flag 00854 Host_ack_remote_wakeup(); 00855 Usb_send_event(EVT_HOST_HWUP); // Send software event 00856 Usb_send_event(EVT_HOST_REMOTE_WAKEUP); 00857 Host_hwup_action(); // Map custom action 00858 #if (USB_OTG_FEATURE == ENABLED) 00859 if (Is_usb_hnp()) 00860 { 00861 // Usb_host_reject_hnp(); 00862 Usb_disable_hnp_error_interrupt(); 00863 Usb_disable_role_exchange_interrupt(); 00864 } 00865 #endif 00866 Host_send_resume(); 00867 } 00868 00869 // Remote Wake Up has been received 00870 if (Is_host_remote_wakeup_interrupt_enabled() && Is_host_remote_wakeup()) 00871 { 00872 Host_disable_remote_wakeup_interrupt(); 00873 Host_disable_hwup_interrupt(); 00874 Host_ack_remote_wakeup(); 00875 Host_ack_hwup(); // Clear HWUP interrupt flag 00876 Pll_start_auto(); // First Restart the PLL for USB operation 00877 Wait_pll_ready(); // Get sure pll is lock 00878 Usb_unfreeze_clock(); // Enable clock on USB interface 00879 Host_enable_sof(); // start sending SOF 00880 Usb_send_event(EVT_HOST_REMOTE_WAKEUP); 00881 Usb_send_event(EVT_HOST_HWUP); // Send software event 00882 #if (USB_OTG_FEATURE == ENABLED) 00883 if (Is_usb_hnp()) 00884 { 00885 // Usb_host_reject_hnp(); 00886 Usb_disable_hnp_error_interrupt(); 00887 Usb_disable_role_exchange_interrupt(); 00888 } 00889 #endif 00890 Host_send_resume(); 00891 } 00892 #endif // End HOST FEATURE MODE 00893 }
Here is the call graph for this function:

| __interrupt void otg_timer_interrupt | ( | ) |
OTG TIMER interrupt subroutine.
This function is called each time a OTG Timer interrupt occurs (every 2ms @ 8 MHz) Function decrements the variables required by OTG program
| none |
OTG Messaging timer
Increments Tb_Srp counter if needed
Increments T_vbus_wait_connect if needed
Decrements Ta_aidl_bdis timer if needed (A_suspend state)
Decrements Timeout_bdev_respond timer if needed
Decrements Ta_vbus_rise timer if needed
Decrements Ta_vbus_fall timer if needed
Needed for compliance only
Definition at line 920 of file usb_task.c.
References A_PERIPHERAL, A_SUSPEND, Decrement_event_msg_delay, Decrement_failure_msg_delay, DEVICE_DEFAULT, device_state, FALSE, Get_event_msg_delay, Get_failure_msg_delay, Is_sof_interrupt_enabled, Is_srp_received_and_waiting_connect, Is_srp_sent_and_waiting_answer, Is_ta_vbus_fall_counter_overflow, Is_ta_vbus_rise_counter_overflow, Is_timeout_bdev_response_overflow, otg_end_hnp_vbus_delay, otg_last_sof_received, otg_last_sof_stored, otg_ta_aidl_bdis_tmr, otg_ta_srp_wait_connect, otg_ta_vbus_rise, otg_tb_srp_cpt, otg_timeout_bdev_respond, OTG_USE_TIMER, reset_received, Timer16_clear_compare_a_it, Timer16_get_counter_low, Timer16_select, timer16_selected, TRUE, Usb_disable_sof_interrupt, Usb_freeze_clock, and Usb_unfreeze_clock.
00922 { 00923 #if (USE_TIMER16 == BOTH_TIMER16) 00924 U8 tmr_sel_save = timer16_selected; // save timer currently selected 00925 #endif 00926 00927 Timer16_select(OTG_USE_TIMER); 00928 Timer16_clear_compare_a_it(); 00929 00931 #if ((OTG_MESSAGING_OUTPUT == OTGMSG_ALL) || (OTG_MESSAGING_OUTPUT == OTGMSG_FAIL)) 00932 if ((Get_failure_msg_delay() != 0x0000) && (Get_failure_msg_delay() != 0xFFFF)) { Decrement_failure_msg_delay(); } 00933 #if (OTG_MESSAGING_OUTPUT == OTGMSG_ALL) 00934 if ((Get_event_msg_delay() != 0x0000) && (Get_event_msg_delay() != 0xFFFF)) { Decrement_event_msg_delay(); } 00935 #endif 00936 #endif 00937 00939 if (Is_srp_sent_and_waiting_answer()) { otg_tb_srp_cpt++; } 00940 00942 if (Is_srp_received_and_waiting_connect()) { otg_ta_srp_wait_connect++; } 00943 00945 if ((device_state == A_SUSPEND) && (otg_ta_aidl_bdis_tmr > 1)) 00946 { otg_ta_aidl_bdis_tmr--; } 00947 00949 if ((device_state == DEVICE_DEFAULT) && (!Is_timeout_bdev_response_overflow())) 00950 { otg_timeout_bdev_respond--; } 00951 00953 if (!Is_ta_vbus_rise_counter_overflow()) { otg_ta_vbus_rise--; } 00954 00956 if (!Is_ta_vbus_fall_counter_overflow()) { otg_end_hnp_vbus_delay--; } 00957 00958 00959 00961 #if (OTG_COMPLIANCE_TRICKS == ENABLED) 00962 00963 if (device_state == A_PERIPHERAL) 00964 { 00965 if (Is_sof_interrupt_enabled() && (reset_received == TRUE)) 00966 { 00967 if (otg_last_sof_stored != otg_last_sof_received) 00968 { 00969 // No SOF is missing 00970 otg_last_sof_received = otg_last_sof_stored; 00971 } 00972 else 00973 { 00974 // SOF seems to be missing.. 00975 Usb_freeze_clock(); 00976 Usb_disable_sof_interrupt(); 00977 reset_received = FALSE; 00978 while (Timer16_get_counter_low() != 20); // overflow set to 62 in usb_task.h 00979 Usb_unfreeze_clock(); 00980 } 00981 otg_last_sof_received = UDFNUML; 00982 otg_last_sof_stored = UDFNUML; 00983 } 00984 } 00985 #endif 00986 00987 #if (USE_TIMER16 == BOTH_TIMER16) 00988 Timer16_select(tmr_sel_save); // restore timer that was selected before entering IT 00989 #endif 00990 }
| void suspend_action | ( | void | ) |
Definition at line 1035 of file usb_task.c.
References Enter_power_down_mode.
01036 { 01037 Enable_interrupt(); 01038 Enter_power_down_mode(); 01039 }
| void host_suspend_action | ( | void | ) |
Definition at line 131 of file usb_host_task.c.
Referenced by host_get_data_interrupt(), host_send_data_interrupt(), usb_general_interrupt(), and usb_pipe_interrupt().
| U8 code log_device_disconnect[] = "Device Disconnected" |
| U8 code log_id_change[] = "Pin Id Change" |
| bit usb_connected |
Public : (bit) usb_connected usb_connected is set to TRUE when VBUS has been detected usb_connected is set to FALSE otherwise Used with USB_DEVICE_FEATURE == ENABLED only /.
Definition at line 52 of file usb_device_task.c.
Referenced by usb_device_task(), and usb_general_interrupt().
| volatile S_pipe_int it_pipe_str[MAX_EP_NB] |
Definition at line 129 of file usb_host_task.c.
Referenced by host_get_data_interrupt(), host_send_data_interrupt(), is_any_interrupt_pipe_active(), reset_it_pipe_str(), usb_general_interrupt(), and usb_pipe_interrupt().
Definition at line 140 of file usb_task.c.
Referenced by usb_general_interrupt(), usb_task(), and usb_task_init().
| volatile U8 otg_last_sof_received |
Definition at line 176 of file usb_task.c.
Referenced by otg_timer_interrupt(), and usb_general_interrupt().
| volatile U8 otg_last_sof_stored |
Definition at line 177 of file usb_task.c.
Referenced by otg_timer_interrupt(), and usb_general_interrupt().
| volatile U8 reset_received |
Definition at line 178 of file usb_task.c.
Referenced by otg_timer_interrupt(), and usb_general_interrupt().
1.5.1-p1