mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/periph/spi: allow use on more boards
- Disable the benchmark on low memory boards - Reduce the help message length on low memory boards - Update to new shell command interface using XFA
This commit is contained in:
parent
20c389870a
commit
b90f985d47
@ -3,11 +3,32 @@
|
||||
# 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 APP_CONSIDERS_BOARD_LOW_MEMORY
|
||||
bool
|
||||
help
|
||||
This disables optional features for boards that are scare on resources
|
||||
default y if BOARD_ARDUINO_DUEMILANOVE
|
||||
default y if BOARD_ARDUINO_LEONARDO
|
||||
default y if BOARD_ARDUINO_NANO
|
||||
default y if BOARD_ARDUINO_UNO
|
||||
default y if BOARD_ATMEGA328P
|
||||
default y if BOARD_ATMEGA328P_XPLAINED_MINI
|
||||
default y if BOARD_ATMEGA8
|
||||
default y if BOARD_MSB_430
|
||||
default y if BOARD_MSB_430H
|
||||
default y if BOARD_NUCLEO_L011K4
|
||||
default y if BOARD_OLIMEX_MSP430_H1611
|
||||
default y if BOARD_OLIMEX_MSP430_H2618
|
||||
default y if BOARD_SAMD10_XMINI
|
||||
default y if BOARD_STM32F030F4_DEMO
|
||||
default y if BOARD_TELOSB
|
||||
default y if BOARD_Z1
|
||||
|
||||
config APPLICATION
|
||||
bool
|
||||
default y
|
||||
imply MODULE_PERIPH_SPI_RECONFIGURE
|
||||
imply MODULE_PERIPH_SPI_ON_QSPI
|
||||
depends on TEST_KCONFIG
|
||||
imply MODULE_PERIPH_SPI_RECONFIGURE if !APP_CONSIDERS_BOARD_LOW_MEMORY
|
||||
select MODULE_SCHEDSTATISTICS if !APP_CONSIDERS_BOARD_LOW_MEMORY
|
||||
|
@ -1,21 +1,55 @@
|
||||
BOARD ?= samr21-xpro
|
||||
include ../Makefile.periph_common
|
||||
|
||||
LOW_MEMORY_BOARDS := samd10-xmini
|
||||
# Disable benchmark, optional features and longer in-app help message
|
||||
# on boards with low RAM/ROM.
|
||||
#
|
||||
# In addition, all MSP430 based boards won't work with schedstatistics, as this
|
||||
# imposes too much overhead for interrupt handlers (when unblocking the shell
|
||||
# thread) for UART RX to work correctly.
|
||||
LOW_MEMORY_BOARDS := \
|
||||
arduino-duemilanove \
|
||||
arduino-leonardo \
|
||||
arduino-nano \
|
||||
arduino-uno \
|
||||
atmega328p \
|
||||
atmega328p-xplained-mini \
|
||||
atmega8 \
|
||||
msb-430 \
|
||||
msb-430h \
|
||||
nucleo-l011k4 \
|
||||
olimex-msp430-h1611 \
|
||||
olimex-msp430-h2618 \
|
||||
samd10-xmini \
|
||||
stm32f030f4-demo \
|
||||
telosb \
|
||||
z1 \
|
||||
#
|
||||
|
||||
FEATURES_REQUIRED += periph_spi
|
||||
FEATURES_OPTIONAL += periph_spi_on_qspi
|
||||
|
||||
ifeq (,$(filter $(BOARD),$(LOW_MEMORY_BOARDS)))
|
||||
FEATURES_OPTIONAL += periph_spi_reconfigure
|
||||
ENABLE_BENCHMARK ?= 1
|
||||
LOW_MEMORY := 0
|
||||
else
|
||||
ENABLE_BENCHMARK ?= 0
|
||||
LOW_MEMORY := 1
|
||||
endif
|
||||
|
||||
USEMODULE += ztimer_usec
|
||||
USEMODULE += ztimer_sec
|
||||
USEMODULE += shell_cmds_default
|
||||
USEMODULE += schedstatistics
|
||||
|
||||
ifeq (1,$(ENABLE_BENCHMARK))
|
||||
USEMODULE += schedstatistics
|
||||
endif
|
||||
|
||||
# avoid running Kconfig by default
|
||||
SHOULD_RUN_KCONFIG ?=
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
CFLAGS += -DENABLE_BENCHMARK=$(ENABLE_BENCHMARK)
|
||||
CFLAGS += -DLOW_MEMORY=$(LOW_MEMORY)
|
||||
|
@ -1,12 +1,4 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
arduino-duemilanove \
|
||||
arduino-leonardo \
|
||||
arduino-nano \
|
||||
arduino-uno \
|
||||
atmega328p \
|
||||
atmega328p-xplained-mini \
|
||||
atmega8 \
|
||||
nucleo-l011k4 \
|
||||
samd10-xmini \
|
||||
stm32f030f4-demo \
|
||||
#
|
||||
|
@ -4,7 +4,6 @@ CONFIG_MODULE_PERIPH_SPI=y
|
||||
|
||||
CONFIG_MODULE_SHELL=y
|
||||
CONFIG_MODULE_SHELL_CMDS_DEFAULT=y
|
||||
CONFIG_MODULE_SCHEDSTATISTICS=y
|
||||
CONFIG_MODULE_ZTIMER=y
|
||||
CONFIG_MODULE_ZTIMER_SEC=y
|
||||
CONFIG_ZTIMER_USEC=y
|
||||
|
@ -44,6 +44,17 @@
|
||||
#define DEFAULT_SPI_CS_PIN 0
|
||||
#endif
|
||||
|
||||
#ifndef ENABLE_BENCHMARK
|
||||
#define ENABLE_BENCHMARK 0
|
||||
#endif
|
||||
|
||||
#ifndef LOW_MEMORY
|
||||
#define LOW_MEMORY 0
|
||||
#endif
|
||||
|
||||
#define BUF_SIZE (128U)
|
||||
|
||||
#if ENABLE_BENCHMARK
|
||||
/**
|
||||
* @brief Some parameters used for benchmarking
|
||||
*/
|
||||
@ -53,8 +64,6 @@
|
||||
#define BENCH_PAYLOAD ('b')
|
||||
#define BENCH_REGADDR (0x23)
|
||||
|
||||
#define BUF_SIZE (512U)
|
||||
|
||||
/**
|
||||
* @brief Benchmark buffers
|
||||
*/
|
||||
@ -62,6 +71,7 @@ static uint8_t bench_wbuf[BENCH_LARGE];
|
||||
static uint8_t bench_rbuf[BENCH_LARGE];
|
||||
|
||||
extern void sched_statistics_cb(kernel_pid_t active_thread, kernel_pid_t next_thread);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Generic buffer used for receiving
|
||||
@ -75,6 +85,7 @@ static struct {
|
||||
spi_cs_t cs;
|
||||
} spiconf;
|
||||
|
||||
#if ENABLE_BENCHMARK
|
||||
/*
|
||||
* @brief Trigger an update of the scheduler runtime statistics.
|
||||
*
|
||||
@ -95,8 +106,9 @@ static uint32_t _ztimer_diff_usec(uint32_t stop, uint32_t start)
|
||||
{
|
||||
return stop - start;
|
||||
}
|
||||
#endif
|
||||
|
||||
void print_bytes(char* title, uint8_t* data, size_t len)
|
||||
static void print_bytes(const char *title, const uint8_t *data, size_t len)
|
||||
{
|
||||
printf("%4s\n", title);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
@ -118,7 +130,7 @@ void print_bytes(char* title, uint8_t* data, size_t len)
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
int cmd_init(int argc, char **argv)
|
||||
static int cmd_init(int argc, char **argv)
|
||||
{
|
||||
int dev, mode, clk, port, pin, tmp;
|
||||
|
||||
@ -128,22 +140,24 @@ int cmd_init(int argc, char **argv)
|
||||
for (int i = 0; i < (int)SPI_NUMOF; i++) {
|
||||
printf("\t\t%i: SPI_DEV(%i)\n", i, i);
|
||||
}
|
||||
puts("\tmode:");
|
||||
puts("\t\t0: POL:0, PHASE:0 - on first rising edge");
|
||||
puts("\t\t1: POL:0, PHASE:1 - on second rising edge");
|
||||
puts("\t\t2: POL:1, PHASE:0 - on first falling edge");
|
||||
puts("\t\t3: POL:1, PHASE:1 - on second falling edge");
|
||||
puts("\tclk:");
|
||||
puts("\t\t0: 100 KHz");
|
||||
puts("\t\t1: 400 KHz");
|
||||
puts("\t\t2: 1 MHz");
|
||||
puts("\t\t3: 5 MHz");
|
||||
puts("\t\t4: 10 MHz");
|
||||
puts("\tcs port:");
|
||||
puts("\t\tPort of the CS pin, set to -1 for hardware chip select");
|
||||
puts("\tcs pin:");
|
||||
puts("\t\tPin used for chip select. If hardware chip select is enabled,\n"
|
||||
"\t\tthis value specifies the internal HWCS line");
|
||||
if (!LOW_MEMORY) {
|
||||
puts("\tmode:\n"
|
||||
"\t\t0: POL:0, PHASE:0 - on first rising edge\n"
|
||||
"\t\t1: POL:0, PHASE:1 - on second rising edge\n"
|
||||
"\t\t2: POL:1, PHASE:0 - on first falling edge\n"
|
||||
"\t\t3: POL:1, PHASE:1 - on second falling edge\n"
|
||||
"\tclk:\n"
|
||||
"\t\t0: 100 KHz\n"
|
||||
"\t\t1: 400 KHz\n"
|
||||
"\t\t2: 1 MHz\n"
|
||||
"\t\t3: 5 MHz\n"
|
||||
"\t\t4: 10 MHz\n"
|
||||
"\tcs port:\n"
|
||||
"\t\tPort of the CS pin, set to -1 for hardware chip select\n"
|
||||
"\tcs pin:\n"
|
||||
"\t\tPin used for chip select. If hardware chip select is enabled,\n"
|
||||
"\t\tthis value specifies the internal HWCS line");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -226,8 +240,9 @@ int cmd_init(int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_COMMAND(init, "Setup a particular SPI configuration", cmd_init);
|
||||
|
||||
int cmd_transfer(int argc, char **argv)
|
||||
static int cmd_transfer(int argc, char **argv)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
@ -258,7 +273,9 @@ int cmd_transfer(int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_COMMAND(send, "Transfer string to slave", cmd_transfer);
|
||||
|
||||
#if ENABLE_BENCHMARK
|
||||
int cmd_bench(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
@ -520,6 +537,8 @@ int cmd_bench(int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_COMMAND(bench, "Runs some benchmarks", cmd_bench);
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_PERIPH_SPI_RECONFIGURE
|
||||
int cmd_spi_gpio(int argc, char **argv)
|
||||
@ -565,18 +584,9 @@ int cmd_spi_gpio(int argc, char **argv)
|
||||
printf("Success: spi_%i re-init\n", dev);
|
||||
return 0;
|
||||
}
|
||||
SHELL_COMMAND(spi_gpio, "Re-configures MISO & MOSI pins to GPIO mode and back.", cmd_spi_gpio);
|
||||
#endif
|
||||
|
||||
static const shell_command_t shell_commands[] = {
|
||||
{ "init", "Setup a particular SPI configuration", cmd_init },
|
||||
{ "send", "Transfer string to slave", cmd_transfer },
|
||||
{ "bench", "Runs some benchmarks", cmd_bench },
|
||||
#ifdef MODULE_PERIPH_SPI_RECONFIGURE
|
||||
{ "spi_gpio", "Re-configures MISO & MOSI pins to GPIO mode and back.", cmd_spi_gpio },
|
||||
#endif
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("Manual SPI peripheral driver test (see README.md)");
|
||||
@ -589,7 +599,7 @@ int main(void)
|
||||
|
||||
/* run the shell */
|
||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user