usb: cdc acm: Read all the received data

Change CDC example to read and echo all the received data
before waiting for a new read interrupt.

Change-Id: I21e1646fb20a2c4f7aea2b396b633a4e0ae429fc
Signed-off-by: Adrian Bradianu <adrian.bradianu@windriver.com>
This commit is contained in:
Adrian Bradianu 2016-06-28 17:46:10 +03:00 committed by Inaky Perez-Gonzalez
commit b6fb004354

View file

@ -56,20 +56,6 @@ static void interrupt_handler(struct device *dev)
}
}
static void read_data(struct device *dev, int *bytes_read)
{
uart_irq_rx_enable(dev);
data_arrived = false;
while (data_arrived == false)
;
/* Read all data */
*bytes_read = uart_fifo_read(dev, data_buf, sizeof(data_buf));
uart_irq_rx_disable(dev);
}
static void write_data(struct device *dev, const char *buf, int len)
{
uart_irq_tx_enable(dev);
@ -82,6 +68,20 @@ static void write_data(struct device *dev, const char *buf, int len)
uart_irq_tx_disable(dev);
}
static void read_and_echo_data(struct device *dev, int *bytes_read)
{
while (data_arrived == false)
;
data_arrived = false;
/* Read all data and echo it back */
while ((*bytes_read = uart_fifo_read(dev,
data_buf, sizeof(data_buf)))) {
write_data(dev, data_buf, *bytes_read);
}
}
void main(void)
{
struct device *dev;
@ -124,9 +124,11 @@ void main(void)
write_data(dev, banner1, strlen(banner1));
write_data(dev, banner2, strlen(banner2));
/* Enable rx interrupts */
uart_irq_rx_enable(dev);
/* Echo the received data */
while (1) {
read_data(dev, &bytes_read);
write_data(dev, data_buf, bytes_read);
read_and_echo_data(dev, &bytes_read);
}
}