Commit 6400f0bf authored by Carles Cufi's avatar Carles Cufi Committed by Fabio Utzig
Browse files

zephyr: serial_adapter: Cleanup queue variables

Remove the simple pointers and use the "&" operator throughout to
simplify the understanding of the code.

Signed-off-by: default avatarCarles Cufi <carles.cufi@nordicsemi.no>
parent b124e39f
Loading
Loading
Loading
Loading
+14 −19
Changes for boot/zephyr/serial_adapter.c: 14 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -40,11 +40,9 @@ struct line_input {
static struct device *uart_dev;
static struct line_input line_bufs[2];

static sys_slist_t free_queue;
static sys_slist_t used_queue;
static sys_slist_t avail_queue;
static sys_slist_t lines_queue;

static sys_slist_t *avail_queue;
static sys_slist_t *lines_queue;
static u16_t cur;

static int boot_uart_fifo_getline(char **line);
@@ -98,20 +96,17 @@ boot_console_init(void)
{
	int i;

	sys_slist_init(&free_queue);
	sys_slist_init(&used_queue);
	/* Zephyr UART handler takes an empty buffer from avail_queue,
	 * stores UART input in it until EOL, and then puts it into
	 * lines_queue.
	 */
	sys_slist_init(&avail_queue);
	sys_slist_init(&lines_queue);

	for (i = 0; i < ARRAY_SIZE(line_bufs); i++) {
		sys_slist_append(&free_queue, &line_bufs[i].node);
		sys_slist_append(&avail_queue, &line_bufs[i].node);
	}

	/* Zephyr UART handler takes an empty buffer from free_queue,
	 * stores UART input in it until EOL, and then puts it into
	 * used_queue.
	 */
	avail_queue = &free_queue;
	lines_queue = &used_queue;

	return boot_uart_fifo_init();
}

@@ -133,7 +128,7 @@ boot_uart_fifo_callback(struct device *dev)
		if (!cmd) {
			sys_snode_t *node;

			node = sys_slist_get(avail_queue);
			node = sys_slist_get(&avail_queue);
			if (!node) {
				return;
			}
@@ -146,7 +141,7 @@ boot_uart_fifo_callback(struct device *dev)

		if (byte ==  '\n') {
			cmd->len = cur;
			sys_slist_append(lines_queue, &cmd->node);
			sys_slist_append(&lines_queue, &cmd->node);
			cur = 0;
			cmd = NULL;
		}
@@ -163,12 +158,12 @@ boot_uart_fifo_getline(char **line)
	key = irq_lock();
	/* Recycle cmd buffer returned previous time */
	if (cmd != NULL) {
		if (sys_slist_peek_tail(&free_queue) != &cmd->node) {
			sys_slist_append(&free_queue, &cmd->node);
		if (sys_slist_peek_tail(&avail_queue) != &cmd->node) {
			sys_slist_append(&avail_queue, &cmd->node);
		}
	}

	node = sys_slist_get(&used_queue);
	node = sys_slist_get(&lines_queue);
	irq_unlock(key);

	if (node == NULL) {