#include "config.h"
#include "conf_usb.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/device_chap9/usb_device_task.h"
Include dependency graph for usb_task.c:
Go to the source code of this file.
Defines | |
#define | LOG_STR_CODE(str) |
Functions | |
void | usb_delay_ms (U8 ms) |
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. | |
Variables | |
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 U16 | delay_usb |
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 |
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 LOG_STR_CODE | ( | str | ) |
Definition at line 74 of file usb_task.c.
void usb_delay_ms | ( | U8 | ms | ) |
Definition at line 292 of file usb_task.c.
References delay_usb, and FOSC.
Referenced by usb_general_interrupt().
00293 { 00294 for(;ms;ms--) 00295 { 00296 for(delay_usb=0;delay_usb<FOSC/16;delay_usb++); 00297 } 00298 }
Here is the caller graph for this function:
__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:
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 206 of file usb_task.c.
References DISABLED, EVT_USB_RESET, EVT_USB_RESUME, EVT_USB_SUSPEND, EVT_USB_WAKE_UP, FALSE, Is_pll_ready, Is_reset_interrupt_enabled, Is_resume_interrupt_enabled, Is_sof_interrupt_enabled, Is_suspend_interrupt_enabled, Is_usb_reset, Is_usb_resume, Is_usb_sof, Is_usb_suspend, Is_usb_wake_up, Is_wake_up_interrupt_enabled, Stop_pll, TRUE, Usb_ack_reset, Usb_ack_resume, Usb_ack_sof, Usb_ack_suspend, Usb_ack_wake_up, usb_delay_ms(), Usb_direct_drive_disable, Usb_direct_drive_usb_enable, Usb_disable_resume_interrupt, Usb_disable_wake_up_interrupt, Usb_drive_dp_low, Usb_enable_reset_interrupt, Usb_enable_resume_interrupt, Usb_enable_suspend_interrupt, Usb_enable_wake_up_interrupt, Usb_freeze_clock, usb_init_device(), usb_remote_wup_feature, Usb_reset_action, Usb_resume_action, Usb_send_event, Usb_sof_action, Usb_suspend_action, usb_suspended, Usb_unfreeze_clock, Usb_wake_up_action, and Wait_pll_ready.
00208 { 00209 // - Device start of frame received 00210 if (Is_usb_sof() && Is_sof_interrupt_enabled()) 00211 { 00212 Usb_ack_sof(); 00213 Usb_sof_action(); 00214 } 00215 // - Device Suspend event (no more USB activity detected) 00216 if (Is_usb_suspend() && Is_suspend_interrupt_enabled()) 00217 { 00218 usb_suspended=TRUE; 00219 Usb_ack_wake_up(); // clear wake up to detect next event 00220 Usb_send_event(EVT_USB_SUSPEND); 00221 Usb_ack_suspend(); 00222 Usb_enable_wake_up_interrupt(); 00223 Usb_disable_resume_interrupt(); 00224 Usb_freeze_clock(); 00225 Stop_pll(); 00226 Usb_suspend_action(); 00227 } 00228 // - Wake up event (USB activity detected): Used to resume 00229 if (Is_usb_wake_up() && Is_wake_up_interrupt_enabled()) 00230 { 00231 if(Is_pll_ready()==FALSE) 00232 { 00233 Pll_start_auto(); 00234 Wait_pll_ready(); 00235 } 00236 Usb_unfreeze_clock(); 00237 Usb_ack_wake_up(); 00238 if(usb_suspended) 00239 { 00240 Usb_enable_resume_interrupt(); 00241 Usb_enable_reset_interrupt(); 00242 while(Is_usb_wake_up()) 00243 { 00244 Usb_ack_wake_up(); 00245 } 00246 usb_delay_ms(2); 00247 if(Is_usb_sof() || Is_usb_resume() || Is_usb_reset() ) 00248 { 00249 Usb_disable_wake_up_interrupt(); 00250 Usb_wake_up_action(); 00251 Usb_send_event(EVT_USB_WAKE_UP); 00252 Usb_enable_suspend_interrupt(); 00253 Usb_enable_resume_interrupt(); 00254 Usb_enable_reset_interrupt(); 00255 00256 } 00257 else // Workarround to make the USB enter power down mode again (spurious transcient detected on the USB lines) 00258 { 00259 if(Is_usb_wake_up()) return; 00260 Usb_drive_dp_low(); 00261 Usb_direct_drive_usb_enable(); 00262 Usb_direct_drive_disable(); 00263 Usb_disable_wake_up_interrupt(); 00264 } 00265 } 00266 } 00267 // - Resume state bus detection 00268 if (Is_usb_resume() && Is_resume_interrupt_enabled()) 00269 { 00270 usb_suspended = FALSE; 00271 Usb_disable_wake_up_interrupt(); 00272 Usb_ack_resume(); 00273 Usb_disable_resume_interrupt(); 00274 Usb_resume_action(); 00275 Usb_send_event(EVT_USB_RESUME); 00276 } 00277 // - USB bus reset detection 00278 if (Is_usb_reset()&& Is_reset_interrupt_enabled()) 00279 { 00280 #if (USB_REMOTE_WAKEUP == ENABLED) 00281 usb_remote_wup_feature = DISABLED; 00282 #endif 00283 Usb_ack_reset(); 00284 usb_init_device(); 00285 Usb_reset_action(); 00286 Usb_send_event(EVT_USB_RESET); 00287 } 00288 00289 }
Here is the call graph for this function:
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 69 of file usb_device_task.c.
Referenced by usb_device_task().
volatile S_pipe_int it_pipe_str[MAX_EP_NB] |
Definition at line 145 of file usb_task.c.