Xmega Application Note | |||||
This module also contains the general USB interrupt subroutine. This subroutine is used to detect asynchronous USB events.
Copyright (c) 2010, Atmel Corporation All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file usb_task.c.
#include "config.h"
#include "conf_usb.h"
#include "usb_task.h"
#include "usb_drv.h"
#include "usb_descriptors.h"
#include "usb_device_task.h"
Go to the source code of this file.
Functions | |
ISR (USB_GEN_vect) | |
USB interrupt subroutine. | |
void | suspend_action (void) |
Suspend action management. | |
void | usb_task (void) |
Entry point of the USB mamnagement. | |
void | usb_task_init (void) |
This function initializes the USB proces. | |
Variables | |
volatile uint16_t | g_usb_event = 0 |
uint8_t | usb_configuration_nb |
Store the number of the USB configuration used by the USB device. | |
uint8_t | usb_connected |
Global connection status byte. |
ISR | ( | USB_GEN_vect | ) |
USB interrupt subroutine.
This function is called each time a USB interrupt occurs. The following USB DEVICE 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)
Definition at line 107 of file usb_task.c.
References EVT_USB_POWERED, EVT_USB_RESET, EVT_USB_RESUME, EVT_USB_SUSPEND, EVT_USB_UNPOWERED, EVT_USB_WAKE_UP, Is_reset_interrupt_enabled, Is_resume_interrupt_enabled, Is_sof_interrupt_enabled, Is_suspend_interrupt_enabled, Is_swake_up_interrupt_enabled, Is_usb_reset, Is_usb_resume, Is_usb_sof, Is_usb_suspend, Is_usb_vbus_high, Is_usb_vbus_interrupt_enabled, Is_usb_vbus_transition, Is_usb_wake_up, Usb_ack_reset, Usb_ack_resume, Usb_ack_sof, Usb_ack_suspend, Usb_ack_vbus_transition, Usb_ack_wake_up, Usb_attach, usb_connected, Usb_disable_resume_interrupt, Usb_disable_wake_up_interrupt, Usb_enable_reset_interrupt, Usb_enable_wake_up_interrupt, Usb_freeze_clock, usb_init_device(), Usb_reset_action, Usb_resume_action, Usb_send_event, Usb_sof_action, usb_start_device(), Usb_suspend_action, Usb_unfreeze_clock, Usb_vbus_off_action, Usb_vbus_on_action, and Usb_wake_up_action.
00108 { 00109 /* VBUS state detection */ 00110 if (Is_usb_vbus_transition() && Is_usb_vbus_interrupt_enabled()){ 00111 Usb_ack_vbus_transition(); 00112 if (Is_usb_vbus_high()){ 00113 usb_connected = true; 00114 Usb_vbus_on_action(); 00115 Usb_send_event(EVT_USB_POWERED); 00116 Usb_enable_reset_interrupt(); 00117 usb_start_device(); 00118 Usb_attach(); 00119 }else{ 00120 Usb_vbus_off_action(); 00121 usb_connected = false; 00122 Usb_send_event(EVT_USB_UNPOWERED); 00123 } 00124 } 00125 /* Device start of frame received */ 00126 if (Is_usb_sof() && Is_sof_interrupt_enabled()){ 00127 Usb_ack_sof(); 00128 Usb_sof_action(); 00129 } 00130 /* Device Suspend event (no more USB activity detected) */ 00131 if (Is_usb_suspend() && Is_suspend_interrupt_enabled()){ 00132 Usb_ack_suspend(); 00133 Usb_enable_wake_up_interrupt(); 00134 Usb_ack_wake_up(); 00135 Usb_freeze_clock(); 00136 Usb_send_event(EVT_USB_SUSPEND); 00137 Usb_suspend_action(); 00138 } 00139 /* Wake up event (USB activity detected): Used to resume */ 00140 if (Is_usb_wake_up() && Is_swake_up_interrupt_enabled()){ 00141 Usb_unfreeze_clock(); 00142 Usb_ack_wake_up(); 00143 Usb_disable_wake_up_interrupt(); 00144 Usb_wake_up_action(); 00145 Usb_send_event(EVT_USB_WAKE_UP); 00146 } 00147 00148 /* Resume state bus detection */ 00149 if (Is_usb_resume() && Is_resume_interrupt_enabled()){ 00150 Usb_disable_wake_up_interrupt(); 00151 Usb_ack_resume(); 00152 Usb_disable_resume_interrupt(); 00153 Usb_resume_action(); 00154 Usb_send_event(EVT_USB_RESUME); 00155 } 00156 00157 /* USB bus reset detection */ 00158 if (Is_usb_reset()&& Is_reset_interrupt_enabled()){ 00159 Usb_ack_reset(); 00160 usb_init_device(); 00161 Usb_reset_action(); 00162 Usb_send_event(EVT_USB_RESET); 00163 } 00164 00165 }
void suspend_action | ( | void | ) |
Suspend action management.
Use this function to handle the suspend command.
Definition at line 171 of file usb_task.c.
void usb_task | ( | void | ) |
Entry point of the USB mamnagement.
Depending on the USB mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the coresponding usb management function.
Definition at line 82 of file usb_task.c.
References usb_device_task().
Referenced by main().
00083 { 00084 usb_device_task(); 00085 00086 }
void usb_task_init | ( | void | ) |
This function initializes the USB proces.
Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls the coresponding usb mode initialization function
Definition at line 70 of file usb_task.c.
References usb_device_task_init(), and Usb_force_device_mode.
Referenced by main().
00071 { 00072 Usb_force_device_mode(); 00073 usb_device_task_init(); 00074 }
volatile uint16_t g_usb_event = 0 |
Definition at line 59 of file usb_task.c.
uint8_t 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
Definition at line 85 of file usb_standard_request.c.
uint8_t usb_connected |
Global connection status byte.
usb_connected is set to true when VBUS has been detected usb_connected is set to false otherwise
Definition at line 65 of file usb_device_task.c.
Referenced by ISR(), usb_device_task(), usb_enum_var_init(), and usb_start_device().
Generated on Mon Jan 18 09:26:15 2010 for AVR1907 Xplain USB Gateway by ![]() |