Skip to content

Commit

Permalink
Merge pull request #17838 from MrKevinWeiss/pr/tests/154_drivers_rework
Browse files Browse the repository at this point in the history
tests: rework ieee802154 drivers
  • Loading branch information
MrKevinWeiss authored Jul 11, 2022
2 parents 747aac2 + 37bdc32 commit 1ba2ef8
Show file tree
Hide file tree
Showing 65 changed files with 1,655 additions and 842 deletions.
1 change: 1 addition & 0 deletions drivers/at86rf215/include/at86rf215_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef AT86RF215_PARAMS_H
#define AT86RF215_PARAMS_H

#include "at86rf215.h"
#include "board.h"

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions drivers/at86rf2xx/include/at86rf2xx_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef AT86RF2XX_PARAMS_H
#define AT86RF2XX_PARAMS_H

#include "at86rf2xx.h"
#include "board.h"

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions drivers/cc2420/include/cc2420_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define CC2420_PARAMS_H

#include "board.h"
#include "cc2420.h"

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 3 additions & 1 deletion drivers/include/kw2xrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/include/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ typedef enum {
NETDEV_W5100,
NETDEV_ENCX24J600,
NETDEV_ATWINC15X0,
NETDEV_KW2XRF,
/* add more if needed */
} netdev_type_t;
/** @} */
Expand Down
4 changes: 4 additions & 0 deletions drivers/kw2xrf/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
SUBMODULES := 1

SRC := kw2xrf.c kw2xrf_getset.c kw2xrf_intern.c kw2xrf_netdev.c kw2xrf_spi.c

include $(RIOTBASE)/Makefile.base
1 change: 1 addition & 0 deletions drivers/kw2xrf/include/kw2xrf_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define KW2XRF_PARAMS_H

#include "board.h"
#include "kw2xrf.h"

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 0 additions & 4 deletions drivers/kw2xrf/include/kw2xrf_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
16 changes: 12 additions & 4 deletions drivers/kw2xrf/include/kw2xrf_tm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion drivers/kw2xrf/kw2xrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/kw2xrf/kw2xrf_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions drivers/kw2xrf/kw2xrf_tm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, &reg, 1);
Expand Down Expand Up @@ -177,5 +175,4 @@ int kw2xrf_set_test_mode(kw2xrf_t *dev, uint8_t mode)
return 1;
}

#endif
/** @} */
1 change: 1 addition & 0 deletions drivers/mrf24j40/include/mrf24j40_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define MRF24J40_PARAMS_H

#include "board.h"
#include "mrf24j40.h"

#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
116 changes: 116 additions & 0 deletions sys/include/test_utils/netdev_ieee802154_minimal.h
Original file line number Diff line number Diff line change
@@ -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 <kevin.weiss@haw-hamburg.de>
*/

#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 */
/** @} */
2 changes: 1 addition & 1 deletion sys/net/gnrc/netif/init_devs/auto_init_kw2xrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions sys/test_utils/Makefile.dep
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions sys/test_utils/netdev_ieee802154_minimal/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = test_utils_netdev_ieee802154_minimal

include $(RIOTBASE)/Makefile.base
7 changes: 7 additions & 0 deletions sys/test_utils/netdev_ieee802154_minimal/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USEMODULE += event
USEMODULE += event_thread
USEMODULE += l2util
USEMODULE += od
USEMODULE += od_string
USEMODULE += shell
USEMODULE += netdev
Loading

0 comments on commit 1ba2ef8

Please sign in to comment.