zephyr: fix serial ISR in serial_adapter

The UART device ISR in serial_adapter expected the device
to fire an interrupt for each byte that was received.
Although this might have worked for some devices it wouldn't
work for USB. This commit fixed the issue by modifying the ISR
according to the uart.h documentation.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
diff --git a/boot/zephyr/serial_adapter.c b/boot/zephyr/serial_adapter.c
index 8aa50ba..92aa6c6 100644
--- a/boot/zephyr/serial_adapter.c
+++ b/boot/zephyr/serial_adapter.c
@@ -19,6 +19,7 @@
 #include <assert.h>
 #include <string.h>
 #include <zephyr.h>
+#include "bootutil/bootutil_log.h"
 
 #ifdef CONFIG_UART_CONSOLE
 #error Zephyr UART console must been disabled if serial_adapter module is used.
@@ -117,12 +118,16 @@
 	u8_t byte;
 	int rx;
 
-	while (uart_irq_update(uart_dev) &&
-	       uart_irq_rx_ready(uart_dev)) {
+	uart_irq_update(uart_dev);
 
+	if (!uart_irq_rx_ready(uart_dev)) {
+		return;
+	}
+
+	while (true) {
 		rx = uart_fifo_read(uart_dev, &byte, 1);
 		if (rx != 1) {
-			continue;
+			break;
 		}
 
 		if (!cmd) {
@@ -130,6 +135,8 @@
 
 			node = sys_slist_get(&avail_queue);
 			if (!node) {
+				BOOT_LOG_ERR("Not enough memory to store"
+					     " incoming data!");
 				return;
 			}
 			cmd = CONTAINER_OF(node, struct line_input, node);
@@ -191,8 +198,10 @@
 	uart_irq_callback_set(uart_dev, boot_uart_fifo_callback);
 
 	/* Drain the fifo */
-	while (uart_irq_rx_ready(uart_dev)) {
-		uart_fifo_read(uart_dev, &c, 1);
+	if (uart_irq_rx_ready(uart_dev)) {
+		while (uart_fifo_read(uart_dev, &c, 1)) {
+			;
+		}
 	}
 
 	cur = 0;
@@ -201,7 +210,8 @@
 
 	/* Enable all interrupts unconditionally. Note that this is due
 	 * to Zephyr issue #8393. This should be removed once the
-	 * issue is fixed in upstream Zephyr. */
+	 * issue is fixed in upstream Zephyr.
+	 */
 	irq_unlock(0);
 
 	return 0;