Browse Source
Adapt the kw2xrf driver for the netdev2 interface. This patch also adds overwrites.h, the header provides overwrite values for the kw2xrf PHY.patch-1


16 changed files with 2783 additions and 1352 deletions
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief get/set interfaces for kw2xrf driver |
||||
* |
||||
* @author Johann Fischer <j.fischer@phytec.de> |
||||
*/ |
||||
|
||||
#include "kw2xrf.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
void kw2xrf_set_tx_power(kw2xrf_t *dev, int16_t txpower); |
||||
|
||||
uint16_t kw2xrf_get_txpower(kw2xrf_t *dev); |
||||
|
||||
uint8_t kw2xrf_get_channel(kw2xrf_t *dev); |
||||
|
||||
int kw2xrf_set_channel(kw2xrf_t *dev, uint8_t val); |
||||
|
||||
void kw2xrf_abort_sequence(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_set_idle_sequence(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_set_sequence(kw2xrf_t *dev, kw2xrf_physeq_t seq); |
||||
|
||||
void kw2xrf_set_pan(kw2xrf_t *dev, uint16_t pan); |
||||
|
||||
void kw2xrf_set_addr_short(kw2xrf_t *dev, uint16_t addr); |
||||
|
||||
void kw2xrf_set_addr_long(kw2xrf_t *dev, uint64_t addr); |
||||
|
||||
uint16_t kw2xrf_get_addr_short(kw2xrf_t *dev); |
||||
|
||||
uint64_t kw2xrf_get_addr_long(kw2xrf_t *dev); |
||||
|
||||
int8_t kw2xrf_get_cca_threshold(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_set_cca_threshold(kw2xrf_t *dev, int8_t value); |
||||
|
||||
void kw2xrf_set_cca_mode(kw2xrf_t *dev, uint8_t mode); |
||||
|
||||
uint8_t kw2xrf_get_cca_mode(kw2xrf_t *dev); |
||||
|
||||
uint32_t kw2xrf_get_rssi(uint32_t value); |
||||
|
||||
netopt_state_t kw2xrf_get_status(kw2xrf_t *dev); |
||||
|
||||
int kw2xrf_cca(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_set_rx_watermark(kw2xrf_t *dev, uint8_t value); |
||||
|
||||
void kw2xrf_set_option(kw2xrf_t *dev, uint16_t option, bool state); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
/** @} */ |
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief Internal function interfaces for kw2xrf driver |
||||
* |
||||
* @author Johann Fischer <j.fischer@phytec.de> |
||||
*/ |
||||
|
||||
#include <stdint.h> |
||||
#include "kw2xrf.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/** Power Modes */ |
||||
typedef enum { |
||||
KW2XRF_HIBERNATE = 0, |
||||
KW2XRF_DOZE, |
||||
KW2XRF_IDLE, |
||||
KW2XRF_AUTODOZE, |
||||
} kw2xrf_powermode_t; |
||||
|
||||
inline void kw2xrf_set_dreg_bit(kw2xrf_t *dev, uint8_t reg, uint8_t bit) |
||||
{ |
||||
uint8_t tmp = kw2xrf_read_dreg(dev, reg); |
||||
tmp |= bit; |
||||
kw2xrf_write_dreg(dev, reg, tmp); |
||||
} |
||||
|
||||
inline void kw2xrf_clear_dreg_bit(kw2xrf_t *dev, uint8_t reg, uint8_t bit) |
||||
{ |
||||
uint8_t tmp = kw2xrf_read_dreg(dev, reg); |
||||
tmp &= ~bit; |
||||
kw2xrf_write_dreg(dev, reg, tmp); |
||||
} |
||||
|
||||
/** Enable any transceiver interrupt to assert IRQ_B */ |
||||
inline void kw2xrf_enable_irq_b(kw2xrf_t *dev) |
||||
{ |
||||
kw2xrf_clear_dreg_bit(dev, MKW2XDM_PHY_CTRL4, MKW2XDM_PHY_CTRL4_TRCV_MSK); |
||||
} |
||||
|
||||
/** Mask all transceiver interrupts to assert IRQ_B */ |
||||
inline void kw2xrf_mask_irq_b(kw2xrf_t *dev) |
||||
{ |
||||
kw2xrf_set_dreg_bit(dev, MKW2XDM_PHY_CTRL4, MKW2XDM_PHY_CTRL4_TRCV_MSK); |
||||
} |
||||
|
||||
void kw2xrf_disable_interrupts(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_update_overwrites(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_set_out_clk(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_set_power_mode(kw2xrf_t *dev, kw2xrf_powermode_t pm); |
||||
|
||||
int kw2xrf_can_switch_to_idle(kw2xrf_t *dev); |
||||
|
||||
typedef enum kw2xrf_timer_timebase { |
||||
KW2XRF_TIMEBASE_500000HZ = 2, |
||||
KW2XRF_TIMEBASE_250000HZ, |
||||
KW2XRF_TIMEBASE_125000HZ, |
||||
KW2XRF_TIMEBASE_62500HZ, |
||||
KW2XRF_TIMEBASE_31250HZ, |
||||
KW2XRF_TIMEBASE_15625HZ, |
||||
} kw2xrf_timer_timebase_t; |
||||
|
||||
/**
|
||||
* Initialize the Event Timer Block (up counter) |
||||
* The Event Timer Block provides: |
||||
* - Abort an RX and CCA sequence at pre-determined time |
||||
* - Latches "timestamp" value during packet reception |
||||
* - Initiates timer-triggered sequences |
||||
*/ |
||||
void kw2xrf_timer_init(kw2xrf_t *dev, kw2xrf_timer_timebase_t tb); |
||||
|
||||
void kw2xrf_timer2_seq_start_on(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_timer2_seq_start_off(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_timer3_seq_abort_on(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_timer3_seq_abort_off(kw2xrf_t *dev); |
||||
|
||||
/**
|
||||
* Use T2CMP or T2PRIMECMP to Trigger Transceiver Operations |
||||
*/ |
||||
void kw2xrf_trigger_tx_ops_enable(kw2xrf_t *dev, uint32_t timeout); |
||||
|
||||
/**
|
||||
* Disable Trigger for Transceiver Operations |
||||
* |
||||
*/ |
||||
void kw2xrf_trigger_tx_ops_disable(kw2xrf_t *dev); |
||||
|
||||
/**
|
||||
* Use T3CMP to Abort an RX operation |
||||
*/ |
||||
void kw2xrf_abort_rx_ops_enable(kw2xrf_t *dev, uint32_t timeout); |
||||
|
||||
/**
|
||||
* Disable Trigger to Abort an RX operation |
||||
*/ |
||||
void kw2xrf_abort_rx_ops_disable(kw2xrf_t *dev); |
||||
|
||||
void kw2xrf_seq_timeout_on(kw2xrf_t *dev, uint32_t timeout); |
||||
|
||||
void kw2xrf_seq_timeout_off(kw2xrf_t *dev); |
||||
|
||||
/**
|
||||
* Returns Timestamp of the actual received packet |
||||
*/ |
||||
uint32_t kw2xrf_get_timestamp(kw2xrf_t *dev); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
/** @} */ |
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief Netdev interface for kw2xrf driver |
||||
* |
||||
* @author Johann Fischer <j.fischer@phytec.de> |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Reference to the netdev device driver struct |
||||
*/ |
||||
extern const netdev2_driver_t kw2xrf_driver; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
/** @} */ |
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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_kw2xrf |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief Testing interfaces for kw2xrf driver |
||||
* |
||||
* @author Johann Fischer <j.fischer@phytec.de> |
||||
*/ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#ifdef KW2XRF_TESTMODE |
||||
|
||||
#include "kw2xrf.h" |
||||
#include "kw2xrf_reg.h" |
||||
#include "kw2xrf_getset.h" |
||||
#include "net/netopt.h" |
||||
|
||||
enum mkw2xrf_testmode { |
||||
KW2XRF_TM_CTX_PREAMBLE = NETOPT_RF_TESTMODE_CTX_PRBS9 + 1, |
||||
KW2XRF_TM_CTX_2MHZ, |
||||
KW2XRF_TM_CTX_200KHZ, |
||||
KW2XRF_TM_CTX_1MBPS_PRBS9, |
||||
KW2XRF_TM_CTX_EXT, |
||||
KW2XRF_TM_CTX_NM0, |
||||
KW2XRF_TM_CTX_NM1, |
||||
}; |
||||
|
||||
int kw2xrf_set_test_mode(kw2xrf_t *dev, uint8_t mode); |
||||
|
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
/** @} */ |
@ -0,0 +1,308 @@
|
||||
/*!
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc. |
||||
* All rights reserved. |
||||
* |
||||
* \file MCR20Overwrites.h |
||||
* Description: Overwrites header file for MCR20 Register values |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* |
||||
* o Redistributions of source code must retain the above copyright notice, this list |
||||
* of conditions and the following disclaimer. |
||||
* |
||||
* o Redistributions in binary form must reproduce the above copyright notice, this |
||||
* list of conditions and the following disclaimer in the documentation and/or |
||||
* other materials provided with the distribution. |
||||
* |
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from this |
||||
* software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef OVERWRITES_H_ |
||||
#define OVERWRITES_H_ |
||||
|
||||
typedef struct overwrites_tag { |
||||
char address; |
||||
char data; |
||||
} overwrites_t; |
||||
|
||||
|
||||
/*****************************************************************************************************************/ |
||||
// This file is created exclusively for use with the transceiver 2.0 silicon
|
||||
// and is provided for the world to use. It contains a list of all
|
||||
// known overwrite values. Overwrite values are non-default register
|
||||
// values that configure the transceiver device to a more optimally performing
|
||||
// posture. It is expected that low level software (i.e. PHY) will
|
||||
// consume this file as a #include, and transfer the contents to the
|
||||
// the indicated addresses in the transceiver's memory space. This file has
|
||||
// at least one required entry, that being its own version current version
|
||||
// number, to be stored at transceiver's location 0x3B the
|
||||
// OVERWRITES_VERSION_NUMBER register. The RAM register is provided in
|
||||
// the transceiver address space to assist in future debug efforts. The
|
||||
// analyst may read this location (once device has been booted with
|
||||
// mysterious software) and have a good indication of what register
|
||||
// overwrites were performed (with all versions of the overwrites.h file
|
||||
// being archived forever at the Compass location shown above.
|
||||
//
|
||||
// The transceiver has an indirect register (IAR) space. Write access to this space
|
||||
// requires 3 or more writes:
|
||||
// 1st) the first write is an index value to the indirect (write Bit7=0, register access Bit 6=0) + 0x3E
|
||||
// 2nd) IAR Register #0x00 - 0xFF.
|
||||
// 3rd) The data to write
|
||||
// nth) Burst mode additional data if required.
|
||||
//
|
||||
// Write access to direct space requires only a single address, data pair.
|
||||
|
||||
overwrites_t const overwrites_direct[] ={ |
||||
{0x3B, 0x0C}, //version 0C: new value for ACKDELAY targeting 198us (23 May, 2013, Larry Roshak)
|
||||
{0x23, 0x17} //PA_PWR new default Power Step is "23"
|
||||
}; |
||||
|
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1 override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07}, //VCO_CTRL2 override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
{0x8A, 0x71}, //PA_TUNING override PA_COILTUNING to 001 (27 Nov 2012, D. Brown, on behalf of S. Eid)
|
||||
{0x79, 0x2F}, //CHF_IBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7A, 0x2F}, //CHF_QBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7B, 0x24}, //CHF_IRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7C, 0x24}, //CHF_QRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7D, 0x24}, //CHF_IL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7E, 0x24}, //CHF_QL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7F, 0x32}, //CHF_CC1 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x80, 0x1D}, //CHF_CCL Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x81, 0x2D}, //CHF_CC2 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x82, 0x24}, //CHF_IROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x83, 0x24}, //CHF_QROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x64, 0x28}, //PA_CAL_DIS=1 Disabled PA calibration
|
||||
{0x52, 0x55}, //AGC_THR1 RSSI tune up
|
||||
{0x53, 0x2D}, //AGC_THR2 RSSI tune up
|
||||
{0x66, 0x5F}, //ATT_RSSI1 tune up
|
||||
{0x67, 0x8F}, //ATT_RSSI2 tune up
|
||||
{0x68, 0x61}, //RSSI_OFFSET
|
||||
{0x78, 0x03}, //CHF_PMAGAIN
|
||||
{0x22, 0x50}, //CCA1_THRESH
|
||||
{0x4D, 0x13}, //CORR_NVAL moved from 0x14 to 0x13 for 0.5 dB improved Rx Sensitivity
|
||||
{0x39, 0x3D} //ACKDELAY new value targeting a delay of 198us (23 May, 2013, Larry Roshak)
|
||||
}; |
||||
|
||||
|
||||
/* begin of deprecated versions
|
||||
|
||||
==VERSION 1== |
||||
(version 1 is empty) |
||||
|
||||
==VERSION 2== |
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02} //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
}; |
||||
|
||||
==VERSION 3== |
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1: override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07} //VCO_CTRL2: override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
}; |
||||
|
||||
==VERSION 4== |
||||
overwrites_t const overwrites_direct[] ={ |
||||
{0x3B, 0x04} //version 04 is the current version: update PA_COILTUNING default
|
||||
}; |
||||
|
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1: override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07} //VCO_CTRL2: override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
{0x8A, 0x71} //PA_TUNING: override PA_COILTUNING to 001 (27 Nov 2012, D. Brown, on behalf of S. Eid)
|
||||
}; |
||||
|
||||
==VERSION 5== |
||||
overwrites_t const overwrites_direct[] ={ |
||||
{0x3B, 0x05} //version 05: updates Channel Filter Register set (21 Dec 2012, on behalf of S. Soca)
|
||||
}; |
||||
|
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1 override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07} //VCO_CTRL2 override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
{0x8A, 0x71} //PA_TUNING override PA_COILTUNING to 001 (27 Nov 2012, D. Brown, on behalf of S. Eid)
|
||||
{0x79, 0x2F} //CHF_IBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7A, 0x2F} //CHF_QBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7B, 0x24} //CHF_IRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7C, 0x24} //CHF_QRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7D, 0x24} //CHF_IL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7E, 0x24} //CHF_QL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x82, 0x24} //CHF_IROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x83, 0x24} //CHF_QROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7F, 0x32} //CHF_CC1 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x80, 0x1D} //CHF_CCL Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x81, 0x2D} //CHF_CC2 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
}; |
||||
|
||||
==VERSION 6== |
||||
overwrites_t const overwrites_direct[] ={ |
||||
{0x3B, 0x06} //version 06: disable PA calibration
|
||||
}; |
||||
|
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1 override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07} //VCO_CTRL2 override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
{0x8A, 0x71} //PA_TUNING override PA_COILTUNING to 001 (27 Nov 2012, D. Brown, on behalf of S. Eid)
|
||||
{0x79, 0x2F} //CHF_IBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7A, 0x2F} //CHF_QBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7B, 0x24} //CHF_IRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7C, 0x24} //CHF_QRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7D, 0x24} //CHF_IL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7E, 0x24} //CHF_QL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x82, 0x24} //CHF_IROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x83, 0x24} //CHF_QROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7F, 0x32} //CHF_CC1 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x80, 0x1D} //CHF_CCL Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x81, 0x2D} //CHF_CC2 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x64, 0x28} //PA_CAL_DIS=1 Disabled PA calibration
|
||||
}; |
||||
|
||||
==VERSION 7== |
||||
overwrites_t const overwrites_direct[] ={ |
||||
{0x3B, 0x07} //version 07: updated registers for ED/RSSI
|
||||
}; |
||||
|
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1 override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07}, //VCO_CTRL2 override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
{0x8A, 0x71}, //PA_TUNING override PA_COILTUNING to 001 (27 Nov 2012, D. Brown, on behalf of S. Eid)
|
||||
{0x79, 0x2F}, //CHF_IBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7A, 0x2F}, //CHF_QBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7B, 0x24}, //CHF_IRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7C, 0x24}, //CHF_QRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7D, 0x24}, //CHF_IL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7E, 0x24}, //CHF_QL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x82, 0x24}, //CHF_IROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x83, 0x24}, //CHF_QROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7F, 0x32}, //CHF_CC1 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x80, 0x1D}, //CHF_CCL Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x81, 0x2D}, //CHF_CC2 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x64, 0x28}, //PA_CAL_DIS=1 Disabled PA calibration
|
||||
{0x52, 0x73}, //AGC_THR1 RSSI tune up
|
||||
{0x53, 0x2D}, //AGC_THR2 RSSI tune up
|
||||
{0x66, 0x5F}, //ATT_RSSI1 tune up
|
||||
{0x67, 0x8F}, //ATT_RSSI2 tune up
|
||||
{0x68, 0x60}, //RSSI_OFFSET
|
||||
{0x69, 0x65} //RSSI_SLOPE
|
||||
}; |
||||
|
||||
|
||||
==VERSION 8== |
||||
overwrites_t const overwrites_direct[] ={ |
||||
{0x3B, 0x08} //version 08: updated registers for ED/RSSI
|
||||
}; |
||||
|
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1 override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07}, //VCO_CTRL2 override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
{0x8A, 0x71}, //PA_TUNING override PA_COILTUNING to 001 (27 Nov 2012, D. Brown, on behalf of S. Eid)
|
||||
{0x79, 0x2F}, //CHF_IBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7A, 0x2F}, //CHF_QBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7B, 0x24}, //CHF_IRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7C, 0x24}, //CHF_QRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7D, 0x24}, //CHF_IL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7E, 0x24}, //CHF_QL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x82, 0x24}, //CHF_IROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x83, 0x24}, //CHF_QROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7F, 0x32}, //CHF_CC1 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x80, 0x1D}, //CHF_CCL Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x81, 0x2D}, //CHF_CC2 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x64, 0x28}, //PA_CAL_DIS=1 Disabled PA calibration
|
||||
{0x52, 0x73}, //AGC_THR1 RSSI tune up
|
||||
{0x53, 0x2D}, //AGC_THR2 RSSI tune up
|
||||
{0x66, 0x5F}, //ATT_RSSI1 tune up
|
||||
{0x67, 0x8F}, //ATT_RSSI2 tune up
|
||||
{0x69, 0x65} //RSSI_SLOPE
|
||||
{0x68, 0x61}, //RSSI_OFFSET
|
||||
{0x78, 0x03} //CHF_PMAGAIN
|
||||
}; |
||||
|
||||
|
||||
==VERSION 9== |
||||
overwrites_t const overwrites_direct[] ={ |
||||
{0x3B, 0x09} //version 09: updated registers for ED/RSSI and PowerStep
|
||||
{0x23, 0x17} //PA_PWR new default value
|
||||
}; |
||||
|
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1 override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07}, //VCO_CTRL2 override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
{0x8A, 0x71}, //PA_TUNING override PA_COILTUNING to 001 (27 Nov 2012, D. Brown, on behalf of S. Eid)
|
||||
{0x79, 0x2F}, //CHF_IBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7A, 0x2F}, //CHF_QBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7B, 0x24}, //CHF_IRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7C, 0x24}, //CHF_QRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7D, 0x24}, //CHF_IL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7E, 0x24}, //CHF_QL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7F, 0x32}, //CHF_CC1 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x80, 0x1D}, //CHF_CCL Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x81, 0x2D}, //CHF_CC2 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x82, 0x24}, //CHF_IROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x83, 0x24}, //CHF_QROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x64, 0x28}, //PA_CAL_DIS=1 Disabled PA calibration
|
||||
{0x52, 0x55}, //AGC_THR1 RSSI tune up
|
||||
{0x53, 0x2D}, //AGC_THR2 RSSI tune up
|
||||
{0x66, 0x5F}, //ATT_RSSI1 tune up
|
||||
{0x67, 0x8F}, //ATT_RSSI2 tune up
|
||||
{0x68, 0x61}, //RSSI_OFFSET
|
||||
{0x78, 0x03} //CHF_PMAGAIN
|
||||
}; |
||||
|
||||
==VERSION A== |
||||
overwrites_t const overwrites_direct[] ={ |
||||
{0x3B, 0x0A} //version 0A: updated registers for CCA
|
||||
{0x23, 0x17} //PA_PWR new default Power Step is "23"
|
||||
}; |
||||
|
||||
overwrites_t const overwrites_indirect[] ={ |
||||
{0x31, 0x02}, //clear MISO_HIZ_EN (for single SPI master/slave pair) and SPI_PUL_EN (minimize HIB currents)
|
||||
{0x91, 0xB3}, //VCO_CTRL1 override VCOALC_REF_TX to 3
|
||||
{0x92, 0x07}, //VCO_CTRL2 override VCOALC_REF_RX to 3, keep VCO_BUF_BOOST = 1
|
||||
{0x8A, 0x71}, //PA_TUNING override PA_COILTUNING to 001 (27 Nov 2012, D. Brown, on behalf of S. Eid)
|
||||
{0x79, 0x2F}, //CHF_IBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7A, 0x2F}, //CHF_QBUF Adjust the gm-C filter gain (+/- 6dB) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7B, 0x24}, //CHF_IRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7C, 0x24}, //CHF_QRIN Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7D, 0x24}, //CHF_IL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7E, 0x24}, //CHF_QL Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x7F, 0x32}, //CHF_CC1 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x80, 0x1D}, //CHF_CCL Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x81, 0x2D}, //CHF_CC2 Adjust the filter center frequency (+/- 1MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x82, 0x24}, //CHF_IROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x83, 0x24}, //CHF_QROUT Adjust the filter bandwidth (+/- 0.5MHz) (21 Dec, 2012, on behalf of S. Soca)
|
||||
{0x64, 0x28}, //PA_CAL_DIS=1 Disabled PA calibration
|
||||
{0x52, 0x55}, //AGC_THR1 RSSI tune up
|
||||
{0x53, 0x2D}, //AGC_THR2 RSSI tune up
|
||||
{0x66, 0x5F}, //ATT_RSSI1 tune up
|
||||
{0x67, 0x8F}, //ATT_RSSI2 tune up
|
||||
{0x68, 0x61}, //RSSI_OFFSET
|
||||
{0x78, 0x03} //CHF_PMAGAIN
|
||||
{0x22, 0x50} //CCA1_THRESH
|
||||
}; |
||||
|
||||
end of deprecated versions */ |
||||
|
||||
|
||||
#endif //OVERWRITES_H_
|
@ -0,0 +1,516 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 drivers_kw2xrf |
||||
* @{ |
||||
* @file |
||||
* @brief get/set functionality of kw2xrf driver |
||||
* |
||||
* @author Johann Fischer <j.fischer@phytec.de> |
||||
* @author Jonas Remmert <j.remmert@phytec.de> |
||||
* @author Oliver Hahm <oliver.hahm@inria.fr> |
||||
* @} |
||||
*/ |
||||
|
||||
#include "kw2xrf.h" |
||||
#include "kw2xrf_spi.h" |
||||
#include "kw2xrf_reg.h" |
||||
#include "kw2xrf_getset.h" |
||||
#include "kw2xrf_intern.h" |
||||
|
||||
#define ENABLE_DEBUG (0) |
||||
#include "debug.h" |
||||
|
||||
#define KW2XRF_LQI_HW_MAX 230 /**< LQI Saturation Level */ |
||||
|
||||
/* Modem_PA_PWR Register (PA Power Control) has a valid range from 3-31 */ |
||||
#define MKW2XDRF_PA_RANGE_MAX 31 /**< Maximum value of PA Power Control Register */ |
||||
#define MKW2XDRF_PA_RANGE_MIN 3 /**< Minimum value of PA Power Control Register */ |
||||
|
||||
/* PLL integer and fractional lookup tables
|
||||
* |
||||
* Fc = 2405 + 5(k - 11) , k = 11,12,...,26 |
||||
* |
||||
* Equation for PLL frequency, MKW2xD Reference Manual, p.255 : |
||||
* F = ((PLL_INT0 + 64) + (PLL_FRAC0/65536))32MHz |
||||
* |
||||
*/ |
||||
static const uint8_t pll_int_lt[16] = { |
||||
11, 11, 11, 11, |
||||
11, 11, 12, 12, |
||||
12, 12, 12, 12, |
||||
13, 13, 13, 13 |
||||
}; |
||||
|
||||
static const uint16_t pll_frac_lt[16] = { |
||||
10240, 20480, 30720, 40960, |
||||
51200, 61440, 6144, 16384, |
||||
26624, 36864, 47104, 57344, |
||||
2048, 12288, 22528, 32768 |
||||
}; |
||||
|
||||
static const uint8_t pow_lt[44] = { |
||||
3, 4, 4, 5, |
||||
6, 6, 7, 7, |
||||
8, 9, 9, 10, |
||||
11, 11, 12, 13, |
||||
13, 14, 14, 15, |
||||
16, 16, 17, 18, |
||||
18, 19, 20, 20, |
||||
21, 21, 22, 23, |
||||
23, 24, 25, 25, |
||||
26, 27, 27, 28, |
||||
28, 29, 30, 31 |
||||
}; |
||||
|
||||
void kw2xrf_set_tx_power(kw2xrf_t *dev, int16_t txpower) |
||||
{ |
||||
if (txpower > MKW2XDRF_OUTPUT_POWER_MAX) { |
||||
txpower = MKW2XDRF_OUTPUT_POWER_MAX; |
||||
} |
||||
|
||||
if (txpower < MKW2XDRF_OUTPUT_POWER_MIN) { |
||||
txpower = MKW2XDRF_OUTPUT_POWER_MIN; |
||||
} |
||||
|
||||
uint8_t level = pow_lt[txpower - MKW2XDRF_OUTPUT_POWER_MIN]; |
||||
kw2xrf_write_dreg(dev, MKW2XDM_PA_PWR, MKW2XDM_PA_PWR(level)); |
||||
dev->tx_power = txpower; |
||||
} |
||||
|
||||
uint16_t kw2xrf_get_txpower(kw2xrf_t *dev) |
||||
{ |
||||
return dev->tx_power; |
||||
} |
||||
|
||||
uint8_t kw2xrf_get_channel(kw2xrf_t *dev) |
||||
{ |
||||
uint8_t pll_int = kw2xrf_read_dreg(dev, MKW2XDM_PLL_INT0); |
||||
uint16_t pll_frac = kw2xrf_read_dreg(dev, MKW2XDM_PLL_FRAC0_LSB); |
||||
pll_frac |= ((uint16_t)kw2xrf_read_dreg(dev, MKW2XDM_PLL_FRAC0_MSB) << 8); |
||||
|
||||
for (int i = 0; i < 16; i++) { |
||||
if ((pll_frac_lt[i] == pll_frac) && (pll_int_lt[i] == pll_int)) { |
||||
return i + 11; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static int kw2xrf_get_sequence(kw2xrf_t *dev) |
||||
{ |
||||
int reg = 0; |
||||
reg = kw2xrf_read_dreg(dev, MKW2XDM_PHY_CTRL1); |
||||
reg &= MKW2XDM_PHY_CTRL1_XCVSEQ_MASK; |
||||
return reg; |
||||
} |
||||
|
||||
int kw2xrf_set_channel(kw2xrf_t *dev, uint8_t channel) |
||||
{ |
||||
/* Save old sequence to restore this state later */ |
||||
uint8_t old_seq = kw2xrf_get_sequence(dev); |
||||
|
||||
if (channel < KW2XRF_MIN_CHANNEL || channel > KW2XRF_MAX_CHANNEL) { |
||||
DEBUG("[kw2xrf]: Invalid channel %i set\n", channel); |
||||
return -1; |
||||
} |
||||
|
||||
if (old_seq) { |
||||
kw2xrf_abort_sequence(dev); |
||||
} |
||||
|
||||
uint8_t tmp = channel - 11; |
||||
kw2xrf_write_dreg(dev, MKW2XDM_PLL_INT0, MKW2XDM_PLL_INT0_VAL(pll_int_lt[tmp])); |
||||
kw2xrf_write_dreg(dev, MKW2XDM_PLL_FRAC0_LSB, (uint8_t)pll_frac_lt[tmp]); |
||||
kw2xrf_write_dreg(dev, MKW2XDM_PLL_FRAC0_MSB, (uint8_t)(pll_frac_lt[tmp] >> 8)); |
||||
|
||||
dev->netdev.chan = channel; |
||||
|
||||
if (old_seq) { |
||||
kw2xrf_set_sequence(dev, old_seq); |
||||
} |
||||
|
||||
DEBUG("[kw2xrf]: set channel to %u\n", channel); |
||||
return 0; |
||||
} |
||||
|
||||
|