summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Guedes <andre.guedes@intel.com>2016-02-29 17:23:09 -0300
committerGerrit Code Review <gerrit@zephyrproject.org>2016-03-04 15:16:20 +0000
commit59912cf13f7763331f818520c3692883933e085b (patch)
tree4b87a87c01055c4f1fabfaa6795e760725967250
parent7393a00a5f48a9781e66e9a3c13fdac8c55084ed (diff)
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>
-rw-r--r--samples/drivers/uart/Makefile5
-rw-r--r--samples/drivers/uart/prj.config1
-rw-r--r--samples/drivers/uart/src/Makefile1
-rw-r--r--samples/drivers/uart/src/main.c55
4 files changed, 62 insertions, 0 deletions
diff --git a/samples/drivers/uart/Makefile b/samples/drivers/uart/Makefile
new file mode 100644
index 000000000..27e0ecfb6
--- /dev/null
+++ b/samples/drivers/uart/Makefile
@@ -0,0 +1,5 @@
+KERNEL_TYPE = nano
+BOARD ?= quark_se_devboard
+CONF_FILE = prj.config
+
+include ${ZEPHYR_BASE}/Makefile.inc
diff --git a/samples/drivers/uart/prj.config b/samples/drivers/uart/prj.config
new file mode 100644
index 000000000..ef2861c78
--- /dev/null
+++ b/samples/drivers/uart/prj.config
@@ -0,0 +1 @@
+CONFIG_SERIAL=y
diff --git a/samples/drivers/uart/src/Makefile b/samples/drivers/uart/src/Makefile
new file mode 100644
index 000000000..00066e156
--- /dev/null
+++ b/samples/drivers/uart/src/Makefile
@@ -0,0 +1 @@
+obj-y = main.o
diff --git a/samples/drivers/uart/src/main.c b/samples/drivers/uart/src/main.c
new file mode 100644
index 000000000..e6058afca
--- /dev/null
+++ b/samples/drivers/uart/src/main.c
@@ -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);
+}