uart_usb_lib.h File Reference

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

Go to the source code of this file.

Functions

void uart_usb_init (void)
bit uart_usb_test_hit (void)
char uart_usb_getchar (void)
bit uart_usb_tx_ready (void)
int uart_usb_putchar (int)
void uart_usb_flush (void)
void uart_usb_send_buffer (U8 *buffer, U8 nb_data)


Detailed Description

This file controls the UART USB functions.

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

Definition in file uart_usb_lib.h.


Function Documentation

void uart_usb_init ( void   ) 

Initializes the uart_usb library

Definition at line 61 of file uart_usb_lib.c.

References rx_counter.

00062 {
00063   rx_counter = 0;
00064 }

bit uart_usb_test_hit ( void   ) 

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

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

Definition at line 71 of file uart_usb_lib.c.

References FALSE, Is_device_enumerated, Is_usb_receive_out, rx_counter, RX_EP, Usb_ack_receive_out, Usb_byte_counter, and Usb_select_endpoint.

00072 {
00073   if(!Is_device_enumerated())
00074      return FALSE;
00075 
00076   if (!rx_counter)
00077   {
00078     Usb_select_endpoint(RX_EP);
00079     if (Is_usb_receive_out())
00080     {
00081       rx_counter = Usb_byte_counter();
00082       if (!rx_counter)
00083       {
00084         Usb_ack_receive_out();
00085       }
00086     }
00087   }
00088   return (rx_counter!=0);
00089 }

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 99 of file uart_usb_lib.c.

References rx_counter, RX_EP, uart_usb_test_hit(), Usb_ack_receive_out, Usb_read_byte, and Usb_select_endpoint.

00100 {
00101   register Uchar data_rx;
00102 
00103   Usb_select_endpoint(RX_EP);
00104   if (!rx_counter) while (!uart_usb_test_hit());
00105   data_rx=Usb_read_byte();
00106   rx_counter--;
00107   if (!rx_counter) Usb_ack_receive_out();
00108   return data_rx;
00109 }

Here is the call graph for this function:

bit 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 118 of file uart_usb_lib.c.

References FALSE, Is_device_enumerated, Is_usb_write_enabled, and TRUE.

00119 {
00120   if(!Is_device_enumerated())
00121      return FALSE;
00122 
00123   if (!Is_usb_write_enabled())
00124   {
00125     return FALSE;
00126   }
00127   return TRUE;
00128 }

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 139 of file uart_usb_lib.c.

References uart_usb_send_buffer().

00140 {
00141    uart_usb_send_buffer((U8*)&data_to_send, 1);
00142    return data_to_send;
00143 }

Here is the call graph for this function:

void uart_usb_flush ( void   ) 

void uart_usb_send_buffer ( U8 buffer,
U8  nb_data 
)

This function transmits a ram buffer content to the USB. This function is mode efficient in term of USB bandwith transfer.

Parameters:
U8 *buffer : the pointer to the RAM buffer to be sent
data_to_send : the number of data to be sent

Definition at line 154 of file uart_usb_lib.c.

References FALSE, Is_device_enumerated, Is_usb_write_enabled, TRUE, TX_EP, TX_EP_SIZE, Usb_ack_in_ready, Usb_select_endpoint, and Usb_write_byte.

00155 {
00156    U8 zlp;
00157 
00158   if(!Is_device_enumerated())
00159      return;
00160    
00161    // Compute if zlp required
00162    if(nb_data%TX_EP_SIZE) 
00163    { zlp=FALSE;} 
00164    else { zlp=TRUE; }
00165    
00166    Usb_select_endpoint(TX_EP);
00167    while (nb_data)
00168    {
00169       while(Is_usb_write_enabled()==FALSE); // Wait Endpoint ready
00170       while(Is_usb_write_enabled() && nb_data)
00171       {
00172          Usb_write_byte(*buffer);
00173          buffer++;
00174          nb_data--;
00175       }
00176       Usb_ack_in_ready();
00177    }
00178    if(zlp)
00179    {
00180       while(Is_usb_write_enabled()==FALSE); // Wait Endpoint ready
00181       Usb_ack_in_ready();
00182    }
00183 }


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