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) |
Definition in file uart_usb_lib.h.
void uart_usb_init | ( | void | ) |
Initializes the uart_usb library
Definition at line 64 of file uart_usb_lib.c.
References rx_counter.
00065 { 00066 rx_counter = 0; 00067 }
bit uart_usb_test_hit | ( | void | ) |
This function checks if a character has been received on the USB bus.
Definition at line 74 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.
00075 { 00076 if(!Is_device_enumerated()) 00077 return FALSE; 00078 00079 if (!rx_counter) 00080 { 00081 Usb_select_endpoint(RX_EP); 00082 if (Is_usb_receive_out()) 00083 { 00084 rx_counter = Usb_byte_counter(); 00085 if (!rx_counter) 00086 { 00087 Usb_ack_receive_out(); 00088 } 00089 } 00090 } 00091 return (rx_counter!=0); 00092 }
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 102 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.
00103 { 00104 register Uchar data_rx; 00105 00106 Usb_select_endpoint(RX_EP); 00107 if (!rx_counter) while (!uart_usb_test_hit()); 00108 data_rx=Usb_read_byte(); 00109 rx_counter--; 00110 if (!rx_counter) Usb_ack_receive_out(); 00111 return data_rx; 00112 }
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 121 of file uart_usb_lib.c.
References FALSE, Is_device_enumerated, Is_usb_write_enabled, and TRUE.
00122 { 00123 if(!Is_device_enumerated()) 00124 return FALSE; 00125 00126 if (!Is_usb_write_enabled()) 00127 { 00128 return FALSE; 00129 } 00130 return TRUE; 00131 }
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 142 of file uart_usb_lib.c.
References uart_usb_send_buffer().
00143 { 00144 uart_usb_send_buffer((U8*)&data_to_send, 1); 00145 return data_to_send; 00146 }
void uart_usb_flush | ( | void | ) |
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 157 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.
00158 { 00159 U8 zlp; 00160 00161 if(!Is_device_enumerated()) 00162 return; 00163 00164 // Compute if zlp required 00165 if(nb_data%TX_EP_SIZE) 00166 { zlp=FALSE;} 00167 else { zlp=TRUE; } 00168 00169 Usb_select_endpoint(TX_EP); 00170 while (nb_data) 00171 { 00172 while(Is_usb_write_enabled()==FALSE); // Wait Endpoint ready 00173 while(Is_usb_write_enabled() && nb_data) 00174 { 00175 Usb_write_byte(*buffer); 00176 buffer++; 00177 nb_data--; 00178 } 00179 Usb_ack_in_ready(); 00180 } 00181 if(zlp) 00182 { 00183 while(Is_usb_write_enabled()==FALSE); // Wait Endpoint ready 00184 Usb_ack_in_ready(); 00185 } 00186 }