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:
parent
273c87b33e
commit
b6fb004354
1 changed files with 18 additions and 16 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue