usb_specific_request.c File Reference

#include "config.h"
#include "conf_usb.h"
#include "lib_mcu/usb/usb_drv.h"
#include "usb_descriptors.h"
#include "modules/usb/device_chap9/usb_standard_request.h"
#include "usb_specific_request.h"
#include "lib_mcu/uart/uart_lib.h"
#include "lib_mcu/flash/flash_drv.h"

Include dependency graph for usb_specific_request.c:

Go to the source code of this file.

Functions

Bool usb_user_read_request (U8 type, U8 request)
 This function checks the specific request and if known then processes it
void usb_user_endpoint_init (U8 conf_nb)
U8 usb_user_interface_get (U16 wInterface)
void usb_user_interface_reset (U16 wInterface, U8 alternate_setting)
Bool usb_user_get_descriptor (U8 type, U8 string)
 This function fills the global descriptor.
void cdc_get_line_coding (void)
 cdc_get_line_coding.
void cdc_set_line_coding (void)
 cdc_set_line_coding.
void cdc_set_control_line_state (U16 state)
 cdc_set_control_line_state.
Bool cdc_update_serial_state ()
 cdc_update_serial_state.
void cdc_send_break (U16 break_duration)

Variables

U8 code * pbuffer
U8 data_to_transfer
S_line_coding line_coding
S_line_status line_status
S_serial_state serial_state
static S_serial_state serial_state_saved
volatile U8 usb_request_break_generation = FALSE


Detailed Description

user call-back functions This file contains the user call-back functions corresponding to the application: - Compiler: IAR EWAVR and GNU GCC for AVR

Definition in file usb_specific_request.c.


Function Documentation

Bool usb_user_read_request ( U8  type,
U8  request 
)

This function checks the specific request and if known then processes it

Parameters:
type corresponding at bmRequestType (see USB specification)
request corresponding at bRequest (see USB specification)
Returns:
TRUE, when the request is processed

FALSE, if the request is'nt know (STALL handshake is managed by the main standard request function).

Definition at line 90 of file usb_specific_request.c.

Referenced by usb_process_request().

00091 {
00092    U16 wValue;
00093 
00094    LSB(wValue) = Usb_read_byte();
00095    MSB(wValue) = Usb_read_byte();
00096 
00097    //** Specific request from Class CDC
00098    if( USB_SETUP_SET_CLASS_INTER == type )
00099    {
00100       switch( request )
00101       {
00102          case SETUP_CDC_SET_LINE_CODING:
00103          cdc_set_line_coding();
00104          return TRUE;
00105          break;
00106    
00107          case SETUP_CDC_SET_CONTROL_LINE_STATE:
00108          cdc_set_control_line_state(wValue); // according cdc spec 1.1 chapter 6.2.14
00109          return TRUE;
00110          break;
00111    
00112          case SETUP_CDC_SEND_BREAK:
00113          cdc_send_break(wValue);             // wValue contains break lenght
00114          return TRUE;
00115          break;
00116       }
00117    }
00118    if( USB_SETUP_GET_CLASS_INTER == type )
00119    {
00120       switch( request )
00121       {
00122          case SETUP_CDC_GET_LINE_CODING:
00123          cdc_get_line_coding();
00124          return TRUE;
00125          break;
00126       }
00127    }
00128    return FALSE;  // No supported request
00129 }

Here is the caller graph for this function:

void usb_user_endpoint_init ( U8  conf_nb  ) 

This function configures the endpoints

Parameters:
conf_nb configuration number choosed by USB host

Definition at line 136 of file usb_specific_request.c.

Referenced by usb_set_configuration().

00137 {
00138   usb_configure_endpoint(INT_EP,        \
00139                          TYPE_INTERRUPT,\
00140                          DIRECTION_IN,  \
00141                          SIZE_32,       \
00142                          ONE_BANK,      \
00143                          NYET_ENABLED);
00144 
00145   usb_configure_endpoint(TX_EP,         \
00146                          TYPE_BULK,     \
00147                          DIRECTION_IN,  \
00148                          SIZE_32,       \
00149                          ONE_BANK,      \
00150                          NYET_ENABLED);
00151 
00152   usb_configure_endpoint(RX_EP,         \
00153                          TYPE_BULK,     \
00154                          DIRECTION_OUT, \
00155                          SIZE_32,       \
00156                          ONE_BANK,      \
00157                          NYET_ENABLED);
00158 
00159   Usb_reset_endpoint(INT_EP);
00160   Usb_reset_endpoint(TX_EP);
00161   Usb_reset_endpoint(RX_EP);
00162 }

Here is the caller graph for this function:

U8 usb_user_interface_get ( U16  wInterface  ) 

This function returns the interface alternate setting

Parameters:
wInterface Interface selected
Returns:
alternate setting configurated

Definition at line 171 of file usb_specific_request.c.

Referenced by usb_get_interface().

00172 {
00173    return 0;  // Only one alternate setting possible for all interface
00174 }

Here is the caller graph for this function:

void usb_user_interface_reset ( U16  wInterface,
U8  alternate_setting 
)

This function selects (and resets) the interface alternate setting

Parameters:
wInterface Interface selected
alternate_setting alternate setting selected

Definition at line 182 of file usb_specific_request.c.

Referenced by usb_set_interface().

00183 {  
00184    // default setting selected = reset data toggle
00185    if( INTERFACE0_NB == wInterface )
00186    {
00187       // Interface CDC ACM Com
00188       Usb_select_endpoint(INT_EP);
00189       Usb_disable_stall_handshake();
00190       Usb_reset_endpoint(INT_EP);
00191       Usb_reset_data_toggle();
00192    }
00193    if( INTERFACE1_NB == wInterface )
00194    {
00195       // Interface CDC ACM Data
00196       Usb_select_endpoint(TX_EP);
00197       Usb_disable_stall_handshake();
00198       Usb_reset_endpoint(TX_EP);
00199       Usb_reset_data_toggle();
00200       Usb_select_endpoint(RX_EP);
00201       Usb_disable_stall_handshake();
00202       Usb_reset_endpoint(RX_EP);
00203       Usb_reset_data_toggle();
00204    }
00205 }

Here is the caller graph for this function:

Bool usb_user_get_descriptor ( U8  type,
U8  string 
)

This function fills the global descriptor.

Parameters:
type corresponding at MSB of wValue (see USB specification)
string corresponding at LSB of wValue (see USB specification)
Returns:
FALSE, if the global descriptor no filled

Definition at line 215 of file usb_specific_request.c.

Referenced by usb_get_descriptor().

00216 { 
00217    switch(type)
00218    {
00219       case DESCRIPTOR_STRING:
00220       switch (string)
00221       {           
00222          case LANG_ID:
00223          data_to_transfer = sizeof (usb_user_language_id);
00224          pbuffer = &(usb_user_language_id.bLength);
00225          return TRUE;
00226          break;
00227                 
00228 #if (USB_DEVICE_SN_USE==ENABLE)              
00229          case SN_INDEX:
00230          data_to_transfer = sizeof (usb_user_serial_number);
00231          pbuffer = &(usb_user_serial_number.bLength);
00232 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00233          f_get_serial_string=TRUE;
00234          data_to_transfer += (SN_LENGTH*4);
00235 #endif
00236          return TRUE;
00237          break;
00238 #endif
00239       }
00240       break;
00241    }
00242    return FALSE;
00243 }

Here is the caller graph for this function:

void cdc_get_line_coding ( void   ) 

cdc_get_line_coding.

This function manages reception of line coding parameters (baudrate...).

Parameters:
none 
Returns:
none

Definition at line 253 of file usb_specific_request.c.

Referenced by usb_user_read_request().

Here is the caller graph for this function:

void cdc_set_line_coding ( void   ) 

cdc_set_line_coding.

This function manages reception of line coding parameters (baudrate...).

Parameters:
none 
Returns:
none

Definition at line 281 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00282 {
00283    Usb_ack_receive_setup();
00284    while (!(Is_usb_receive_out()));
00285    LSB0(line_coding.dwDTERate) = Usb_read_byte();
00286    LSB1(line_coding.dwDTERate) = Usb_read_byte();
00287    LSB2(line_coding.dwDTERate) = Usb_read_byte();
00288    LSB3(line_coding.dwDTERate) = Usb_read_byte();
00289    line_coding.bCharFormat = Usb_read_byte();
00290    line_coding.bParityType = Usb_read_byte();
00291    line_coding.bDataBits = Usb_read_byte();
00292      Usb_ack_receive_out();
00293 
00294      Usb_send_control_in();                // send a ZLP for STATUS phase
00295      while(!(Is_usb_read_control_enabled()));
00296 #ifdef UART_U2
00297    Uart_set_baudrate((line_coding.dwDTERate)/2);
00298 #else
00299    Uart_set_baudrate(line_coding.dwDTERate);
00300 #endif
00301 }

Here is the caller graph for this function:

void cdc_set_control_line_state ( U16  state  ) 

cdc_set_control_line_state.

This function manages the SET_CONTROL_LINE_LINE_STATE CDC request.

Todo:
Manages here hardware flow control...
Parameters:
none 
Returns:
none

Definition at line 314 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00315 {
00316      Usb_ack_receive_setup();
00317    Usb_send_control_in();
00318    line_status.all = state;
00319    
00320      while(!(Is_usb_read_control_enabled()));
00321 
00322 }

Here is the caller graph for this function:

Bool cdc_update_serial_state (  ) 

cdc_update_serial_state.

This function checks if serial state has changed and updates host with that information.

Todo:
Return TRUE only if update was accepted by host, to detect need for resending
Parameters:
none 
Returns:
TRUE if updated state was sent otherwise FALSE
upr: Added for hardware handshake support according cdc spec 1.1 chapter 6.3.5

Definition at line 336 of file usb_specific_request.c.

Referenced by cdc_task().

00337 {
00338    if( serial_state_saved.all != serial_state.all)
00339    {
00340       serial_state_saved.all = serial_state.all;
00341       
00342       Usb_select_endpoint(INT_EP);
00343       if (Is_usb_write_enabled())
00344       {
00345          Usb_write_byte(USB_SETUP_GET_CLASS_INTER);   // bmRequestType
00346          Usb_write_byte(SETUP_CDC_BN_SERIAL_STATE);   // bNotification
00347          
00348          Usb_write_byte(0x00);   // wValue (zero)
00349          Usb_write_byte(0x00);
00350          
00351          Usb_write_byte(0x00);   // wIndex (Interface)
00352          Usb_write_byte(0x00);
00353          
00354          Usb_write_byte(0x02);   // wLength (data count = 2)
00355          Usb_write_byte(0x00);
00356          
00357          Usb_write_byte(LSB(serial_state.all));   // data 0: LSB first of serial state
00358          Usb_write_byte(MSB(serial_state.all));   // data 1: MSB follows
00359          Usb_ack_in_ready();
00360       }
00361       return TRUE;
00362    }
00363    return FALSE;
00364 }

Here is the caller graph for this function:

void cdc_send_break ( U16  break_duration  ) 

This function manages the SEND_BREAK CDC request.

Todo:
Manages here hardware flow control...
Parameters:
break lenght

Definition at line 372 of file usb_specific_request.c.

Referenced by usb_user_read_request().

Here is the caller graph for this function:


Variable Documentation

U8 code* pbuffer

Definition at line 94 of file usb_standard_request.c.

Referenced by usb_get_descriptor(), and usb_user_get_descriptor().

U8 data_to_transfer

Definition at line 99 of file usb_standard_request.c.

Referenced by usb_get_descriptor(), and usb_user_get_descriptor().

S_line_coding line_coding

Definition at line 74 of file cdc_task.c.

S_line_status line_status

Definition at line 75 of file cdc_task.c.

S_serial_state serial_state

Definition at line 76 of file cdc_task.c.

S_serial_state serial_state_saved [static]

Definition at line 76 of file usb_specific_request.c.

volatile U8 usb_request_break_generation = FALSE

Definition at line 77 of file usb_specific_request.c.


Generated on Fri Sep 11 14:25:29 2009 for ATMEL by  doxygen 1.5.3