From ea6248b8709b534d52d8ea439aaf4d9aa67a2fd0 Mon Sep 17 00:00:00 2001 From: Florian Grandel Date: Mon, 25 Sep 2023 13:54:07 +0200 Subject: [PATCH] drivers: ieee802154: cc1200: SUN-FSK compatibility Preparative change to introduce build-time configured channel pages. This fixes the description of the driver's available PHYs and makes channel page and channel range independent from runtime attributes. Signed-off-by: Florian Grandel --- drivers/ieee802154/Kconfig.cc1200 | 15 +++++++++++--- drivers/ieee802154/ieee802154_cc1200.c | 25 ++++++++++++++++------- drivers/ieee802154/ieee802154_cc1200_rf.h | 9 +++++--- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/drivers/ieee802154/Kconfig.cc1200 b/drivers/ieee802154/Kconfig.cc1200 index 0e8329ed153..b1f18a7520d 100644 --- a/drivers/ieee802154/Kconfig.cc1200 +++ b/drivers/ieee802154/Kconfig.cc1200 @@ -85,13 +85,22 @@ choice Set the RF preset you want to use. config IEEE802154_CC1200_RF_SET_0 - bool "868MHz - 50Kbps - 2-GFSK - IEEE 802.15.4g compliant - ETSI" + bool "IEEE 802.15.4g SUN MR-FSK, 863MHz band, mode #1 - channel page 9, 34 channels, 50Kbps (ETSI)" + help + This is a legacy IEEE 802.15.4g-2012 SUN MR-FSK PHY that does no + longer exist in recent standards (IEEE 802.15.4-2015+). config IEEE802154_CC1200_RF_SET_1 - bool "920MHz - 50Kbps - 2-GFSK - IEEE 802.15.4g compliant - ARIB" + bool "IEEE 802.15.4g SUN MR-FSK 920MHz band, mode #1 - channel page 9, 39 channels, 50Kbps (ARIB)" + help + This is a legacy IEEE 802.15.4g-2012 SUN MR-FSK PHY that does no + longer exist in recent standards (IEEE 802.15.4-2015+). config IEEE802154_CC1200_RF_SET_2 - bool "434MHz - 50Kbps - 2-GFSK - IEEE 802.15.4g compliant - ETSI" + bool "IEEE 802.15.4 Non-Standard 2-GFSK 433MHz band - channel page 9, 15 channels, 50Kbps (ETSI)" + help + This is a non-standard PHY similar to the IEEE 802.15.4g-2012 SUN + MR-FSK PHY but not in one of the standard bands. endchoice diff --git a/drivers/ieee802154/ieee802154_cc1200.c b/drivers/ieee802154/ieee802154_cc1200.c index a5c4f37c47f..396f8878bf2 100644 --- a/drivers/ieee802154/ieee802154_cc1200.c +++ b/drivers/ieee802154/ieee802154_cc1200.c @@ -543,6 +543,15 @@ static int cc1200_cca(const struct device *dev) static int cc1200_set_channel(const struct device *dev, uint16_t channel) { struct cc1200_context *cc1200 = dev->data; + uint32_t freq; + + /* As SUN FSK provides a host of configurations with extremely different + * channel counts it doesn't make sense to validate (aka -EINVAL) a + * global upper limit on the number of supported channels on this page. + */ + if (channel > IEEE802154_CC1200_CHANNEL_LIMIT) { + return -ENOTSUP; + } /* Unlike usual 15.4 chips, cc1200 is closer to a bare metal radio modem * and thus does not provide any means to select a channel directly, but @@ -552,14 +561,16 @@ static int cc1200_set_channel(const struct device *dev, uint16_t channel) * See rf_evaluate_freq_setting() above. */ - if (atomic_get(&cc1200->rx) == 0) { - uint32_t freq = rf_evaluate_freq_setting(dev, channel); + if (atomic_get(&cc1200->rx) != 0) { + return -EIO; + } - if (!write_reg_freq(dev, freq) || - rf_calibrate(dev)) { - LOG_ERR("Could not set channel %u", channel); - return -EIO; - } + freq = rf_evaluate_freq_setting(dev, channel); + + if (!write_reg_freq(dev, freq) || + rf_calibrate(dev)) { + LOG_ERR("Could not set channel %u", channel); + return -EIO; } return 0; diff --git a/drivers/ieee802154/ieee802154_cc1200_rf.h b/drivers/ieee802154/ieee802154_cc1200_rf.h index 8135fcad3cf..e3788d7d7c2 100644 --- a/drivers/ieee802154/ieee802154_cc1200_rf.h +++ b/drivers/ieee802154/ieee802154_cc1200_rf.h @@ -23,9 +23,10 @@ #if defined(CONFIG_IEEE802154_CC1200_RF_SET_0) +#define IEEE802154_CC1200_CHANNEL_LIMIT 33 + const struct cc1200_rf_registers_set cc1200_rf_settings = { .chan_center_freq0 = 863125, - .channel_limit = 33, .channel_spacing = 2000, /* 200 KHz */ .registers = { 0x6F, /* SYNC3 */ @@ -133,9 +134,10 @@ const struct cc1200_rf_registers_set cc1200_rf_settings = { #elif defined(CONFIG_IEEE802154_CC1200_RF_SET_1) +#define IEEE802154_CC1200_CHANNEL_LIMIT 38 + const struct cc1200_rf_registers_set cc1200_rf_settings = { .chan_center_freq0 = 920600, - .channel_limit = 38, .channel_spacing = 2000, /* 200 KHz */ .registers = { 0x6F, /* SYNC3 */ @@ -243,9 +245,10 @@ const struct cc1200_rf_registers_set cc1200_rf_settings = { #elif defined(CONFIG_IEEE802154_CC1200_RF_SET_2) +#define IEEE802154_CC1200_CHANNEL_LIMIT 14 + const struct cc1200_rf_registers_set cc1200_rf_settings = { .chan_center_freq0 = 433164, - .channel_limit = 14, .channel_spacing = 2000, /* 200 KHz */ .registers = { 0x6F, /* SYNC3 */