mirror of
https://github.com/google/pebble.git
synced 2025-05-05 09:21:40 -04:00
57 lines
1.6 KiB
C
57 lines
1.6 KiB
C
/* Copyright (c) 2016 Linaro
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <zephyr.h>
|
|
#include <uart.h>
|
|
#include <drivers/console/uart_console.h>
|
|
#include "getline-zephyr.h"
|
|
|
|
/* While app processes one input line, Zephyr will have another line
|
|
buffer to accumulate more console input. */
|
|
static struct uart_console_input line_bufs[2];
|
|
|
|
static struct nano_fifo free_queue;
|
|
static struct nano_fifo used_queue;
|
|
|
|
char *zephyr_getline(void)
|
|
{
|
|
static struct uart_console_input *cmd;
|
|
|
|
/* Recycle cmd buffer returned previous time */
|
|
if (cmd != NULL)
|
|
{
|
|
nano_fifo_put(&free_queue, cmd);
|
|
}
|
|
|
|
cmd = nano_fifo_get(&used_queue, TICKS_UNLIMITED);
|
|
return cmd->line;
|
|
}
|
|
|
|
void zephyr_getline_init(void)
|
|
{
|
|
int i;
|
|
|
|
nano_fifo_init(&used_queue);
|
|
nano_fifo_init(&free_queue);
|
|
for (i = 0; i < sizeof(line_bufs) / sizeof(*line_bufs); i++)
|
|
{
|
|
nano_fifo_put(&free_queue, &line_bufs[i]);
|
|
}
|
|
|
|
/* Zephyr UART handler takes an empty buffer from free_queue,
|
|
stores UART input in it until EOL, and then puts it into
|
|
used_queue. */
|
|
uart_register_input(&free_queue, &used_queue, NULL);
|
|
}
|