1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/kw2xrf/kw2xrf_tm.c
smlng b283b7784c make: fix various compile errors with Wextra
pkg, nordic_softdevice_ble: disable CFLAGS to omit compiler error
        sys, pm_layered: fix casting nonscalar to the same type
        cpu, stm32_common: fix type-limits, remove always true assert
        cpu, stm32f4: fix pointer arithmetic in periph/i2c
        drivers, at86rf2xx: fix type-limits where condition always true
        saul, gpio: fix if no gpio configured for saul
        cpu, saml21: add frequency check to periph/timer
        driver, cc110x: fix unused param and type-limts errors
        boards, wsn430-common: fix old-style-declaration
        make: fix old style definition
        drivers, sdcard_spi: fix old style typedef
        driver, at30tse: remove unnecessary check
        driver, nrf24: fix type-limit
        driver, pn532: change buffer from char to uint8_t
        tests/driver_sdcard: fix type limits
        boards, feather-m0: add missing field inits
        driver, tcs37727: fix type limits
        pkg, emb6: disable some compiler warnings
        tests/emb6: disable some compiler warings
        pkg, openthread: fix sign compare and unused params
        tests/trickle: fix struct init
        tests/pthread_cooperation: fix type limits
        board, mips-malta: remove feature periph_uart
        shell: fix var size for netif command
        gnrc, netif: fix sign-compare
        gnrc, nib: fix sign-compare
        shell: fix output in netif command
        posix: fix type-limits in pthread_cond
2017-11-28 18:31:43 +01:00

182 lines
5.7 KiB
C

/*
* 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 Testing function of kw2xrf driver
*
* @author Johann Fischer <j.fischer@phytec.de>
*/
#include "kw2xrf.h"
#include "kw2xrf_spi.h"
#include "kw2xrf_reg.h"
#include "kw2xrf_tm.h"
#ifdef KW2XRF_TESTMODE
static inline void enable_xcvr_test_mode(kw2xrf_t *dev)
{
uint8_t reg;
kw2xrf_read_iregs(dev, MKW2XDMI_DTM_CTRL1, &reg, 1);
reg |= MKW2XDMI_DTM_CTRL1_DTM_EN;
kw2xrf_write_iregs(dev, MKW2XDMI_DTM_CTRL1, &reg, 1);
kw2xrf_read_iregs(dev, MKW2XDMI_TESTMODE_CTRL, &reg, 1);
reg |= MKW2XDMI_TESTMODE_CTRL_CONTINUOUS_EN | MKW2XDMI_TESTMODE_CTRL_IDEAL_PFC_EN;
kw2xrf_write_iregs(dev, MKW2XDMI_TESTMODE_CTRL, &reg, 1);
}
static inline void disable_xcvr_test_mode(kw2xrf_t *dev)
{
uint8_t reg;
kw2xrf_read_iregs(dev, MKW2XDMI_DTM_CTRL1, &reg, 1);
reg &= MKW2XDMI_DTM_CTRL1_DTM_EN;
kw2xrf_write_iregs(dev, MKW2XDMI_DTM_CTRL1, &reg, 1);
kw2xrf_read_iregs(dev, MKW2XDMI_TESTMODE_CTRL, &reg, 1);
reg &= ~(MKW2XDMI_TESTMODE_CTRL_CONTINUOUS_EN | MKW2XDMI_TESTMODE_CTRL_IDEAL_PFC_EN);
kw2xrf_write_iregs(dev, MKW2XDMI_TESTMODE_CTRL, &reg, 1);
}
int kw2xrf_set_test_mode(kw2xrf_t *dev, uint8_t mode)
{
uint8_t reg = 0;
uint8_t buf[2];
kw2xrf_abort_sequence(dev);
disable_xcvr_test_mode(dev);
kw2xrf_set_channel(dev, dev->netdev.chan);
switch(mode) {
case NETOPT_RF_TESTMODE_IDLE:
reg = 0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
kw2xrf_set_sequence(dev, XCVSEQ_IDLE);
break;
case NETOPT_RF_TESTMODE_CRX:
/* set continuous RX mode */
reg = 0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
/* set data length */
reg = 127;
kw2xrf_write_iregs(dev, MKW2XDMI_DUAL_PAN_DWELL, &reg, 1);
kw2xrf_set_sequence(dev, XCVSEQ_RECEIVE);
break;
case KW2XRF_TM_CTX_PREAMBLE:
/* set continuous TX mode, transmit 10101010 pattern */
reg = 0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
buf[0] = 1;
buf[1] = 0xaa;
kw2xrf_write_fifo(dev, buf, buf[0] + 1);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case NETOPT_RF_TESTMODE_CTX_CW:
/* set continuous TX mode, transmit unmodulated carrier */
reg = MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
/* fix pll frequency for cw mode */
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);
pll_frac -= 0x400;
kw2xrf_write_dreg(dev, MKW2XDM_PLL_FRAC0_LSB, (uint8_t)pll_frac);
kw2xrf_write_dreg(dev, MKW2XDM_PLL_FRAC0_MSB, (uint8_t)(pll_frac >> 8));
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_NM1:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_NM0:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS1;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_2MHZ:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS1 | MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_200KHZ:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS2;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_1MBPS_PRBS9:
/* set continuous TX mode, transmit PRBS9 pattern */
reg = MKW2XDMI_TX_MODE_CTRL_DTS2 | MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_EXT:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS2 | MKW2XDMI_TX_MODE_CTRL_DTS1;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case NETOPT_RF_TESTMODE_CTX_PRBS9:
/* set continuous TX mode, transmit PRBS9 pattern */
reg = MKW2XDMI_TX_MODE_CTRL_DTS2 | MKW2XDMI_TX_MODE_CTRL_DTS1
| MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, &reg, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
}
return 1;
}
#endif
/** @} */