Skip to content

Commit

Permalink
Merge pull request #5977 from miri64/ieee802154/enh/centralize-defaul…
Browse files Browse the repository at this point in the history
…t-values

ieee802154: centralize default values
  • Loading branch information
miri64 authored Oct 26, 2016
2 parents eb4ec4b + 964cd75 commit 9e97b0a
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 82 deletions.
18 changes: 6 additions & 12 deletions cpu/cc2538/include/cc2538_rf.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <stdbool.h>

#include "net/ieee802154.h"
#include "net/netdev2.h"
#include "net/netdev2/ieee802154.h"

Expand All @@ -45,25 +46,18 @@ extern "C" {
#define IEEE802154_MIN_FREQ (2405) /**< Min. frequency (2405 MHz) */
#define IEEE802154_MAX_FREQ (2480) /**< Max. frequency (2480 MHz) */

#define IEEE802154_MIN_CHANNEL (11) /**< Min. channel (2405 MHz) */
#define IEEE802154_MAX_CHANNEL (26) /**< Max. channel (2480 MHz) */
#define IEEE802154_CHANNEL_SPACING (5) /**< Channel spacing in MHz */

#define IEEE802154_CHAN2FREQ(chan) ( IEEE802154_MIN_FREQ + ((chan) - IEEE802154_MIN_CHANNEL) * IEEE802154_CHANNEL_SPACING )
#define IEEE802154_FREQ2CHAN(freq) ( IEEE802154_MIN_CHANNEL + ((freq) - IEEE802154_MIN_FREQ) / IEEE802154_CHANNEL_SPACING )
#define IEEE802154_CHAN2FREQ(chan) ( IEEE802154_MIN_FREQ + ((chan) - IEEE802154_CHANNEL_MIN) * IEEE802154_CHANNEL_SPACING )
#define IEEE802154_FREQ2CHAN(freq) ( IEEE802154_CHANNEL_MIN + ((freq) - IEEE802154_MIN_FREQ) / IEEE802154_CHANNEL_SPACING )
/* /TODO */

#define CC2538_MIN_FREQ (2394)
#define CC2538_MAX_FREQ (2507)

#define CC2538_RF_POWER_DEFAULT (3) /**< Default output power in dBm */
#ifdef DEFAULT_CHANNEL
#define CC2538_RF_CHANNEL_DEFAULT (DEFAULT_CHANNEL)
#endif
#ifndef CC2538_RF_CHANNEL_DEFAULT
#define CC2538_RF_CHANNEL_DEFAULT (26U)
#endif
#define CC2538_RF_PANID_DEFAULT (0x0023)
#define CC2538_RF_POWER_DEFAULT (IEEE802154_DEFAULT_TXPOWER) /**< Default output power in dBm */
#define CC2538_RF_CHANNEL_DEFAULT (IEEE802154_DEFAULT_CHANNEL)
#define CC2538_RF_PANID_DEFAULT (IEEE802154_DEFAULT_PANID)

#define OUTPUT_POWER_MIN (-24) /**< Min output power in dBm */
#define OUTPUT_POWER_MAX (7) /**< Max output power in dBm */
Expand Down
12 changes: 6 additions & 6 deletions cpu/cc2538/radio/cc2538_rf_getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ void cc2538_set_chan(unsigned int chan)
{
DEBUG("%s(%u): Setting channel to ", __FUNCTION__, chan);

if (chan < IEEE802154_MIN_CHANNEL) {
chan = IEEE802154_MIN_CHANNEL;
if (chan < IEEE802154_CHANNEL_MIN) {
chan = IEEE802154_CHANNEL_MIN;
}
else if (chan > IEEE802154_MAX_CHANNEL) {
chan = IEEE802154_MAX_CHANNEL;
else if (chan > IEEE802154_CHANNEL_MAX) {
chan = IEEE802154_CHANNEL_MAX;
}

DEBUG("%i (range %i-%i)\n", chan, IEEE802154_MIN_CHANNEL,
IEEE802154_MAX_CHANNEL);
DEBUG("%i (range %i-%i)\n", chan, IEEE802154_CHANNEL_MIN,
IEEE802154_CHANNEL_MAX);

cc2538_set_freq(IEEE802154_CHAN2FREQ(chan));
}
Expand Down
4 changes: 2 additions & 2 deletions cpu/cc2538/radio/cc2538_rf_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *value, size_t value_len)
}
else {
uint8_t chan = ((uint8_t *)value)[0];
if (chan < IEEE802154_MIN_CHANNEL ||
chan > IEEE802154_MAX_CHANNEL) {
if (chan < IEEE802154_CHANNEL_MIN ||
chan > IEEE802154_CHANNEL_MAX) {
res = -EINVAL;
}
else {
Expand Down
28 changes: 9 additions & 19 deletions drivers/include/at86rf2xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extern "C" {
/**
* @brief Maximum possible packet size in byte
*/
#define AT86RF2XX_MAX_PKT_LENGTH (127)
#define AT86RF2XX_MAX_PKT_LENGTH (IEEE802154_FRAME_LEN_MAX)

/**
* @brief Default addresses used if the CPUID module is not present
Expand All @@ -62,23 +62,13 @@ extern "C" {
*/
#ifdef MODULE_AT86RF212B
/* the AT86RF212B has a sub-1GHz radio */
#define AT86RF2XX_MIN_CHANNEL (0)
#define AT86RF2XX_MAX_CHANNEL (10)
#ifdef DEFAULT_CHANNEL
#define AT86RF2XX_DEFAULT_CHANNEL (DEFAULT_CHANNEL)
#endif
#ifndef AT86RF2XX_DEFAULT_CHANNEL
#define AT86RF2XX_DEFAULT_CHANNEL (5)
#endif
#define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN_SUBGHZ)
#define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX_SUBGHZ)
#define AT86RF2XX_DEFAULT_CHANNEL (IEEE802154_DEFAULT_SUBGHZ_CHANNEL)
#else
#define AT86RF2XX_MIN_CHANNEL (11U)
#define AT86RF2XX_MAX_CHANNEL (26U)
#ifdef DEFAULT_CHANNEL
#define AT86RF2XX_DEFAULT_CHANNEL (DEFAULT_CHANNEL)
#endif
#ifndef AT86RF2XX_DEFAULT_CHANNEL
#define AT86RF2XX_DEFAULT_CHANNEL (26U)
#endif
#define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN)
#define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX)
#define AT86RF2XX_DEFAULT_CHANNEL (IEEE802154_DEFAULT_CHANNEL)
#endif
/** @} */

Expand All @@ -87,12 +77,12 @@ extern "C" {
*
* @todo Read some global network stack specific configuration value
*/
#define AT86RF2XX_DEFAULT_PANID (0x0023)
#define AT86RF2XX_DEFAULT_PANID (IEEE802154_DEFAULT_PANID)

/**
* @brief Default TX power (0dBm)
*/
#define AT86RF2XX_DEFAULT_TXPOWER (0U)
#define AT86RF2XX_DEFAULT_TXPOWER (IEEE802154_DEFAULT_TXPOWER)

/**
* @brief Base (minimal) RSSI value in dBm
Expand Down
17 changes: 6 additions & 11 deletions drivers/include/cc2420.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
/**
* @brief Maximum possible packet size in byte
*/
#define CC2420_PKT_MAXLEN (127U)
#define CC2420_PKT_MAXLEN (IEEE802154_FRAME_LEN_MAX)

/**
* @brief Default addresses used if the CPUID module is not present
Expand All @@ -49,20 +49,15 @@ extern "C" {
/**
* @brief PAN ID configuration
*/
#define CC2420_PANID_DEFAULT (0x0023)
#define CC2420_PANID_DEFAULT (IEEE802154_DEFAULT_PANID)

/**
* @brief Channel configuration
* @{
*/
#define CC2420_CHAN_MIN (11U)
#define CC2420_CHAN_MAX (26U)
#ifdef DEFAULT_CHANNEL
#define CC2420_CHAN_DEFAULT (DEFAULT_CHANNEL)
#endif
#ifndef CC2420_CHAN_DEFAULT
#define CC2420_CHAN_DEFAULT (26U)
#endif
#define CC2420_CHAN_MIN (IEEE802154_CHANNEL_MIN)
#define CC2420_CHAN_MAX (IEEE802154_CHANNEL_MAX)
#define CC2420_CHAN_DEFAULT (IEEE802154_DEFAULT_CHANNEL)
/** @} */

/**
Expand All @@ -71,7 +66,7 @@ extern "C" {
*/
#define CC2420_TXPOWER_MIN (-25)
#define CC2420_TXPOWER_MAX (0)
#define CC2420_TXPOWER_DEFAULT (0)
#define CC2420_TXPOWER_DEFAULT (IEEE802154_DEFAULT_TXPOWER)
/** @} */

/**
Expand Down
9 changes: 5 additions & 4 deletions drivers/include/kw2xrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "periph/spi.h"
#include "periph/gpio.h"
#include "net/gnrc/netdev.h"
#include "net/ieee802154.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -36,7 +37,7 @@ extern "C" {
/**
* @brief Maximum packet length
*/
#define KW2XRF_MAX_PKT_LENGTH (127U)
#define KW2XRF_MAX_PKT_LENGTH (IEEE802154_FRAME_LEN_MAX)

/**
* @brief Default protocol for data that is coming in
Expand All @@ -60,7 +61,7 @@ extern "C" {
/**
* @brief Default PAN ID used after initialization
*/
#define KW2XRF_DEFAULT_PANID (0x0023)
#define KW2XRF_DEFAULT_PANID (IEEE802154_DEFAULT_PANID)

/**
* @brief Default channel used after initialization
Expand All @@ -69,13 +70,13 @@ extern "C" {
#define KW2XRF_DEFAULT_CHANNEL (DEFAULT_CHANNEL)
#endif
#ifndef KW2XRF_DEFAULT_CHANNEL
#define KW2XRF_DEFAULT_CHANNEL (26U)
#define KW2XRF_DEFAULT_CHANNEL (IEEE802154_DEFAULT_CHANNEL)
#endif

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

/**
* @brief Maximum output power of the kw2x device in dBm
Expand Down
9 changes: 2 additions & 7 deletions drivers/include/xbee.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,12 @@ extern "C" {
/**
* @brief Default PAN ID used after initialization
*/
#define XBEE_DEFAULT_PANID (0x0023)
#define XBEE_DEFAULT_PANID (IEEE802154_DEFAULT_PANID)

/**
* @brief Default channel used after initialization
*/
#ifdef DEFAULT_CHANNEL
#define XBEE_DEFAULT_CHANNEL (DEFAULT_CHANNEL)
#endif
#ifndef XBEE_DEFAULT_CHANNEL
#define XBEE_DEFAULT_CHANNEL (23U)
#endif
#define XBEE_DEFAULT_CHANNEL (IEEE802154_DEFAULT_CHANNEL)

/**
* @name Address flags
Expand Down
18 changes: 14 additions & 4 deletions examples/default/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,18 @@ ifneq (,$(filter msba2,$(BOARD)))
USEMODULE += random
endif

# Set a custom 802.15.4 channel if needed
DEFAULT_CHANNEL ?= 26
CFLAGS += -DDEFAULT_CHANNEL=$(DEFAULT_CHANNEL)

include $(RIOTBASE)/Makefile.include

# Set a custom channel if needed
ifeq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz
DEFAULT_CHANNEL ?= 0
CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
else
ifeq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz
DEFAULT_CHANNEL ?= 5
CFLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL)
else # radio is IEEE 802.15.4 2.4 GHz
DEFAULT_CHANNEL ?= 26
CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
endif
endif
18 changes: 14 additions & 4 deletions examples/gnrc_border_router/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ USEMODULE += ps
# include UHCP client
USEMODULE += gnrc_uhcpc

# Set a custom 802.15.4 channel if needed
DEFAULT_CHANNEL ?= 26
CFLAGS += -DDEFAULT_CHANNEL=$(DEFAULT_CHANNEL)

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
Expand All @@ -66,3 +62,17 @@ term: host-tools

host-tools:
$(AD)env -u CC -u CFLAGS make -C $(RIOTBASE)/dist/tools

# Set a custom channel if needed
ifeq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz
DEFAULT_CHANNEL ?= 0
CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
else
ifeq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz
DEFAULT_CHANNEL ?= 5
CFLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL)
else # radio is IEEE 802.15.4 2.4 GHz
DEFAULT_CHANNEL ?= 26
CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
endif
endif
18 changes: 14 additions & 4 deletions examples/gnrc_minimal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,23 @@ USEMODULE += gnrc_icmpv6_echo
# Use minimal standard PRNG
USEMODULE += prng_minstd

# Set a custom 802.15.4 channel if needed
DEFAULT_CHANNEL ?= 26
CFLAGS += -DDEFAULT_CHANNEL=$(DEFAULT_CHANNEL)

CFLAGS += -DGNRC_PKTBUF_SIZE=512 -DGNRC_IPV6_NETIF_ADDR_NUMOF=4 -DGNRC_IPV6_NC_SIZE=1

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

include $(RIOTBASE)/Makefile.include

# Set a custom channel if needed
ifeq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz
DEFAULT_CHANNEL ?= 0
CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
else
ifeq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz
DEFAULT_CHANNEL ?= 5
CFLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL)
else # radio is IEEE 802.15.4 2.4 GHz
DEFAULT_CHANNEL ?= 26
CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
endif
endif
18 changes: 14 additions & 4 deletions examples/microcoap_server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ CFLAGS += -DMICROCOAP_DEBUG
# include this for printing IP addresses
USEMODULE += shell_commands

# Set a custom 802.15.4 channel if needed
DEFAULT_CHANNEL ?= 26
CFLAGS += -DDEFAULT_CHANNEL=$(DEFAULT_CHANNEL)

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
Expand All @@ -60,3 +56,17 @@ endif
QUIET ?= 1

include $(RIOTBASE)/Makefile.include

# Set a custom channel if needed
ifeq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz
DEFAULT_CHANNEL ?= 0
CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
else
ifeq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz
DEFAULT_CHANNEL ?= 5
CFLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL)
else # radio is IEEE 802.15.4 2.4 GHz
DEFAULT_CHANNEL ?= 26
CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
endif
endif
8 changes: 4 additions & 4 deletions sys/include/net/gnrc/zep.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ extern "C" {
* @brief Channel configuration
* @{
*/
#define GNRC_ZEP_MIN_CHANNEL (11U)
#define GNRC_ZEP_MAX_CHANNEL (26U)
#define GNRC_ZEP_DEFAULT_CHANNEL (26U)
#define GNRC_ZEP_MIN_CHANNEL (IEEE802154_CHANNEL_MIN)
#define GNRC_ZEP_MAX_CHANNEL (IEEE802154_CHANNEL_MAX)
#define GNRC_ZEP_DEFAULT_CHANNEL (IEEE802154_DEFAULT_CHANNEL)
/**
* @}
*/
Expand All @@ -94,7 +94,7 @@ extern "C" {
*
* @todo Read some global network stack specific configuration value
*/
#define GNRC_ZEP_DEFAULT_PANID (0x0023)
#define GNRC_ZEP_DEFAULT_PANID (IEEE802154_DEFAULT_PANID)

/**
* @brief Option flags for the ZEP device
Expand Down
Loading

0 comments on commit 9e97b0a

Please sign in to comment.