[radio] remove OT_RADIO_CHANNEL_PAGE_MAX and address gcc warnings (#6646)

This commit modifies the (<=) usage in two ‘if’ conditions as these
operations as written today (with constants), are resulting in the
compile time warnings (and cmake errors) specifically when working
with proprietary radio configurations and setting Channel Min to 0.

Updated the radio header to get rid of OT_RADIO_CHANNEL_PAGE_MAX. Also
adds a compile-time error, if a user sets the proprietary channel page
to a value greater than 31, as it is currently not supported.
This commit is contained in:
Sagar Chinchani
2021-05-20 17:16:24 -07:00
committed by GitHub
parent f1ab57bb66
commit a17d12a263
5 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (115)
#define OPENTHREAD_API_VERSION (116)
/**
* @addtogroup api-instance
-1
View File
@@ -88,7 +88,6 @@ enum
OT_RADIO_CHANNEL_PAGE_0_MASK = (1U << OT_RADIO_CHANNEL_PAGE_0), ///< 2.4 GHz IEEE 802.15.4-2006
OT_RADIO_CHANNEL_PAGE_2 = 2, ///< 915 MHz IEEE 802.15.4-2006
OT_RADIO_CHANNEL_PAGE_2_MASK = (1U << OT_RADIO_CHANNEL_PAGE_2), ///< 915 MHz IEEE 802.15.4-2006
OT_RADIO_CHANNEL_PAGE_MAX = OT_RADIO_CHANNEL_PAGE_2, ///< Maximum supported channel page value
};
/**
+4
View File
@@ -140,6 +140,10 @@
OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK\
to be defined by Platform."
#endif
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE > 31
#error "Maximum Proprietary Channel Page value currently supported is 31."
#endif
#endif
#endif // CONFIG_PLATFORM_H_
+7 -3
View File
@@ -173,7 +173,6 @@ bool ChannelTlv::IsValid(void) const
bool ret = false;
VerifyOrExit(GetLength() == sizeof(*this) - sizeof(Tlv));
VerifyOrExit(mChannelPage <= OT_RADIO_CHANNEL_PAGE_MAX);
VerifyOrExit((1U << mChannelPage) & Radio::kSupportedChannelPages);
VerifyOrExit(Radio::kChannelMin <= GetChannel() && GetChannel() <= Radio::kChannelMax);
ret = true;
@@ -201,8 +200,9 @@ void ChannelTlv::SetChannel(uint16_t aChannel)
#endif
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT
if ((OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN <= aChannel) &&
(aChannel <= OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX))
if ((OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN == aChannel) ||
((OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN < aChannel) &&
(aChannel <= OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX)))
{
channelPage = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE;
}
@@ -228,7 +228,11 @@ bool ChannelMaskBaseTlv::IsValid(void) const
channelPage = cur->GetChannelPage();
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT
if (channelPage == OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE)
#else
if ((channelPage == OT_RADIO_CHANNEL_PAGE_0) || (channelPage == OT_RADIO_CHANNEL_PAGE_2))
#endif
{
VerifyOrExit(static_cast<const ChannelMaskEntry *>(cur)->IsValid());
}
+2 -1
View File
@@ -635,7 +635,8 @@ public:
*/
static bool IsCslChannelValid(uint8_t aCslChannel)
{
return (aCslChannel == 0) || ((kChannelMin <= aCslChannel) && (aCslChannel <= kChannelMax));
return ((aCslChannel == 0) ||
((kChannelMin == aCslChannel) || ((kChannelMin < aCslChannel) && (aCslChannel <= kChannelMax))));
}
private: