usb_specific_request.h File Reference

#include "config.h"

Include dependency graph for usb_specific_request.h:

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

Go to the source code of this file.

Data Structures

struct  S_line_coding
union  S_line_status
union  S_serial_state

Functions

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

Variables

code
S_usb_device_descriptor 
usb_dev_desc
code
S_usb_user_configuration_descriptor 
usb_conf_desc
code
S_usb_manufacturer_string_descriptor 
usb_user_manufacturer_string_descriptor
code
S_usb_product_string_descriptor 
usb_user_product_string_descriptor
code S_usb_serial_number usb_user_serial_number
code S_usb_language_id usb_user_language_id


Detailed Description

Specific enumeration process requests header file - Compiler: IAR EWAVR and GNU GCC for AVR

Definition in file usb_specific_request.h.


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 87 of file usb_specific_request.c.

References cdc_get_line_coding(), cdc_send_break(), cdc_set_control_line_state(), cdc_set_line_coding(), FALSE, LSB, MSB, SETUP_CDC_GET_LINE_CODING, SETUP_CDC_SEND_BREAK, SETUP_CDC_SET_CONTROL_LINE_STATE, SETUP_CDC_SET_LINE_CODING, TRUE, Usb_read_byte, USB_SETUP_GET_CLASS_INTER, and USB_SETUP_SET_CLASS_INTER.

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

Here is the call 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 133 of file usb_specific_request.c.

References DIRECTION_IN, DIRECTION_OUT, INT_EP, NYET_ENABLED, ONE_BANK, RX_EP, SIZE_32, SIZE_64, TWO_BANKS, TX_EP, TYPE_BULK, TYPE_INTERRUPT, usb_configure_endpoint, and Usb_reset_endpoint.

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

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 168 of file usb_specific_request.c.

00169 {
00170    return 0;  // Only one alternate setting possible for all interface
00171 }

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 179 of file usb_specific_request.c.

References INT_EP, INTERFACE0_NB, INTERFACE1_NB, RX_EP, TX_EP, Usb_disable_stall_handshake, Usb_reset_data_toggle, Usb_reset_endpoint, and Usb_select_endpoint.

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

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 212 of file usb_specific_request.c.

References FALSE.

00213 { 
00214    return FALSE;
00215 }

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 225 of file usb_specific_request.c.

References S_line_coding::bCharFormat, S_line_coding::bDataBits, S_line_coding::bParityType, S_line_coding::dwDTERate, Is_usb_read_control_enabled, Is_usb_receive_out, LSB0, LSB1, LSB2, LSB3, Usb_ack_receive_out, Usb_ack_receive_setup, Usb_send_control_in, and Usb_write_byte.

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 253 of file usb_specific_request.c.

References S_line_coding::bCharFormat, S_line_coding::bDataBits, S_line_coding::bParityType, S_line_coding::dwDTERate, Is_usb_read_control_enabled, Is_usb_receive_out, LSB0, LSB1, LSB2, LSB3, Uart_set_baudrate, Usb_ack_receive_out, Usb_ack_receive_setup, Usb_read_byte, and Usb_send_control_in.

00254 {
00255    Usb_ack_receive_setup();
00256    while (!(Is_usb_receive_out()));
00257    LSB0(line_coding.dwDTERate) = Usb_read_byte();
00258    LSB1(line_coding.dwDTERate) = Usb_read_byte();
00259    LSB2(line_coding.dwDTERate) = Usb_read_byte();
00260    LSB3(line_coding.dwDTERate) = Usb_read_byte();
00261    line_coding.bCharFormat = Usb_read_byte();
00262    line_coding.bParityType = Usb_read_byte();
00263    line_coding.bDataBits = Usb_read_byte();
00264      Usb_ack_receive_out();
00265 
00266      Usb_send_control_in();                // send a ZLP for STATUS phase
00267      while(!(Is_usb_read_control_enabled()));
00268 #ifdef UART_U2
00269    Uart_set_baudrate((line_coding.dwDTERate)/2);
00270 #else
00271    Uart_set_baudrate(line_coding.dwDTERate);
00272 #endif
00273 }

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 286 of file usb_specific_request.c.

References S_line_status::all, Is_usb_read_control_enabled, Usb_ack_receive_setup, and Usb_send_control_in.

00287 {
00288      Usb_ack_receive_setup();
00289    Usb_send_control_in();
00290    line_status.all = state;
00291    
00292      while(!(Is_usb_read_control_enabled()));
00293 
00294 }

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 344 of file usb_specific_request.c.

References Is_usb_read_control_enabled, TRUE, Usb_ack_receive_setup, usb_request_break_generation, and Usb_send_control_in.

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 308 of file usb_specific_request.c.

References S_serial_state::all, FALSE, INT_EP, Is_usb_write_enabled, LSB, MSB, SETUP_CDC_BN_SERIAL_STATE, TRUE, Usb_ack_in_ready, Usb_select_endpoint, USB_SETUP_GET_CLASS_INTER, and Usb_write_byte.

00309 {
00310    if( serial_state_saved.all != serial_state.all)
00311    {
00312       serial_state_saved.all = serial_state.all;
00313       
00314       Usb_select_endpoint(INT_EP);
00315       if (Is_usb_write_enabled())
00316       {
00317          Usb_write_byte(USB_SETUP_GET_CLASS_INTER);   // bmRequestType
00318          Usb_write_byte(SETUP_CDC_BN_SERIAL_STATE);   // bNotification
00319          
00320          Usb_write_byte(0x00);   // wValue (zero)
00321          Usb_write_byte(0x00);
00322          
00323          Usb_write_byte(0x00);   // wIndex (Interface)
00324          Usb_write_byte(0x00);
00325          
00326          Usb_write_byte(0x02);   // wLength (data count = 2)
00327          Usb_write_byte(0x00);
00328          
00329          Usb_write_byte(LSB(serial_state.all));   // data 0: LSB first of serial state
00330          Usb_write_byte(MSB(serial_state.all));   // data 1: MSB follows
00331          Usb_ack_in_ready();
00332       }
00333       return TRUE;
00334    }
00335    return FALSE;
00336 }


Variable Documentation

code S_usb_device_descriptor usb_dev_desc

Definition at line 66 of file usb_descriptors.c.

code S_usb_user_configuration_descriptor usb_conf_desc

Definition at line 85 of file usb_descriptors.c.

code S_usb_manufacturer_string_descriptor usb_user_manufacturer_string_descriptor

Definition at line 151 of file usb_descriptors.c.

code S_usb_product_string_descriptor usb_user_product_string_descriptor

Definition at line 160 of file usb_descriptors.c.

code S_usb_serial_number usb_user_serial_number

Definition at line 169 of file usb_descriptors.c.

code S_usb_language_id usb_user_language_id

Definition at line 183 of file usb_descriptors.c.


Generated on Fri Oct 31 15:55:14 2008 for ATMEL by  doxygen 1.5.3