diff --git a/tests/periph_pio/Kconfig b/tests/periph_pio/Kconfig new file mode 100644 index 0000000000000..baffd0aa94776 --- /dev/null +++ b/tests/periph_pio/Kconfig @@ -0,0 +1,11 @@ +# Copyright (c) 2021 Otto-von-Guericke Universität Magdeburg +# +# 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. +# + +config APPLICATION + bool + default y + depends on TEST_KCONFIG diff --git a/tests/periph_pio/Makefile b/tests/periph_pio/Makefile new file mode 100644 index 0000000000000..2ee86e7864271 --- /dev/null +++ b/tests/periph_pio/Makefile @@ -0,0 +1,8 @@ +include ../Makefile.tests_common + +FEATURES_REQUIRED += periph_pio + +# avoid running Kconfig by default +SHOULD_RUN_KCONFIG ?= + +include $(RIOTBASE)/Makefile.include diff --git a/tests/periph_pio/Makefile.ci b/tests/periph_pio/Makefile.ci new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/tests/periph_pio/Readme.md b/tests/periph_pio/Readme.md new file mode 100644 index 0000000000000..d815d3b0b2b91 --- /dev/null +++ b/tests/periph_pio/Readme.md @@ -0,0 +1,12 @@ +Peripheral PIO Test Application +===================================== + +This application tests basic PIO functionality. +- allocation and deallocation of instruction memory +- state machine claim and release + +Expected Output on Success +-------------------------- + + main(): This is RIOT! (Version: ) + TEST SUCCEEDED! diff --git a/tests/periph_pio/app.config.test b/tests/periph_pio/app.config.test new file mode 100644 index 0000000000000..550933221c249 --- /dev/null +++ b/tests/periph_pio/app.config.test @@ -0,0 +1,3 @@ +# this file enables modules defined in Kconfig. Do not use this file for +# application configuration. This is only needed during migration. +CONFIG_MODULE_PERIPH_PIO=y diff --git a/tests/periph_pio/main.c b/tests/periph_pio/main.c new file mode 100644 index 0000000000000..1924e15fb3c3f --- /dev/null +++ b/tests/periph_pio/main.c @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2021 Otto-von-Guericke Universität Magdeburg + * + * 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 application for the PIO peripheral driver + * + * @author Fabian Hüßler + * + * @} + */ + +#include +#include "shell.h" +#include "periph_conf.h" +#include "periph/pio.h" +#define ENABLE_DEBUG 0 +#include "debug.h" + +#if ENABLE_DEBUG +#define DEBUG_TEST_FAILED(msg, ...) \ +DEBUG("[Test PIO] %s failed at %d: " msg "\n", __func__, __LINE__, __VA_ARGS__); +#else +#define DEBUG_TEST_FAILED(msg, ...) +#endif + +static int _test_pio_alloc_and_free(pio_t pio) +{ + int error = 1; + pio_program_t pro; + for (int i = 0; i < PIO_INSTR_NUMOF; i++) { + pro = (pio_program_t){.location = PIO_PROGRAM_NOT_LOADED, .instr_numof = 1}; + if (pio_alloc_program(pio, &pro)) { + DEBUG_TEST_FAILED("Could not allocate program at %d", i); + goto CLEAN; + } + } + if (!pio_alloc_program(pio, &pro)) { + DEBUG_TEST_FAILED("Program impossibly allocated"); + goto CLEAN; + } + pio_free_program(pio, &pro); + pro.location = PIO_PROGRAM_NOT_LOADED; + if (pio_alloc_program(pio, &pro)) { + DEBUG_TEST_FAILED("Program could not be allocated after free"); + goto CLEAN; + } + error = 0; +CLEAN: + for (int i = 0; i < PIO_INSTR_NUMOF; i++) { + pro = (pio_program_t){.location = i, .instr_numof = 1}; + pio_free_program(pio, &pro); + } + return error; +} + +static int _test_pio_sm_lock_unlock(pio_t pio) +{ + int error = 1; + pio_sm_t sm; + for (pio_sm_t i = 0; i < PIO_SM_NUMOF; i++) { + if ((sm = pio_sm_lock(pio)) < 0) { + DEBUG_TEST_FAILED("Could not lock state machine %d", i); + goto CLEAN; + } + } + if (pio_sm_lock(pio) >= 0) { + DEBUG_TEST_FAILED("State machine impossibly locked"); + goto CLEAN; + } + pio_sm_unlock(pio, sm); + if (sm != pio_sm_lock(pio)) { + DEBUG_TEST_FAILED("State machine could not be locked after unlock"); + goto CLEAN; + } + error = 0; +CLEAN: + for (pio_sm_t i = 0; i < PIO_SM_NUMOF; i++) { + pio_sm_unlock(pio, i); + } + return error; +} + +static int _test_pio_sm_program_any(void) +{ + int error = 1; + pio_t pio; + pio_sm_t sm; + pio_program_t pro = {.location = PIO_PROGRAM_NOT_LOADED, .instr_numof = PIO_INSTR_NUMOF}; + if (pio_alloc_program_sm_lock_any(&pio, &sm, &pro)) { + DEBUG_TEST_FAILED("Could not allocate program for any state machine"); + goto CLEAN; + } + error = 0; +CLEAN: + pio_sm_unlock(pio, sm); + pio_free_program(pio, &pro); + return error; +} + +int main(void) +{ + int error = 0; + + for (pio_t pio = 0; pio < PIO_NUMOF; pio++) { + error = _test_pio_alloc_and_free(pio) ? 1 : error; + error = _test_pio_sm_lock_unlock(pio) ? 1 : error; + } + error = _test_pio_sm_program_any() ? 1 : error; + + puts(error ? "TEST FAILED!" : "TEST SUCCEEDED!"); + return 0; +}