Skip to content

Commit 82826c0

Browse files
nordic-bamijukkar
authored andcommitted
tests: drivers: Extend coverage for lpuart driver
Add more test that cover NRF SW lpuart Signed-off-by: Bartosz Miller <[email protected]>
1 parent 5f57e88 commit 82826c0

File tree

1 file changed

+81
-24
lines changed
  • tests/drivers/lpuart/src

1 file changed

+81
-24
lines changed

tests/drivers/lpuart/src/main.c

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ static void on_rx_buf_req(const struct device *dev)
160160
}
161161
}
162162

163-
static void uart_callback(const struct device *dev,
164-
struct uart_event *evt, void *user_data)
163+
static void uart_callback(const struct device *dev, struct uart_event *evt, void *user_data)
165164
{
166165
switch (evt->type) {
167166
case UART_TX_DONE:
@@ -249,8 +248,7 @@ ZTEST(test_lpuart_stress, test_stress)
249248

250249
static uint8_t tx_buf[] = {0xA, 0xAA, 0xB, 0xBB};
251250

252-
static void resilency_uart_callback(const struct device *dev,
253-
struct uart_event *evt,
251+
static void resilency_uart_callback(const struct device *dev, struct uart_event *evt,
254252
void *user_data)
255253
{
256254
switch (evt->type) {
@@ -290,6 +288,35 @@ static void resilency_uart_callback(const struct device *dev,
290288
}
291289
}
292290

291+
static void tx_abort_expected_callback(const struct device *dev, struct uart_event *evt,
292+
void *user_data)
293+
{
294+
switch (evt->type) {
295+
case UART_TX_ABORTED:
296+
tx_abort_cnt++;
297+
TC_PRINT("TX aborted.\n");
298+
break;
299+
case UART_TX_DONE:
300+
TC_PRINT("UART_TX_DONE.\n");
301+
break;
302+
case UART_RX_RDY:
303+
TC_PRINT("UART_RX_RDY.\n");
304+
break;
305+
case UART_RX_BUF_REQUEST:
306+
TC_PRINT("UART_RX_BUF_REQUEST.\n");
307+
break;
308+
case UART_RX_BUF_RELEASED:
309+
TC_PRINT("UART_RX_BUF_RELEASED.\n");
310+
break;
311+
case UART_RX_DISABLED:
312+
TC_PRINT("UART_RX_DISABLED.\n");
313+
break;
314+
case UART_RX_STOPPED:
315+
TC_PRINT("UART_RX_STOPPED.\n");
316+
break;
317+
}
318+
}
319+
293320
static void validate_lpuart(const struct device *lpuart)
294321
{
295322
int err;
@@ -321,12 +348,8 @@ static void next_alarm(const struct device *counter, struct counter_alarm_cfg *a
321348

322349
static nrf_gpio_pin_pull_t pin_toggle(uint32_t pin, nrf_gpio_pin_pull_t pull)
323350
{
324-
nrf_gpio_cfg(pin,
325-
NRF_GPIO_PIN_DIR_INPUT,
326-
NRF_GPIO_PIN_INPUT_DISCONNECT,
327-
pull,
328-
NRF_GPIO_PIN_S0S1,
329-
NRF_GPIO_PIN_NOSENSE);
351+
nrf_gpio_cfg(pin, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, pull,
352+
NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
330353
return (pull == NRF_GPIO_PIN_PULLUP) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_PULLUP;
331354
}
332355

@@ -361,20 +384,12 @@ static void pins_to_default(int32_t tx_pin)
361384
{
362385
nrfx_gpiote_pin_t req_pin = DT_INST_PROP(0, req_pin);
363386

364-
nrf_gpio_cfg(req_pin,
365-
NRF_GPIO_PIN_DIR_OUTPUT,
366-
NRF_GPIO_PIN_INPUT_DISCONNECT,
367-
NRF_GPIO_PIN_NOPULL,
368-
NRF_GPIO_PIN_S0S1,
369-
NRF_GPIO_PIN_NOSENSE);
387+
nrf_gpio_cfg(req_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
388+
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
370389

371390
if (tx_pin > 0) {
372-
nrf_gpio_cfg(tx_pin,
373-
NRF_GPIO_PIN_DIR_OUTPUT,
374-
NRF_GPIO_PIN_INPUT_DISCONNECT,
375-
NRF_GPIO_PIN_NOPULL,
376-
NRF_GPIO_PIN_S0S1,
377-
NRF_GPIO_PIN_NOSENSE);
391+
nrf_gpio_cfg(tx_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
392+
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
378393
}
379394
}
380395

@@ -383,8 +398,7 @@ struct test_data {
383398
int32_t tx_pin;
384399
};
385400

386-
static void counter_alarm_callback(const struct device *dev,
387-
uint8_t chan_id, uint32_t ticks,
401+
static void counter_alarm_callback(const struct device *dev, uint8_t chan_id, uint32_t ticks,
388402
void *user_data)
389403
{
390404
struct test_data *data = (struct test_data *)user_data;
@@ -455,6 +469,49 @@ ZTEST(test_lpuart_resilency, test_resilency_with_tx_pin_float)
455469
test_resilency(true);
456470
}
457471

472+
ZTEST(test_lpuart_resilency, test_tx_abort_rx_not_enabled)
473+
{
474+
Z_TEST_SKIP_IFNDEF(CONFIG_TEST_LPUART_LOOPBACK);
475+
476+
int err;
477+
const struct device *lpuart = DEVICE_DT_GET(DT_NODELABEL(lpuart));
478+
479+
zassert_true(device_is_ready(lpuart), NULL);
480+
uart_callback_set(lpuart, tx_abort_expected_callback, NULL);
481+
482+
err = uart_tx(lpuart, tx_buf, sizeof(tx_buf), 1000);
483+
zassert_equal(err, 0, "uart_tx - unexpected err: %d", err);
484+
k_msleep(10);
485+
zassert_equal(tx_abort_cnt, 1, "tx_abort_cnt != 1: %d", tx_abort_cnt);
486+
tx_abort_cnt = 0;
487+
}
488+
489+
ZTEST(test_lpuart_resilency, test_tx_abort_from_api)
490+
{
491+
Z_TEST_SKIP_IFNDEF(CONFIG_TEST_LPUART_LOOPBACK);
492+
493+
int err;
494+
uint8_t tx_buffer[50] = {0};
495+
uint8_t rx_buffer[50] = {0};
496+
const struct device *lpuart = DEVICE_DT_GET(DT_NODELABEL(lpuart));
497+
498+
zassert_true(device_is_ready(lpuart), NULL);
499+
uart_callback_set(lpuart, tx_abort_expected_callback, NULL);
500+
501+
err = uart_rx_enable(lpuart, rx_buffer, sizeof(rx_buffer), 100);
502+
zassert_equal(err, 0, "uart_rx_enable - unexpected err:%d", err);
503+
err = uart_tx(lpuart, tx_buffer, sizeof(tx_buffer), 1000);
504+
zassert_equal(err, 0, "uart_tx - unexpected err:%d", err);
505+
k_msleep(1);
506+
err = uart_tx_abort(lpuart);
507+
zassert_equal(err, 0, "uart_tx_abort - unexpected err:%d", err);
508+
k_msleep(10);
509+
err = uart_rx_disable(lpuart);
510+
zassert_equal(err, 0, "uart_rx_disable - unexpected err:%d", err);
511+
zassert_equal(tx_abort_cnt, 1, "tx_abort_cnt != 1: %d", tx_abort_cnt);
512+
tx_abort_cnt = 0;
513+
}
514+
458515
static void *suite_setup(void)
459516
{
460517
/* Read first random number. There are some generators which do not support

0 commit comments

Comments
 (0)