Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: add kw41zrf #12277

Merged
merged 2 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions boards/common/kw41z/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_adc
USEMODULE += saul_gpio
endif

ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
USEMODULE += kw41zrf
endif
7 changes: 3 additions & 4 deletions boards/openlabs-kw41z-mini/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif

# TODO uncomment after #12277 (add support for kw41zrf) is merged
# ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
# USEMODULE += kw41zrf
# endif
ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
USEMODULE += kw41zrf
endif
10 changes: 10 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ ifneq (,$(filter kw2xrf,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio_irq
endif

ifneq (,$(filter kw41zrf,$(USEMODULE)))
USEMODULE += luid
USEMODULE += netif
USEMODULE += ieee802154
USEMODULE += netdev_ieee802154
USEMODULE += core_thread_flags
USEMODULE += random
USEMODULE += mcux_xcvr_mkw41z
endif

ifneq (,$(filter l3g4200d,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
endif
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ ifneq (,$(filter kw2xrf,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/kw2xrf/include
endif

ifneq (,$(filter kw41zrf,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/kw41zrf/include
endif

ifneq (,$(filter l3g4200d,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/l3g4200d/include
endif
Expand Down
170 changes: 170 additions & 0 deletions drivers/include/kw41zrf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
* Copyright (C) 2017 SKF AB
*
* 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 drivers_kw41zrf KW41Z radio-driver
* @ingroup drivers_netdev
* @brief Device driver for the NXP KW41Z, KW21Z in-cpu transceiver
* @{
*
* @file
* @brief Interface definition for the kw41zrf driver
*
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*/

#ifndef KW41ZRF_H
#define KW41ZRF_H

#include <stdint.h>

#include "mutex.h"
#include "board.h"
#include "net/netdev.h"
#include "net/netdev/ieee802154.h"
#include "net/gnrc/nettype.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Maximum packet length
*/
#define KW41ZRF_MAX_PKT_LENGTH (IEEE802154_FRAME_LEN_MAX)

/**
* @brief Default channel used after initialization
*
* @{
*/
#ifndef KW41ZRF_DEFAULT_CHANNEL
#define KW41ZRF_DEFAULT_CHANNEL (IEEE802154_DEFAULT_CHANNEL)
#endif
/** @} */

/**
* @brief Default CCA threshold
*
* @{
*/
#ifndef KW41ZRF_DEFAULT_CCA_THRESHOLD
#define KW41ZRF_DEFAULT_CCA_THRESHOLD (-60)
#endif
/** @} */

/**
* @brief Default LQI compensation
*
* @{
*/
#ifndef KW41ZRF_DEFAULT_LQI_COMPENSATION
#define KW41ZRF_DEFAULT_LQI_COMPENSATION (102)
#endif
/** @} */

/**
* @brief Allowed range of channels
*
* @{
*/
#define KW41ZRF_MIN_CHANNEL (11U)
#define KW41ZRF_MAX_CHANNEL (26U)
/** @} */

/**
* @brief Default TX_POWER in dbm used after initialization
*/
#define KW41ZRF_DEFAULT_TX_POWER (IEEE802154_DEFAULT_TXPOWER)

/**
* @brief Maximum output power of the kw41z device in dBm
*/
#define KW41ZRF_OUTPUT_POWER_MAX (4)

/**
* @brief Minimum output power of the kw41z device in dBm
*/
#define KW41ZRF_OUTPUT_POWER_MIN (-19)

/**
* @brief ISR callback function type
*/
typedef void (*kw41zrf_cb_t)(void *arg);

/**
* @brief Device descriptor for KW41ZRF radio devices
*
* @extends netdev_ieee802154_t
*/
typedef struct {
netdev_ieee802154_t netdev; /**< netdev parent struct */
/**
* @name device specific fields
* @{
*/
thread_t *thread; /**< Network driver thread, for providing feedback from IRQ handler */
uint32_t tx_warmup_time; /**< TX warmup time, in event timer ticks */
uint32_t rx_warmup_time; /**< RX warmup time, in event timer ticks */
uint32_t rf_osc_en_idle; /**< RF_OSC_EN bits setting when RF module is in standby */
int16_t tx_power; /**< The current tx-power setting of the device */
uint8_t flags; /**< Internal driver option flags */
uint8_t max_retrans; /**< Maximum number of frame retransmissions
* when no Ack frame is received (macMaxFrameRetries) */
uint8_t csma_max_backoffs; /**< Maximum number of CSMA backoffs when
* waiting for channel clear (macMaxCsmaBackoffs) */
uint8_t csma_min_be; /**< Minimum backoff exponent (macMinBe) */
uint8_t csma_max_be; /**< Maximum backoff exponent (macMaxBe) */
uint8_t idle_seq; /**< state to return to after sending */
uint8_t cca_result; /**< Used for passing CCA result from ISR to user */
uint8_t csma_be; /**< Counter used internally by send implementation */
uint8_t csma_num_backoffs; /**< Counter used internally by send implementation */
uint8_t num_retrans; /**< Counter used internally by send implementation */
uint32_t backoff_delay; /**< CSMA delay for the current TX operation */
uint32_t tx_timeout; /**< Used to timeout waiting for ACK during TRX */
uint8_t pm_blocked; /**< true if we have blocked a low power mode in the CPU */
uint8_t recv_blocked; /**< blocks moving to XCVSEQ_RECEIVE to prevent
* overwriting the RX buffer before the higher
* layers have copied it to system RAM */
/** @} */
} kw41zrf_t;

/**
* @brief Setup an KW41ZRF based device state
*
* @param[out] dev device descriptor
*/
void kw41zrf_setup(kw41zrf_t *dev);

/**
* @brief Initialize the given KW41ZRF device
*
* @param[out] dev device descriptor
* @param[in] cb irq callback
*
* @return 0 on success
* @return <0 on error
*/
int kw41zrf_init(kw41zrf_t *dev, kw41zrf_cb_t cb);

/**
* @brief Reset radio hardware and restore default settings
*
* @param[in] dev device to reset
*
* @return 0 on success
* @return <0 on initialization failure
*/
int kw41zrf_reset(kw41zrf_t *dev);

#ifdef __cplusplus
}
#endif

#endif /* KW41ZRF_H */
/** @} */
4 changes: 4 additions & 0 deletions drivers/kw41zrf/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Use vendor-supplied low level XCVR hardware initialization
DIRS += vendor/XCVR/MKW41Z4

include $(RIOTBASE)/Makefile.base
Loading