Commit 5ceeddb4 authored by Carles Cufi's avatar Carles Cufi Committed by Carles Cufí
Browse files

zephyr: Use sys_slist instead of k_fifo in serial adapter

The k_fifo_* primitives are not available when multithreading is
disabled. Use sys_slist_* instead.

Signed-off-by: default avatarCarles Cufi <carles.cufi@nordicsemi.no>
parent df4d9a4d
Loading
Loading
Loading
Loading
+25 −14
Changes for boot/zephyr/serial_adapter.c: 25 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -29,8 +29,8 @@
 * This struct is used to represent an input line from a serial interface.
 */
struct line_input {
    /** FIFO uses first 4 bytes itself, reserve space */
    int _unused;
	/** Required to use sys_slist */
	sys_snode_t node;

	int len;
	/** Buffer where the input line is recorded */
@@ -40,11 +40,11 @@ struct line_input {
static struct device *uart_dev;
static struct line_input line_bufs[2];

static K_FIFO_DEFINE(free_queue);
static K_FIFO_DEFINE(used_queue);
static sys_slist_t free_queue;
static sys_slist_t used_queue;

static struct k_fifo *avail_queue;
static struct k_fifo *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,8 +98,11 @@ boot_console_init(void)
{
	int i;

	sys_slist_init(&free_queue);
	sys_slist_init(&used_queue);

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

	/* Zephyr UART handler takes an empty buffer from free_queue,
@@ -123,12 +126,18 @@ boot_uart_fifo_callback(struct device *dev)
	       uart_irq_rx_ready(uart_dev)) {

		rx = uart_fifo_read(uart_dev, &byte, 1);
		if (rx != 1) {
			continue;
		}

		if (!cmd) {
            cmd = k_fifo_get(avail_queue, K_NO_WAIT);
            if (!cmd) {
			sys_snode_t *node;

			node = sys_slist_get(avail_queue);
			if (!node) {
				return;
			}
			cmd = CONTAINER_OF(node, struct line_input, node);
		}

		if (cur < CONFIG_BOOT_MAX_LINE_INPUT_LEN) {
@@ -137,10 +146,9 @@ boot_uart_fifo_callback(struct device *dev)

		if (byte ==  '\n') {
			cmd->len = cur;
            k_fifo_put(lines_queue, cmd);
			sys_slist_append(lines_queue, &cmd->node);
			cur = 0;
		}

	}
}

@@ -148,19 +156,22 @@ static int
boot_uart_fifo_getline(char **line)
{
	static struct line_input *cmd;
	sys_snode_t *node;

	/* Recycle cmd buffer returned previous time */
	if (cmd != NULL) {
        k_fifo_put(&free_queue, cmd);
		sys_slist_append(&free_queue, &cmd->node);
	}

    cmd = k_fifo_get(&used_queue, K_NO_WAIT);
	node = sys_slist_get(&used_queue);

    if (cmd == NULL) {
	if (node == NULL) {
		cmd = NULL;
		*line = NULL;
		return 0;
	}

	cmd = CONTAINER_OF(node, struct line_input, node);
	*line = cmd->line;
	return cmd->len;
}