diff --git a/cpu/cc2538/include/cc2538_rf.h b/cpu/cc2538/include/cc2538_rf.h index aecd7ac43c63..6a96d7a86856 100644 --- a/cpu/cc2538/include/cc2538_rf.h +++ b/cpu/cc2538/include/cc2538_rf.h @@ -24,6 +24,7 @@ #include +#include "net/ieee802154.h" #include "net/netdev2.h" #include "net/netdev2/ieee802154.h" @@ -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 */ diff --git a/cpu/cc2538/radio/cc2538_rf_getset.c b/cpu/cc2538/radio/cc2538_rf_getset.c index 6a97a042482d..309275d9b628 100644 --- a/cpu/cc2538/radio/cc2538_rf_getset.c +++ b/cpu/cc2538/radio/cc2538_rf_getset.c @@ -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)); } diff --git a/cpu/cc2538/radio/cc2538_rf_netdev.c b/cpu/cc2538/radio/cc2538_rf_netdev.c index fcde218d5eb7..3eca36ee55fc 100644 --- a/cpu/cc2538/radio/cc2538_rf_netdev.c +++ b/cpu/cc2538/radio/cc2538_rf_netdev.c @@ -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 { diff --git a/drivers/include/at86rf2xx.h b/drivers/include/at86rf2xx.h index 0b468dd28ffd..5ae164f85d29 100644 --- a/drivers/include/at86rf2xx.h +++ b/drivers/include/at86rf2xx.h @@ -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 @@ -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 /** @} */ @@ -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 diff --git a/drivers/include/cc2420.h b/drivers/include/cc2420.h index 0ac7f98c2166..797cdeca5cec 100644 --- a/drivers/include/cc2420.h +++ b/drivers/include/cc2420.h @@ -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 @@ -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) /** @} */ /** @@ -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) /** @} */ /** diff --git a/drivers/include/kw2xrf.h b/drivers/include/kw2xrf.h index 71ba2856c707..f37ea2688e06 100644 --- a/drivers/include/kw2xrf.h +++ b/drivers/include/kw2xrf.h @@ -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" { @@ -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 @@ -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 @@ -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 diff --git a/drivers/include/xbee.h b/drivers/include/xbee.h index 01769ea71d61..9a868021a987 100644 --- a/drivers/include/xbee.h +++ b/drivers/include/xbee.h @@ -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 diff --git a/examples/default/Makefile b/examples/default/Makefile index d7c6fa6fe147..5d0f9788a502 100644 --- a/examples/default/Makefile +++ b/examples/default/Makefile @@ -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 diff --git a/examples/gnrc_border_router/Makefile b/examples/gnrc_border_router/Makefile index 3d855058ac8f..7f87a85cbaf3 100644 --- a/examples/gnrc_border_router/Makefile +++ b/examples/gnrc_border_router/Makefile @@ -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: @@ -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 diff --git a/examples/gnrc_minimal/Makefile b/examples/gnrc_minimal/Makefile index a6e798b08af5..10945a0e10eb 100644 --- a/examples/gnrc_minimal/Makefile +++ b/examples/gnrc_minimal/Makefile @@ -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 diff --git a/examples/microcoap_server/Makefile b/examples/microcoap_server/Makefile index b4e3a46a1e24..0d31dd2c8e37 100644 --- a/examples/microcoap_server/Makefile +++ b/examples/microcoap_server/Makefile @@ -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: @@ -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 diff --git a/sys/include/net/gnrc/zep.h b/sys/include/net/gnrc/zep.h index 8195bb1b6e57..9e0e55b97cdd 100644 --- a/sys/include/net/gnrc/zep.h +++ b/sys/include/net/gnrc/zep.h @@ -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) /** * @} */ @@ -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 diff --git a/sys/include/net/ieee802154.h b/sys/include/net/ieee802154.h index 65f59862e75c..ff169fb21ef0 100644 --- a/sys/include/net/ieee802154.h +++ b/sys/include/net/ieee802154.h @@ -77,6 +77,21 @@ extern "C" { #define IEEE802154_FCF_SRC_ADDR_LONG (0xc0) /**< source address length is 8 */ /** @} */ +/** + * @brief Channel ranges + * @{ + */ +/** + * @brief Minimum channel for sub-GHz band + */ +#define IEEE802154_CHANNEL_MIN_SUBGHZ (0U) +#define IEEE802154_CHANNEL_MAX_SUBGHZ (10U) /**< Maximum channel for sub-GHz band */ +#define IEEE802154_CHANNEL_MIN (11U) /**< Minimum channel for 2.4 GHz band */ +#define IEEE802154_CHANNEL_MAX (26U) /**< Maximum channel for 2.4 GHz band */ +/** @} */ + +#define IEEE802154_FRAME_LEN_MAX (127U) /**< maximum frame length */ + /** * @brief Special address defintions * @{ @@ -97,6 +112,28 @@ extern "C" { extern const uint8_t ieee802154_addr_bcast[IEEE802154_ADDR_BCAST_LEN]; /** @} */ +/** + * @{ + * @name Default values + * @brief Default values for devices to choose + */ +#ifndef IEEE802154_DEFAULT_SUBGHZ_CHANNEL +#define IEEE802154_DEFAULT_SUBGHZ_CHANNEL (5U) +#endif + +#ifndef IEEE802154_DEFAULT_CHANNEL +#define IEEE802154_DEFAULT_CHANNEL (26U) +#endif + +#ifndef IEEE802154_DEFAULT_PANID +#define IEEE802154_DEFAULT_PANID (0x0023U) +#endif + +#ifndef IEEE802154_DEFAULT_TXPOWER +#define IEEE802154_DEFAULT_TXPOWER (0) /* in dBm */ +#endif +/** @} */ + /** * @brief Initializes an IEEE 802.15.4 MAC frame header in @p buf. * diff --git a/tests/driver_xbee/Makefile b/tests/driver_xbee/Makefile index 3ef2fec07adf..a285f49f0388 100644 --- a/tests/driver_xbee/Makefile +++ b/tests/driver_xbee/Makefile @@ -3,7 +3,7 @@ include ../Makefile.tests_common FEATURES_REQUIRED = periph_uart periph_gpio -BOARD_INSUFFICIENT_MEMORY := stm32f0discovery weio nucleo-f030 +BOARD_INSUFFICIENT_MEMORY := nucleo-f030 nucleo-f334 stm32f0discovery weio USEMODULE += xbee USEMODULE += gnrc_netif