[radio] replace enum constants with constexpr (#6909)

This commit is contained in:
Abtin Keshavarzian
2021-08-10 18:44:43 -07:00
committed by GitHub
parent 0ad8245702
commit bd6e7d88b3
5 changed files with 46 additions and 73 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ namespace ot {
class MaxPowerTable
{
public:
static const int8_t kPowerDefault = 30; ///< Default power 1 watt (30 dBm).
static constexpr int8_t kPowerDefault = 30; ///< Default power 1 watt (30 dBm).
MaxPowerTable(void) { memset(mPowerTable, kPowerDefault, sizeof(mPowerTable)); }
+31 -43
View File
@@ -44,27 +44,21 @@
namespace ot {
enum
{
kUsPerTenSymbols = OT_US_PER_TEN_SYMBOLS, ///< The microseconds per 10 symbols.
static constexpr uint32_t kUsPerTenSymbols = OT_US_PER_TEN_SYMBOLS; ///< The microseconds per 10 symbols.
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
/**
* Minimum CSL period supported in units of 10 symbols.
*
*/
kMinCslPeriod = OPENTHREAD_CONFIG_MAC_CSL_MIN_PERIOD * 1000 / kUsPerTenSymbols,
kMaxCslTimeout = OPENTHREAD_CONFIG_MAC_CSL_MAX_TIMEOUT
/**
* Minimum CSL period supported in units of 10 symbols.
*
*/
static constexpr uint64_t kMinCslPeriod = OPENTHREAD_CONFIG_MAC_CSL_MIN_PERIOD * 1000 / kUsPerTenSymbols;
static constexpr uint64_t kMaxCslTimeout = OPENTHREAD_CONFIG_MAC_CSL_MAX_TIMEOUT;
#endif
};
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
enum : uint8_t
{
kCslWorstCrystalPpm = 255, ///< Worst possible crystal accuracy, in units of ± ppm.
kCslWorstUncertainty = 255, ///< Worst possible scheduling uncertainty, in units of 10 us.
kUsPerUncertUnit = 10, ///< Number of microseconds by uncertainty unit.
};
static constexpr uint8_t kCslWorstCrystalPpm = 255; ///< Worst possible crystal accuracy, in units of ± ppm.
static constexpr uint8_t kCslWorstUncertainty = 255; ///< Worst possible scheduling uncertainty, in units of 10 us.
static constexpr uint8_t kUsPerUncertUnit = 10; ///< Number of microseconds by uncertainty unit.
#endif
/**
@@ -86,38 +80,32 @@ class Radio : public InstanceLocator, private NonCopyable
friend class Instance;
public:
/**
* This enumeration defines the IEEE 802.15.4 channel related parameters. It also
* supports proprietary channel parameters defined by platform.
*/
enum
{
#if (OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT && OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT)
kNumChannelPages = 2,
kSupportedChannels = OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK | OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK,
kChannelMin = OT_RADIO_915MHZ_OQPSK_CHANNEL_MIN,
kChannelMax = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX,
kSupportedChannelPages = OT_RADIO_CHANNEL_PAGE_0_MASK | OT_RADIO_CHANNEL_PAGE_2_MASK,
static constexpr uint16_t kNumChannelPages = 2;
static constexpr uint32_t kSupportedChannels =
OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK | OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK;
static constexpr uint8_t kChannelMin = OT_RADIO_915MHZ_OQPSK_CHANNEL_MIN;
static constexpr uint8_t kChannelMax = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX;
static constexpr uint32_t kSupportedChannelPages = OT_RADIO_CHANNEL_PAGE_0_MASK | OT_RADIO_CHANNEL_PAGE_2_MASK;
#elif OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
kNumChannelPages = 1,
kSupportedChannels = OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK,
kChannelMin = OT_RADIO_915MHZ_OQPSK_CHANNEL_MIN,
kChannelMax = OT_RADIO_915MHZ_OQPSK_CHANNEL_MAX,
kSupportedChannelPages = OT_RADIO_CHANNEL_PAGE_2_MASK,
static constexpr uint16_t kNumChannelPages = 1;
static constexpr uint32_t kSupportedChannels = OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK;
static constexpr uint8_t kChannelMin = OT_RADIO_915MHZ_OQPSK_CHANNEL_MIN;
static constexpr uint8_t kChannelMax = OT_RADIO_915MHZ_OQPSK_CHANNEL_MAX;
static constexpr uint32_t kSupportedChannelPages = OT_RADIO_CHANNEL_PAGE_2_MASK;
#elif OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT
kNumChannelPages = 1,
kSupportedChannels = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK,
kChannelMin = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MIN,
kChannelMax = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX,
kSupportedChannelPages = OT_RADIO_CHANNEL_PAGE_0_MASK,
static constexpr uint16_t kNumChannelPages = 1;
static constexpr uint32_t kSupportedChannels = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK;
static constexpr uint8_t kChannelMin = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MIN;
static constexpr uint8_t kChannelMax = OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX;
static constexpr uint32_t kSupportedChannelPages = OT_RADIO_CHANNEL_PAGE_0_MASK;
#elif OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT
kNumChannelPages = 1,
kSupportedChannels = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK,
kChannelMin = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN,
kChannelMax = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX,
kSupportedChannelPages = (1U << OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE),
static constexpr uint16_t kNumChannelPages = 1;
static constexpr uint32_t kSupportedChannels = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK;
static constexpr uint8_t kChannelMin = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN;
static constexpr uint8_t kChannelMax = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX;
static constexpr uint32_t kSupportedChannelPages = (1 << OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE);
#endif
};
static_assert((OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT || OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT ||
OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT),
+1 -4
View File
@@ -108,10 +108,7 @@ public:
void HandleReceived(uint8_t *aBuffer, uint16_t aLength);
private:
enum
{
kUdpPort = 19788, // UDP port (same as MLE port).
};
static constexpr uint16_t kUdpPort = 19788; // UDP port (same as MLE port).
void CreateMulticastIp6Address(Ip6::Address &aIp6Address);
+6 -12
View File
@@ -73,11 +73,8 @@ class Link : public InstanceLocator
friend class Interface;
public:
enum
{
kMtuSize = 1280 - 48 - sizeof(Header), ///< MTU size for TREL frame.
kFcsSize = 0, ///< FCS size for TREL frame.
};
static constexpr uint16_t kMtuSize = 1280 - 48 - sizeof(Header); ///< MTU size for TREL frame.
static constexpr uint8_t kFcsSize = 0; ///< FCS size for TREL frame.
/**
* This constructor initializes the `Link` object.
@@ -150,13 +147,10 @@ public:
void Send(void);
private:
enum
{
kMaxHeaderSize = sizeof(Header),
k154AckFrameSize = 3 + kFcsSize,
kRxRssi = -20, // The RSSI value used for received frames on TREL radio link.
kAckWaitWindow = 750, // (in msec)
};
static constexpr uint16_t kMaxHeaderSize = sizeof(Header);
static constexpr uint16_t k154AckFrameSize = 3 + kFcsSize;
static constexpr int8_t kRxRssi = -20; // The RSSI value used for received frames on TREL radio link.
static constexpr uint32_t kAckWaitWindow = 750; // (in msec)
enum State : uint8_t
{
+7 -13
View File
@@ -58,7 +58,7 @@ public:
* This enumeration defines packet types.
*
*/
enum Type
enum Type : uint8_t
{
kTypeBroadcast = 0, ///< A TREL broadcast packet.
kTypeUnicast = 1, ///< A TREL unicast packet.
@@ -69,16 +69,13 @@ public:
* This enumeration represents Ack Mode field in TREL header.
*
*/
enum AckMode
enum AckMode : uint8_t
{
kNoAck, ///< No TREL Ack is requested.
kAckRequested, ///< A TREL Ack is requested.
};
enum
{
kInfoStringSize = 128, ///< Max chars needed for the info string representation (@sa ToInfoString()).
};
static constexpr uint16_t kInfoStringSize = 128; ///< Max chars for the info string (@sa ToInfoString()).
/**
* This type defines the fixed-length `String` object returned from `ToString()` method.
@@ -237,13 +234,10 @@ public:
InfoString ToString(void) const;
private:
enum
{
kTypeMask = (3 << 0), // Bits 0-1 specify packet `Type`
kAckModeFlag = (1 << 2), // Bit 2 indicate "ack mode" (TREL ack requested or not).
kVersionMask = (7 << 5), // Bits 5-7 specify the version.
kVersion = (0 << 5), // Current TREL header version.
};
static constexpr uint8_t kTypeMask = (3 << 0); // Bits 0-1 specify packet `Type`
static constexpr uint8_t kAckModeFlag = (1 << 2); // Bit 2 indicate "ack mode" (TREL ack requested or not).
static constexpr uint8_t kVersionMask = (7 << 5); // Bits 5-7 specify the version.
static constexpr uint8_t kVersion = (0 << 5); // Current TREL header version.
// All header fields are big-endian.