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:
parent
7393a00a5f
commit
59912cf13f
4 changed files with 62 additions and 0 deletions
5
samples/drivers/uart/Makefile
Normal file
5
samples/drivers/uart/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
KERNEL_TYPE = nano
|
||||
BOARD ?= quark_se_devboard
|
||||
CONF_FILE = prj.config
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
1
samples/drivers/uart/prj.config
Normal file
1
samples/drivers/uart/prj.config
Normal file
|
@ -0,0 +1 @@
|
|||
CONFIG_SERIAL=y
|
1
samples/drivers/uart/src/Makefile
Normal file
1
samples/drivers/uart/src/Makefile
Normal file
|
@ -0,0 +1 @@
|
|||
obj-y = main.o
|
55
samples/drivers/uart/src/main.c
Normal file
55
samples/drivers/uart/src/main.c
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue