uart_usb_lib.h File Reference


Detailed Description

This file controls the UART USB functions.

These functions allow to use en USB endpoint as we would do using an UART. This is particurly well suited for USB CDC class.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file uart_usb_lib.h.

Go to the source code of this file.

Functions

void uart_usb_flush (void)
 This function sends the data stored in the USB transmit buffer.
char uart_usb_getchar (void)
 This function reads one byte from the USB bus.
void uart_usb_init (void)
 This function initializes the UART over USB emulation driver.
int uart_usb_putchar (int data_to_send)
 This function fills the USB transmit buffer with the new data.
Bool uart_usb_test_hit (void)
 This function checks if a character has been received on the USB bus.
Bool uart_usb_tx_ready (void)
 This function checks if the USB emission buffer is ready to accept at at least 1 byte.


Function Documentation

void uart_usb_flush ( void   ) 

This function sends the data stored in the USB transmit buffer.

This function does nothing if there is no data in the buffer.

Definition at line 137 of file uart_usb_lib.c.

References b_tx_new, and TX_EP.

Referenced by device_cdc_task().

00138 {
00139   if( 0 != Usb_nb_busy_bank(TX_EP) )
00140      return; // Don't flush because a previous flush is on-going and all bank don't be busy
00141   Usb_ack_in_ready_send(TX_EP);
00142   b_tx_new = TRUE;
00143 }

char uart_usb_getchar ( void   ) 

This function reads one byte from the USB bus.

If one byte is present in the USB fifo, this byte is returned. If no data is present in the USB fifo, this function waits for USB data.

Returns:
U8 byte received

Definition at line 93 of file uart_usb_lib.c.

References b_rx_new, RX_EP, and uart_usb_test_hit().

Referenced by device_cdc_task().

00094 {
00095   register char data_rx;
00096 
00097   while( !uart_usb_test_hit() );
00098   data_rx=Usb_read_endpoint_data(RX_EP, 8);
00099   if( 0==Usb_byte_count(RX_EP) ) {
00100       Usb_ack_out_received_free(RX_EP);
00101       b_rx_new = TRUE;
00102   }
00103   return data_rx;
00104 }

void uart_usb_init ( void   ) 

This function initializes the UART over USB emulation driver.

Definition at line 64 of file uart_usb_lib.c.

References b_rx_new, and b_tx_new.

Referenced by device_cdc_task_init().

00065 {
00066    b_tx_new = TRUE;
00067    b_rx_new = TRUE;
00068 }

int uart_usb_putchar ( int  data_to_send  ) 

This function fills the USB transmit buffer with the new data.

This buffer is sent if complete. To flush this buffer before waiting full, launch the uart_usb_flush() function.

Parameters:
data_to_send 
Returns:

Definition at line 124 of file uart_usb_lib.c.

References b_tx_new, TX_EP, and uart_usb_tx_ready().

Referenced by device_cdc_task().

00125 {
00126   while( !uart_usb_tx_ready() ); // Wait Endpoint ready
00127   Usb_write_endpoint_data(TX_EP, 8, data_to_send);
00128   if( !Is_usb_write_enabled(TX_EP) ) // If Endpoint full -> flush
00129   {
00130      Usb_ack_in_ready_send(TX_EP);
00131      b_tx_new = TRUE;
00132   }
00133   return data_to_send;
00134 }

Bool uart_usb_test_hit ( void   ) 

This function checks if a character has been received on the USB bus.

Returns:
Bool (true if a byte is ready to be read)

Definition at line 73 of file uart_usb_lib.c.

References b_rx_new, and RX_EP.

Referenced by device_cdc_task(), and uart_usb_getchar().

00074 {
00075    if( Is_usb_out_received(RX_EP) )
00076    {
00077       if( 0!=Usb_byte_count(RX_EP) )
00078       {
00079          if( b_rx_new )
00080          {
00081             Usb_reset_endpoint_fifo_access(RX_EP);
00082             b_rx_new = FALSE;
00083          }
00084          return TRUE;
00085       }
00086       Usb_ack_out_received_free(RX_EP);
00087       b_rx_new = TRUE;
00088    }
00089    return FALSE;
00090 }

Bool uart_usb_tx_ready ( void   ) 

This function checks if the USB emission buffer is ready to accept at at least 1 byte.

Returns:
Boolean. TRUE if the firmware can write a new byte to transmit.

Definition at line 109 of file uart_usb_lib.c.

References b_tx_new, and TX_EP.

Referenced by device_cdc_task(), and uart_usb_putchar().

00110 {
00111   if( Is_usb_write_enabled(TX_EP) )
00112   {
00113       if( b_tx_new )
00114       {
00115          Usb_reset_endpoint_fifo_access(TX_EP);
00116          b_tx_new = FALSE;
00117       }
00118       return TRUE;
00119   }
00120   return FALSE;
00121 }


Generated on Fri Feb 19 02:32:25 2010 for AVR32 - USB CDC Example by  doxygen 1.5.5