2015-04-02 17:09:29 +02:00
|
|
|
/*
|
2016-05-20 17:13:31 +02:00
|
|
|
* Copyright (C) 2016 PHYTEC Messtechnik GmbH
|
2015-04-02 17:09:29 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2016-05-20 17:13:31 +02:00
|
|
|
* @ingroup drivers_kw2xrf
|
2015-04-02 17:09:29 +02:00
|
|
|
* @{
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2015-04-02 17:09:29 +02:00
|
|
|
* @brief Basic functionality of kw2xrf driver
|
|
|
|
*
|
|
|
|
* @author Johann Fischer <j.fischer@phytec.de>
|
|
|
|
* @author Jonas Remmert <j.remmert@phytec.de>
|
2015-09-21 18:04:40 +02:00
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
2017-01-31 13:26:01 +01:00
|
|
|
* @author Sebastian Meiling <s@mlng.net>
|
2015-04-02 17:09:29 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2016-05-20 17:13:31 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2017-01-31 13:26:01 +01:00
|
|
|
#include "log.h"
|
2015-04-02 17:09:29 +02:00
|
|
|
#include "mutex.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "periph/gpio.h"
|
2015-06-12 16:31:47 +02:00
|
|
|
#include "periph/cpuid.h"
|
2015-08-10 02:41:08 +02:00
|
|
|
#include "net/gnrc.h"
|
2015-08-07 14:36:04 +02:00
|
|
|
#include "net/ieee802154.h"
|
2017-02-24 08:57:11 +01:00
|
|
|
#include "luid.h"
|
2015-04-02 17:09:29 +02:00
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
#include "kw2xrf.h"
|
|
|
|
#include "kw2xrf_spi.h"
|
|
|
|
#include "kw2xrf_reg.h"
|
|
|
|
#include "kw2xrf_netdev.h"
|
|
|
|
#include "kw2xrf_getset.h"
|
|
|
|
#include "kw2xrf_intern.h"
|
|
|
|
|
2020-10-22 11:34:31 +02:00
|
|
|
#define ENABLE_DEBUG 0
|
2015-04-02 17:09:29 +02:00
|
|
|
#include "debug.h"
|
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
static void kw2xrf_set_address(kw2xrf_t *dev)
|
2015-04-02 17:39:10 +02:00
|
|
|
{
|
2017-01-31 13:26:01 +01:00
|
|
|
DEBUG("[kw2xrf] set MAC addresses\n");
|
2016-05-20 17:13:31 +02:00
|
|
|
eui64_t addr_long;
|
2017-01-31 13:26:01 +01:00
|
|
|
/* get an 8-byte unique ID to use as hardware address */
|
2017-02-24 08:57:11 +01:00
|
|
|
luid_get(addr_long.uint8, IEEE802154_LONG_ADDRESS_LEN);
|
2017-01-31 13:26:01 +01:00
|
|
|
/* make sure we mark the address as non-multicast and not globally unique */
|
|
|
|
addr_long.uint8[0] &= ~(0x01);
|
|
|
|
addr_long.uint8[0] |= (0x02);
|
|
|
|
/* set short and long address */
|
2017-04-13 11:35:35 +02:00
|
|
|
kw2xrf_set_addr_long(dev, ntohll(addr_long.uint64.u64));
|
|
|
|
kw2xrf_set_addr_short(dev, ntohs(addr_long.uint16[0].u16));
|
2015-04-02 17:39:10 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
void kw2xrf_reset_phy(kw2xrf_t *dev)
|
2015-04-02 17:39:10 +02:00
|
|
|
{
|
2016-05-20 17:13:31 +02:00
|
|
|
dev->tx_power = KW2XRF_DEFAULT_TX_POWER;
|
|
|
|
kw2xrf_set_tx_power(dev, dev->tx_power);
|
2015-04-02 17:39:10 +02:00
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
kw2xrf_set_channel(dev, KW2XRF_DEFAULT_CHANNEL);
|
2015-04-02 17:09:29 +02:00
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
kw2xrf_set_address(dev);
|
2015-04-02 17:39:10 +02:00
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
kw2xrf_set_cca_mode(dev, 1);
|
2015-04-02 17:39:10 +02:00
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
kw2xrf_set_rx_watermark(dev, 1);
|
2015-04-02 17:09:29 +02:00
|
|
|
|
2022-07-28 18:27:16 +02:00
|
|
|
if (!IS_ACTIVE(CONFIG_IEEE802154_AUTO_ACK_DISABLE)) {
|
|
|
|
kw2xrf_set_option(dev, KW2XRF_OPT_AUTOACK, true);
|
|
|
|
}
|
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
kw2xrf_set_option(dev, KW2XRF_OPT_ACK_REQ, true);
|
|
|
|
kw2xrf_set_option(dev, KW2XRF_OPT_AUTOCCA, true);
|
2015-04-02 17:09:29 +02:00
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
kw2xrf_set_power_mode(dev, KW2XRF_AUTODOZE);
|
|
|
|
kw2xrf_set_sequence(dev, dev->idle_state);
|
2015-04-02 17:39:10 +02:00
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
kw2xrf_clear_dreg_bit(dev, MKW2XDM_PHY_CTRL2, MKW2XDM_PHY_CTRL2_SEQMSK);
|
2015-04-02 17:09:29 +02:00
|
|
|
|
2016-05-20 17:13:31 +02:00
|
|
|
kw2xrf_enable_irq_b(dev);
|
2015-04-02 17:09:29 +02:00
|
|
|
|
2018-11-13 21:11:28 +01:00
|
|
|
DEBUG("[kw2xrf] init phy and (re)set to channel %d.\n",
|
|
|
|
KW2XRF_DEFAULT_CHANNEL);
|
2015-04-02 17:09:29 +02:00
|
|
|
}
|