1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

tests/periph/uart: update to API change

Release the UART before acquiring it again to not dead-lock the code
if acquire/release semantics is implemented by the UART peripheral.
This commit is contained in:
Marian Buschsieweke 2024-04-25 22:54:42 +02:00 committed by Marian Buschsieweke
parent e1cfa0b2db
commit ebec3258c3
No known key found for this signature in database
GPG Key ID: 758BD52517F79C41
2 changed files with 22 additions and 3 deletions

View File

@ -6,6 +6,7 @@ FEATURES_OPTIONAL += periph_uart_collision
FEATURES_OPTIONAL += periph_uart_modecfg
FEATURES_OPTIONAL += periph_uart_rxstart_irq
USEMODULE += bitfield
USEMODULE += shell
USEMODULE += ztimer_msec

View File

@ -22,11 +22,12 @@
#include <string.h>
#include <stdlib.h>
#include "bitfield.h"
#include "msg.h"
#include "periph/uart.h"
#include "ringbuffer.h"
#include "shell.h"
#include "thread.h"
#include "msg.h"
#include "ringbuffer.h"
#include "periph/uart.h"
#include "ztimer.h"
#ifdef MODULE_STDIO_UART
@ -86,6 +87,8 @@ static uart_stop_bits_t stop_bits_lut[] = { UART_STOP_BITS_1, UART_STOP_BITS_2 }
static int stop_bits_lut_len = ARRAY_SIZE(stop_bits_lut);
#endif
static BITFIELD(uarts_initialized_mask, UART_NUMOF);
static int parse_dev(char *arg)
{
unsigned dev = atoi(arg);
@ -180,6 +183,9 @@ static int _self_test(uart_t dev, unsigned baud)
uart_collision_detect_disable(dev);
#endif
uart_poweroff(UART_DEV(dev));
test_mode = false;
return 0;
failure:
@ -248,6 +254,11 @@ static int cmd_init(int argc, char **argv)
}
baud = strtol(argv[2], NULL, 0);
if (bf_isset(uarts_initialized_mask, dev)) {
uart_poweroff(UART_DEV(dev));
bf_unset(uarts_initialized_mask, dev);
}
/* initialize UART */
res = uart_init(UART_DEV(dev), baud, rx_cb, (void *)(intptr_t)dev);
if (res == UART_NOBAUD) {
@ -260,6 +271,8 @@ static int cmd_init(int argc, char **argv)
}
printf("Success: Initialized UART_DEV(%i) at BAUD %"PRIu32"\n", dev, baud);
bf_set(uarts_initialized_mask, dev);
/* also test if poweron() and poweroff() work (or at least don't break
* anything) */
sleep_test(dev, UART_DEV(dev));
@ -396,6 +409,11 @@ static int cmd_test(int argc, char **argv)
puts("[START]");
if (bf_isset(uarts_initialized_mask, dev)) {
uart_poweroff(UART_DEV(dev));
bf_unset(uarts_initialized_mask, dev);
}
/* run self test with different baud rates */
test_mode = true;
for (unsigned i = 1; i <= 12; ++i) {