1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/periph/pio: Add basic PIO test

This commit is contained in:
Fabian Hüßler 2021-12-16 15:00:48 +01:00 committed by Fabian Hüßler
parent a74379ef16
commit 117a901d6f
5 changed files with 156 additions and 0 deletions

11
tests/periph/pio/Kconfig Normal file
View File

@ -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

View File

@ -0,0 +1,8 @@
include ../Makefile.periph_common
FEATURES_REQUIRED += periph_pio
# avoid running Kconfig by default
SHOULD_RUN_KCONFIG ?=
include $(RIOTBASE)/Makefile.include

View File

@ -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: <INSERT VERSION HERE>)
TEST SUCCEEDED!

View File

@ -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

122
tests/periph/pio/main.c Normal file
View File

@ -0,0 +1,122 @@
/*
* 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 <fabian.huessler@ovgu.de>
*
* @}
*/
#include <stddef.h>
#include "shell.h"
#include "periph_conf.h"
#include "periph/pio.h"
#include "pio/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;
}