otg_user_task.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define SESSION_HOST   0xF0
#define SESSION_DEVICE   0x0F
#define SESSION_OFF   0x00
#define USB_NEW_PACKET   0xFF
#define USB_READ_PACKET   0x00
#define OTG_MOUSE_SPEED   15
#define Clear_usb_report()   (Usb_report[0]=0, Usb_report[1]=0, Usb_report[2]=0, Usb_report[3]=0)
#define Led_usb_connected_on()   Led0_on()
#define Led_usb_connected_off()   Led0_off()
#define Led_hid_toggle()   Led1_toggle()
#define Led_hid_off()   Led1_off()
#define Led_unsupported_on()   Led2_on()
#define Led_unsupported_off()   Led2_off()
#define Led_noresponse_on()   Led3_on()
#define Led_noresponse_off()   Led3_off()
#define Timer_select(ts)   Timer16_select(ts)
#define TIMER_DELAY   TIMER16_3
#define Delay_config(ms)
#define Delay_reset()   (Timer16_set_counter(0x0000), Timer16_clear_compare_a_it())
#define Is_delay_end()   (Timer16_get_compare_a_it())
#define Is_not_delay_end()   (!(Timer16_get_compare_a_it()))
#define Bp_delay_debounce()
#define host_hid_set_idle()
 this function send the hid specific request "hid_set_idle"
#define host_get_hid_repport_descriptor()
 this function send the hid specific request "get hid repport descriptor"

Functions

void otg_user_task_init (void)
void otg_user_task (void)
void Led_print_otg_status (void)


Define Documentation

#define SESSION_HOST   0xF0

Definition at line 11 of file otg_user_task.h.

Referenced by Led_print_otg_status(), and otg_user_task().

#define SESSION_DEVICE   0x0F

Definition at line 12 of file otg_user_task.h.

Referenced by Led_print_otg_status(), otg_user_task(), and otg_user_task_init().

#define SESSION_OFF   0x00

Definition at line 13 of file otg_user_task.h.

Referenced by Led_print_otg_status(), otg_user_task(), and otg_user_task_init().

#define USB_NEW_PACKET   0xFF

Definition at line 15 of file otg_user_task.h.

Referenced by otg_user_task().

#define USB_READ_PACKET   0x00

Definition at line 16 of file otg_user_task.h.

Referenced by otg_user_task(), and otg_user_task_init().

#define OTG_MOUSE_SPEED   15

Definition at line 18 of file otg_user_task.h.

 
#define Clear_usb_report (  )     (Usb_report[0]=0, Usb_report[1]=0, Usb_report[2]=0, Usb_report[3]=0)

Definition at line 20 of file otg_user_task.h.

Referenced by otg_user_task(), and otg_user_task_init().

 
#define Led_usb_connected_on (  )     Led0_on()

Definition at line 25 of file otg_user_task.h.

Referenced by Led_print_otg_status(), and otg_user_task().

 
#define Led_usb_connected_off (  )     Led0_off()

Definition at line 26 of file otg_user_task.h.

Referenced by Led_print_otg_status(), and otg_user_task().

 
#define Led_hid_toggle (  )     Led1_toggle()

Definition at line 28 of file otg_user_task.h.

Referenced by otg_user_task().

 
#define Led_hid_off (  )     Led1_off()

Definition at line 29 of file otg_user_task.h.

Referenced by otg_user_task().

 
#define Led_unsupported_on (  )     Led2_on()

Definition at line 31 of file otg_user_task.h.

Referenced by Otg_output_failure_msg().

 
#define Led_unsupported_off (  )     Led2_off()

Definition at line 32 of file otg_user_task.h.

Referenced by Otg_clear_failure_message(), and Otg_messaging_init().

 
#define Led_noresponse_on (  )     Led3_on()

Definition at line 34 of file otg_user_task.h.

Referenced by Otg_output_failure_msg().

 
#define Led_noresponse_off (  )     Led3_off()

Definition at line 35 of file otg_user_task.h.

Referenced by Otg_clear_failure_message(), and Otg_messaging_init().

#define Timer_select ( ts   )     Timer16_select(ts)

Definition at line 56 of file otg_user_task.h.

#define TIMER_DELAY   TIMER16_3

Definition at line 57 of file otg_user_task.h.

#define Delay_config ( ms   ) 

Value:

Definition at line 61 of file otg_user_task.h.

 
#define Delay_reset (  )     (Timer16_set_counter(0x0000), Timer16_clear_compare_a_it())

Definition at line 65 of file otg_user_task.h.

 
#define Is_delay_end (  )     (Timer16_get_compare_a_it())

Definition at line 66 of file otg_user_task.h.

 
#define Is_not_delay_end (  )     (!(Timer16_get_compare_a_it()))

Definition at line 67 of file otg_user_task.h.

 
#define Bp_delay_debounce (  ) 

Value:

Definition at line 71 of file otg_user_task.h.

Referenced by otg_user_task().

 
#define host_hid_set_idle (  ) 

Value:

this function send the hid specific request "hid_set_idle"

Parameters:
none 
Returns:
status

Definition at line 85 of file otg_user_task.h.

Referenced by otg_user_task().

 
#define host_get_hid_repport_descriptor (  ) 

Value:

this function send the hid specific request "get hid repport descriptor"

Parameters:
none 
Returns:
status

Definition at line 102 of file otg_user_task.h.

Referenced by otg_user_task().


Function Documentation

void otg_user_task_init ( void   ) 

Definition at line 67 of file otg_user_task.c.

References button_high, Clear_usb_report, device_connected, FALSE, Hwb_button_init, Joy_init, Led_print_otg_status(), Leds_init, Leds_off, previous_session, previous_vbus, SESSION_DEVICE, SESSION_OFF, USB_READ_PACKET, and Usb_report_status.

00068 {
00069   // Board init
00070   Leds_init();
00071   Joy_init();
00072   Hwb_button_init();
00073   Leds_off();
00074   
00075   previous_session = SESSION_DEVICE;  // to make the function Led_print_otg_status() display the first status
00076   previous_vbus = 0;
00077   device_connected = SESSION_OFF;
00078   Led_print_otg_status();
00079 
00080   Enable_interrupt();
00081   
00082   Clear_usb_report();
00083   Usb_report_status = USB_READ_PACKET;
00084   button_high = FALSE;
00085 }

Here is the call graph for this function:

void otg_user_task ( void   ) 

Definition at line 88 of file otg_user_task.c.

References Bp_delay_debounce, button_high, Clear_usb_report, device_connected, EP_SPIDER_IN, FALSE, Get_class, Get_ep_addr, Get_nb_supported_interface, Get_protocol, HID_CLASS, Host_ack_in_received, Host_continuous_in_mode, host_get_hid_repport_descriptor, host_get_hwd_pipe_nb(), host_hid_set_idle, Host_read_byte, Host_select_pipe, Host_send_in, Host_unfreeze_pipe, Is_device_disconnection_event, Is_host_in_received, Is_host_ready, Is_host_stall, Is_hwb, Is_joy_select, Is_new_device_connection_event, Is_usb_device_enabled, Is_usb_host_enabled, Is_usb_id_host, Is_usb_write_enabled, Led_hid_off, Led_hid_toggle, Led_print_otg_status(), Led_usb_connected_off, Led_usb_connected_on, mouse_move, MOUSE_PROTOCOL, PIPE_SPIDER_IN, SESSION_DEVICE, SESSION_HOST, SESSION_OFF, Set_user_request_hnp, Set_user_request_srp, Set_user_request_vbus, TRUE, Usb_ack_fifocon, usb_configuration_nb, USB_NEW_PACKET, USB_READ_PACKET, Usb_report, Usb_report_status, Usb_select_endpoint, and Usb_write_byte.

00089 {
00090 U8 i;
00091 
00092   // ==============================
00093   // ** USB low-level management **
00094   // ==============================
00095 
00096   // ================
00097   // In HOST mode, USB high-level management
00098   // ================
00099   if (Is_usb_host_enabled())
00100   {
00101     if (Is_host_ready())
00102     {
00103     // In HOST mode, check if a new peripheral has been connected
00104       if (Is_new_device_connection_event())
00105       {
00106         for(i=0;i<Get_nb_supported_interface();i++)
00107         {
00108            if (Get_class(i)==HID_CLASS && Get_protocol(i)==MOUSE_PROTOCOL)
00109            {
00110               device_connected = SESSION_HOST;
00111               Led_usb_connected_off();
00112               Led_hid_off();
00113               host_hid_set_idle();
00114               host_get_hid_repport_descriptor();
00115               PIPE_SPIDER_IN = host_get_hwd_pipe_nb(Get_ep_addr(i,0));
00116               Host_select_pipe(PIPE_SPIDER_IN);
00117               Host_continuous_in_mode();
00118               Host_unfreeze_pipe();
00119               button_high = FALSE;
00120               mouse_move = 0;
00121               break;
00122            }
00123         }
00124       }
00125     }
00126     else
00127     {
00128       Led_usb_connected_off();
00129       Led_hid_off();
00130       device_connected = SESSION_OFF;
00131     }
00132       
00133 
00134     // Disconnection event
00135     if(Is_device_disconnection_event())
00136     {
00137       Led_usb_connected_off();
00138       Led_hid_off();
00139       device_connected = SESSION_OFF;
00140     }
00141 
00142     // In HOST mode, check for new packet received
00143     if (device_connected == SESSION_HOST)  // Peripheral is connected and enumerated
00144     {
00145       // 1. Get new data from Device
00146       Host_select_pipe(PIPE_SPIDER_IN);
00147       if ((Is_host_in_received()) && (Is_host_stall()==FALSE) && (Usb_report_status != USB_NEW_PACKET))
00148       {
00149         i = 0;
00150         while ((UPBCLX != 0) && (i != 4))
00151         {
00152           Usb_report[i] = Host_read_byte();
00153           i++;
00154         }
00155         Usb_report_status = USB_NEW_PACKET;
00156 
00157         Host_ack_in_received();
00158         Host_send_in();
00159       }
00160     }
00161   }
00162 
00163   // ================
00164   // In DEVICE mode, USB high-level management
00165   // ================
00166   if (Is_usb_device_enabled())
00167   {
00168     if (usb_configuration_nb != 0)  // is device configured and enumerated ?
00169     {
00170       Led_usb_connected_on();
00171       device_connected = SESSION_DEVICE;
00172       Usb_select_endpoint(EP_SPIDER_IN);    // endpoint sending data to HOST
00173       if ((Is_usb_write_enabled()) && (Usb_report_status == USB_NEW_PACKET))
00174       {
00175         Usb_write_byte(Usb_report[0]);
00176         Usb_write_byte(Usb_report[1]);
00177         Usb_write_byte(Usb_report[2]);
00178         Usb_write_byte(Usb_report[3]);
00179         Usb_report_status = USB_READ_PACKET;
00180         Usb_ack_fifocon();               // Send data over the USB
00181         Clear_usb_report();
00182       }
00183     }
00184     else
00185     {
00186       Led_usb_connected_off();
00187       Led_hid_off();
00188       device_connected = SESSION_OFF;
00189     }
00190   }
00191 
00192 
00193   // =======================
00194   // ** Application level **
00195   // DEVICE mode : send HID report with information about CENTER pushbutton (push / release)
00196   // HOST mode : toggle the LED according to button position
00197   // =======================
00198   if (device_connected == SESSION_DEVICE)
00199   {
00200     // Acquires moves from mouse
00201     // If notorious change (more than 4%), the difference is sent to Host
00202     if (Usb_report_status != USB_NEW_PACKET)
00203     {
00204       if (Is_joy_select())
00205       {
00206         // Pushbutton debounce is handled by USB Pipe polling frequency (EP_INTERVAL_1 value in "usb_descriptors.h")
00207         Usb_report[0] = 0x01;
00208         Usb_report_status = USB_NEW_PACKET;
00209       }
00210       else
00211       {
00212         Usb_report[0] = 0x00;
00213         Usb_report_status = USB_NEW_PACKET;
00214       }
00215     }
00216   }
00217 
00218   if (device_connected == SESSION_HOST)
00219   {
00220     if (Usb_report_status == USB_NEW_PACKET)
00221     {
00222       if ((Usb_report[0]&0x01) == 0)
00223       {
00224         if (button_high == TRUE)    { button_high = FALSE; }
00225       }
00226       else
00227       {
00228         if (button_high == FALSE)
00229         {
00230           button_high = TRUE;
00231           Led_hid_toggle();
00232         }        
00233       }
00234       Usb_report_status = USB_READ_PACKET;
00235       Clear_usb_report();
00236     }
00237   }
00238 
00239   
00240   
00241   // =================================================================
00242   // OTG User Request Management
00243   // According to the Role, pushbuttons will initiate different events
00244   // =================================================================
00245   if (Is_usb_device_enabled())
00246   {
00247     if (!Is_usb_id_host() && (usb_configuration_nb == 0))
00248     {
00249       // SRP Request : HWB Button
00250       // ***********
00251       if (Is_hwb())
00252       {
00253         Bp_delay_debounce();
00254         while (Is_hwb());
00255         Bp_delay_debounce();
00256         Set_user_request_srp();
00257       }
00258     }
00259     if (Is_usb_id_host())
00260     {
00261       // VBUS Toggle Request : HWB Button   // to allow session ends when in A-PERIPHERAL mode
00262       // *******************
00263       if (Is_hwb())
00264       {
00265         Bp_delay_debounce();
00266         while (Is_hwb());
00267         Bp_delay_debounce();
00268         Set_user_request_vbus();
00269       }
00270     }
00271   }
00272 
00273   if (Is_usb_host_enabled())
00274   {
00275     // VBUS Toggle Request : HWB Button
00276     // *******************
00277     if (Is_hwb())
00278     {
00279       Bp_delay_debounce();
00280       while (Is_hwb());
00281       Bp_delay_debounce();
00282       Set_user_request_vbus();
00283     }
00284     
00285     // HNP Toggle Request : CENTER Button
00286     // *******************
00287     if (Is_joy_select())
00288     {
00289       Bp_delay_debounce();
00290       while (Is_joy_select());
00291       Bp_delay_debounce();
00292       Set_user_request_hnp();
00293     }
00294   }
00295 
00296   Led_print_otg_status();
00297 }

Here is the call graph for this function:

void Led_print_otg_status ( void   ) 

Definition at line 305 of file otg_user_task.c.

References device_connected, Is_usb_id_host, Is_usb_vbus_high, Led_usb_connected_off, Led_usb_connected_on, previous_session, previous_vbus, SESSION_DEVICE, SESSION_HOST, and SESSION_OFF.

Referenced by otg_user_task(), and otg_user_task_init().

00306 {
00307   U8 vbus_state = 0;
00308   if ((Is_usb_vbus_high()) || ((Is_usb_id_host()) && ((PORTE&0x80) != 0)))    { vbus_state = 1; }
00309   if ((previous_session != device_connected) || (previous_vbus != vbus_state))
00310   {
00311     switch (device_connected)
00312     {
00313     case SESSION_HOST:
00314       Led_usb_connected_off();
00315       break;
00316 
00317     case SESSION_DEVICE:
00318       Led_usb_connected_on();
00319       break;
00320 
00321     case SESSION_OFF:
00322       Led_usb_connected_off();
00323       break;
00324 
00325     default:
00326       Led_usb_connected_off();
00327       break;
00328     }
00329     previous_session = device_connected;
00330     previous_vbus = vbus_state;
00331   }
00332 }


Generated on Mon Feb 19 09:31:52 2007 for Atmel by  doxygen 1.5.1-p1