Skip to content

Commit

Permalink
Merge pull request #16637 from maribu/tests/periph_uart_mode
Browse files Browse the repository at this point in the history
tests/periph_uart_mode: Drop dep to periph_timer
  • Loading branch information
benpicco committed Jul 14, 2021
2 parents 9ca9efd + ca7c126 commit f877886
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 1 addition & 2 deletions tests/periph_uart_mode/Makefile
Expand Up @@ -2,8 +2,7 @@ include ../Makefile.tests_common

FEATURES_REQUIRED += periph_uart
FEATURES_REQUIRED += periph_uart_modecfg

USEMODULE += xtimer
FEATURES_OPTIONAL += periph_timer

# Set this to prevent welcome message from printing and confusing output
CFLAGS+=-DLOG_LEVEL=LOG_NONE
Expand Down
3 changes: 3 additions & 0 deletions tests/periph_uart_mode/Makefile.board.dep
@@ -0,0 +1,3 @@
ifneq (,$(filter periph_timer,$(FEATURES_USED)))
USEMODULE += xtimer
endif
23 changes: 22 additions & 1 deletion tests/periph_uart_mode/main.c
Expand Up @@ -22,7 +22,9 @@
#include <string.h>
#include <stdlib.h>

#include "board.h"
#include "periph/uart.h"
#include "periph_conf.h"
#include "stdio_uart.h"
#include "xtimer.h"

Expand Down Expand Up @@ -52,6 +54,25 @@
/* Stores each mode string for printing at the end of the test */
static char mode_strings[TOTAL_OPTIONS][MODE_STR_LEN];

static void _delay(void)
{
if (IS_USED(MODULE_XTIMER)) {
xtimer_usleep(DELAY_US);
}
else {
/*
* As fallback for freshly ported boards with no timer drivers written
* yet, we just use the CPU to delay execution and assume that roughly
* 20 CPU cycles are spend per loop iteration.
*
* Note that the volatile qualifier disables compiler optimizations for
* all accesses to the counter variable. Without volatile, modern
* compilers would detect that the loop is only wasting CPU cycles and
* optimize it out - but here the wasting of CPU cycles is desired.
*/
for (volatile uint32_t i = 0; i < CLOCK_CORECLOCK / 20; i++) { }
}
}

static void _get_mode(const uart_data_bits_t data_bits,
const uart_parity_t parity, const uart_stop_bits_t stop_bits, char* mode_str) {
Expand Down Expand Up @@ -153,7 +174,7 @@ int main(void)
if (status == UART_OK) {
results[ridx] = true;
printf("%s\n", mode_strings[ridx]);
xtimer_usleep(DELAY_US);
_delay();
}
else {
results[ridx] = false;
Expand Down

0 comments on commit f877886

Please sign in to comment.