#include "config.h"#include "lib_mcu/usb/usb_drv.h"#include "usb_descriptors.h"#include "uart_usb_lib.h"
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 data_to_send) |
| void | uart_usb_send_buffer (U8 *buffer, U8 nb_data) |
Variables | |
| Uchar | rx_counter |
Definition in file uart_usb_lib.c.
| void uart_usb_init | ( | void | ) |
Initializes the uart_usb library
Definition at line 61 of file uart_usb_lib.c.
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.
Definition at line 71 of file uart_usb_lib.c.
Referenced by cdc_task(), and uart_usb_getchar().
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.
Definition at line 99 of file uart_usb_lib.c.
Referenced by cdc_task(), and cdc_task_init().
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 }
| 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 118 of file uart_usb_lib.c.
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.
| data_to_send |
Definition at line 139 of file uart_usb_lib.c.
00140 { 00141 uart_usb_send_buffer((U8*)&data_to_send, 1); 00142 return data_to_send; 00143 }
This function transmits a ram buffer content to the USB. This function is mode efficient in term of USB bandwith transfer.
| 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.
Referenced by uart_usb_putchar(), and usart_receive_interrupt().
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 }
Definition at line 54 of file uart_usb_lib.c.
1.5.3