targets/zephyr/Makefile.zephyr: Use zephyr_getline module for line input.

The original implementation used shell facility, but it was designed for
a unix shell like input, and automatically tokenized it into
space-separated "words", with limit of 10 (i.e. 9 spaces per line). For
JavaScript input, it is quite easy to have more than 9 spaces per line,
and get error:

Too many parameters (max 10)

After consultation with upstream
(https://jira.zephyrproject.org/browse/ZEP-532) it was decided that the
best approach is to skip using shell facility and use Zephyr console
facility. That however requires some Zephyr-specific boilerplate code.
This code was implemented as reusable modules in
https://github.com/pfalcon/zephyr_console_helpers repository, to be
usable for other console-based projects too. zephyr_getline.h/c in this
commits are direct imports from this repository.

JerryScript-DCO-1.0-Signed-off-by: Paul Sokolovsky paul.sokolovsky@linaro.org
This commit is contained in:
Paul Sokolovsky
2016-08-11 17:22:12 +03:00
parent 27253112c2
commit 314e74f8ce
5 changed files with 106 additions and 136 deletions
+58
View File
@@ -0,0 +1,58 @@
/*
* 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);
}