From b1d92846c052c38a61193694d6c6d9ef11fdf65f Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 30 Jul 2019 13:52:54 -0700 Subject: [PATCH] [radio] add radio folder to core (#4045) This commit renames existing `phy` folder into `radio`. It also renames some of the related files in this folder. It also moves all default/weak `otPlatRadio` implementations to a common `radio_platform_defaults.cpp` file. --- Android.mk | 2 +- src/core/Makefile.am | 6 +++--- src/core/api/instance_api.cpp | 6 ------ src/core/api/link_api.cpp | 2 +- src/core/diags/factory_diags.cpp | 6 +++--- src/core/mac/channel_mask.cpp | 4 ++-- src/core/mac/channel_mask.hpp | 4 ++-- src/core/mac/mac.cpp | 4 ++-- src/core/meshcop/dataset_manager.cpp | 2 +- src/core/meshcop/meshcop_tlvs.cpp | 4 ++-- src/core/meshcop/meshcop_tlvs.hpp | 4 ++-- src/core/{phy/phy.hpp => radio/radio.hpp} | 16 ++++++++-------- .../radio_platform_defaults.cpp} | 14 ++++++++++---- src/core/thread/announce_sender.cpp | 2 +- src/core/thread/mesh_forwarder.cpp | 2 +- src/core/thread/network_diagnostic.cpp | 2 +- src/core/thread/network_diagnostic_tlvs.hpp | 4 ++-- src/core/utils/channel_manager.cpp | 2 +- src/core/utils/channel_monitor.cpp | 6 +++--- src/core/utils/channel_monitor.hpp | 4 ++-- src/ncp/ncp_base.cpp | 4 ++-- tests/unit/test_mac_frame.cpp | 16 ++++++++-------- 22 files changed, 58 insertions(+), 58 deletions(-) rename src/core/{phy/phy.hpp => radio/radio.hpp} (92%) rename src/core/{phy/radio_weak.cpp => radio/radio_platform_defaults.cpp} (86%) diff --git a/Android.mk b/Android.mk index 1c5ef30d0..dce2dd2c0 100644 --- a/Android.mk +++ b/Android.mk @@ -188,7 +188,7 @@ LOCAL_SRC_FILES := \ src/core/net/ip6_mpl.cpp \ src/core/net/netif.cpp \ src/core/net/udp6.cpp \ - src/core/phy/radio_weak.cpp \ + src/core/radio/radio_platform_defaults.cpp \ src/core/thread/address_resolver.cpp \ src/core/thread/announce_begin_server.cpp \ src/core/thread/announce_sender.cpp \ diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 2cdd51a08..2be93abbb 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -194,7 +194,7 @@ SOURCES_COMMON = \ net/netif.cpp \ net/sntp_client.cpp \ net/udp6.cpp \ - phy/radio_weak.cpp \ + radio/radio_platform_defaults.cpp \ thread/address_resolver.cpp \ thread/announce_begin_server.cpp \ thread/announce_sender.cpp \ @@ -255,7 +255,7 @@ libopenthread_radio_a_SOURCES = \ mac/mac_frame.cpp \ mac/sub_mac.cpp \ mac/sub_mac_callbacks.cpp \ - phy/radio_weak.cpp \ + radio/radio_platform_defaults.cpp \ thread/link_quality.cpp \ utils/missing_strlcat.c \ utils/missing_strlcpy.c \ @@ -390,7 +390,7 @@ HEADERS_COMMON = \ net/socket.hpp \ net/tcp.hpp \ net/udp6.hpp \ - phy/phy.hpp \ + radio/radio.hpp \ thread/address_resolver.hpp \ thread/announce_begin_server.hpp \ thread/announce_sender.hpp \ diff --git a/src/core/api/instance_api.cpp b/src/core/api/instance_api.cpp index 13525113a..233928952 100644 --- a/src/core/api/instance_api.cpp +++ b/src/core/api/instance_api.cpp @@ -155,9 +155,3 @@ const char *otGetRadioVersionString(otInstance *aInstance) { return otPlatRadioGetVersionString(aInstance); } - -OT_TOOL_WEAK const char *otPlatRadioGetVersionString(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - return otGetVersionString(); -} diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index bf8df9b68..29a9830b3 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -38,7 +38,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" #include "mac/mac.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" using namespace ot; diff --git a/src/core/diags/factory_diags.cpp b/src/core/diags/factory_diags.cpp index 77e6b3108..5b2183512 100644 --- a/src/core/diags/factory_diags.cpp +++ b/src/core/diags/factory_diags.cpp @@ -41,7 +41,7 @@ #include "common/code_utils.hpp" #include "common/instance.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" #include "utils/parse_cmdline.hpp" #include "utils/wrap_string.h" @@ -71,7 +71,7 @@ void Diags::ProcessChannel(int aArgCount, char *aArgVector[], char *aOutput, siz VerifyOrExit(aArgCount == 1, error = OT_ERROR_INVALID_ARGS); SuccessOrExit(error = ParseLong(aArgVector[0], value)); - VerifyOrExit(value >= Phy::kChannelMin && value <= Phy::kChannelMax, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(value >= Radio::kChannelMin && value <= Radio::kChannelMax, error = OT_ERROR_INVALID_ARGS); mChannel = static_cast(value); otPlatDiagChannelSet(mChannel); @@ -172,7 +172,7 @@ void Diags::ProcessChannel(int aArgCount, char *aArgVector[], char *aOutput, siz long value; SuccessOrExit(error = ParseLong(aArgVector[0], value)); - VerifyOrExit(value >= Phy::kChannelMin && value <= Phy::kChannelMax, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(value >= Radio::kChannelMin && value <= Radio::kChannelMax, error = OT_ERROR_INVALID_ARGS); mChannel = static_cast(value); otPlatRadioReceive(&GetInstance(), mChannel); diff --git a/src/core/mac/channel_mask.cpp b/src/core/mac/channel_mask.cpp index 76a49fc76..a51442b1b 100644 --- a/src/core/mac/channel_mask.cpp +++ b/src/core/mac/channel_mask.cpp @@ -58,10 +58,10 @@ otError ChannelMask::GetNextChannel(uint8_t &aChannel) const if (aChannel == kChannelIteratorFirst) { - aChannel = (Phy::kChannelMin - 1); + aChannel = (Radio::kChannelMin - 1); } - for (aChannel++; aChannel <= Phy::kChannelMax; aChannel++) + for (aChannel++; aChannel <= Radio::kChannelMax; aChannel++) { if (ContainsChannel(aChannel)) { diff --git a/src/core/mac/channel_mask.hpp b/src/core/mac/channel_mask.hpp index 2b6d1cb14..58b2cb7d9 100644 --- a/src/core/mac/channel_mask.hpp +++ b/src/core/mac/channel_mask.hpp @@ -40,7 +40,7 @@ #include #include "common/string.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" #include "utils/static_assert.hpp" namespace ot { @@ -252,7 +252,7 @@ public: InfoString ToString(void) const; private: - OT_STATIC_ASSERT((Phy::kChannelMin < 32) && (Phy::kChannelMax < 32), + OT_STATIC_ASSERT((Radio::kChannelMin < 32) && (Radio::kChannelMax < 32), "The channel number is larger than 32. `ChannelMask` uses 32 bit mask."); uint32_t mMask; }; diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 16c9cf79f..41b9ba31d 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -46,7 +46,7 @@ #include "crypto/aes_ccm.hpp" #include "crypto/sha256.hpp" #include "mac/mac_frame.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" #include "thread/link_quality.hpp" #include "thread/mle_router.hpp" #include "thread/thread_netif.hpp" @@ -96,7 +96,7 @@ Mac::Mac(Instance &aInstance) , mRadioChannel(OPENTHREAD_CONFIG_DEFAULT_CHANNEL) , mRadioChannelAcquisitionId(0) , mSupportedChannelMask(otPlatRadioGetSupportedChannelMask(&aInstance)) - , mScanChannel(Phy::kChannelMin) + , mScanChannel(Radio::kChannelMin) , mScanDuration(0) , mScanChannelMask() , mActiveScanHandler(NULL) /* Initialize `mActiveScanHandler` and `mEnergyScanHandler` union */ diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 9dbed95fd..bb314a2f1 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -41,7 +41,7 @@ #include "common/logging.hpp" #include "meshcop/meshcop.hpp" #include "meshcop/meshcop_tlvs.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" #include "thread/thread_netif.hpp" #include "thread/thread_tlvs.hpp" #include "thread/thread_uri_paths.hpp" diff --git a/src/core/meshcop/meshcop_tlvs.cpp b/src/core/meshcop/meshcop_tlvs.cpp index f407dc24a..c3dd06414 100644 --- a/src/core/meshcop/meshcop_tlvs.cpp +++ b/src/core/meshcop/meshcop_tlvs.cpp @@ -121,8 +121,8 @@ bool ChannelTlv::IsValid(void) const VerifyOrExit(GetLength() == sizeof(*this) - sizeof(Tlv)); VerifyOrExit(mChannelPage <= OT_RADIO_CHANNEL_PAGE_MAX); - VerifyOrExit((1U << mChannelPage) & Phy::kSupportedChannelPages); - VerifyOrExit(Phy::kChannelMin <= GetChannel() && GetChannel() <= Phy::kChannelMax); + VerifyOrExit((1U << mChannelPage) & Radio::kSupportedChannelPages); + VerifyOrExit(Radio::kChannelMin <= GetChannel() && GetChannel() <= Radio::kChannelMax); ret = true; exit: diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 6ed186498..4956a1261 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -49,7 +49,7 @@ #include "common/tlvs.hpp" #include "meshcop/timestamp.hpp" #include "net/ip6_address.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" namespace ot { namespace MeshCoP { @@ -1661,7 +1661,7 @@ public: private: enum { - kNumMaskEntries = Phy::kNumChannelPages, + kNumMaskEntries = Radio::kNumChannelPages, }; ChannelMaskEntry mEntries[kNumMaskEntries]; diff --git a/src/core/phy/phy.hpp b/src/core/radio/radio.hpp similarity index 92% rename from src/core/phy/phy.hpp rename to src/core/radio/radio.hpp index f919a6eef..986e7578f 100644 --- a/src/core/phy/phy.hpp +++ b/src/core/radio/radio.hpp @@ -28,11 +28,11 @@ /** * @file - * This file includes definitions for the IEEE 802.15.4 PHY. + * This file includes definitions for OpenThread definition of radio abstraction. */ -#ifndef PHY_HPP_ -#define PHY_HPP_ +#ifndef RADIO_HPP_ +#define RADIO_HPP_ #include "openthread-core-config.h" @@ -43,16 +43,16 @@ namespace ot { /** - * @addtogroup core-phy + * @addtogroup core-radio * * @brief - * This module includes definitions for the IEEE 802.15.4 PHY + * This module includes definitions for OpenThread radio abstraction. * * @{ * */ -namespace Phy { +namespace Radio { /** * This enumeration defines the IEEE 802.15.4 channel related parameters. @@ -84,7 +84,7 @@ enum OT_STATIC_ASSERT((OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT || OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT), "OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT or OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT " "must be set to 1 to specify the radio mode"); -} // namespace Phy +} // namespace Radio } // namespace ot -#endif // PHY_HPP_ +#endif // RADIO_HPP_ diff --git a/src/core/phy/radio_weak.cpp b/src/core/radio/radio_platform_defaults.cpp similarity index 86% rename from src/core/phy/radio_weak.cpp rename to src/core/radio/radio_platform_defaults.cpp index e377c58a8..ee35d14bf 100644 --- a/src/core/phy/radio_weak.cpp +++ b/src/core/radio/radio_platform_defaults.cpp @@ -27,12 +27,12 @@ /** * @file - * This file implements the default radio platform APIs. + * This file implements the default/weak radio platform APIs. */ -#include +#include -#include "phy/phy.hpp" +#include "radio/radio.hpp" using namespace ot; @@ -40,10 +40,16 @@ OT_TOOL_WEAK uint32_t otPlatRadioGetSupportedChannelMask(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - return Phy::kSupportedChannels; + return Radio::kSupportedChannels; } OT_TOOL_WEAK uint32_t otPlatRadioGetPreferredChannelMask(otInstance *aInstance) { return otPlatRadioGetSupportedChannelMask(aInstance); } + +OT_TOOL_WEAK const char *otPlatRadioGetVersionString(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + return otGetVersionString(); +} diff --git a/src/core/thread/announce_sender.cpp b/src/core/thread/announce_sender.cpp index dfbdc8ef3..4e5a27a3e 100644 --- a/src/core/thread/announce_sender.cpp +++ b/src/core/thread/announce_sender.cpp @@ -42,7 +42,7 @@ #include "common/random.hpp" #include "meshcop/meshcop.hpp" #include "meshcop/meshcop_tlvs.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" namespace ot { diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 90beda838..5000bac2e 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -46,7 +46,7 @@ #include "net/netif.hpp" #include "net/tcp.hpp" #include "net/udp6.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" #include "thread/mle.hpp" #include "thread/mle_router.hpp" #include "thread/thread_netif.hpp" diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index c05a6b664..94d297091 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -422,7 +422,7 @@ otError NetworkDiagnostic::FillRequestedTlvs(Message & aRequest, case NetworkDiagnosticTlv::kChannelPages: { uint8_t length = 0; - uint8_t pageMask = Phy::kSupportedChannelPages; + uint8_t pageMask = Radio::kSupportedChannelPages; ChannelPagesTlv tlv; tlv.Init(); diff --git a/src/core/thread/network_diagnostic_tlvs.hpp b/src/core/thread/network_diagnostic_tlvs.hpp index 15d4e7e2a..c0ac7beb1 100644 --- a/src/core/thread/network_diagnostic_tlvs.hpp +++ b/src/core/thread/network_diagnostic_tlvs.hpp @@ -45,7 +45,7 @@ #include "common/tlvs.hpp" #include "meshcop/meshcop_tlvs.hpp" #include "net/ip6_address.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" #include "thread/device_mode.hpp" #include "thread/mle_constants.hpp" @@ -1377,7 +1377,7 @@ public: uint8_t *GetChannelPages(void) { return mChannelPages; } private: - uint8_t mChannelPages[Phy::kNumChannelPages]; + uint8_t mChannelPages[Radio::kNumChannelPages]; } OT_TOOL_PACKED_END; /** diff --git a/src/core/utils/channel_manager.cpp b/src/core/utils/channel_manager.cpp index 369db848d..02270e90d 100644 --- a/src/core/utils/channel_manager.cpp +++ b/src/core/utils/channel_manager.cpp @@ -39,7 +39,7 @@ #include "common/locator-getters.hpp" #include "common/logging.hpp" #include "common/random.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" #if OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE && OPENTHREAD_FTD diff --git a/src/core/utils/channel_monitor.cpp b/src/core/utils/channel_monitor.cpp index a6048af6c..a8b84edcc 100644 --- a/src/core/utils/channel_monitor.cpp +++ b/src/core/utils/channel_monitor.cpp @@ -105,8 +105,8 @@ uint16_t ChannelMonitor::GetChannelOccupancy(uint8_t aChannel) const { uint16_t occupancy = 0; - VerifyOrExit((Phy::kChannelMin <= aChannel) && (aChannel <= Phy::kChannelMax)); - occupancy = mChannelOccupancy[aChannel - Phy::kChannelMin]; + VerifyOrExit((Radio::kChannelMin <= aChannel) && (aChannel <= Radio::kChannelMax)); + occupancy = mChannelOccupancy[aChannel - Radio::kChannelMin]; exit: return occupancy; @@ -146,7 +146,7 @@ void ChannelMonitor::HandleEnergyScanResult(otEnergyScanResult *aResult) } else { - uint8_t channelIndex = (aResult->mChannel - Phy::kChannelMin); + uint8_t channelIndex = (aResult->mChannel - Radio::kChannelMin); uint32_t newAverage = mChannelOccupancy[channelIndex]; uint32_t newValue = 0; uint32_t weight; diff --git a/src/core/utils/channel_monitor.hpp b/src/core/utils/channel_monitor.hpp index aba9cb127..493a929e7 100644 --- a/src/core/utils/channel_monitor.hpp +++ b/src/core/utils/channel_monitor.hpp @@ -41,7 +41,7 @@ #include "common/locator.hpp" #include "common/timer.hpp" #include "mac/mac.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" namespace ot { namespace Utils { @@ -192,7 +192,7 @@ private: #else kNumChannelMasks = 4, #endif - kNumChannels = (Phy::kChannelMax - Phy::kChannelMin + 1), + kNumChannels = (Radio::kChannelMax - Radio::kChannelMin + 1), kTimerInterval = (kSampleInterval / kNumChannelMasks), kMaxJitterInterval = 4096, kMaxOccupancy = 0xffff, diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index f4baf6265..b5702a2c9 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -46,7 +46,7 @@ #include "common/code_utils.hpp" #include "common/debug.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" namespace ot { namespace Ncp { @@ -204,7 +204,7 @@ NcpBase::NcpBase(Instance *aInstance) , mDecoder() , mHostPowerStateInProgress(false) , mLastStatus(SPINEL_STATUS_OK) - , mScanChannelMask(Phy::kSupportedChannels) + , mScanChannelMask(Radio::kSupportedChannels) , mScanPeriod(200) , mDiscoveryScanJoinerFlag(false) , mDiscoveryScanEnableFiltering(false) diff --git a/tests/unit/test_mac_frame.cpp b/tests/unit/test_mac_frame.cpp index 2a5a7dafe..6946de498 100644 --- a/tests/unit/test_mac_frame.cpp +++ b/tests/unit/test_mac_frame.cpp @@ -30,7 +30,7 @@ #include "common/debug.hpp" #include "mac/mac.hpp" #include "mac/mac_frame.hpp" -#include "phy/phy.hpp" +#include "radio/radio.hpp" #include "utils/wrap_string.h" #include "test_util.h" @@ -94,7 +94,7 @@ void VerifyChannelMaskContent(const Mac::ChannelMask &aMask, uint8_t *aChannels, uint8_t index = 0; uint8_t channel; - for (channel = Phy::kChannelMin; channel <= Phy::kChannelMax; channel++) + for (channel = Radio::kChannelMin; channel <= Radio::kChannelMax; channel++) { if (index < aLength) { @@ -141,7 +141,7 @@ void TestMacChannelMask(void) uint8_t channles4[] = {20}; Mac::ChannelMask mask1; - Mac::ChannelMask mask2(Phy::kSupportedChannels); + Mac::ChannelMask mask2(Radio::kSupportedChannels); printf("Testing Mac::ChannelMask\n"); @@ -149,12 +149,12 @@ void TestMacChannelMask(void) printf("empty = %s\n", mask1.ToString().AsCString()); VerifyOrQuit(!mask2.IsEmpty(), "ChannelMask.IsEmpty failed\n"); - VerifyOrQuit(mask2.GetMask() == Phy::kSupportedChannels, "ChannelMask.GetMask() failed\n"); + VerifyOrQuit(mask2.GetMask() == Radio::kSupportedChannels, "ChannelMask.GetMask() failed\n"); printf("all_channels = %s\n", mask2.ToString().AsCString()); - mask1.SetMask(Phy::kSupportedChannels); + mask1.SetMask(Radio::kSupportedChannels); VerifyOrQuit(!mask1.IsEmpty(), "ChannelMask.IsEmpty failed\n"); - VerifyOrQuit(mask1.GetMask() == Phy::kSupportedChannels, "ChannelMask.GetMask() failed\n"); + VerifyOrQuit(mask1.GetMask() == Radio::kSupportedChannels, "ChannelMask.GetMask() failed\n"); VerifyChannelMaskContent(mask1, all_channels, sizeof(all_channels)); @@ -204,8 +204,8 @@ void TestMacChannelMask(void) mask2.Clear(); VerifyOrQuit(mask1 == mask2, "ChannelMask.operator== failed\n"); - mask1.SetMask(Phy::kSupportedChannels); - mask2.SetMask(Phy::kSupportedChannels); + mask1.SetMask(Radio::kSupportedChannels); + mask2.SetMask(Radio::kSupportedChannels); VerifyOrQuit(mask1 == mask2, "ChannelMask.operator== failed\n"); mask1.Clear();