Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

usb_task.c File Reference

Copyright (c) 2004 This file manages the USB controller. More...

#include "config.h"
#include "conf\conf_usb.h"
#include "usb_task.h"
#include "lib_mcu\usb\usb_drv.h"
#include "modules\usb\usb_enum.h"
#include "intrins.h"

Go to the source code of this file.

Functions

void usb_task_init (void)
 This function initializes the USB the associated variables.

void usb_start_device (void)
 This function initializes the USB device controller.

void usb_task (void)
 Entry point of the USB mamnagement.

void usb_interrupt (void)
 USB interrupt process.


Variables

volatile 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 /.

U8 xdata sof_counter
volatile U8 data toggle_next_time
_MEM_TYPE_SLOW_ U8 usb_configuration_nb
volatile bit usb_continuous_mode
U8 send_free = 0
S_hid_set_control SetControlBytes


Detailed Description

Copyright (c) 2004 This file manages the USB controller.

Please read file license.txt for copyright notice.

The USB task checks the income of new requests from the USB Host. When a Setup request occurs, this task will launch the processing of this setup contained in the usb_enum.c file. Other class specific requests are also processed in this file. This file manages all the USB events: Suspend / Resume / Reset / Start Of Frame / Wake Up / Vbus events

Version:
1.10.2.2 (c5131-usb-generic-1_2_0)

Todo:

Bug:
/

Definition in file usb_task.c.


Function Documentation

void usb_task_init void   ) 
 

This function initializes the USB the associated variables.

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.

Warning:
Code:?? bytes (function code length)
Parameters:
none 
Returns:
none
/

Definition at line 68 of file usb_task.c.

References FALSE, Set_page_usb, sof_counter, toggle_next_time, TRUE, usb_connected, usb_continuous_mode, Usb_enable, and usb_start_device().

00069 { 00070 Set_page_usb(); 00071 Usb_enable(); // enable the USB controller 00072 usb_start_device(); 00073 sof_counter = 0; 00074 usb_connected = TRUE; 00075 toggle_next_time = 0; 00076 usb_continuous_mode = FALSE; 00077 }

void usb_start_device void   ) 
 

This function initializes the USB device controller.

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.

Warning:
Code:?? bytes (function code length)
Parameters:
none 
Returns:
none
/

Definition at line 95 of file usb_task.c.

References Enable_interrupt, Enable_usb_interrupt, Set_page_usb, U16, Usb_ack_suspend, Usb_attach, Usb_detach, Usb_enable_reset_interrupt, Usb_enable_resume_interrupt, Usb_enable_sof_interrupt, Usb_enable_suspend_interrupt, Usb_enable_wake_up_interrupt, usb_generate_clock(), usb_init_device(), Usb_set_speed, and Usb_unfreeze_clock.

Referenced by usb_task_init().

00096 { 00097 U16 c; 00098 usb_generate_clock(); 00099 Set_page_usb(); 00100 Usb_unfreeze_clock(); 00101 Usb_set_speed(); // for speed analysis 00102 Usb_ack_suspend(); 00103 Usb_detach(); 00104 for (c=0; c<1000; c++); 00105 Usb_attach(); 00106 Usb_enable_suspend_interrupt(); 00107 Usb_enable_resume_interrupt(); 00108 Usb_enable_reset_interrupt(); 00109 Usb_enable_wake_up_interrupt(); 00110 Usb_enable_sof_interrupt(); 00111 Enable_usb_interrupt(); 00112 Enable_interrupt(); 00113 usb_init_device(); // configure the USB controller EP0 00114 00115 Usb_attach(); 00116 }

void usb_task void   ) 
 

Entry point of the USB mamnagement.

This function is the entry point of the USB management. Each USB event is checked here in order to launch the appropriate action. If a Setup request occurs on the Default Control Endpoint, the usb_process_request() function is call in the usb_enum.c file If a new USB mass storage Command Block Wrapper (CBW) occurs, this one will be decoded and the SCSI command will be taken in charge by the scsi decoder.

Warning:
Code:?? bytes (function code length)
Parameters:
none 
Returns:
none

this part of the code can be modify following the application

end of modification

Definition at line 133 of file usb_task.c.

References Disable_ale, Enable_interrupt, EP_CONTROL, EP_HID_IN, FALSE, Is_usb_in_ready, Is_usb_receive_setup, Led_all_off, Pll_stop, send_free, Set_page_usb, SetControlBytes, TRUE, S_hid_set_control::type, Usb_ack_in_ready, usb_connected, usb_continuous_mode, usb_process_request(), Usb_select_endpoint, and Usb_suspend_action.

00134 { 00135 if (!usb_connected) /* power down mode when USB not connected */ 00136 { 00137 Pll_stop(); /* disable PLL before going in power down mode */ 00138 Enable_interrupt(); 00139 00140 // Shutdown board ressources 00141 Led_all_off(); 00142 Disable_ale(); 00143 if (!usb_connected) 00144 { 00145 Usb_suspend_action(); // see in conf_usb.h 00146 _nop_(); 00147 } 00148 } 00149 else //USB Connected 00150 { 00151 // USB MANAGEMENT 00152 00153 Set_page_usb (); 00154 00155 Usb_select_endpoint(EP_CONTROL); 00156 if (Is_usb_receive_setup()) 00157 { 00158 usb_process_request(); 00159 if(SetControlBytes.type==0) { usb_continuous_mode = FALSE; } 00160 if(SetControlBytes.type==1) { usb_continuous_mode = TRUE ; } 00161 00162 } 00166 00167 if(usb_continuous_mode == TRUE) 00168 { 00169 Usb_select_endpoint(EP_HID_IN); 00170 if(Is_usb_in_ready()) 00171 { 00172 send_free = 1; 00173 Usb_ack_in_ready(); 00174 } 00175 } 00176 00180 } 00181 }

void usb_interrupt void   ) 
 

USB interrupt process.

This function is called each time a USB interrupt occurs. The following USB events are taken in charge:

  • Suspend
  • Wake-Up
  • Reset For each event, the user can launch an action by completing the associate define

Warning:
Code:?? bytes (function code length)
Parameters:
none 
Returns:
none

Definition at line 199 of file usb_task.c.

References Enable_ale, FALSE, Is_usb_reset, Is_usb_sof, Is_usb_suspend, Is_usb_wake_up, Pll_enable, sof_counter, Switch_ale, TRUE, Usb_ack_reset, Usb_ack_sof, Usb_ack_suspend, Usb_ack_wake_up, usb_connected, usb_continuous_mode, Usb_enable_sof_interrupt, Usb_enable_suspend_interrupt, Usb_enable_wake_up_interrupt, usb_enum_var_init(), Usb_freeze_clock, and Usb_unfreeze_clock.

00200 { 00201 if (Is_usb_sof()) 00202 { 00203 Usb_ack_sof(); 00204 sof_counter++; 00205 if (usb_continuous_mode == FALSE) 00206 { 00207 if (sof_counter == 0x40) 00208 { 00209 Switch_ale(); 00210 sof_counter = 0; 00211 } 00212 } 00213 else 00214 { 00215 if (sof_counter == 0xFF) 00216 { 00217 Switch_ale(); 00218 } 00219 } 00220 return; 00221 } 00222 00223 if (Is_usb_suspend()) 00224 { 00225 Usb_ack_suspend(); 00226 Usb_freeze_clock(); 00227 usb_connected = FALSE; 00228 } 00229 00230 if (Is_usb_wake_up()) 00231 { 00232 if (!usb_connected) /* reconfigure PLL when exiting power down mode */ 00233 { 00234 Pll_enable(); 00235 } 00236 Usb_unfreeze_clock(); 00237 Enable_ale(); 00238 Usb_ack_suspend(); 00239 Usb_ack_wake_up(); 00240 usb_connected = TRUE; 00241 } 00242 00243 if (Is_usb_reset()) 00244 { 00245 Usb_ack_reset(); 00246 usb_enum_var_init(); 00247 Usb_enable_suspend_interrupt(); 00248 Usb_enable_wake_up_interrupt(); 00249 Usb_enable_sof_interrupt(); 00250 usb_connected = TRUE; 00251 } 00252 }


Variable Documentation

volatile 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 /.

Definition at line 42 of file usb_task.c.

Referenced by usb_enum_var_init(), usb_interrupt(), usb_task(), and usb_task_init().

U8 xdata sof_counter
 

Definition at line 43 of file usb_task.c.

Referenced by usb_interrupt(), and usb_task_init().

volatile U8 data toggle_next_time
 

Definition at line 44 of file usb_task.c.

Referenced by usb_task_init().

_MEM_TYPE_SLOW_ U8 usb_configuration_nb
 

Definition at line 46 of file usb_task.c.

volatile bit usb_continuous_mode
 

Definition at line 48 of file usb_task.c.

Referenced by usb_interrupt(), usb_task(), and usb_task_init().

U8 send_free = 0
 

Definition at line 49 of file usb_task.c.

Referenced by usb_task(), usb_user_endpoint_init(), and usb_write_continuous().

S_hid_set_control SetControlBytes
 

Definition at line 51 of file usb_task.c.

Referenced by usb_task(), and usb_user_read_request().


Generated on Mon Apr 10 17:23:31 2006 for Atmel by doxygen 1.3.7