From 413c263b62c960c23e34cc296517c41f4f3af2f7 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 11:35:49 +0100 Subject: [PATCH 01/18] drivers/at86rf215: Fix missing .h file in params --- drivers/at86rf215/include/at86rf215_params.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/at86rf215/include/at86rf215_params.h b/drivers/at86rf215/include/at86rf215_params.h index 82dc9e8f6c96..9aafac1a71a5 100644 --- a/drivers/at86rf215/include/at86rf215_params.h +++ b/drivers/at86rf215/include/at86rf215_params.h @@ -20,6 +20,7 @@ #ifndef AT86RF215_PARAMS_H #define AT86RF215_PARAMS_H +#include "at86rf215.h" #include "board.h" #ifdef __cplusplus From 659618aeebe4043eabdde944844b8281718df6aa Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 11:36:24 +0100 Subject: [PATCH 02/18] drivers/at86rf2xx: Fix missing .h file in params --- drivers/at86rf2xx/include/at86rf2xx_params.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/at86rf2xx/include/at86rf2xx_params.h b/drivers/at86rf2xx/include/at86rf2xx_params.h index 9484f61b8246..01184d32f162 100644 --- a/drivers/at86rf2xx/include/at86rf2xx_params.h +++ b/drivers/at86rf2xx/include/at86rf2xx_params.h @@ -20,6 +20,7 @@ #ifndef AT86RF2XX_PARAMS_H #define AT86RF2XX_PARAMS_H +#include "at86rf2xx.h" #include "board.h" #ifdef __cplusplus From 34d7c0def66627868e84350610467780a87c5cff Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 10:09:11 +0100 Subject: [PATCH 03/18] drivers/cc2420: Fix missing .h file in params --- drivers/cc2420/include/cc2420_params.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/cc2420/include/cc2420_params.h b/drivers/cc2420/include/cc2420_params.h index eb9f6a9655cf..8f43cd1e1840 100644 --- a/drivers/cc2420/include/cc2420_params.h +++ b/drivers/cc2420/include/cc2420_params.h @@ -20,6 +20,7 @@ #define CC2420_PARAMS_H #include "board.h" +#include "cc2420.h" #ifdef __cplusplus extern "C" { From d6ba7c14281f942ef94d352a409b32ce1a478d56 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 11:36:47 +0100 Subject: [PATCH 04/18] drivers/kw2xrf: Fix missing .h file in params --- drivers/kw2xrf/include/kw2xrf_params.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/kw2xrf/include/kw2xrf_params.h b/drivers/kw2xrf/include/kw2xrf_params.h index 5142b5dfa151..e282c00d8bdb 100644 --- a/drivers/kw2xrf/include/kw2xrf_params.h +++ b/drivers/kw2xrf/include/kw2xrf_params.h @@ -20,6 +20,7 @@ #define KW2XRF_PARAMS_H #include "board.h" +#include "kw2xrf.h" #ifdef __cplusplus extern "C" { From e3ec242ecf0833844995df5a2637f021ccd73a36 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 11:37:06 +0100 Subject: [PATCH 05/18] drivers/mrf24j40: Fix missing .h file in params --- drivers/mrf24j40/include/mrf24j40_params.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mrf24j40/include/mrf24j40_params.h b/drivers/mrf24j40/include/mrf24j40_params.h index 212246f34862..858dcdfc0324 100644 --- a/drivers/mrf24j40/include/mrf24j40_params.h +++ b/drivers/mrf24j40/include/mrf24j40_params.h @@ -22,6 +22,7 @@ #define MRF24J40_PARAMS_H #include "board.h" +#include "mrf24j40.h" #ifdef __cplusplus extern "C" { From 4a3231f7635a63582b67aa8f25a9342c2fb35b94 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 10 Mar 2022 12:03:26 +0100 Subject: [PATCH 06/18] drivers/kw2xrf: add setup function with global index This index is used to register the network device. --- drivers/include/kw2xrf.h | 4 +++- drivers/include/net/netdev.h | 1 + drivers/kw2xrf/kw2xrf.c | 5 ++++- sys/net/gnrc/netif/init_devs/auto_init_kw2xrf.c | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/include/kw2xrf.h b/drivers/include/kw2xrf.h index 5b63b4200c6d..45af58593641 100644 --- a/drivers/include/kw2xrf.h +++ b/drivers/include/kw2xrf.h @@ -138,8 +138,10 @@ typedef struct { * * @param[out] dev device descriptor * @param[in] params parameters for device initialization + * @param[in] index index of @p params in a global parameter struct array. + * If initialized manually, pass a unique identifier instead. */ -void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params); +void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params, uint8_t index); /** * @brief Initialize the given KW2XRF device diff --git a/drivers/include/net/netdev.h b/drivers/include/net/netdev.h index c4d37fcb268c..0942ae8fbf63 100644 --- a/drivers/include/net/netdev.h +++ b/drivers/include/net/netdev.h @@ -328,6 +328,7 @@ typedef enum { NETDEV_W5100, NETDEV_ENCX24J600, NETDEV_ATWINC15X0, + NETDEV_KW2XRF, /* add more if needed */ } netdev_type_t; /** @} */ diff --git a/drivers/kw2xrf/kw2xrf.c b/drivers/kw2xrf/kw2xrf.c index faff81582966..808d2f9b9a3f 100644 --- a/drivers/kw2xrf/kw2xrf.c +++ b/drivers/kw2xrf/kw2xrf.c @@ -54,7 +54,7 @@ static void kw2xrf_set_address(kw2xrf_t *dev) kw2xrf_set_addr_short(dev, ntohs(addr_long.uint16[0].u16)); } -void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params) +void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params, uint8_t index) { netdev_t *netdev = &dev->netdev.netdev; @@ -71,6 +71,9 @@ void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params) kw2xrf_clear_dreg_bit(dev, MKW2XDM_PHY_CTRL2, MKW2XDM_PHY_CTRL2_RXMSK); kw2xrf_clear_dreg_bit(dev, MKW2XDM_PHY_CTRL2, MKW2XDM_PHY_CTRL2_TXMSK); DEBUG("[kw2xrf] setup finished\n"); + + /* register with netdev */ + netdev_register(netdev, NETDEV_KW2XRF, index); } int kw2xrf_init(kw2xrf_t *dev, gpio_cb_t cb) diff --git a/sys/net/gnrc/netif/init_devs/auto_init_kw2xrf.c b/sys/net/gnrc/netif/init_devs/auto_init_kw2xrf.c index bbfa53ade10c..5288b32c42f5 100644 --- a/sys/net/gnrc/netif/init_devs/auto_init_kw2xrf.c +++ b/sys/net/gnrc/netif/init_devs/auto_init_kw2xrf.c @@ -51,7 +51,7 @@ void auto_init_kw2xrf(void) const kw2xrf_params_t *p = &kw2xrf_params[i]; LOG_DEBUG("[auto_init_netif] initializing kw2xrf #%u\n", i); - kw2xrf_setup(&kw2xrf_devs[i], (kw2xrf_params_t*) p); + kw2xrf_setup(&kw2xrf_devs[i], (kw2xrf_params_t*) p, i); gnrc_netif_ieee802154_create(&_netif[i], _kw2xrf_stacks[i], KW2XRF_MAC_STACKSIZE, KW2XRF_MAC_PRIO, "kw2xrf", &kw2xrf_devs[i].netdev.netdev); From 98455c265d8073743ac68ff1f63a480696d576b3 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 10 Mar 2022 09:16:55 +0100 Subject: [PATCH 07/18] drivers/kw2xrf: turn test mode into a submodule --- drivers/kw2xrf/Makefile | 4 ++++ drivers/kw2xrf/include/kw2xrf_tm.h | 16 ++++++++++++---- drivers/kw2xrf/kw2xrf_netdev.c | 2 +- drivers/kw2xrf/kw2xrf_tm.c | 5 +---- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/kw2xrf/Makefile b/drivers/kw2xrf/Makefile index 48422e909a47..77bdb4e0164e 100644 --- a/drivers/kw2xrf/Makefile +++ b/drivers/kw2xrf/Makefile @@ -1 +1,5 @@ +SUBMODULES := 1 + +SRC := kw2xrf.c kw2xrf_getset.c kw2xrf_intern.c kw2xrf_netdev.c kw2xrf_spi.c + include $(RIOTBASE)/Makefile.base diff --git a/drivers/kw2xrf/include/kw2xrf_tm.h b/drivers/kw2xrf/include/kw2xrf_tm.h index 8e7f8f5e982c..f5e57689a1d9 100644 --- a/drivers/kw2xrf/include/kw2xrf_tm.h +++ b/drivers/kw2xrf/include/kw2xrf_tm.h @@ -23,13 +23,14 @@ extern "C" { #endif -#ifdef KW2XRF_TESTMODE - #include "kw2xrf.h" #include "kw2xrf_reg.h" #include "kw2xrf_getset.h" #include "net/netopt.h" +/** + * @brief Valid test modes to be used with @ref kw2xrf_set_test_mode. + */ enum mkw2xrf_testmode { KW2XRF_TM_CTX_PREAMBLE = NETOPT_RF_TESTMODE_CTX_PRBS9 + 1, KW2XRF_TM_CTX_2MHZ, @@ -40,10 +41,17 @@ enum mkw2xrf_testmode { KW2XRF_TM_CTX_NM1, }; +/** + * @brief Set the test mode for the kw2xrf device. + * + * @param[in] dev Device descriptor + * @param[in] mode Test mode (must be one of @ref mkw2xrf_testmode) + * + * @retval 1 on success + * @retval != 1 otherwise + */ int kw2xrf_set_test_mode(kw2xrf_t *dev, uint8_t mode); -#endif - #ifdef __cplusplus } #endif diff --git a/drivers/kw2xrf/kw2xrf_netdev.c b/drivers/kw2xrf/kw2xrf_netdev.c index 7298a665feef..386571a74ce8 100644 --- a/drivers/kw2xrf/kw2xrf_netdev.c +++ b/drivers/kw2xrf/kw2xrf_netdev.c @@ -512,7 +512,7 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t len) break; case NETOPT_RF_TESTMODE: -#ifdef KW2XRF_TESTMODE +#ifdef MODULE_KW2XRF_TESTMODE if (len < sizeof(uint8_t)) { res = -EOVERFLOW; } diff --git a/drivers/kw2xrf/kw2xrf_tm.c b/drivers/kw2xrf/kw2xrf_tm.c index e0e9d6b24fb9..c3d3f3c3511b 100644 --- a/drivers/kw2xrf/kw2xrf_tm.c +++ b/drivers/kw2xrf/kw2xrf_tm.c @@ -21,8 +21,6 @@ #include "kw2xrf_reg.h" #include "kw2xrf_tm.h" -#ifdef KW2XRF_TESTMODE - static inline void enable_xcvr_test_mode(kw2xrf_t *dev) { uint8_t reg; @@ -58,7 +56,7 @@ int kw2xrf_set_test_mode(kw2xrf_t *dev, uint8_t mode) disable_xcvr_test_mode(dev); kw2xrf_set_channel(dev, dev->netdev.chan); - switch(mode) { + switch (mode) { case NETOPT_RF_TESTMODE_IDLE: reg = 0; kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1); @@ -177,5 +175,4 @@ int kw2xrf_set_test_mode(kw2xrf_t *dev, uint8_t mode) return 1; } -#endif /** @} */ From 124dd868450a4674bf5d81fde320b7274832755a Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Mon, 14 Mar 2022 17:30:49 +0100 Subject: [PATCH 08/18] drivers/kw2xrf/spi: fix documentation on return value --- drivers/kw2xrf/include/kw2xrf_spi.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/kw2xrf/include/kw2xrf_spi.h b/drivers/kw2xrf/include/kw2xrf_spi.h index 7870456cd537..8d4070023af9 100644 --- a/drivers/kw2xrf/include/kw2xrf_spi.h +++ b/drivers/kw2xrf/include/kw2xrf_spi.h @@ -120,8 +120,6 @@ void kw2xrf_read_iregs(kw2xrf_t *dev, uint8_t addr, uint8_t *buf, uint8_t length * @param[in] dev device descriptor * @param[in] data A buffer with the value to write to the fifo. * @param[in] data_length The count of bytes which should be written. - * - * @return number of bytes written. */ void kw2xrf_write_fifo(kw2xrf_t *dev, uint8_t *data, uint8_t data_length); @@ -131,8 +129,6 @@ void kw2xrf_write_fifo(kw2xrf_t *dev, uint8_t *data, uint8_t data_length); * @param[in] dev device descriptor * @param[out] data A buffer to store the value of the fifo. * @param[in] data_length The count of bytes which should be read. - * - * @return number of bytes read. */ void kw2xrf_read_fifo(kw2xrf_t *dev, uint8_t *data, uint8_t data_length); From 3095afafd2eb049d577e478c316d95b1c28e735a Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Mon, 21 Mar 2022 14:29:11 +0100 Subject: [PATCH 09/18] sys/test_utils: add netdev ieee802154 minimal processing --- sys/Makefile | 3 + sys/Makefile.include | 4 + .../test_utils/netdev_ieee802154_minimal.h | 116 +++++++ sys/test_utils/Makefile.dep | 3 + .../netdev_ieee802154_minimal/Makefile | 3 + .../netdev_ieee802154_minimal/Makefile.dep | 7 + .../netdev_ieee802154_minimal.c | 243 +++++++++++++++ .../netdev_ieee802154_minimal_internal.h | 47 +++ .../shell_commands.c | 284 ++++++++++++++++++ 9 files changed, 710 insertions(+) create mode 100644 sys/include/test_utils/netdev_ieee802154_minimal.h create mode 100644 sys/test_utils/netdev_ieee802154_minimal/Makefile create mode 100644 sys/test_utils/netdev_ieee802154_minimal/Makefile.dep create mode 100644 sys/test_utils/netdev_ieee802154_minimal/netdev_ieee802154_minimal.c create mode 100644 sys/test_utils/netdev_ieee802154_minimal/netdev_ieee802154_minimal_internal.h create mode 100644 sys/test_utils/netdev_ieee802154_minimal/shell_commands.c diff --git a/sys/Makefile b/sys/Makefile index 8ba54ef260f5..aa7e9418970b 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -194,6 +194,9 @@ endif ifneq (,$(filter test_utils_netdev_eth_minimal,$(USEMODULE))) DIRS += test_utils/netdev_eth_minimal endif +ifneq (,$(filter test_utils_netdev_ieee802154_minimal,$(USEMODULE))) + DIRS += test_utils/netdev_ieee802154_minimal +endif ifneq (,$(filter test_utils_print_stack_usage,$(USEMODULE))) DIRS += test_utils/print_stack_usage endif diff --git a/sys/Makefile.include b/sys/Makefile.include index 4e90267c108b..91b24e55fc9c 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -139,6 +139,10 @@ ifneq (,$(filter test_utils_result_output,$(USEMODULE))) include $(RIOTBASE)/sys/test_utils/result_output/Makefile.include endif +ifneq (,$(filter test_utils_netdev_ieee802154_minimal,$(USEMODULE))) + CFLAGS += -DCONFIG_NETDEV_REGISTER_SIGNAL +endif + ifneq (,$(filter ztimer,$(USEMODULE))) include $(RIOTBASE)/sys/ztimer/Makefile.include endif diff --git a/sys/include/test_utils/netdev_ieee802154_minimal.h b/sys/include/test_utils/netdev_ieee802154_minimal.h new file mode 100644 index 000000000000..fcc7fce63163 --- /dev/null +++ b/sys/include/test_utils/netdev_ieee802154_minimal.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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. + */ + +/** + * @defgroup test_utils_netdev_ieee802154_minimal Minimal netdev IEEE 802.15.4 device processing + * @ingroup sys + * + * @{ + * @file + * @brief Provides basic functionalities to interact with an + * IEEE 802.15.4 networking device which implements the + * @ref drivers_netdev_api. + * + * To use the functionalities, include the module + * `USEMODULE += test_utils_netdev_ieee802154_minimal`. + * The test application should provide: + * - device initialization, via the implementation of @ref netdev_ieee802154_minimal_init_devs + * - number of devices to test, via the definition of @ref NETDEV_IEEE802154_MINIMAL_NUMOF + * in `init_dev.h` + * + * @author Kevin Weiss + */ + +#ifndef TEST_UTILS_NETDEV_IEEE802154_MINIMAL_H +#define TEST_UTILS_NETDEV_IEEE802154_MINIMAL_H + +#include "net/netdev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef DOXYGEN +/** + * @brief Maximum number of devices to handle. + * @note Should be provided by the application via `init_dev.h`. + */ +#define NETDEV_IEEE802154_MINIMAL_NUMOF +#endif + +/** + * @brief Device-under-test initialization function. + * @note Should be implemented by the test application + * + * @param[in] cb Callback to be set to @ref netdev::event_callback + * + * @retval 0 on success + * @retval != 0 on error + */ +int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb); + +/** + * @brief Initialize the module. + * + * @retval 0 on success + * @retval != 0 on error + */ +int netdev_ieee802154_minimal_init(void); + +/** + * @brief Send a IEEE 802.15.4 frame + * This is wrapper for the internal netdev send function, that ensures + * all netdev functions are called from the same thread. It is safe + * to call this function from anywhere. + * + * @param[in] dev Pointer to the netdev descriptor. + * @param[in] pkt Packet to be sent. + * + * @retval 0 on success + * @retval != 0 on error + */ +int netdev_ieee802154_minimal_send(struct netdev *dev, iolist_t *pkt); + +/** + * @brief Get an option from netdev minimal. + * This is wrapper for the internal netdev get function, that ensures + * all netdev functions are called from the same thread. It is safe + * to call this function from anywhere. + * + * @param[in] dev Pointer to the netdev descriptor. + * @param[in] opt The netopt option + * @param[out] data Buffer to store the option + * @param[in] max_len Maximum length of the buffer + * + * @retval 0 on success + * @retval != 0 on error + */ +int netdev_ieee802154_minimal_get(struct netdev *dev, netopt_t opt, void *data, size_t max_len); + +/** + * @brief Set an option to netdev minimal. + * This is wrapper for the internal netdev set function, that ensures + * all netdev functions are called from the same thread. It is safe + * to call this function from anywhere. + * + * @param[in] dev Pointer to the netdev descriptor. + * @param[in] opt The netopt option + * @param[in] data Pointer to the data to be set + * @param[in] len Length of the data + * + * @retval 0 on success + * @retval != 0 on error + */ +int netdev_ieee802154_minimal_set(struct netdev *dev, netopt_t opt, void *data, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_UTILS_NETDEV_IEEE802154_MINIMAL_H */ +/** @} */ diff --git a/sys/test_utils/Makefile.dep b/sys/test_utils/Makefile.dep index ad9c48b3c9ee..e3fd40416913 100644 --- a/sys/test_utils/Makefile.dep +++ b/sys/test_utils/Makefile.dep @@ -1,6 +1,9 @@ ifneq (,$(filter test_utils_result_output,$(USEMODULE))) include $(RIOTBASE)/sys/test_utils/result_output/Makefile.dep endif +ifneq (,$(filter test_utils_netdev_ieee802154_minimal,$(USEMODULE))) + include $(RIOTBASE)/sys/test_utils/netdev_ieee802154_minimal/Makefile.dep +endif ifneq (,$(filter test_utils_interactive_sync,$(USEMODULE))) USEMODULE += stdin endif diff --git a/sys/test_utils/netdev_ieee802154_minimal/Makefile b/sys/test_utils/netdev_ieee802154_minimal/Makefile new file mode 100644 index 000000000000..f67f2bcde74e --- /dev/null +++ b/sys/test_utils/netdev_ieee802154_minimal/Makefile @@ -0,0 +1,3 @@ +MODULE = test_utils_netdev_ieee802154_minimal + +include $(RIOTBASE)/Makefile.base diff --git a/sys/test_utils/netdev_ieee802154_minimal/Makefile.dep b/sys/test_utils/netdev_ieee802154_minimal/Makefile.dep new file mode 100644 index 000000000000..41a448eb5a88 --- /dev/null +++ b/sys/test_utils/netdev_ieee802154_minimal/Makefile.dep @@ -0,0 +1,7 @@ +USEMODULE += event +USEMODULE += event_thread +USEMODULE += l2util +USEMODULE += od +USEMODULE += od_string +USEMODULE += shell +USEMODULE += netdev diff --git a/sys/test_utils/netdev_ieee802154_minimal/netdev_ieee802154_minimal.c b/sys/test_utils/netdev_ieee802154_minimal/netdev_ieee802154_minimal.c new file mode 100644 index 000000000000..f4e80509c899 --- /dev/null +++ b/sys/test_utils/netdev_ieee802154_minimal/netdev_ieee802154_minimal.c @@ -0,0 +1,243 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 test_utils_netdev_ieee802154_minimal + * @{ + * + * @file + * @brief Implementation of netdev IEEE 802.15.4 minimal test utility + * module + * + * @author Leandro Lanzieri + */ +#include + +#include "event.h" +#include "event/thread.h" +#include "od.h" +#include "net/ieee802154.h" +#include "net/l2util.h" +#include "net/netdev.h" +#include "net/netdev/ieee802154.h" +#include "test_utils/netdev_ieee802154_minimal.h" +#include "netdev_ieee802154_minimal_internal.h" + +/* provided by the test application */ +#include "init_dev.h" + +device_reg_entry_t _devices[NETDEV_IEEE802154_MINIMAL_NUMOF]; +static uint8_t _buffer[IEEE802154_FRAME_LEN_MAX]; +static char _addr_str[IEEE802154_LONG_ADDRESS_LEN * 3]; + +struct event_pkt_desc { + event_t event; + struct netdev *dev; + iolist_t *pkt; + int res; +}; + +struct event_getset_desc { + event_t event; + struct netdev *dev; + netopt_t opt; + void *data; + size_t len; + int res; +}; + +static void _post_send_event(event_t *event) +{ + struct event_pkt_desc *desc = (struct event_pkt_desc*) event; + struct netdev *dev = desc->dev; + + int res = dev->driver->send(dev, desc->pkt); + desc->res = res; +} + +static void _post_get_event(event_t *event) +{ + struct event_getset_desc *desc = (struct event_getset_desc*) event; + struct netdev *dev = desc->dev; + netopt_t opt = desc->opt; + void *data = desc->data; + size_t max_len = desc->len; + + int res = dev->driver->get(dev, opt, data, max_len); + desc->res = res; +} + +static void _post_set_event(event_t *event) +{ + struct event_getset_desc *desc = (struct event_getset_desc*) event; + struct netdev *dev = desc->dev; + netopt_t opt = desc->opt; + void *data = desc->data; + size_t len = desc->len; + + int res = dev->driver->set(dev, opt, data, len); + desc->res = res; +} + +void _recv(netdev_t *dev) +{ + uint8_t src[IEEE802154_LONG_ADDRESS_LEN], dst[IEEE802154_LONG_ADDRESS_LEN]; + int data_len, src_len, dst_len; + size_t mhr_len; + netdev_ieee802154_rx_info_t rx_info; + le_uint16_t src_pan, dst_pan; + + putchar('\n'); + /* receive the frame */ + data_len = dev->driver->recv(dev, _buffer, sizeof(_buffer), &rx_info); + mhr_len = ieee802154_get_frame_hdr_len(_buffer); + if (mhr_len == 0) { + puts("Unexpected MHR for incoming packet"); + return; + } + + /* get and print addresses */ + dst_len = ieee802154_get_dst(_buffer, dst, &dst_pan); + src_len = ieee802154_get_src(_buffer, src, &src_pan); + + l2util_addr_to_str(dst, dst_len, _addr_str); + printf("Dest. PAN: 0x%04x\n", byteorder_ltohs(dst_pan)); + printf("Dest. addr.: %s\n", _addr_str); + + l2util_addr_to_str(src, src_len, _addr_str); + printf("Src. PAN: 0x%04x\n", byteorder_ltohs(src_pan)); + printf("Src. addr.: %s\n", _addr_str); + + /* check frame type */ + switch (_buffer[0] & IEEE802154_FCF_TYPE_MASK) { + case IEEE802154_FCF_TYPE_BEACON: + puts("BEACON"); + break; + case IEEE802154_FCF_TYPE_DATA: + puts("DATA"); + break; + case IEEE802154_FCF_TYPE_ACK: + puts("ACK"); + break; + case IEEE802154_FCF_TYPE_MACCMD: + puts("MACCMD"); + break; + default: + puts("UNKNOWN"); + break; + } + + /* print flag information */ + printf("\nSecurity: %s", _buffer[0] & IEEE802154_FCF_SECURITY_EN ? "1, " : "0, "); + + printf("Frame pend.: %s", _buffer[0] & IEEE802154_FCF_FRAME_PEND ? "1, " : "0, "); + + printf("ACK req.: %s", _buffer[0] & IEEE802154_FCF_ACK_REQ ? "1, " : "0, "); + + printf("PAN comp.:%s", _buffer[0] & IEEE802154_FCF_PAN_COMP ? "1, " : "0, "); + + printf("Version: "); + printf("%u, ", (unsigned)((_buffer[1] & IEEE802154_FCF_VERS_MASK) >> 4)); + + printf("Seq.: %u\n", (unsigned)ieee802154_get_seq(_buffer)); + + printf("RSSI: %i, LQI: %u\n\n", rx_info.rssi, rx_info.lqi); + + /* dump the payload */ + od_hex_dump(_buffer + mhr_len, data_len - mhr_len, 0); +} + +static void _isr_event_handler(event_t *event) +{ + /* recover the netdev from the event */ + device_reg_entry_t *netdev_event = container_of(event, device_reg_entry_t, event); + netdev_t *netdev = netdev_event->dev; + netdev->driver->isr(netdev); +} + +static void _event_cb(netdev_t *dev, netdev_event_t event) +{ + device_reg_entry_t *device = dev->context; + + switch (event) { + case NETDEV_EVENT_ISR: + event_post(EVENT_PRIO_HIGHEST, &device->event); + break; + + case NETDEV_EVENT_RX_COMPLETE: + _recv(dev); + break; + + case NETDEV_EVENT_TX_COMPLETE: + puts("Tx complete"); + break; + + case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING: + puts("Tx complete (with pending data)"); + break; + + case NETDEV_EVENT_TX_MEDIUM_BUSY: + puts("Medium busy"); + break; + + case NETDEV_EVENT_TX_NOACK: + puts("No ACK"); + break; + + default: + printf("Event: %d\n", event); + break; + } +} + +/* Implement netdev_register_signal hook to associate registered devices to specific event + * structures. + */ +void netdev_register_signal(struct netdev *dev, netdev_type_t type, uint8_t index) +{ + (void) type; + + if (index > NETDEV_IEEE802154_MINIMAL_NUMOF) { + return; + } + printf("Device %d registered (type: %d)\n", index, type); + dev->context = &_devices[index]; + _devices[index].dev = dev; + _devices[index].event.handler = _isr_event_handler; +} + +int netdev_ieee802154_minimal_init(void) +{ + return netdev_ieee802154_minimal_init_devs(_event_cb); +} + +int netdev_ieee802154_minimal_send(struct netdev *dev, iolist_t *pkt) +{ + struct event_pkt_desc desc = {.event.handler=_post_send_event, .pkt = pkt, + .dev = dev}; + event_post(EVENT_PRIO_HIGHEST, (event_t*) &desc); + return desc.res; +} + +int netdev_ieee802154_minimal_get(struct netdev *dev, netopt_t opt, void *data, size_t max_len) +{ + struct event_getset_desc desc = {.event.handler = _post_get_event, .opt = opt, + .data = data, .len = max_len, .dev = dev}; + event_post(EVENT_PRIO_HIGHEST, (event_t*) &desc); + return desc.res; +} + +int netdev_ieee802154_minimal_set(struct netdev *dev, netopt_t opt, void *data, size_t len) +{ + struct event_getset_desc desc = {.event.handler = _post_set_event, .opt = opt, + .data = data, .len = len, .dev = dev}; + event_post(EVENT_PRIO_HIGHEST, (event_t*) &desc); + return desc.res; +} + +/** @} */ diff --git a/sys/test_utils/netdev_ieee802154_minimal/netdev_ieee802154_minimal_internal.h b/sys/test_utils/netdev_ieee802154_minimal/netdev_ieee802154_minimal_internal.h new file mode 100644 index 000000000000..7d53508e3953 --- /dev/null +++ b/sys/test_utils/netdev_ieee802154_minimal/netdev_ieee802154_minimal_internal.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 test_utils_netdev_ieee802154_minimal + * + * @{ + * @file + * @brief Internal definitions for the netdev_ieee802154_minimal module + * + * @author Leandro Lanzieri + */ + +#ifndef NETDEV_IEEE802154_MINIMAL_INTERNAL_H +#define NETDEV_IEEE802154_MINIMAL_INTERNAL_H + +#include "net/netdev.h" +#include "event.h" +#include "init_dev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef DOXYGEN + +typedef struct { + event_t event; /**< event to serve ISR */ + netdev_t *dev; /**< pointer to the device */ +} device_reg_entry_t; + +extern device_reg_entry_t _devices[NETDEV_IEEE802154_MINIMAL_NUMOF]; + +#endif /* DOXYGEN */ + +#ifdef __cplusplus +} +#endif + +#endif /* NETDEV_IEEE802154_MINIMAL_INTERNAL_H */ + +/** @} */ diff --git a/sys/test_utils/netdev_ieee802154_minimal/shell_commands.c b/sys/test_utils/netdev_ieee802154_minimal/shell_commands.c new file mode 100644 index 000000000000..f155b1def518 --- /dev/null +++ b/sys/test_utils/netdev_ieee802154_minimal/shell_commands.c @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 test_utils_netdev_ieee802154_minimal + * @{ + * + * @file + * @brief Shell commands for netdev Eth minimal test utility module + * + * @author Leandro Lanzieri + */ + +#include +#include +#include +#include + +#include "iolist.h" +#include "kernel_defines.h" +#include "net/netdev/ieee802154.h" +#include "net/ieee802154.h" +#include "net/l2util.h" +#include "od.h" +#include "shell.h" + +#include "netdev_ieee802154_minimal_internal.h" +#include "test_utils/netdev_ieee802154_minimal.h" +#include "init_dev.h" + +#define ENABLE_DEBUG 0 +#include "debug.h" + +static char _addr_str[IEEE802154_LONG_ADDRESS_LEN * 3]; + +static int send(int iface, le_uint16_t dst_pan, uint8_t *dst_addr, + size_t dst_len, char *data); + +int ifconfig_list(int idx) +{ + int res; + uint8_t tmp[IEEE802154_LONG_ADDRESS_LEN]; + netdev_t *netdev = _devices[idx].dev; + netdev_ieee802154_t *dev = container_of(netdev, netdev_ieee802154_t, netdev); + + netopt_enable_t enable_val; + uint16_t u16_val; + + printf("Iface %3d HWaddr: ", idx); + res = netdev_ieee802154_minimal_get(netdev, NETOPT_ADDRESS, tmp, IEEE802154_SHORT_ADDRESS_LEN); + l2util_addr_to_str(tmp, IEEE802154_SHORT_ADDRESS_LEN, _addr_str); + printf("%s", _addr_str); + + printf(", Long HWaddr: "); + res = netdev_ieee802154_minimal_get(netdev, NETOPT_ADDRESS_LONG, tmp, IEEE802154_LONG_ADDRESS_LEN); + l2util_addr_to_str(tmp, IEEE802154_LONG_ADDRESS_LEN, _addr_str); + printf("%s", _addr_str); + + printf(", PAN: 0x%04x", dev->pan); + + res = netdev_ieee802154_minimal_get(netdev, NETOPT_ADDR_LEN, &u16_val, sizeof(u16_val)); + if (res == -ENOTSUP) { + puts("\n Address length: ENOTSUP"); + } + else if (res < 0) { + printf("\n Address length: %i", (int)res); + return 1; + } + else { + printf("\n Address length: %u", (unsigned)u16_val); + } + + res = netdev_ieee802154_minimal_get(netdev, NETOPT_SRC_LEN, &u16_val, sizeof(u16_val)); + if (res == -ENOTSUP) { + puts(", Source address length: ENOTSUP"); + } + else if (res < 0) { + printf(", Source address length: %i", (int)res); + return 1; + } + else { + printf(", Source address length: %u", (unsigned)u16_val); + } + + res = netdev_ieee802154_minimal_get(netdev, NETOPT_MAX_PDU_SIZE, &u16_val, sizeof(u16_val)); + if (res == -ENOTSUP) { + puts(", Max.Payload: ENOTSUP"); + } + else if (res < 0) { + printf(", Max.Payload: %i", (int)res); + return 1; + } + else { + printf(", Max.Payload: %u", (unsigned)u16_val); + } + printf("\n Channel: %u", dev->chan); + + res = netdev_ieee802154_minimal_get(netdev, NETOPT_CHANNEL_PAGE, &u16_val, sizeof(u16_val)); + if (res == -ENOTSUP) { + puts(", Ch.page: ENOTSUP"); + } + else if (res < 0) { + printf(", Ch.page: %i", (int)res); + return 1; + } + else { + printf(", Ch.page: %u", (unsigned)u16_val); + } + + res = netdev_ieee802154_minimal_get(netdev, NETOPT_TX_POWER, &u16_val, sizeof(u16_val)); + if (res == -ENOTSUP) { + puts(", TXPower: ENOTSUP"); + } + else if (res < 0) { + printf(", TXPower: %i", (int)res); + return 1; + } + else { + printf(", TXPower: %u", (unsigned)u16_val); + } + res = netdev_ieee802154_minimal_get(netdev, NETOPT_IS_WIRED, &u16_val, sizeof(u16_val)); + if (res < 0) { + puts(", wireless"); + } + else { + puts(", wired"); + } + + printf(" "); + res = netdev_ieee802154_minimal_get(netdev, NETOPT_PRELOADING, &enable_val, + sizeof(netopt_enable_t)); + if ((res > 0) && (enable_val == NETOPT_ENABLE)) { + printf(" PRELOAD"); + } + res = netdev_ieee802154_minimal_get(netdev, NETOPT_AUTOACK, &enable_val, + sizeof(netopt_enable_t)); + if ((res > 0) && (enable_val == NETOPT_ENABLE)) { + printf(" AUTOACK"); + } + res = netdev_ieee802154_minimal_get(netdev, NETOPT_RAWMODE, &enable_val, + sizeof(netopt_enable_t)); + if ((res > 0) && (enable_val == NETOPT_ENABLE)) { + printf(" RAW"); + } + res = netdev_ieee802154_minimal_get(netdev, NETOPT_AUTOCCA, &enable_val, + sizeof(netopt_enable_t)); + if ((res > 0) && (enable_val == NETOPT_ENABLE)) { + printf(" AUTOCCA"); + } + res = netdev_ieee802154_minimal_get(netdev, NETOPT_CSMA, &enable_val, + sizeof(netopt_enable_t)); + if ((res > 0) && (enable_val == NETOPT_ENABLE)) { + printf(" CSMA"); + } + puts(""); + + return 0; +} + +int cmd_ifconfig(int argc, char **argv) +{ + (void)argc; + (void)argv; + for (unsigned int i = 0; i < NETDEV_IEEE802154_MINIMAL_NUMOF; i++) { + ifconfig_list(i); + } + return 0; +} + +static void txtsnd_usage(char *cmd_name) +{ + printf("usage: %s [] \n", cmd_name); +} + +static int cmd_txtsnd(int argc, char **argv) +{ + char *text; + uint8_t addr[IEEE802154_LONG_ADDRESS_LEN]; + int iface, idx = 2; + size_t res; + le_uint16_t pan = { 0 }; + + switch (argc) { + case 4: + break; + case 5: + res = l2util_addr_from_str(argv[idx++], pan.u8); + if ((res == 0) || (res > sizeof(pan))) { + txtsnd_usage(argv[0]); + return 1; + } + pan.u16 = byteorder_swaps(pan.u16); + break; + default: + txtsnd_usage(argv[0]); + return 1; + } + + iface = atoi(argv[1]); + res = l2util_addr_from_str(argv[idx++], addr); + if (res == 0) { + txtsnd_usage(argv[0]); + return 1; + } + text = argv[idx++]; + return send(iface, pan, addr, res, text); +} + +static int send(int iface, le_uint16_t dst_pan, uint8_t *dst, size_t dst_len, + char *data) +{ + int res; + netdev_ieee802154_t *dev; + uint8_t *src; + size_t src_len; + uint8_t mhr[IEEE802154_MAX_HDR_LEN]; + uint8_t flags; + le_uint16_t src_pan; + + if (((unsigned)iface) > (NETDEV_IEEE802154_MINIMAL_NUMOF - 1)) { + printf("txtsnd: %d is not an interface\n", iface); + return 1; + } + + iolist_t iol_data = { + .iol_base = data, + .iol_len = strlen(data) + }; + + dev = container_of(_devices[iface].dev, netdev_ieee802154_t, netdev); + flags = (uint8_t)(dev->flags & NETDEV_IEEE802154_SEND_MASK); + flags |= IEEE802154_FCF_TYPE_DATA; + src_pan = byteorder_btols(byteorder_htons(dev->pan)); + if (dst_pan.u16 == 0) { + dst_pan = src_pan; + } + if (dev->flags & NETDEV_IEEE802154_SRC_MODE_LONG) { + src_len = 8; + src = dev->long_addr; + } + else { + src_len = 2; + src = dev->short_addr; + } + /* fill MAC header, seq should be set by device */ + if ((res = ieee802154_set_frame_hdr(mhr, src, src_len, + dst, dst_len, + src_pan, dst_pan, + flags, dev->seq++)) < 0) { + puts("txtsnd: Error preperaring frame"); + return 1; + } + + iolist_t iol_hdr = { + .iol_next = &iol_data, + .iol_base = mhr, + .iol_len = (size_t)res + }; + + be_uint16_t _dst_pan = byteorder_ltobs(dst_pan); + l2util_addr_to_str(dst, dst_len, _addr_str); + printf("txtsnd: sending %u bytes to %s", (unsigned)iol_data.iol_len, _addr_str); + l2util_addr_to_str((uint8_t*) &_dst_pan, sizeof(dst_pan), _addr_str); + printf(" (PAN: %s)\n", _addr_str); + + res = netdev_ieee802154_minimal_send(&dev->netdev, &iol_hdr); + + if (res < 0) { + puts("txtsnd: Error on sending"); + return 1; + } + return 0; +} + +/* declare shell commands */ +SHELL_COMMAND(ifconfig, "Configure the device", cmd_ifconfig); +SHELL_COMMAND(txtsnd, "Send an IEEE 802.15.4 packet", cmd_txtsnd); + +/** @} */ From 9d3a546e1d8a463cb3658f7a60314351276999d8 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Mon, 21 Mar 2022 14:31:13 +0100 Subject: [PATCH 10/18] tests/driver_at86rf2xx: rewrite without GNRC --- tests/driver_at86rf2xx/Makefile | 12 +- tests/driver_at86rf2xx/Makefile.ci | 3 +- tests/driver_at86rf2xx/README.md | 6 +- tests/driver_at86rf2xx/addr.c | 31 --- tests/driver_at86rf2xx/cmd.c | 335 ----------------------------- tests/driver_at86rf2xx/common.h | 57 ----- tests/driver_at86rf2xx/init_dev.h | 36 ++++ tests/driver_at86rf2xx/main.c | 142 ++++++------ tests/driver_at86rf2xx/recv.c | 117 ---------- 9 files changed, 110 insertions(+), 629 deletions(-) delete mode 100644 tests/driver_at86rf2xx/addr.c delete mode 100644 tests/driver_at86rf2xx/cmd.c delete mode 100644 tests/driver_at86rf2xx/common.h create mode 100644 tests/driver_at86rf2xx/init_dev.h delete mode 100644 tests/driver_at86rf2xx/recv.c diff --git a/tests/driver_at86rf2xx/Makefile b/tests/driver_at86rf2xx/Makefile index bc34b8e98a7e..281ead754722 100644 --- a/tests/driver_at86rf2xx/Makefile +++ b/tests/driver_at86rf2xx/Makefile @@ -1,11 +1,9 @@ -include ../Makefile.tests_common +INCLUDES += -I$(APPDIR) +BOARD ?= samr21-xpro -DISABLE_MODULE += auto_init_at86rf2xx +include ../Makefile.tests_common -USEMODULE += od -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += ps +USEMODULE += test_utils_netdev_ieee802154_minimal # define the driver to be used for selected boards ifneq (,$(filter samr21-xpro,$(BOARD))) @@ -24,4 +22,6 @@ DRIVER ?= at86rf231 # include the selected driver USEMODULE += $(DRIVER) +CFLAGS += -DEVENT_THREAD_STACKSIZE_DEFAULT=1024 + include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_at86rf2xx/Makefile.ci b/tests/driver_at86rf2xx/Makefile.ci index d5368f025e74..fa21afb84b05 100644 --- a/tests/driver_at86rf2xx/Makefile.ci +++ b/tests/driver_at86rf2xx/Makefile.ci @@ -3,9 +3,8 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-leonardo \ arduino-nano \ arduino-uno \ - atmega328p \ atmega328p-xplained-mini \ - nucleo-f031k6 \ + atmega328p \ nucleo-l011k4 \ samd10-xmini \ stm32f030f4-demo \ diff --git a/tests/driver_at86rf2xx/README.md b/tests/driver_at86rf2xx/README.md index 78441d90b64e..32e938ba05b7 100644 --- a/tests/driver_at86rf2xx/README.md +++ b/tests/driver_at86rf2xx/README.md @@ -1,16 +1,16 @@ # About -This is a manual test application for the AT86RF2xx radio driver +This is a manual test application for the AT86RF2xx radio driver. For running this test, you need to connect/configure the following pins of your radio device: - SPI MISO - SPI MOSI - SPI CLK -- CS (ship select) +- CS (chip select) - RESET - SLEEP - INT (external interrupt) # Usage -For testing the radio driver you can use the netif and txtsnd shell commands +For testing the radio driver you can use the ifconfig and txtsnd shell commands that are included in this application. diff --git a/tests/driver_at86rf2xx/addr.c b/tests/driver_at86rf2xx/addr.c deleted file mode 100644 index 0d6c01861d84..000000000000 --- a/tests/driver_at86rf2xx/addr.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) Freie Universität Berlin - * - * 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. - */ - -/** - * @{ - * - * @file - * @author Martine Lenders - */ - -#include -#include - -#include "common.h" - -void print_addr(uint8_t *addr, size_t addr_len) -{ - for (size_t i = 0; i < addr_len; i++) { - if (i != 0) { - printf(":"); - } - printf("%02x", (unsigned)addr[i]); - } -} - -/** @} */ diff --git a/tests/driver_at86rf2xx/cmd.c b/tests/driver_at86rf2xx/cmd.c deleted file mode 100644 index 4668ece95ea2..000000000000 --- a/tests/driver_at86rf2xx/cmd.c +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (C) 2016 Freie Universität Berlin - * - * 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. - */ - -/** - * @{ - * - * @file - * @author Martine Lenders - */ - -#include -#include -#include -#include - -#include "at86rf2xx_internal.h" -#include "common.h" -#include "net/ieee802154.h" -#include "net/netdev/ieee802154.h" -#include "od.h" -#include "test_utils/expect.h" - -#define _MAX_ADDR_LEN (8) -#define MAC_VECTOR_SIZE (2) /* mhr + payload */ - -static size_t _parse_addr(uint8_t *out, size_t out_len, const char *in); -static int send(int iface, le_uint16_t dst_pan, uint8_t *dst_addr, - size_t dst_len, char *data); - -int ifconfig_list(int idx) -{ - int res; - netdev_ieee802154_t *dev = &devs[idx].netdev; - - int (*get)(netdev_t *, netopt_t, void *, size_t) = dev->netdev.driver->get; - netopt_enable_t enable_val; - uint16_t u16_val; - - printf("Iface %3d HWaddr: ", idx); - print_addr(dev->short_addr, IEEE802154_SHORT_ADDRESS_LEN); - printf(", Long HWaddr: "); - print_addr(dev->long_addr, IEEE802154_LONG_ADDRESS_LEN); - printf(", PAN: 0x%04x", dev->pan); - - res = get(&dev->netdev, NETOPT_ADDR_LEN, &u16_val, sizeof(u16_val)); - if (res < 0) { - puts("(err)"); - return 1; - } - printf("\n Address length: %u", (unsigned)u16_val); - - res = get(&dev->netdev, NETOPT_SRC_LEN, &u16_val, sizeof(u16_val)); - if (res < 0) { - puts("(err)"); - return 1; - } - printf(", Source address length: %u", (unsigned)u16_val); - - res = get(&dev->netdev, NETOPT_MAX_PDU_SIZE, &u16_val, - sizeof(u16_val)); - if (res < 0) { - puts("(err)"); - return 1; - } - printf(", Max.Payload: %u", (unsigned)u16_val); - printf("\n Channel: %u", dev->chan); - - res = get(&dev->netdev, NETOPT_CHANNEL_PAGE, &u16_val, sizeof(u16_val)); - if (res < 0) { - puts("(err)"); - return 1; - } - printf(", Ch.page: %u", (unsigned)u16_val); - - res = get(&dev->netdev, NETOPT_TX_POWER, &u16_val, sizeof(u16_val)); - if (res < 0) { - puts("(err)"); - return 1; - } - printf(", TXPower: %d dBm", (int)u16_val); - res = get(&dev->netdev, NETOPT_IS_WIRED, &u16_val, sizeof(u16_val)); - if (res < 0) { - puts(", wireless"); - } - else { - puts(", wired"); - } - - printf(" "); - res = get(&dev->netdev, NETOPT_PRELOADING, &enable_val, - sizeof(netopt_enable_t)); - if ((res > 0) && (enable_val == NETOPT_ENABLE)) { - printf(" PRELOAD"); - } - res = get(&dev->netdev, NETOPT_AUTOACK, &enable_val, - sizeof(netopt_enable_t)); - if ((res > 0) && (enable_val == NETOPT_ENABLE)) { - printf(" AUTOACK"); - } - res = get(&dev->netdev, NETOPT_RAWMODE, &enable_val, - sizeof(netopt_enable_t)); - if ((res > 0) && (enable_val == NETOPT_ENABLE)) { - printf(" RAW"); - } - res = get(&dev->netdev, NETOPT_AUTOCCA, &enable_val, - sizeof(netopt_enable_t)); - if ((res > 0) && (enable_val == NETOPT_ENABLE)) { - printf(" AUTOCCA"); - } - res = get(&dev->netdev, NETOPT_CSMA, &enable_val, - sizeof(netopt_enable_t)); - if ((res > 0) && (enable_val == NETOPT_ENABLE)) { - printf(" CSMA"); - } - puts(""); - - return 0; -} - -int ifconfig(int argc, char **argv) -{ - (void)argc; - (void)argv; - for (unsigned int i = 0; i < AT86RF2XX_NUM; i++) { - ifconfig_list(i); - } - return 0; -} - -static void txtsnd_usage(char *cmd_name) -{ - printf("usage: %s [] \n", cmd_name); -} - -int txtsnd(int argc, char **argv) -{ - char *text; - uint8_t addr[_MAX_ADDR_LEN]; - int iface, idx = 2; - size_t res; - le_uint16_t pan = { 0 }; - - switch (argc) { - case 4: - break; - case 5: - res = _parse_addr((uint8_t *)&pan, sizeof(pan), argv[idx++]); - if ((res == 0) || (res > sizeof(pan))) { - txtsnd_usage(argv[0]); - return 1; - } - pan.u16 = byteorder_swaps(pan.u16); - break; - default: - txtsnd_usage(argv[0]); - return 1; - } - - iface = atoi(argv[1]); - res = _parse_addr(addr, sizeof(addr), argv[idx++]); - if (res == 0) { - txtsnd_usage(argv[0]); - return 1; - } - text = argv[idx++]; - return send(iface, pan, addr, res, text); -} - -static inline int _dehex(char c, int default_) -{ - if ('0' <= c && c <= '9') { - return c - '0'; - } - else if ('A' <= c && c <= 'F') { - return c - 'A' + 10; - } - else if ('a' <= c && c <= 'f') { - return c - 'a' + 10; - } - else { - return default_; - } -} - -static size_t _parse_addr(uint8_t *out, size_t out_len, const char *in) -{ - const char *end_str = in; - uint8_t *out_end = out; - size_t count = 0; - int assert_cell = 1; - - if (!in || !*in) { - return 0; - } - while (end_str[1]) { - ++end_str; - } - - while (end_str >= in) { - int a = 0, b = _dehex(*end_str--, -1); - if (b < 0) { - if (assert_cell) { - return 0; - } - else { - assert_cell = 1; - continue; - } - } - assert_cell = 0; - - if (end_str >= in) { - a = _dehex(*end_str--, 0); - } - - if (++count > out_len) { - return 0; - } - *out_end++ = (a << 4) | b; - } - if (assert_cell) { - return 0; - } - /* out is reversed */ - - while (out < --out_end) { - uint8_t tmp = *out_end; - *out_end = *out; - *out++ = tmp; - } - - return count; -} - -static int send(int iface, le_uint16_t dst_pan, uint8_t *dst, size_t dst_len, - char *data) -{ - int res; - netdev_ieee802154_t *dev; - uint8_t *src; - size_t src_len; - uint8_t mhr[IEEE802154_MAX_HDR_LEN]; - uint8_t flags; - le_uint16_t src_pan; - - if (((unsigned)iface) > (AT86RF2XX_NUM - 1)) { - printf("txtsnd: %d is not an interface\n", iface); - return 1; - } - - iolist_t iol_data = { - .iol_base = data, - .iol_len = strlen(data) - }; - - dev = &devs[iface].netdev; - flags = (uint8_t)(dev->flags & NETDEV_IEEE802154_SEND_MASK); - flags |= IEEE802154_FCF_TYPE_DATA; - src_pan = byteorder_btols(byteorder_htons(dev->pan)); - if (dst_pan.u16 == 0) { - dst_pan = src_pan; - } - if (dev->flags & NETDEV_IEEE802154_SRC_MODE_LONG) { - src_len = 8; - src = dev->long_addr; - } - else { - src_len = 2; - src = dev->short_addr; - } - /* fill MAC header, seq should be set by device */ - if ((res = ieee802154_set_frame_hdr(mhr, src, src_len, - dst, dst_len, - src_pan, dst_pan, - flags, dev->seq++)) < 0) { - puts("txtsnd: Error preperaring frame"); - return 1; - } - - iolist_t iol_hdr = { - .iol_next = &iol_data, - .iol_base = mhr, - .iol_len = (size_t)res - }; - - res = dev->netdev.driver->send(&dev->netdev, &iol_hdr); - if (res < 0) { - puts("txtsnd: Error on sending"); - return 1; - } - else { - printf("txtsnd: send %u bytes to ", (unsigned)iol_data.iol_len); - print_addr(dst, dst_len); - printf(" (PAN: "); - print_addr((uint8_t *)&dst_pan, sizeof(dst_pan)); - puts(")"); - } - return 0; -} - -#if AT86RF2XX_RANDOM_NUMBER_GENERATOR -void random_net_api(uint8_t idx, uint32_t *value) -{ - netdev_ieee802154_t *dev = &devs[idx].netdev; - int retval = dev->netdev.driver->get(&dev->netdev, NETOPT_RANDOM, - value, sizeof(uint32_t)); - if (retval < 0) { - printf("get(NETOPT_RANDOM) failed: %s\n", strerror(-retval)); - } - else { - expect(retval == sizeof(*value)); - } -} - -int random_by_at86rf2xx(int argc, char **argv) -{ - (void)argc; - (void)argv; - for (unsigned int i = 0; i < AT86RF2XX_NUM; i++) { - uint32_t test = 0; - at86rf2xx_get_random(&devs[i], (uint8_t *)&test, sizeof(test)); - printf("Random number for device %u via native API: %" PRIx32 "\n", i, test); - test = 0; - random_net_api(i, &test); - printf("Random number for device %u via netopt: %" PRIx32 "\n", i, test); - } - return 0; -} -#endif -/** @} */ diff --git a/tests/driver_at86rf2xx/common.h b/tests/driver_at86rf2xx/common.h deleted file mode 100644 index a648e37fa36b..000000000000 --- a/tests/driver_at86rf2xx/common.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2016 Martine Lenders - * - * 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 Common header for at86rf2xx tests - * - * @author Martine Lenders - */ -#ifndef COMMON_H -#define COMMON_H - -#include - -#include "at86rf2xx.h" -#include "at86rf2xx_params.h" -#include "net/netdev.h" -#include "kernel_defines.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Application-internal functions and variables for at86rf2xx tests - * @internal - * @{ - */ -#define AT86RF2XX_NUM ARRAY_SIZE(at86rf2xx_params) - -extern at86rf2xx_t devs[AT86RF2XX_NUM]; - -void recv(netdev_t *dev); -int ifconfig(int argc, char **argv); -int txtsnd(int argc, char **argv); -#if AT86RF2XX_RANDOM_NUMBER_GENERATOR -int random_by_at86rf2xx(int argc, char **argv); -#endif -void print_addr(uint8_t *addr, size_t addr_len); -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* COMMON_H */ -/** @} */ diff --git a/tests/driver_at86rf2xx/init_dev.h b/tests/driver_at86rf2xx/init_dev.h new file mode 100644 index 000000000000..df6c4dd78e96 --- /dev/null +++ b/tests/driver_at86rf2xx/init_dev.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 Device-specific test header file AT86RF2XX IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include "at86rf2xx_params.h" +#include "kernel_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AT86RF2XX_NUM ARRAY_SIZE(at86rf2xx_params) +#define NETDEV_IEEE802154_MINIMAL_NUMOF AT86RF2XX_NUM + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_at86rf2xx/main.c b/tests/driver_at86rf2xx/main.c index a46ec658252d..a24251eab3ed 100644 --- a/tests/driver_at86rf2xx/main.c +++ b/tests/driver_at86rf2xx/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Freie Universität Berlin + * Copyright (C) 2022 HAW Hamburg * * 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 @@ -11,110 +11,92 @@ * @{ * * @file - * @brief Test application for AT86RF2xx network device driver + * @brief Test application for AT86RF2XX IEEE 802.15.4 device driver * - * @author Hauke Petersen + * @author Leandro Lanzieri * * @} */ #include -#include "net/netdev.h" +#include "at86rf2xx.h" +#include "at86rf2xx_params.h" +#include "at86rf2xx_internal.h" +#include "init_dev.h" +#include "net/ieee802154.h" +#include "net/netdev/ieee802154.h" #include "shell.h" -#include "thread.h" -#include "xtimer.h" +#include "test_utils/netdev_ieee802154_minimal.h" +#include "test_utils/expect.h" -#include "common.h" +static at86rf2xx_t at86rf2xx[AT86RF2XX_NUM]; -#define _STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF) -#define MSG_TYPE_ISR (0x3456) - -static char stack[_STACKSIZE]; -static kernel_pid_t _recv_pid; - -at86rf2xx_t devs[AT86RF2XX_NUM]; - -static const shell_command_t shell_commands[] = { - { "ifconfig", "Configure netdev", ifconfig }, - { "txtsnd", "Send IEEE 802.15.4 packet", txtsnd }, #if AT86RF2XX_RANDOM_NUMBER_GENERATOR - { "random", "Get a value from Random Number Generator", random_by_at86rf2xx }, -#endif - { NULL, NULL, NULL } -}; - -static void _event_cb(netdev_t *dev, netdev_event_t event) +void random_net_api(uint8_t idx, uint32_t *value) { - if (event == NETDEV_EVENT_ISR) { - msg_t msg; - - msg.type = MSG_TYPE_ISR; - msg.content.ptr = dev; - - if (msg_send(&msg, _recv_pid) <= 0) { - puts("gnrc_netdev: possibly lost interrupt."); - } + netdev_ieee802154_t *dev = &at86rf2xx[idx].netdev; + dev->netdev.driver->get(&dev->netdev, NETOPT_RANDOM, value, sizeof(uint32_t)); + int retval = dev->netdev.driver->get(&dev->netdev, NETOPT_RANDOM, + value, sizeof(uint32_t)); + if (retval < 0) { + printf("get(NETOPT_RANDOM) failed: %s\n", strerror(-retval)); } else { - switch (event) { - case NETDEV_EVENT_RX_COMPLETE: - { - recv(dev); - - break; - } - default: - puts("Unexpected event received"); - break; - } + expect(retval == sizeof(*value)); } } -void *_recv_thread(void *arg) +int random_by_at86rf2xx(int argc, char **argv) { - (void)arg; - while (1) { - msg_t msg; - msg_receive(&msg); - if (msg.type == MSG_TYPE_ISR) { - netdev_t *dev = msg.content.ptr; - dev->driver->isr(dev); - } - else { - puts("unexpected message type"); - } + (void)argc; + (void)argv; + for (unsigned int i = 0; i < AT86RF2XX_NUM; i++) { + uint32_t test = 0; + at86rf2xx_get_random(&at86rf2xx[i], (uint8_t *)&test, sizeof(test)); + printf("Random number for device %u via native API: %" PRIx32 "\n", i, test); + test = 0; + random_net_api(i, &test); + printf("Random number for device %u via netopt: %" PRIx32 "\n", i, test); } + return 0; } -int main(void) -{ - puts("AT86RF2xx device driver test"); - unsigned dev_success = 0; +static const shell_command_t shell_commands[] = { + { "random", "Get a value from Random Number Generator", random_by_at86rf2xx }, + { NULL, NULL, NULL } +}; +#endif + +int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { + + puts("Initializing AT86RF2XX devices"); + for (unsigned i = 0; i < AT86RF2XX_NUM; i++) { - const at86rf2xx_params_t *p = &at86rf2xx_params[i]; - netdev_t *dev = &devs[i].netdev.netdev; - - printf("Initializing AT86RF2xx radio at SPI_%d\n", p->spi); - at86rf2xx_setup(&devs[i], p, i); - dev->event_callback = _event_cb; - if (dev->driver->init(dev) < 0) { - continue; + printf("%d out of %d\n", i + 1, AT86RF2XX_NUM); + /* setup the specific driver */ + at86rf2xx_setup(&at86rf2xx[i], &at86rf2xx_params[i], i); + + /* set the application-provided callback */ + at86rf2xx[i].netdev.netdev.event_callback = cb; + + /* initialize the device driver */ + int res = at86rf2xx[i].netdev.netdev.driver->init(&at86rf2xx[i].netdev.netdev); + if (res != 0) { + return -1; } - dev_success++; } - if (!dev_success) { - puts("No device could be initialized"); - return 1; - } + return 0; +} - _recv_pid = thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN - 1, - THREAD_CREATE_STACKTEST, _recv_thread, NULL, - "recv_thread"); +int main(void) +{ + puts("Test application for AT86RF2XX IEEE 802.15.4 device driver"); - if (_recv_pid <= KERNEL_PID_UNDEF) { - puts("Creation of receiver thread failed"); + int res = netdev_ieee802154_minimal_init(); + if (res) { + puts("Error initializing devices"); return 1; } @@ -122,7 +104,11 @@ int main(void) puts("Initialization successful - starting the shell now"); char line_buf[SHELL_DEFAULT_BUFSIZE]; +#if AT86RF2XX_RANDOM_NUMBER_GENERATOR shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); +#else + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); +#endif return 0; } diff --git a/tests/driver_at86rf2xx/recv.c b/tests/driver_at86rf2xx/recv.c deleted file mode 100644 index 85b2a5d526e4..000000000000 --- a/tests/driver_at86rf2xx/recv.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) Freie Universität Berlin - * - * 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. - */ - -/** - * @{ - * - * @file - * @author Martine Lenders - */ - -#include - -#include "at86rf2xx.h" -#include "od.h" -#include "net/ieee802154.h" -#include "net/netdev.h" - -#include "common.h" - -#define MAX_LINE (80) - -static uint8_t buffer[AT86RF2XX_MAX_PKT_LENGTH]; - -void recv(netdev_t *dev) -{ - uint8_t src[IEEE802154_LONG_ADDRESS_LEN], dst[IEEE802154_LONG_ADDRESS_LEN]; - size_t mhr_len, data_len, src_len, dst_len; - netdev_ieee802154_rx_info_t rx_info; - le_uint16_t src_pan, dst_pan; - - putchar('\n'); - data_len = dev->driver->recv(dev, buffer, sizeof(buffer), &rx_info); - mhr_len = ieee802154_get_frame_hdr_len(buffer); - if (mhr_len == 0) { - puts("Unexpected MHR for incoming packet"); - return; - } - dst_len = ieee802154_get_dst(buffer, dst, &dst_pan); - src_len = ieee802154_get_src(buffer, src, &src_pan); - switch (buffer[0] & IEEE802154_FCF_TYPE_MASK) { - case IEEE802154_FCF_TYPE_BEACON: - puts("BEACON"); - break; - case IEEE802154_FCF_TYPE_DATA: - puts("DATA"); - break; - case IEEE802154_FCF_TYPE_ACK: - puts("ACK"); - break; - case IEEE802154_FCF_TYPE_MACCMD: - puts("MACCMD"); - break; - default: - puts("UNKNOWN"); - break; - } - printf("Dest. PAN: 0x%04x, Dest. addr.: ", - byteorder_ltohs(dst_pan)); - print_addr(dst, dst_len); - printf("\nSrc. PAN: 0x%04x, Src. addr.: ", - byteorder_ltohs(src_pan)); - print_addr(src, src_len); - printf("\nSecurity: "); - if (buffer[0] & IEEE802154_FCF_SECURITY_EN) { - printf("1, "); - } - else { - printf("0, "); - } - printf("Frame pend.: "); - if (buffer[0] & IEEE802154_FCF_FRAME_PEND) { - printf("1, "); - } - else { - printf("0, "); - } - printf("ACK req.: "); - if (buffer[0] & IEEE802154_FCF_ACK_REQ) { - printf("1, "); - } - else { - printf("0, "); - } - printf("PAN comp.: "); - if (buffer[0] & IEEE802154_FCF_PAN_COMP) { - puts("1"); - } - else { - puts("0"); - } - printf("Version: "); - printf("%u, ", (unsigned)((buffer[1] & IEEE802154_FCF_VERS_MASK) >> 4)); - printf("Seq.: %u\n", (unsigned)ieee802154_get_seq(buffer)); - od_hex_dump(buffer + mhr_len, data_len - mhr_len, 0); - printf("txt: "); - for (size_t i = mhr_len; i < data_len; i++) { - if ((buffer[i] > 0x1F) && (buffer[i] < 0x80)) { - putchar((char)buffer[i]); - } - else { - putchar('?'); - } - if (((((i - mhr_len) + 1) % (MAX_LINE - sizeof("txt: "))) == 1) && - (i - mhr_len) != 0) { - printf("\n "); - } - } - printf("\n"); - printf("RSSI: %i, LQI: %u\n\n", rx_info.rssi, rx_info.lqi); -} - -/** @} */ From e78a129ba4fc6974f33cc2da6adcdc0f7bedcb29 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Mon, 21 Mar 2022 14:46:22 +0100 Subject: [PATCH 11/18] tests/driver_at86rf215: modify to use as generic IEEE 802.15.4 test --- tests/driver_at86rf215/Makefile | 9 +- tests/driver_at86rf215/Makefile.ci | 23 +---- tests/driver_at86rf215/README.md | 16 ++++ tests/driver_at86rf215/init_dev.h | 37 ++++++++ tests/driver_at86rf215/main.c | 137 +++++++++++++++++++---------- 5 files changed, 151 insertions(+), 71 deletions(-) create mode 100644 tests/driver_at86rf215/README.md create mode 100644 tests/driver_at86rf215/init_dev.h diff --git a/tests/driver_at86rf215/Makefile b/tests/driver_at86rf215/Makefile index 1681dfce5a65..6b6106c106e0 100644 --- a/tests/driver_at86rf215/Makefile +++ b/tests/driver_at86rf215/Makefile @@ -1,10 +1,15 @@ +INCLUDES += -I$(APPDIR) BOARD ?= openmote-b +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_ieee802154_minimal + # the radio driver to test USEMODULE += at86rf215 USEMODULE += at86rf215_batmon USEMODULE += netdev_ieee802154_rx_timestamp -CFLAGS += -DCONFIG_NETDEV_REGISTER_SIGNAL +CFLAGS += -DEVENT_THREAD_STACKSIZE_DEFAULT=1024 -include ../driver_netdev_common/Makefile.netdev.mk +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_at86rf215/Makefile.ci b/tests/driver_at86rf215/Makefile.ci index 2ce525a91483..04f2d9e5f90b 100644 --- a/tests/driver_at86rf215/Makefile.ci +++ b/tests/driver_at86rf215/Makefile.ci @@ -1,35 +1,14 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-duemilanove \ arduino-leonardo \ - arduino-mega2560 \ arduino-nano \ arduino-uno \ - atmega1284p \ - atmega328p \ atmega328p-xplained-mini \ - atxmega-a3bu-xplained \ - bluepill-stm32f030c8 \ - derfmega128 \ - i-nucleo-lrwan1 \ - mega-xplained \ - microduino-corerf \ - msb-430 \ - msb-430h \ + atmega328p \ nucleo-f031k6 \ - nucleo-f042k6 \ - nucleo-f303k8 \ - nucleo-f334r8 \ nucleo-l011k4 \ nucleo-l031k6 \ - nucleo-l053r8 \ samd10-xmini \ - slstk3400a \ stk3200 \ stm32f030f4-demo \ - stm32f0discovery \ - stm32l0538-disco \ - telosb \ - waspmote-pro \ - zigduino \ - z1 # diff --git a/tests/driver_at86rf215/README.md b/tests/driver_at86rf215/README.md new file mode 100644 index 000000000000..ccf081b3249d --- /dev/null +++ b/tests/driver_at86rf215/README.md @@ -0,0 +1,16 @@ +# About +This is a manual test application for the AT86RF215 radio driver. + +For running this test, you need to connect/configure the following pins of your +radio device: +- SPI MISO +- SPI MOSI +- SPI CLK +- CS (chip select) +- RESET +- SLEEP +- INT (external interrupt) + +# Usage +For testing the radio driver you can use the ifconfig and txtsnd shell commands +that are included in this application. diff --git a/tests/driver_at86rf215/init_dev.h b/tests/driver_at86rf215/init_dev.h new file mode 100644 index 000000000000..60e368f6b3ce --- /dev/null +++ b/tests/driver_at86rf215/init_dev.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 Device-specific test header file AT86RF215 IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include "at86rf215_params.h" +#include "kernel_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define AT86RF215_NUM ARRAY_SIZE(at86rf215_params) +/* AT86RF215 contains one sub-GHz and one 2.4 GHz driver */ +#define NETDEV_IEEE802154_MINIMAL_NUMOF (2 * AT86RF215_NUM) + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_at86rf215/main.c b/tests/driver_at86rf215/main.c index c1ca9c4e707a..39e54df5e814 100644 --- a/tests/driver_at86rf215/main.c +++ b/tests/driver_at86rf215/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 ML!PA Consulting GmbH + * Copyright (C) 2022 HAW Hamburg * * 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 @@ -11,9 +11,10 @@ * @{ * * @file - * @brief Test application for at86rf215 driver + * @brief Test application for AT86RF215 IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri * - * @author Benjamin Valentin * @} */ @@ -21,28 +22,20 @@ #include "at86rf215.h" #include "at86rf215_internal.h" -#include "thread.h" +#include "at86rf215_params.h" +#include "init_dev.h" #include "shell.h" -#include "sys/bus.h" +#include "test_utils/netdev_ieee802154_minimal.h" -#include "net/gnrc/pktdump.h" -#include "net/gnrc/netif.h" -#include "net/gnrc.h" +#include "thread.h" +#include "event.h" +#include "event/thread.h" +#include "sys/bus.h" #include "od.h" -static char batmon_stack[THREAD_STACKSIZE_MAIN]; -static at86rf215_t *dev; +static at86rf215_t at86rf215[NETDEV_IEEE802154_MINIMAL_NUMOF]; -void netdev_register_signal(netdev_t *netdev, netdev_type_t type, uint8_t index) -{ - (void) index; - netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, - netdev_ieee802154_t, - netdev); - if (type == NETDEV_AT86RF215 && !dev) { - dev = container_of(netdev_ieee802154, at86rf215_t, netdev); - } -} +static char batmon_stack[THREAD_STACKSIZE_MAIN]; void *batmon_thread(void *arg) { @@ -65,21 +58,15 @@ static int cmd_enable_batmon(int argc, char **argv) { int res; uint16_t voltage; - gnrc_netif_t* netif = gnrc_netif_iter(NULL); + netdev_t *netdev = &(at86rf215[0].netdev.netdev); if (argc < 2) { printf("usage: %s \n", argv[0]); return -1; } - if (netif == NULL) { - puts("no netif found"); - return -1; - } - voltage = atoi(argv[1]); - res = gnrc_netapi_set(netif->pid, NETOPT_BATMON, 0, - &voltage, sizeof(voltage)); + res = netdev->driver->set(netdev, NETOPT_BATMON, &voltage, sizeof(voltage)); if (res != sizeof(voltage)) { puts("value out of range"); @@ -96,17 +83,13 @@ static int cmd_set_trim(int argc, char **argv) } uint8_t trim = atoi(argv[1]); + at86rf215_t *dev = at86rf215; if (trim > 0xF) { puts("Trim value out of range"); return 1; } - if (dev == NULL) { - puts("No at86rf215 radio found"); - return 1; - } - printf("setting trim to %u fF\n", 300U * trim); at86rf215_set_trim(dev, trim); @@ -127,6 +110,7 @@ static int cmd_set_clock_out(int argc, char **argv) }; at86rf215_clko_freq_t freq = AT86RF215_CLKO_26_MHz; + at86rf215_t *dev = at86rf215; if (argc > 1) { unsigned tmp = 0xFF; @@ -150,11 +134,6 @@ static int cmd_set_clock_out(int argc, char **argv) freq = tmp; } - if (dev == NULL) { - puts("No at86rf215 radio found"); - return 1; - } - printf("Clock output set to %s %s\n", keys[freq], freq ? "MHz" : ""); at86rf215_set_clock_output(dev, AT86RF215_CLKO_4mA, freq); @@ -165,6 +144,7 @@ static int cmd_get_random(int argc, char **argv) { uint8_t values; uint8_t buffer[256]; + at86rf215_t *dev = at86rf215; if (argc > 1) { values = atoi(argv[1]); @@ -178,11 +158,6 @@ static int cmd_get_random(int argc, char **argv) return 1; } - if (dev == NULL) { - puts("No at86rf215 radio found"); - return 1; - } - at86rf215_get_random(dev, buffer, values); od_hex_dump(buffer, values, 0); @@ -190,6 +165,69 @@ static int cmd_get_random(int argc, char **argv) return 0; } +int test_init(void) +{ + /* create battery monitor thread */ + thread_create(batmon_stack, sizeof(batmon_stack), THREAD_PRIORITY_MAIN - 1, + THREAD_CREATE_STACKTEST, batmon_thread, NULL, "batmon"); + return 0; +} + + +static int _init_driver(netdev_t *netdev, netdev_event_cb_t cb) +{ + /* set the application-provided callback */ + netdev->event_callback = cb; + + /* initialize the device driver */ + return netdev->driver->init(netdev); +} + +int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { + unsigned idx = 0; + + puts("Initializing AT86RF215 at86rf215"); + + for (unsigned i = 0; i < AT86RF215_NUM; i++) { + at86rf215_t *at86rf215_subghz = NULL; + at86rf215_t *at86rf215_24ghz = NULL; + + printf("%d out of %d\n", i + 1, AT86RF215_NUM); + + if (IS_USED(MODULE_AT86RF215_SUBGHZ)) { + puts("Sub-GHz"); + at86rf215_subghz = &at86rf215[idx]; + idx++; + } + + if (IS_USED(MODULE_AT86RF215_24GHZ)) { + puts("2.4 GHz"); + at86rf215_24ghz = &at86rf215[idx]; + idx++; + } + + /* setup the specific driver */ + at86rf215_setup(at86rf215_subghz, at86rf215_24ghz, &at86rf215_params[i], i); + + int res = 0; + if (at86rf215_subghz) { + res = _init_driver(&at86rf215_subghz->netdev.netdev, cb); + if (res) { + return res; + } + } + + if (at86rf215_24ghz) { + res = _init_driver(&at86rf215_24ghz->netdev.netdev, cb); + if (res) { + return res; + } + } + } + + return 0; +} + static const shell_command_t shell_commands[] = { { "batmon", "Enable the battery monitor", cmd_enable_batmon }, { "set_trim", "at86rf215: Set the trim value of the crystal oscillator", cmd_set_trim }, @@ -200,16 +238,21 @@ static const shell_command_t shell_commands[] = { int main(void) { - /* enable pktdump output */ - gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, - gnrc_pktdump_pid); - gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump); + puts("Test application for AT86RF215 IEEE 802.15.4 device driver"); + + int res = netdev_ieee802154_minimal_init(); + if (res) { + puts("Error initializing at86rf215"); + return 1; + } /* create battery monitor thread */ thread_create(batmon_stack, sizeof(batmon_stack), THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST, batmon_thread, NULL, "batmon"); /* start the shell */ + puts("Initialization successful - starting the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); From f1d6b25c6242574f8234fd0ff19b3976ce8fad1d Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 10:09:53 +0100 Subject: [PATCH 12/18] tests: add cc2420 driver test --- tests/driver_cc2420/Makefile | 13 +++++++ tests/driver_cc2420/Makefile.ci | 11 ++++++ tests/driver_cc2420/README.md | 19 +++++++++ tests/driver_cc2420/init_dev.h | 36 +++++++++++++++++ tests/driver_cc2420/main.c | 69 +++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 tests/driver_cc2420/Makefile create mode 100644 tests/driver_cc2420/Makefile.ci create mode 100644 tests/driver_cc2420/README.md create mode 100644 tests/driver_cc2420/init_dev.h create mode 100644 tests/driver_cc2420/main.c diff --git a/tests/driver_cc2420/Makefile b/tests/driver_cc2420/Makefile new file mode 100644 index 000000000000..924080e56426 --- /dev/null +++ b/tests/driver_cc2420/Makefile @@ -0,0 +1,13 @@ +INCLUDES += -I$(APPDIR) +BOARD ?= z1 + +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_ieee802154_minimal + +# select the driver to test +USEMODULE += cc2420 + +CFLAGS += -DEVENT_THREAD_STACKSIZE_DEFAULT=1024 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_cc2420/Makefile.ci b/tests/driver_cc2420/Makefile.ci new file mode 100644 index 000000000000..fa21afb84b05 --- /dev/null +++ b/tests/driver_cc2420/Makefile.ci @@ -0,0 +1,11 @@ +BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-leonardo \ + arduino-nano \ + arduino-uno \ + atmega328p-xplained-mini \ + atmega328p \ + nucleo-l011k4 \ + samd10-xmini \ + stm32f030f4-demo \ + # diff --git a/tests/driver_cc2420/README.md b/tests/driver_cc2420/README.md new file mode 100644 index 000000000000..7f9e1b9afc05 --- /dev/null +++ b/tests/driver_cc2420/README.md @@ -0,0 +1,19 @@ +# About +This is a manual test application for the CC2420 radio driver. + +For running this test, you need to connect/configure the following pins of your +radio device: +- SPI MISO +- SPI MOSI +- SPI CLK +- CS (chip select) +- FIFO +- FIFOP +- CCA +- SFD +- VREFEN +- RESET + +# Usage +For testing the radio driver you can use the ifconfig and txtsnd shell commands +that are included in this application. diff --git a/tests/driver_cc2420/init_dev.h b/tests/driver_cc2420/init_dev.h new file mode 100644 index 000000000000..cf412b85f750 --- /dev/null +++ b/tests/driver_cc2420/init_dev.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 Device-specific test header file CC2420 IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include "cc2420_params.h" +#include "kernel_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define CC2420_NUM ARRAY_SIZE(cc2420_params) +#define NETDEV_IEEE802154_MINIMAL_NUMOF CC2420_NUM + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_cc2420/main.c b/tests/driver_cc2420/main.c new file mode 100644 index 000000000000..8ec9fcb014ed --- /dev/null +++ b/tests/driver_cc2420/main.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 CC2420 IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "cc2420.h" +#include "init_dev.h" +#include "shell.h" +#include "test_utils/netdev_ieee802154_minimal.h" + +static cc2420_t cc2420[CC2420_NUM]; + +int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { + puts("Initializing CC2420 devices"); + + for (unsigned i = 0; i < CC2420_NUM; i++) { + printf("%d out of %d\n", i + 1, CC2420_NUM); + netdev_t *netdev = &cc2420[i].netdev.netdev; + + /* setup the specific driver */ + cc2420_setup(&cc2420[i], &cc2420_params[i], i); + + /* set the application-provided callback */ + netdev->event_callback = cb; + + /* initialize the device driver */ + int res = netdev->driver->init(netdev); + if (res) { + return res; + } + } + return 0; +} + +int main(void) +{ + puts("Test application for CC2420 IEEE 802.15.4 device driver"); + + int res = netdev_ieee802154_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 485ee122c0d53faa7454d485a51056144a9ea1cc Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 09:41:01 +0100 Subject: [PATCH 13/18] tests: add cc2538_rf driver test --- tests/driver_cc2538_rf/Makefile | 15 +++++++ tests/driver_cc2538_rf/README.md | 6 +++ tests/driver_cc2538_rf/init_dev.h | 33 ++++++++++++++ tests/driver_cc2538_rf/main.c | 72 +++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 tests/driver_cc2538_rf/Makefile create mode 100644 tests/driver_cc2538_rf/README.md create mode 100644 tests/driver_cc2538_rf/init_dev.h create mode 100644 tests/driver_cc2538_rf/main.c diff --git a/tests/driver_cc2538_rf/Makefile b/tests/driver_cc2538_rf/Makefile new file mode 100644 index 000000000000..86b555603d18 --- /dev/null +++ b/tests/driver_cc2538_rf/Makefile @@ -0,0 +1,15 @@ +INCLUDES += -I$(APPDIR) +BOARD ?= remote-revb + +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_ieee802154_minimal + +# select the driver to test +USEMODULE += cc2538_rf + +FEATURES_REQUIRED += cpu_cc2538 + +CFLAGS += -DEVENT_THREAD_STACKSIZE_DEFAULT=1024 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_cc2538_rf/README.md b/tests/driver_cc2538_rf/README.md new file mode 100644 index 000000000000..5d11697f24d6 --- /dev/null +++ b/tests/driver_cc2538_rf/README.md @@ -0,0 +1,6 @@ +# About +This is a manual test application for the CC2538_RF radio driver. + +# Usage +For testing the radio driver you can use the ifconfig and txtsnd shell commands +that are included in this application. diff --git a/tests/driver_cc2538_rf/init_dev.h b/tests/driver_cc2538_rf/init_dev.h new file mode 100644 index 000000000000..19ebb1354aff --- /dev/null +++ b/tests/driver_cc2538_rf/init_dev.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 Device-specific test header file CC2538_RF IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define CC2538_RF_NUM 1 +#define NETDEV_IEEE802154_MINIMAL_NUMOF CC2538_RF_NUM + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_cc2538_rf/main.c b/tests/driver_cc2538_rf/main.c new file mode 100644 index 000000000000..aa85f91c713f --- /dev/null +++ b/tests/driver_cc2538_rf/main.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 CC2538_RF IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "cc2538_rf.h" +#include "init_dev.h" +#include "net/netdev/ieee802154_submac.h" +#include "shell.h" +#include "test_utils/netdev_ieee802154_minimal.h" + +static netdev_ieee802154_submac_t cc2538_rf; + +int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { + netdev_t *netdev = &cc2538_rf.dev.netdev; + + puts("Initializing CC2538_RF device"); + + netdev_register(netdev, NETDEV_CC2538, 0); + netdev_ieee802154_submac_init(&cc2538_rf); + + /* setup and initialize the specific driver */ + cc2538_rf_hal_setup(&cc2538_rf.submac.dev); + cc2538_init(); + + /* set the application-provided callback */ + netdev->event_callback = cb; + + /* initialize the device driver */ + int res = netdev->driver->init(netdev); + if (res != 0) { + return -1; + } + + return 0; +} + +int main(void) +{ + puts("Test application for CC2538_RF IEEE 802.15.4 device driver"); + + int res = netdev_ieee802154_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From f8db5eadbcc3cd0f31416e5e0e174a2519911788 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 08:38:58 +0100 Subject: [PATCH 14/18] tests/driver_kw2xrf: rewrite without GNRC --- tests/driver_kw2xrf/Makefile | 16 +++---- tests/driver_kw2xrf/Makefile.ci | 15 +------ tests/driver_kw2xrf/README.md | 11 ++++- tests/driver_kw2xrf/init_dev.h | 40 +++++++++++++++++ tests/driver_kw2xrf/kw2xrf_params.h | 64 ---------------------------- tests/driver_kw2xrf/main.c | 66 ++++++++++++++++++++--------- 6 files changed, 102 insertions(+), 110 deletions(-) create mode 100644 tests/driver_kw2xrf/init_dev.h delete mode 100644 tests/driver_kw2xrf/kw2xrf_params.h diff --git a/tests/driver_kw2xrf/Makefile b/tests/driver_kw2xrf/Makefile index ae4b5ea01226..7121a3097d7f 100644 --- a/tests/driver_kw2xrf/Makefile +++ b/tests/driver_kw2xrf/Makefile @@ -1,15 +1,13 @@ +INCLUDES += -I$(APPDIR) +BOARD ?= pba-d-01-kw2x + include ../Makefile.tests_common -USEMODULE += auto_init_gnrc_netif -USEMODULE += gnrc -USEMODULE += fmt -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += ps +USEMODULE += test_utils_netdev_ieee802154_minimal -DRIVER ?= kw2xrf +# the radio driver to test +USEMODULE += kw2xrf -# finally include the actual chosen driver -USEMODULE += $(DRIVER) +CFLAGS += -DEVENT_THREAD_STACKSIZE_DEFAULT=1024 include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_kw2xrf/Makefile.ci b/tests/driver_kw2xrf/Makefile.ci index 57b75c3dab19..fa21afb84b05 100644 --- a/tests/driver_kw2xrf/Makefile.ci +++ b/tests/driver_kw2xrf/Makefile.ci @@ -1,24 +1,11 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-duemilanove \ arduino-leonardo \ - arduino-mega2560 \ arduino-nano \ arduino-uno \ - atmega328p \ atmega328p-xplained-mini \ - bluepill-stm32f030c8 \ - i-nucleo-lrwan1 \ - nucleo-f031k6 \ - nucleo-f042k6 \ - nucleo-f334r8 \ + atmega328p \ nucleo-l011k4 \ - nucleo-l031k6 \ - nucleo-l053r8 \ samd10-xmini \ - slstk3400a \ - stk3200 \ stm32f030f4-demo \ - stm32f0discovery \ - stm32l0538-disco \ - waspmote-pro \ # diff --git a/tests/driver_kw2xrf/README.md b/tests/driver_kw2xrf/README.md index 6012c2ae9b54..93a181278f22 100644 --- a/tests/driver_kw2xrf/README.md +++ b/tests/driver_kw2xrf/README.md @@ -1,8 +1,15 @@ # About -This is a manual test application for testing the KW2XRF device driver. It enables several shell commands, allowing for special test modes of that device. Without deeper knowledge about the hardware, this application might be useless except for compile tests. If you want an example to use this radio, check the [examples](../../examples) folder. +This is a manual test application for testing the KW2XRF device driver. +It enables several shell commands, allowing for special test modes of that +device. +Without deeper knowledge about the hardware, this application might be useless +except for compile tests. +If you want an example to use this radio, check the +[examples](../../examples) folder. For running this test, you need to connect/configure the following pins of your -radio device. If you are running on a phyNODE, this is already the on-board default. +radio device. If you are running on a phyNODE, this is already the on-board +default. - SPI DEV - CS (chip select) diff --git a/tests/driver_kw2xrf/init_dev.h b/tests/driver_kw2xrf/init_dev.h new file mode 100644 index 000000000000..b43761bb5cfd --- /dev/null +++ b/tests/driver_kw2xrf/init_dev.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 Device-specific test header file KW2XRF IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include "kernel_defines.h" +#include "kw2xrf_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define KW2XRF_NUM ARRAY_SIZE(kw2xrf_params) +#define NETDEV_IEEE802154_MINIMAL_NUMOF KW2XRF_NUM + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_kw2xrf/kw2xrf_params.h b/tests/driver_kw2xrf/kw2xrf_params.h deleted file mode 100644 index 6d97054de5ca..000000000000 --- a/tests/driver_kw2xrf/kw2xrf_params.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2015 Kaspar Schleiser - * Copyright (C) 2014 PHYTEC Messtechnik GmbH - * - * 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 - * @brief generic kw2xrf pin config - * - * Copyright (C) 2014 PHYTEC Messtechnik GmbH - * @{ - * @file - * - * @author Kaspar Schleiser - * @author Jonas Remmert - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef KW2XRF_PARAMS_H -#define KW2XRF_PARAMS_H - -/** - * @brief make sure the SPI port and the needed GPIO pins are defined - * @{ - */ -#ifndef KWRF_SPI -#error "SPI not defined" -#endif -#ifndef KWRF_CS -#error "Chip select pin not defined" -#endif -#ifndef KWRF_INT -#error "Interrupt pin not defined" -#endif -#ifndef KWRF_SPI_CLK -#define KWRF_SPI_CLK (SPI_CLK_10MHZ) -#endif -/**@}*/ - -/** - * @name KW2XRF configuration - */ -static const kw2xrf_params_t kw2xrf_params[] = { - { - .spi = KWRF_SPI, - .spi_clk = KWRF_SPI_CLK, - .cs_pin = KWRF_CS, - .int_pin = KWRF_INT, - }, -}; -/** @} */ - -#ifdef __cplusplus -} -#endif -#endif /* KW2XRF_PARAMS_H */ -/** @} */ diff --git a/tests/driver_kw2xrf/main.c b/tests/driver_kw2xrf/main.c index fed86b7c355d..b3cf92384de3 100644 --- a/tests/driver_kw2xrf/main.c +++ b/tests/driver_kw2xrf/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 PHYTEC Messtechnik GmbH + * Copyright (C) 2022 HAW Hamburg * * 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 @@ -7,41 +7,43 @@ */ /** - * @{ * @ingroup tests + * @{ + * * @file - * @brief Test application for KW2x network device driver + * @brief Test application for KW2XRF IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri * - * @author Hauke Petersen - * @author Jonas Remmert * @} */ #include #include "fmt.h" -#include "shell.h" +#include "init_dev.h" #include "kw2xrf.h" -#include "net/gnrc.h" -#include "net/gnrc/netapi.h" -#include "net/netopt.h" - -#define KW2XRF_TESTMODE (1) - -#ifdef KW2XRF_TESTMODE #include "kw2xrf_tm.h" +#include "kw2xrf_params.h" +#include "shell.h" +#include "test_utils/netdev_ieee802154_minimal.h" + +static kw2xrf_t kw2xrf[KW2XRF_NUM]; /* utility functions */ static void _set_test_mode(int argc, char **argv, uint8_t mode) { (void) argc; if (fmt_is_number(argv[1])) { - kernel_pid_t dev = atoi(argv[1]); - - if (gnrc_netif_get_by_pid(dev)) { - gnrc_netapi_set(dev, NETOPT_RF_TESTMODE, 0, (void *)&mode, sizeof(mode)); + int idx = atoi(argv[1]); + if (idx >= (int)KW2XRF_NUM) { + puts("invalid interface ID"); return; } + + netdev_t *dev = &(kw2xrf[idx].netdev.netdev); + dev->driver->set(dev, NETOPT_RF_TESTMODE, &mode, sizeof(mode)); + return; } printf("usage: %s \n", argv[0]); return; @@ -113,10 +115,28 @@ static int _tm_ctx_nm1(int argc, char **argv) return 0; } -#endif +int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { + puts("Initializing KW2XRF devices"); + + for (unsigned i = 0; i < KW2XRF_NUM; i++) { + printf("%d out of %d\n", i + 1, KW2XRF_NUM); + /* setup the specific driver */ + kw2xrf_setup(&kw2xrf[i], &kw2xrf_params[i], i); + + /* set the application-provided callback */ + kw2xrf[i].netdev.netdev.event_callback = cb; + + /* initialize the device driver */ + int res = kw2xrf[i].netdev.netdev.driver->init(&kw2xrf[i].netdev.netdev); + if (res != 0) { + return -1; + } + } + + return 0; +} static const shell_command_t shell_commands[] = { -#ifdef KW2XRF_TESTMODE { "idle", "xcvr idle mode", _tm_idle }, { "ctx_prbs9", "continues transmit the prbs9 pattern", _tm_ctx_prbs9 }, { "crx", "continues receive mode, useful for current measuring", _tm_crx }, @@ -128,14 +148,18 @@ static const shell_command_t shell_commands[] = { { "ctx_ext", "continues transmit modulated carrier", _tm_ctx_ext }, { "ctx_nm0", "continues transmit modulated carrier", _tm_ctx_nm0 }, { "ctx_nm1", "continues transmit modulated carrier", _tm_ctx_nm1 }, -#endif { NULL, NULL, NULL } }; int main(void) { + puts("Test application for KW2XRF IEEE 802.15.4 device driver"); - puts("KW2XRF device driver test"); + int res = netdev_ieee802154_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } /* start the shell */ puts("Initialization successful - starting the shell now"); From bacfe50893437071d1210df03925770a05b28a92 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 22 Mar 2022 08:44:45 +0100 Subject: [PATCH 15/18] tests/driver_mrf24j40: rewrite without GNRC --- tests/driver_mrf24j40/Makefile | 14 +++++-- tests/driver_mrf24j40/Makefile.ci | 14 +------ tests/driver_mrf24j40/README.md | 15 +++++++ tests/driver_mrf24j40/init_dev.h | 36 ++++++++++++++++ tests/driver_mrf24j40/main.c | 70 ++++++++++++++++++++++++++++++- 5 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 tests/driver_mrf24j40/README.md create mode 100644 tests/driver_mrf24j40/init_dev.h mode change 120000 => 100644 tests/driver_mrf24j40/main.c diff --git a/tests/driver_mrf24j40/Makefile b/tests/driver_mrf24j40/Makefile index 2cb5ded7e62b..92ef43837d8b 100644 --- a/tests/driver_mrf24j40/Makefile +++ b/tests/driver_mrf24j40/Makefile @@ -1,4 +1,12 @@ -# the radio driver to test -USEMODULE = mrf24j40md +INCLUDES += -I$(APPDIR) -include ../driver_netdev_common/Makefile.netdev.mk +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_ieee802154_minimal + +# select the driver to test +USEMODULE += mrf24j40ma + +CFLAGS += -DEVENT_THREAD_STACKSIZE_DEFAULT=1024 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_mrf24j40/Makefile.ci b/tests/driver_mrf24j40/Makefile.ci index 586364d98393..fa21afb84b05 100644 --- a/tests/driver_mrf24j40/Makefile.ci +++ b/tests/driver_mrf24j40/Makefile.ci @@ -1,23 +1,11 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-duemilanove \ arduino-leonardo \ - arduino-mega2560 \ arduino-nano \ arduino-uno \ - atmega328p \ atmega328p-xplained-mini \ - bluepill-stm32f030c8 \ - i-nucleo-lrwan1 \ - nucleo-f031k6 \ - nucleo-f042k6 \ + atmega328p \ nucleo-l011k4 \ - nucleo-l031k6 \ - nucleo-l053r8 \ samd10-xmini \ - slstk3400a \ - stk3200 \ stm32f030f4-demo \ - stm32f0discovery \ - stm32l0538-disco \ - waspmote-pro \ # diff --git a/tests/driver_mrf24j40/README.md b/tests/driver_mrf24j40/README.md new file mode 100644 index 000000000000..1d845afe08b4 --- /dev/null +++ b/tests/driver_mrf24j40/README.md @@ -0,0 +1,15 @@ +# About +This is a manual test application for the MRF24J40 radio driver. + +For running this test, you need to connect/configure the following pins of your +radio device: +- SPI MISO +- SPI MOSI +- SPI CLK +- CS (chip select) +- RESET +- INT (external interrupt) + +# Usage +For testing the radio driver you can use the ifconfig and txtsnd shell commands +that are included in this application. diff --git a/tests/driver_mrf24j40/init_dev.h b/tests/driver_mrf24j40/init_dev.h new file mode 100644 index 000000000000..8ac5f271b5e2 --- /dev/null +++ b/tests/driver_mrf24j40/init_dev.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 Device-specific test header file MRF24J40 IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include "kernel_defines.h" +#include "mrf24j40_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MRF24J40_NUM ARRAY_SIZE(mrf24j40_params) +#define NETDEV_IEEE802154_MINIMAL_NUMOF MRF24J40_NUM + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_mrf24j40/main.c b/tests/driver_mrf24j40/main.c deleted file mode 120000 index a3f88db08e84..000000000000 --- a/tests/driver_mrf24j40/main.c +++ /dev/null @@ -1 +0,0 @@ -../driver_netdev_common/main.c \ No newline at end of file diff --git a/tests/driver_mrf24j40/main.c b/tests/driver_mrf24j40/main.c new file mode 100644 index 000000000000..1a0b3ea8875b --- /dev/null +++ b/tests/driver_mrf24j40/main.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 MRF24J40 IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "init_dev.h" +#include "mrf24j40.h" +#include "mrf24j40_params.h" +#include "shell.h" +#include "test_utils/netdev_ieee802154_minimal.h" + +static mrf24j40_t mrf24j40[MRF24J40_NUM]; + +int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { + puts("Initializing MRF24J40 devices"); + + for (unsigned i = 0; i < MRF24J40_NUM; i++) { + printf("%d out of %d\n", i + 1, MRF24J40_NUM); + /* setup the specific driver */ + mrf24j40_setup(&mrf24j40[i], &mrf24j40_params[i], i); + + /* set the application-provided callback */ + mrf24j40[i].netdev.netdev.event_callback = cb; + + /* initialize the device driver */ + int res = mrf24j40[i].netdev.netdev.driver->init(&mrf24j40[i].netdev.netdev); + if (res != 0) { + return -1; + } + } + + return 0; +} + +int main(void) +{ + puts("Test application for MRF24J40 IEEE 802.15.4 device driver"); + + int res = netdev_ieee802154_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 61f14145f41ffc9f5005ecc4607f8464e4a70b13 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Mon, 14 Mar 2022 17:14:33 +0100 Subject: [PATCH 16/18] tests/driver_netdev_common: add virtual board with IEEE802.15.4 drivers --- .../netdev-ci-boards/nrf52840-ci-ieee802154/Makefile | 6 ++++++ .../netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.dep | 7 +++++++ .../nrf52840-ci-ieee802154/Makefile.features | 1 + .../nrf52840-ci-ieee802154/Makefile.include | 5 +++++ 4 files changed, 19 insertions(+) create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.dep create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.features create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.include diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile new file mode 100644 index 000000000000..cb44db6740de --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile @@ -0,0 +1,6 @@ +# This must be a different name than 'board' as it is implemented by 'nrf52840dk' +MODULE = board_nrf52840_ci_ieee802154 + +DIRS += $(RIOTBOARD)/nrf52840dk + +include $(RIOTBASE)/Makefile.base diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.dep b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.dep new file mode 100644 index 000000000000..4758e814c4a4 --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.dep @@ -0,0 +1,7 @@ +USEMODULE += board_nrf52840_ci_ieee802154 + +ifneq (,$(filter netdev_default,$(USEMODULE))) + USEMODULE += mrf24j40 +endif + +include $(RIOTBOARD)/nrf52840dk/Makefile.dep diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.features b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.features new file mode 100644 index 000000000000..1ad8a41f8546 --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.features @@ -0,0 +1 @@ +include $(RIOTBOARD)/nrf52840dk/Makefile.features diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.include b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.include new file mode 100644 index 000000000000..09950248082b --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-ieee802154/Makefile.include @@ -0,0 +1,5 @@ +# We must duplicate the include done by $(RIOTBASE)/Makefile.include +# to also include the main board header +INCLUDES += $(addprefix -I,$(wildcard $(RIOTBOARD)/nrf52840dk/include)) + +include $(RIOTBOARD)/nrf52840dk/Makefile.include From a2ac1c86db5a2da2d2b5feb4b042fb46ea650ebf Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 16 Jun 2022 13:23:58 +0200 Subject: [PATCH 17/18] tests/driver_at86rf215: add nucleo-f042k6 to BOARD_INSUFFICIENT_MEMORY --- tests/driver_at86rf215/Makefile.ci | 1 + tests/driver_at86rf215/main.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/driver_at86rf215/Makefile.ci b/tests/driver_at86rf215/Makefile.ci index 04f2d9e5f90b..4f0caf68cd6a 100644 --- a/tests/driver_at86rf215/Makefile.ci +++ b/tests/driver_at86rf215/Makefile.ci @@ -6,6 +6,7 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega328p-xplained-mini \ atmega328p \ nucleo-f031k6 \ + nucleo-f042k6 \ nucleo-l011k4 \ nucleo-l031k6 \ samd10-xmini \ diff --git a/tests/driver_at86rf215/main.c b/tests/driver_at86rf215/main.c index 39e54df5e814..c91f43a0acb7 100644 --- a/tests/driver_at86rf215/main.c +++ b/tests/driver_at86rf215/main.c @@ -173,7 +173,6 @@ int test_init(void) return 0; } - static int _init_driver(netdev_t *netdev, netdev_event_cb_t cb) { /* set the application-provided callback */ From 37bdc32e30a542bc8276045cc3b2bb643e672b8c Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 28 Jun 2022 18:21:04 +0200 Subject: [PATCH 18/18] tests/driver_nrf802154: Initial driver test --- tests/driver_nrf802154/Makefile | 15 +++++++ tests/driver_nrf802154/README.md | 6 +++ tests/driver_nrf802154/init_dev.h | 33 ++++++++++++++ tests/driver_nrf802154/main.c | 72 +++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 tests/driver_nrf802154/Makefile create mode 100644 tests/driver_nrf802154/README.md create mode 100644 tests/driver_nrf802154/init_dev.h create mode 100644 tests/driver_nrf802154/main.c diff --git a/tests/driver_nrf802154/Makefile b/tests/driver_nrf802154/Makefile new file mode 100644 index 000000000000..f5cdebecbc8b --- /dev/null +++ b/tests/driver_nrf802154/Makefile @@ -0,0 +1,15 @@ +INCLUDES += -I$(APPDIR) +BOARD ?= nrf52dk + +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_ieee802154_minimal + +# select the driver to test +USEMODULE += nrf802154 + +FEATURES_REQUIRED += cpu_nrf52 + +CFLAGS += -DEVENT_THREAD_STACKSIZE_DEFAULT=1024 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_nrf802154/README.md b/tests/driver_nrf802154/README.md new file mode 100644 index 000000000000..6d0620ccaca2 --- /dev/null +++ b/tests/driver_nrf802154/README.md @@ -0,0 +1,6 @@ +# About +This is a manual test application for the NRF802154 radio driver. + +# Usage +For testing the radio driver you can use the ifconfig and txtsnd shell commands +that are included in this application. diff --git a/tests/driver_nrf802154/init_dev.h b/tests/driver_nrf802154/init_dev.h new file mode 100644 index 000000000000..14b3ca0689b3 --- /dev/null +++ b/tests/driver_nrf802154/init_dev.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 Device-specific test header file NRF802154 IEEE 802.15.4 device driver + * + * @author Kevin Weiss + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define NRF802154_NUM 1 +#define NETDEV_IEEE802154_MINIMAL_NUMOF NRF802154_NUM + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_nrf802154/main.c b/tests/driver_nrf802154/main.c new file mode 100644 index 000000000000..9c0bc7555a7c --- /dev/null +++ b/tests/driver_nrf802154/main.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 NRF802154 IEEE 802.15.4 device driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "nrf802154.h" +#include "init_dev.h" +#include "net/netdev/ieee802154_submac.h" +#include "shell.h" +#include "test_utils/netdev_ieee802154_minimal.h" + +static netdev_ieee802154_submac_t nrf802154; + +int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { + netdev_t *netdev = &nrf802154.dev.netdev; + + puts("Initializing NRF802154 device"); + + netdev_register(netdev, NETDEV_CC2538, 0); + netdev_ieee802154_submac_init(&nrf802154); + + /* setup and initialize the specific driver */ + nrf802154_hal_setup(&nrf802154.submac.dev); + nrf802154_init(); + + /* set the application-provided callback */ + netdev->event_callback = cb; + + /* initialize the device driver */ + int res = netdev->driver->init(netdev); + if (res != 0) { + return -1; + } + + return 0; +} + +int main(void) +{ + puts("Test application for NRF802154 IEEE 802.15.4 device driver"); + + int res = netdev_ieee802154_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +}