usb_host_task.c File Reference

,vThis file manages the USB Host controller, the host enumeration process and suspend resume host requests. More...

#include "config.h"
#include "conf_usb.h"
#include "modules/usb/usb_task.h"
#include "usb_host_task.h"
#include "lib_mcu/usb/usb_drv.h"
#include "lib_mcu/pll/pll_drv.h"
#include "modules/usb/host_chap9/usb_host_enum.h"
#include "modules/usb/device_chap9/usb_device_task.h"

Include dependency graph for usb_host_task.c:

Go to the source code of this file.

Defines

#define Host_device_class_not_supported_action()

Functions

void usb_host_task_init (void)
 This function initializes the USB controller in host mode, the associated variables and interrupts enables.
void usb_host_task (void)
 Entry point of the host management.
U8 host_send_data (U8 pipe, U16 nb_data, U8 *buf)
 This function send nb_data pointed with *buf with the pipe number specified.
U8 host_get_data (U8 pipe, U16 *nb_data, U8 *buf)
 This function receives nb_data pointed with *buf with the pipe number specified.
void reset_it_pipe_str (void)
U8 is_any_interrupt_pipe_active (void)
U8 host_get_data_interrupt (U8 pipe, U16 nb_data, U8 *buf, void(*handle)(U8 status, U16 nb_byte))
 This function receives nb_data pointed with *buf with the pipe number specified.
U8 host_send_data_interrupt (U8 pipe, U16 nb_data, U8 *buf, void(*handle)(U8 status, U16 nb_byte))
 This function send nb_data pointed with *buf with the pipe number specified.
__interrupt void usb_pipe_interrupt ()
 USB pipe interrupt subroutine.

Variables

U8 code log_device_connected [] = "Device Connection"
U8 code log_device_enumerated [] = "Device Enumerated"
U8 code log_device_unsupported [] = "Unsupported Device"
U8 code log_going_to_suspend [] = "Usb suspend"
U8 code log_usb_resumed [] = "Usb resumed"
volatile S_pipe_int it_pipe_str [MAX_EP_NB]
volatile U8 pipe_nb_save
U8 g_sav_int_sof_enable
U16 otg_ta_srp_wait_connect
 Public : (U8) otg_device_connected; Min.
U16 otg_ta_aidl_bdis_tmr
 Public : (U8) otg_device_connected; Max.
U8 otg_ta_vbus_rise
 Public : (U8) otg_device_connected; Max.
U16 otg_timeout_bdev_respond
 Public : (U8) otg_device_connected; Max.
U8 otg_device_connected
 Public : (U8) otg_device_connected; Indicates if the connected peripheral is an OTG Device or not.
U8 otg_a_device_srp
 Public : (U8) otg_a_device_srp; Stores special events about SRP in A-Device mode.
U16 otg_end_hnp_vbus_delay
 Public : (U8) otg_end_hnp_vbus_delay; Variable used for timing Vbus discharge to avoid bounces around vbus_valid threshold.
U8 device_state
 Public : U8 device_state Its value represent the current state of the device connected to the usb host controller Value can be:
  • DEVICE_ATTACHED
  • DEVICE_POWERED
  • DEVICE_SUSPENDED
  • DEVICE_DEFAULT
  • DEVICE_ADDRESSED
  • DEVICE_CONFIGURED
  • DEVICE_ERROR
  • DEVICE_UNATTACHED
  • DEVICE_READY
  • DEVICE_WAIT_RESUME
  • DEVICE_DISCONNECTED
  • DEVICE_DISCONNECTED_ACK.

S_usb_setup_data usb_request
 For control requests management over pipe 0.
U8 data_stage [250]
 Public : U8 data_stage[SIZEOF_DATA_STAGE]; Internal RAM buffer for USB data stage content This buffer is required to setup host enumeration process Its contains the device descriptors received.
U8 device_status
U8 request_resume
static U16 c
U8 new_device_connected = 0


Detailed Description

,vThis file manages the USB Host controller, the host enumeration process and suspend resume host requests.

Copyright (c) 2004 Atmel.

Please read file license.txt for copyright notice.

This task dos not belongs to the scheduler tasks but is called directly from the general usb_task

Version:
1.21 at90usb128-otg-dual_role-toggle-1_0_0
Id
usb_host_task.c,v 1.21 2007/02/13 12:10:34 arobert Exp
Todo:
Bug:

Definition in file usb_host_task.c.


Define Documentation

 
#define Host_device_class_not_supported_action (  ) 

Definition at line 102 of file usb_host_task.c.

Referenced by usb_host_task().


Function Documentation

__interrupt void usb_pipe_interrupt (  ) 

USB pipe interrupt subroutine.

Parameters:
none 
Returns:
none

Definition at line 1639 of file usb_host_task.c.

References DISABLE, S_pipe_int::enable, FALSE, g_sav_int_sof_enable, S_pipe_int::handle, Host_ack_all_errors, Host_ack_in_received, Host_ack_nak_received, Host_ack_out_sent, Host_byte_counter, Host_disable_sof_interrupt, Host_error_status, Host_freeze_pipe, Host_get_pipe_length, Host_get_pipe_type, Host_get_selected_pipe, Host_read_byte, Host_select_pipe, Host_send_in, Host_send_out, Host_stop_pipe_interrupt, Host_unfreeze_pipe, Host_write_byte, is_any_interrupt_pipe_active(), Is_host_in_received, Is_host_nak_received, Is_host_out_sent, Is_host_pipe_error, Is_host_stall, it_pipe_str, NAK_RECEIVE_TIMEOUT, NAK_SEND_TIMEOUT, S_pipe_int::nak_timeout, S_pipe_int::nb_byte_on_going, S_pipe_int::nb_byte_processed, S_pipe_int::nb_byte_to_process, PIPE_GOOD, PIPE_NAK_TIMEOUT, pipe_nb_save, PIPE_STALL, private_sof_counter, S_pipe_int::ptr_buf, S_pipe_int::status, S_pipe_int::timeout, TRUE, TYPE_INTERRUPT, and usb_get_nb_pipe_interrupt().

01641 {
01642    U8 pipe_nb;
01643    U8 *ptr_buf;
01644    void  (*fct_handle)(U8 status,U16 nb_byte);
01645    U16 n;
01646    U8 i;
01647    U8 do_call_back=FALSE;
01648 
01649    pipe_nb_save = Host_get_selected_pipe();       // Important! Save here working pipe number
01650    pipe_nb=usb_get_nb_pipe_interrupt();  // work with the correct pipe number that generates the interrupt
01651    Host_select_pipe(pipe_nb);                        // Select this pipe
01652    fct_handle=*(it_pipe_str[pipe_nb].handle);
01653 
01654    // Now try to detect what event generate an interrupt...
01655 
01656    if (Is_host_pipe_error())             // Any error ?
01657    {
01658       it_pipe_str[pipe_nb].status = Host_error_status();
01659       it_pipe_str[pipe_nb].enable=DISABLE;
01660       Host_stop_pipe_interrupt(pipe_nb);
01661       Host_ack_all_errors();
01662       do_call_back=TRUE;
01663       goto usb_pipe_interrupt_end;
01664    }
01665 
01666    if (Is_host_stall())                  // Stall handshake received ?
01667    {
01668       it_pipe_str[pipe_nb].status=PIPE_STALL;
01669       it_pipe_str[pipe_nb].enable=DISABLE;
01670       Host_stop_pipe_interrupt(pipe_nb);
01671       do_call_back=TRUE;
01672       goto usb_pipe_interrupt_end;
01673    }
01674 
01675    #if (NAK_TIMEOUT_ENABLE==ENABLE)
01676    if (Is_host_nak_received())           // NAK ?
01677    {
01678       Host_ack_nak_received();
01679       // check if number of NAK timeout error occurs (not for interrupt type pipe)
01680       if((--it_pipe_str[pipe_nb].nak_timeout==0) && (Host_get_pipe_type()!=TYPE_INTERRUPT))
01681       {
01682          it_pipe_str[pipe_nb].status=PIPE_NAK_TIMEOUT;
01683          it_pipe_str[pipe_nb].enable=DISABLE;
01684          Host_stop_pipe_interrupt(pipe_nb);
01685          do_call_back=TRUE;
01686          goto usb_pipe_interrupt_end;
01687       }
01688    }
01689    #endif
01690 
01691    if (Is_host_in_received())            // Pipe IN reception ?
01692    {
01693       ptr_buf=it_pipe_str[pipe_nb].ptr_buf+it_pipe_str[pipe_nb].nb_byte_processed;       // Build pointer to data buffer
01694       n=it_pipe_str[pipe_nb].nb_byte_to_process-it_pipe_str[pipe_nb].nb_byte_processed;  // Remaining data bytes
01695       Host_freeze_pipe();
01696       if (Host_byte_counter()<=n)
01697       {
01698          if ((Host_byte_counter() < n)&&(Host_byte_counter()<Host_get_pipe_length())) //Received less than remaining, but less than pipe capacity
01699                                                                                       //TODO: error code
01700          {
01701             n=0;
01702          }
01703          else
01704          {
01705             n-=Host_byte_counter();
01706          }
01707          it_pipe_str[pipe_nb].nb_byte_processed+=Host_byte_counter();  // Update nb of byte received
01708          for (i=Host_byte_counter();i;i--)
01709          { *ptr_buf=Host_read_byte(); ptr_buf++;}
01710       }
01711       else  // more bytes received than expected
01712       {     // TODO error code management
01713          it_pipe_str[pipe_nb].nb_byte_processed+=n;
01714          for (i=n;i;i--)                  // Byte number limited to the initial request (limit tab over pb)
01715          { *ptr_buf=Host_read_byte(); ptr_buf++;}
01716          n=0;
01717       }
01718       Host_ack_in_received();
01719       if(n>0) //still something to process
01720       {
01721          Host_unfreeze_pipe();            // Request another IN transfer
01722          Host_send_in();
01723          private_sof_counter=0;           // Reset the counter in SOF detection sub-routine
01724          it_pipe_str[pipe_nb].timeout=0;  // Reset timeout
01725          it_pipe_str[pipe_nb].nak_timeout=NAK_RECEIVE_TIMEOUT;
01726 
01727       }
01728       else //end of transfer
01729       {
01730          it_pipe_str[pipe_nb].enable=DISABLE;
01731          it_pipe_str[pipe_nb].status=PIPE_GOOD;
01732          Host_stop_pipe_interrupt(pipe_nb);
01733          do_call_back=TRUE;
01734       }
01735    }
01736 
01737    if(Is_host_out_sent())                  // Pipe OUT sent ?
01738    {
01739       Host_ack_out_sent();
01740       it_pipe_str[pipe_nb].nb_byte_processed+=it_pipe_str[pipe_nb].nb_byte_on_going;
01741       it_pipe_str[pipe_nb].nb_byte_on_going=0;
01742       ptr_buf=it_pipe_str[pipe_nb].ptr_buf+it_pipe_str[pipe_nb].nb_byte_processed;       // Build pointer to data buffer
01743       n=it_pipe_str[pipe_nb].nb_byte_to_process-it_pipe_str[pipe_nb].nb_byte_processed;  // Remaining data bytes
01744       if(n>0)   // Still data to process...
01745       {
01746          Host_unfreeze_pipe();
01747         // Prepare data to be sent
01748          i = Host_get_pipe_length();
01749          if ( i > n)     // Pipe size> remaining data
01750          {
01751             i = n;
01752             n = 0;
01753          }
01754          else                // Pipe size < remaining data
01755          {  n -= i; }
01756          it_pipe_str[pipe_nb].nb_byte_on_going+=i;   // Update nb data processed
01757          while (i!=0)                     // Load Pipe buffer
01758          {
01759             Host_write_byte(*ptr_buf++); i--;
01760          }
01761          private_sof_counter=0;           // Reset the counter in SOF detection sub-routine
01762          it_pipe_str[pipe_nb].timeout=0;  // Refresh timeout counter
01763          it_pipe_str[pipe_nb].nak_timeout=NAK_SEND_TIMEOUT;
01764          Host_send_out();                 // Send the USB frame
01765       }
01766       else                                //n==0 Transfer is finished
01767       {
01768          it_pipe_str[pipe_nb].enable=DISABLE;    // Tranfer end
01769          it_pipe_str[pipe_nb].status=PIPE_GOOD;  // Status OK
01770          Host_stop_pipe_interrupt(pipe_nb);
01771          do_call_back=TRUE;
01772       }
01773    }
01774 
01775 usb_pipe_interrupt_end:
01776    Host_select_pipe(pipe_nb_save);   // Restore pipe number !!!!
01777    if (is_any_interrupt_pipe_active()==FALSE)    // If no more transfer is armed
01778    {
01779       if (g_sav_int_sof_enable==FALSE)
01780       {
01781          Host_disable_sof_interrupt();
01782       }
01783    }
01784    if(do_call_back)      // Any callback functions to perform ?
01785    {
01786       fct_handle(it_pipe_str[pipe_nb].status,it_pipe_str[pipe_nb].nb_byte_processed);
01787    }
01788 }

Here is the call graph for this function:


Variable Documentation

U8 code log_device_connected[] = "Device Connection"

Definition at line 117 of file usb_host_task.c.

Referenced by usb_host_task().

U8 code log_device_enumerated[] = "Device Enumerated"

Definition at line 118 of file usb_host_task.c.

Referenced by usb_host_task().

U8 code log_device_unsupported[] = "Unsupported Device"

Definition at line 119 of file usb_host_task.c.

Referenced by usb_host_task().

U8 code log_going_to_suspend[] = "Usb suspend"

Definition at line 120 of file usb_host_task.c.

Referenced by usb_host_task().

U8 code log_usb_resumed[] = "Usb resumed"

Definition at line 121 of file usb_host_task.c.

Referenced by usb_host_task().

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().

volatile U8 pipe_nb_save

Definition at line 130 of file usb_host_task.c.

Referenced by usb_pipe_interrupt().

U8 g_sav_int_sof_enable

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().

U16 c [static]

Definition at line 209 of file usb_host_task.c.

Referenced by host_check_class(), host_check_VID_PID(), host_send_control(), host_send_data(), and usb_host_task().


Generated on Mon Feb 19 09:32:05 2007 for Atmel by  doxygen 1.5.1-p1