#include "config.h"
#include "lib_mcu\usb\usb_drv.h"
#include "usb_descriptors.h"
#include "uart_usb_lib.h"
Include dependency graph for uart_usb_lib.c:
Go to the source code of this file.
Functions | |
void | uart_usb_init (void) |
Initializes the uart_usb library. | |
bit | uart_usb_test_hit (void) |
This function checks if a character has been received on the USB bus. | |
char | uart_usb_getchar (void) |
This function reads one byte from the USB bus. | |
bit | uart_usb_tx_ready (void) |
This function checks if the USB emission buffer is ready to accept at at least 1 byte. | |
int | putchar (int data_to_send) |
This function fills the USB transmit buffer with the new data. | |
void | uart_usb_flush (void) |
This function sends the data stored in the USB transmit buffer. | |
Variables | |
Uchar | tx_counter |
Uchar | rx_counter |
Copyright (c) 2006 Atmel.
Please read file license.txt for copyright notice.
Definition in file uart_usb_lib.c.
void uart_usb_init | ( | void | ) |
Initializes the uart_usb library.
Definition at line 33 of file uart_usb_lib.c.
References rx_counter, and tx_counter.
00034 { 00035 tx_counter = 0; 00036 rx_counter = 0; 00037 }
bit uart_usb_test_hit | ( | void | ) |
This function checks if a character has been received on the USB bus.
Definition at line 44 of file uart_usb_lib.c.
References Is_usb_receive_out, rx_counter, RX_EP, Usb_ack_receive_out, Usb_byte_counter, and Usb_select_endpoint.
Referenced by cdc_task(), and uart_usb_getchar().
00045 { 00046 if (!rx_counter) 00047 { 00048 Usb_select_endpoint(RX_EP); 00049 if (Is_usb_receive_out()) 00050 { 00051 rx_counter = Usb_byte_counter(); 00052 if (!rx_counter) 00053 { 00054 Usb_ack_receive_out(); 00055 } 00056 } 00057 } 00058 return (rx_counter!=0); 00059 }
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.
Definition at line 69 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.
Referenced by cdc_task(), and cdc_task_init().
00070 { 00071 register Uchar data_rx; 00072 00073 Usb_select_endpoint(RX_EP); 00074 if (!rx_counter) while (!uart_usb_test_hit()); 00075 data_rx=Usb_read_byte(); 00076 rx_counter--; 00077 if (!rx_counter) Usb_ack_receive_out(); 00078 return data_rx; 00079 }
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.
Definition at line 88 of file uart_usb_lib.c.
References FALSE, Is_usb_write_enabled, and TRUE.
Referenced by putchar().
00089 { 00090 if (!Is_usb_write_enabled()) 00091 { 00092 return FALSE; 00093 } 00094 return TRUE; 00095 }
int 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.
data_to_send |
Definition at line 106 of file uart_usb_lib.c.
References Is_usb_write_enabled, tx_counter, TX_EP, uart_usb_flush(), uart_usb_tx_ready(), Usb_select_endpoint, and Usb_write_byte.
00107 { 00108 Usb_select_endpoint(TX_EP); 00109 while(!uart_usb_tx_ready()); // Wait Endpoint ready 00110 Usb_write_byte(data_to_send); 00111 tx_counter++; 00112 if(!Is_usb_write_enabled()) //If Endpoint full -> flush 00113 { 00114 uart_usb_flush(); 00115 } 00116 return data_to_send; 00117 }
Here is the call graph for this function:
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 124 of file uart_usb_lib.c.
References tx_counter, TX_EP, Usb_select_endpoint, and Usb_send_in.
Referenced by cdc_task(), and putchar().
00125 { 00126 Usb_select_endpoint(TX_EP); 00127 Usb_send_in(); 00128 tx_counter = 0; 00129 00130 }
Definition at line 25 of file uart_usb_lib.c.
Referenced by cdc_task(), putchar(), uart_usb_flush(), and uart_usb_init().
Definition at line 26 of file uart_usb_lib.c.
Referenced by cdc_task(), uart_usb_getchar(), uart_usb_init(), and uart_usb_test_hit().