From 6b43125c16e07cdb391a10502553d1436563b5cd Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 16 Feb 2016 09:22:09 +0100 Subject: [PATCH] tests: added SAUL test application --- tests/saul/Makefile | 11 +++++++++ tests/saul/README.md | 11 +++++++++ tests/saul/main.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 tests/saul/Makefile create mode 100644 tests/saul/README.md create mode 100644 tests/saul/main.c diff --git a/tests/saul/Makefile b/tests/saul/Makefile new file mode 100644 index 0000000000..d0c4790b5f --- /dev/null +++ b/tests/saul/Makefile @@ -0,0 +1,11 @@ +APPLICATION = saul +include ../Makefile.tests_common + +# include and auto-initialize all available sensors +USEMODULE += saul_reg +USEMODULE += saul_default +USEMODULE += auto_init_saul + +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include diff --git a/tests/saul/README.md b/tests/saul/README.md new file mode 100644 index 0000000000..f7584a2fd8 --- /dev/null +++ b/tests/saul/README.md @@ -0,0 +1,11 @@ +Expected result +=============== +This test application is polling all available SAUL devices periodically for +their data. This data is then printed to STDIO. + +Background +========== +The actual devices that are actually polled depend on the devices that are +configured for a particular platform. If you want to test the SAUL interface +to a particular device, you should just connect it to your BOARD and include +the corresponding device driver using the `USEMODULE` environment variable. diff --git a/tests/saul/main.c b/tests/saul/main.c new file mode 100644 index 0000000000..4cdb1806e7 --- /dev/null +++ b/tests/saul/main.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * + * @file + * @brief Test the SAUL interface of devices by periodically reading from + * them + * + * @author Hauke Petersen + * + */ + +#include + +#include "xtimer.h" +#include "phydat.h" +#include "saul_reg.h" + +/** + * @brief Read th sensors every second + */ +#define INTERVAL (1000000U) + + +int main(void) +{ + phydat_t res; + uint32_t last = xtimer_now(); + + puts("SAUL test application"); + + while (1) { + saul_reg_t *dev = saul_reg; + + if (dev == NULL) { + puts("No SAUL devices present"); + return 1; + } + + while (dev) { + int dim = saul_reg_read(dev, &res); + phydat_dump(&res, dim); + dev = dev->next; + } + + xtimer_usleep_until(&last, INTERVAL); + } + + return 0; +}