From 97843ed32218752de08b32e5bcf13156fa1427b6 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 22 Sep 2016 11:27:18 +0200 Subject: [PATCH 1/5] cc1200: use Hz instead of kHz for channel spacing --- dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c | 4 ++-- dev/cc1200/cc1200-rf-cfg.h | 4 ++-- dev/cc1200/cc1200.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c b/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c index 95fae730c..27d504a45 100644 --- a/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c +++ b/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c @@ -47,8 +47,8 @@ /* Base frequency in kHz */ #define RF_CFG_CHAN_CENTER_F0 863125 -/* Channel spacing in kHz */ -#define RF_CFG_CHAN_SPACING 200 +/* Channel spacing in Hz */ +#define RF_CFG_CHAN_SPACING 200000 /* The minimum channel */ #define RF_CFG_MIN_CHANNEL 0 /* The maximum channel */ diff --git a/dev/cc1200/cc1200-rf-cfg.h b/dev/cc1200/cc1200-rf-cfg.h index c7ba53527..18d795c77 100644 --- a/dev/cc1200/cc1200-rf-cfg.h +++ b/dev/cc1200/cc1200-rf-cfg.h @@ -69,8 +69,8 @@ typedef struct cc1200_rf_cfg { rtimer_clock_t tx_pkt_lifetime; /* Base frequency in kHz */ uint32_t chan_center_freq0; - /* Channel spacing in kHz */ - uint16_t chan_spacing; + /* Channel spacing in Hz */ + uint32_t chan_spacing; /* The minimum channel */ uint8_t min_channel; /* The maximum channel */ diff --git a/dev/cc1200/cc1200.c b/dev/cc1200/cc1200.c index 013c54ee6..490ffcb26 100644 --- a/dev/cc1200/cc1200.c +++ b/dev/cc1200/cc1200.c @@ -2013,7 +2013,7 @@ calculate_freq(uint8_t channel) uint32_t freq; - freq = CC1200_RF_CFG.chan_center_freq0 + channel * CC1200_RF_CFG.chan_spacing; + freq = CC1200_RF_CFG.chan_center_freq0 + (channel * CC1200_RF_CFG.chan_spacing) / 1000 /* /1000 because chan_spacing is in Hz */; freq *= FREQ_MULTIPLIER; freq /= FREQ_DIVIDER; From 622d57643937f40facac06b5a3c3e060cce86ade Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 22 Sep 2016 11:28:27 +0200 Subject: [PATCH 2/5] cc1200: configure RSSI offset as part of cc1200_rf_cfg --- dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c | 3 +++ dev/cc1200/cc1200-conf.h | 12 ------------ dev/cc1200/cc1200-rf-cfg.h | 3 +++ dev/cc1200/cc1200.c | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c b/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c index 27d504a45..f7e7a0b62 100644 --- a/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c +++ b/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c @@ -57,6 +57,8 @@ #define RF_CFG_MAX_TXPOWER CC1200_CONST_TX_POWER_MAX /* The carrier sense level used for CCA in dBm */ #define RF_CFG_CCA_THRESHOLD (-91) +/* The RSSI offset in dBm */ +#define RF_CFG_RSSI_OFFSET (-81) /*---------------------------------------------------------------------------*/ static const char rf_cfg_descriptor[] = "802.15.4g 863-870MHz MR-FSK mode #1"; /*---------------------------------------------------------------------------*/ @@ -162,5 +164,6 @@ const cc1200_rf_cfg_t cc1200_802154g_863_870_fsk_50kbps = { .max_channel = RF_CFG_MAX_CHANNEL, .max_txpower = RF_CFG_MAX_TXPOWER, .cca_threshold = RF_CFG_CCA_THRESHOLD, + .rssi_offset = RF_CFG_RSSI_OFFSET, }; /*---------------------------------------------------------------------------*/ diff --git a/dev/cc1200/cc1200-conf.h b/dev/cc1200/cc1200-conf.h index 9d28922a4..27dc6eb6e 100644 --- a/dev/cc1200/cc1200-conf.h +++ b/dev/cc1200/cc1200-conf.h @@ -121,18 +121,6 @@ #define CC1200_RF_CFG cc1200_802154g_863_870_fsk_50kbps #endif /*---------------------------------------------------------------------------*/ -/* - * The RSSI offset in dBm (int8_t) - * - * Might be hardware dependent, so we make it a configuration parameter. - * This parameter is written to AGC_GAIN_ADJUST.GAIN_ADJUSTMENT - */ -#ifdef CC1200_CONF_RSSI_OFFSET -#define CC1200_RSSI_OFFSET CC1200_CONF_RSSI_OFFSET -#else -#define CC1200_RSSI_OFFSET (-81) -#endif -/*---------------------------------------------------------------------------*/ /* * The frequency offset * diff --git a/dev/cc1200/cc1200-rf-cfg.h b/dev/cc1200/cc1200-rf-cfg.h index 18d795c77..57af1f85a 100644 --- a/dev/cc1200/cc1200-rf-cfg.h +++ b/dev/cc1200/cc1200-rf-cfg.h @@ -82,6 +82,9 @@ typedef struct cc1200_rf_cfg { * CC1200_CONST_CCA_THRESHOLD_MIN and CC1200_CONST_CCA_THRESHOLD_MAX. */ int8_t cca_threshold; + /* The RSSI offset in dBm. + * -99 when MDMCFG1.DVGA_GAIN=00, -81 when MDMCFG1.DVGA_GAIN=01 */ + int8_t rssi_offset; } cc1200_rf_cfg_t; /*---------------------------------------------------------------------------*/ #endif /* CC1200_RF_CFG_H */ diff --git a/dev/cc1200/cc1200.c b/dev/cc1200/cc1200.c index 490ffcb26..6e766855a 100644 --- a/dev/cc1200/cc1200.c +++ b/dev/cc1200/cc1200.c @@ -1459,7 +1459,7 @@ configure(void) #endif /* RSSI offset */ - single_write(CC1200_AGC_GAIN_ADJUST, (int8_t)CC1200_RSSI_OFFSET); + single_write(CC1200_AGC_GAIN_ADJUST, (int8_t)CC1200_RF_CFG.rssi_offset); /*************************************************************************** * RF test modes needed during hardware development From 086499a864da7622ed8461b09cece640a554cc44 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 22 Sep 2016 11:29:03 +0200 Subject: [PATCH 3/5] cc1200: added configuration for 868 MHz 2-FSK at 1.2 kbps --- dev/cc1200/cc1200-868-fsk-1-2kbps.c | 136 ++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 dev/cc1200/cc1200-868-fsk-1-2kbps.c diff --git a/dev/cc1200/cc1200-868-fsk-1-2kbps.c b/dev/cc1200/cc1200-868-fsk-1-2kbps.c new file mode 100644 index 000000000..390779e1f --- /dev/null +++ b/dev/cc1200/cc1200-868-fsk-1-2kbps.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2015, Weptech elektronik GmbH Germany + * http://www.weptech.de + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of the copyright holder 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. + * + * This file is part of the Contiki operating system. + */ + +#include "cc1200-rf-cfg.h" +#include "cc1200-const.h" + +/* + * This is a setup for the following configuration: + * + * cc1200 at 1.2 kbps, 2-FSK, 12.5 kHz Channel Spacing (868 MHz). + */ + +/* Base frequency in kHz */ +#define RF_CFG_CHAN_CENTER_F0 867787 +/* Channel spacing in Hz */ +#define RF_CFG_CHAN_SPACING 12500 +/* The minimum channel */ +#define RF_CFG_MIN_CHANNEL 0 +/* The maximum channel */ +#define RF_CFG_MAX_CHANNEL 33 +/* The maximum output power in dBm */ +#define RF_CFG_MAX_TXPOWER CC1200_CONST_TX_POWER_MAX +/* The carrier sense level used for CCA in dBm */ +#define RF_CFG_CCA_THRESHOLD (-91) +/* The RSSI offset in dBm */ +#define RF_CFG_RSSI_OFFSET (-99) +/*---------------------------------------------------------------------------*/ +static const char rf_cfg_descriptor[] = "868MHz 2-FSK 1.2 kbps"; +/*---------------------------------------------------------------------------*/ +/* + * Register settings exported from SmartRF Studio using the standard template + * "trxEB RF Settings Performance Line". + */ + +// Modulation format = 2-FSK +// Whitening = false +// Symbol rate = 1.2 +// Deviation = 3.986359 +// Carrier frequency = 867.999878 +// Manchester enable = false +// Bit rate = 1.2 +// RX filter BW = 10.964912 + +static const registerSetting_t preferredSettings[]= +{ + {CC1200_IOCFG2, 0x06}, + {CC1200_DEVIATION_M, 0xD1}, + {CC1200_MODCFG_DEV_E, 0x00}, + {CC1200_DCFILT_CFG, 0x5D}, + {CC1200_PREAMBLE_CFG0, 0x8A}, + {CC1200_IQIC, 0xCB}, + {CC1200_CHAN_BW, 0xA6}, + {CC1200_MDMCFG1, 0x40}, + {CC1200_MDMCFG0, 0x05}, + {CC1200_SYMBOL_RATE2, 0x3F}, + {CC1200_SYMBOL_RATE1, 0x75}, + {CC1200_SYMBOL_RATE0, 0x10}, + {CC1200_AGC_REF, 0x20}, + {CC1200_AGC_CS_THR, 0xEC}, + {CC1200_AGC_CFG1, 0x51}, + {CC1200_AGC_CFG0, 0x87}, + {CC1200_FIFO_CFG, 0x00}, + {CC1200_FS_CFG, 0x12}, + {CC1200_PKT_CFG2, 0x00}, + {CC1200_PKT_CFG0, 0x20}, + {CC1200_PKT_LEN, 0xFF}, + {CC1200_IF_MIX_CFG, 0x1C}, + {CC1200_FREQOFF_CFG, 0x22}, + {CC1200_MDMCFG2, 0x0C}, + {CC1200_FREQ2, 0x56}, + {CC1200_FREQ1, 0xCC}, + {CC1200_FREQ0, 0xCC}, + {CC1200_IF_ADC1, 0xEE}, + {CC1200_IF_ADC0, 0x10}, + {CC1200_FS_DIG1, 0x07}, + {CC1200_FS_DIG0, 0xAF}, + {CC1200_FS_CAL1, 0x40}, + {CC1200_FS_CAL0, 0x0E}, + {CC1200_FS_DIVTWO, 0x03}, + {CC1200_FS_DSM0, 0x33}, + {CC1200_FS_DVC0, 0x17}, + {CC1200_FS_PFD, 0x00}, + {CC1200_FS_PRE, 0x6E}, + {CC1200_FS_REG_DIV_CML, 0x1C}, + {CC1200_FS_SPARE, 0xAC}, + {CC1200_FS_VCO0, 0xB5}, + {CC1200_XOSC5, 0x0E}, + {CC1200_XOSC1, 0x03}, +}; +/*---------------------------------------------------------------------------*/ +/* Global linkage: symbol name must be different in each exported file! */ +const cc1200_rf_cfg_t cc1200_868_fsk_1_2kbps = { + .cfg_descriptor = rf_cfg_descriptor, + .register_settings = preferredSettings, + .size_of_register_settings = sizeof(preferredSettings), + .tx_pkt_lifetime = (2 * RTIMER_SECOND), + .chan_center_freq0 = RF_CFG_CHAN_CENTER_F0, + .chan_spacing = RF_CFG_CHAN_SPACING, + .min_channel = RF_CFG_MIN_CHANNEL, + .max_channel = RF_CFG_MAX_CHANNEL, + .max_txpower = RF_CFG_MAX_TXPOWER, + .cca_threshold = RF_CFG_CCA_THRESHOLD, + .rssi_offset = RF_CFG_RSSI_OFFSET, +}; +/*---------------------------------------------------------------------------*/ From 5dd3d0369998d1d178d4b6860e7a94466647bfe8 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 23 Sep 2016 09:07:58 +0200 Subject: [PATCH 4/5] cc1200: call watchdog_periodic while in busy-wait --- dev/cc1200/cc1200.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/cc1200/cc1200.c b/dev/cc1200/cc1200.c index 6e766855a..6cb1d1be6 100644 --- a/dev/cc1200/cc1200.c +++ b/dev/cc1200/cc1200.c @@ -40,6 +40,7 @@ #include "net/netstack.h" #include "net/packetbuf.h" #include "net/rime/rimestats.h" +#include "dev/watchdog.h" #include "dev/leds.h" @@ -289,7 +290,9 @@ extern const cc1200_rf_cfg_t CC1200_RF_CFG; do { \ rtimer_clock_t t0; \ t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) {} \ + while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) { \ + watchdog_periodic(); \ + } \ } while(0) /*---------------------------------------------------------------------------*/ #if CC1200_USE_GPIO2 From ba739f679e958ab29a328cb9f982e0857974042d Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 23 Sep 2016 09:39:58 +0200 Subject: [PATCH 5/5] cc1200: configurable tx-rx turaround time --- dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c | 1 + dev/cc1200/cc1200-868-fsk-1-2kbps.c | 1 + dev/cc1200/cc1200-rf-cfg.h | 2 ++ dev/cc1200/cc1200.c | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c b/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c index f7e7a0b62..0fe452999 100644 --- a/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c +++ b/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c @@ -158,6 +158,7 @@ const cc1200_rf_cfg_t cc1200_802154g_863_870_fsk_50kbps = { .register_settings = preferredSettings, .size_of_register_settings = sizeof(preferredSettings), .tx_pkt_lifetime = (RTIMER_SECOND / 20), + .tx_rx_turnaround = (RTIMER_SECOND / 100), .chan_center_freq0 = RF_CFG_CHAN_CENTER_F0, .chan_spacing = RF_CFG_CHAN_SPACING, .min_channel = RF_CFG_MIN_CHANNEL, diff --git a/dev/cc1200/cc1200-868-fsk-1-2kbps.c b/dev/cc1200/cc1200-868-fsk-1-2kbps.c index 390779e1f..7c8d52cb4 100644 --- a/dev/cc1200/cc1200-868-fsk-1-2kbps.c +++ b/dev/cc1200/cc1200-868-fsk-1-2kbps.c @@ -125,6 +125,7 @@ const cc1200_rf_cfg_t cc1200_868_fsk_1_2kbps = { .register_settings = preferredSettings, .size_of_register_settings = sizeof(preferredSettings), .tx_pkt_lifetime = (2 * RTIMER_SECOND), + .tx_rx_turnaround = (RTIMER_SECOND / 2), .chan_center_freq0 = RF_CFG_CHAN_CENTER_F0, .chan_spacing = RF_CFG_CHAN_SPACING, .min_channel = RF_CFG_MIN_CHANNEL, diff --git a/dev/cc1200/cc1200-rf-cfg.h b/dev/cc1200/cc1200-rf-cfg.h index 57af1f85a..4b206959b 100644 --- a/dev/cc1200/cc1200-rf-cfg.h +++ b/dev/cc1200/cc1200-rf-cfg.h @@ -67,6 +67,8 @@ typedef struct cc1200_rf_cfg { * synch word + phy header, payload + CRC. */ rtimer_clock_t tx_pkt_lifetime; + /* The maximum time it takes to switch from Tx to Rx */ + rtimer_clock_t tx_rx_turnaround; /* Base frequency in kHz */ uint32_t chan_center_freq0; /* Channel spacing in Hz */ diff --git a/dev/cc1200/cc1200.c b/dev/cc1200/cc1200.c index 6cb1d1be6..fef495e31 100644 --- a/dev/cc1200/cc1200.c +++ b/dev/cc1200/cc1200.c @@ -802,7 +802,7 @@ transmit(unsigned short transmit_len) */ BUSYWAIT_UNTIL_STATE(STATE_RX, - RTIMER_SECOND / 100); + CC1200_RF_CFG.tx_rx_turnaround); ENABLE_GPIO_INTERRUPTS();