samples: Add UART application

This patch adds a very simple UART sample application which demonstrates
how to use the UART APIs. This sample is also useful to quickly verify
if a given UART driver is working properly. For now, the application
tests uart_poll_in() and uart_poll_out() APIs only, but new APIs should
be added in future.

Change-Id: If815f358f11efb058e947291b234d3d4130581d8
Signed-off-by: Andre Guedes <andre.guedes@intel.com>
This commit is contained in:
Andre Guedes 2016-02-29 17:23:09 -03:00 committed by Gerrit Code Review
commit 59912cf13f
4 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,5 @@
KERNEL_TYPE = nano
BOARD ?= quark_se_devboard
CONF_FILE = prj.config
include ${ZEPHYR_BASE}/Makefile.inc

View file

@ -0,0 +1 @@
CONFIG_SERIAL=y

View file

@ -0,0 +1 @@
obj-y = main.o

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* 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 <string.h>
#include <device.h>
#include <uart.h>
#include <zephyr.h>
static const char *banner1 = "Send any character to the UART device\n";
static const char *banner2 = "Character read:\n";
#ifdef CONFIG_BOARD_QUARK_SE_DEVBOARD
#define UART_DEVICE "UART_1"
#elif CONFIG_BOARD_QUARK_D2000_CRB
#define UART_DEVICE "UART_0"
#else
/* For any other board not specified above, we use UART_0 by default. */
#define UART_DEVICE "UART_0"
#endif
static void write_string(struct device *dev, const char *str, int len)
{
for (int i = 0; i < len; i++)
uart_poll_out(dev, str[i]);
}
void main(void)
{
struct device *dev = device_get_binding(UART_DEVICE);
unsigned char data;
write_string(dev, banner1, strlen(banner1));
/* Poll in the character */
while (uart_poll_in(dev, &data) == -1)
;
write_string(dev, banner2, strlen(banner2));
write_string(dev, &data, 1);
write_string(dev, "\n", 1);
}