From 4a0b4d60685a2e0fd6b00ca1770bc8682000f70e Mon Sep 17 00:00:00 2001 From: Mason Tran Date: Thu, 29 Feb 2024 00:16:32 -0500 Subject: [PATCH] [slc][platform] add OpenThread vendor extension and ot_crash_handler to platform projects The new `ot_vendor_extension` component implements the `ot::Extension::Extension` class. This will print the efr32 on NCP/RCP initialization. The rest of the class is stubbed out. --- slc/component/ot_vendor_extension.slcc | 17 +++ .../openthread-efr32-rcp-spi.slcp | 3 + .../openthread-efr32-rcp-uart.slcp | 3 + ...32-soc-with-buttons-power-manager-csl.slcp | 3 + ...-efr32-soc-with-buttons-power-manager.slcp | 3 + .../openthread-efr32-soc-with-buttons.slcp | 3 + .../openthread-efr32-soc.slcp | 3 + src/openthread/core/vendor_extension.cpp | 109 ++++++++++++++++++ 8 files changed, 144 insertions(+) create mode 100644 slc/component/ot_vendor_extension.slcc create mode 100644 src/openthread/core/vendor_extension.cpp diff --git a/slc/component/ot_vendor_extension.slcc b/slc/component/ot_vendor_extension.slcc new file mode 100644 index 00000000..ef4732bd --- /dev/null +++ b/slc/component/ot_vendor_extension.slcc @@ -0,0 +1,17 @@ +id: ot_vendor_extension +label: Silicon Labs OpenThread Vendor Extension +package: OpenThread +category: OpenThread +quality: production +description: This component implements ot::Extension::ExtensionBase for EFR32 +provides: + - name: ot_vendor_extension +include: + - path: openthread/src/ + file_list: + - path: ncp/ncp_base.hpp +source: + - path: src/openthread/core/vendor_extension.cpp +define: + - name: OPENTHREAD_ENABLE_VENDOR_EXTENSION + value: 1 diff --git a/slc/platform_projects/openthread-efr32-rcp-spi.slcp b/slc/platform_projects/openthread-efr32-rcp-spi.slcp index e5071802..f1fd6d36 100644 --- a/slc/platform_projects/openthread-efr32-rcp-spi.slcp +++ b/slc/platform_projects/openthread-efr32-rcp-spi.slcp @@ -6,10 +6,13 @@ category: OpenThread Examples quality: production component: + - id: ot_crash_handler - id: ot_platform_abstraction_core - id: ot_mbedtls - id: ot_stack_features_config from: ot-efr32 + - id: ot_vendor_extension + from: ot-efr32 - id: ot_ncp_spidrv - id: rail_util_pti diff --git a/slc/platform_projects/openthread-efr32-rcp-uart.slcp b/slc/platform_projects/openthread-efr32-rcp-uart.slcp index 7b3a2833..4719a392 100644 --- a/slc/platform_projects/openthread-efr32-rcp-uart.slcp +++ b/slc/platform_projects/openthread-efr32-rcp-uart.slcp @@ -6,10 +6,13 @@ category: OpenThread Examples quality: production component: + - id: ot_crash_handler - id: ot_platform_abstraction_core - id: ot_mbedtls - id: ot_stack_features_config from: ot-efr32 + - id: ot_vendor_extension + from: ot-efr32 - id: uartdrv_usart instance: - vcom diff --git a/slc/platform_projects/openthread-efr32-soc-with-buttons-power-manager-csl.slcp b/slc/platform_projects/openthread-efr32-soc-with-buttons-power-manager-csl.slcp index e11cbf77..c080ad64 100644 --- a/slc/platform_projects/openthread-efr32-soc-with-buttons-power-manager-csl.slcp +++ b/slc/platform_projects/openthread-efr32-soc-with-buttons-power-manager-csl.slcp @@ -7,11 +7,14 @@ category: OpenThread Examples quality: production component: + - id: ot_crash_handler - id: ot_platform_abstraction_core - id: ot_psa_crypto - id: ot_mbedtls - id: ot_stack_features_config from: ot-efr32 + - id: ot_vendor_extension + from: ot-efr32 - id: uartdrv_usart instance: - vcom diff --git a/slc/platform_projects/openthread-efr32-soc-with-buttons-power-manager.slcp b/slc/platform_projects/openthread-efr32-soc-with-buttons-power-manager.slcp index 49fe6e0f..e23fd039 100644 --- a/slc/platform_projects/openthread-efr32-soc-with-buttons-power-manager.slcp +++ b/slc/platform_projects/openthread-efr32-soc-with-buttons-power-manager.slcp @@ -7,11 +7,14 @@ category: OpenThread Examples quality: production component: + - id: ot_crash_handler - id: ot_platform_abstraction_core - id: ot_psa_crypto - id: ot_mbedtls - id: ot_stack_features_config from: ot-efr32 + - id: ot_vendor_extension + from: ot-efr32 - id: uartdrv_usart instance: - vcom diff --git a/slc/platform_projects/openthread-efr32-soc-with-buttons.slcp b/slc/platform_projects/openthread-efr32-soc-with-buttons.slcp index 931829e9..70ad50a2 100644 --- a/slc/platform_projects/openthread-efr32-soc-with-buttons.slcp +++ b/slc/platform_projects/openthread-efr32-soc-with-buttons.slcp @@ -7,11 +7,14 @@ category: OpenThread Examples quality: production component: + - id: ot_crash_handler - id: ot_platform_abstraction_core - id: ot_psa_crypto - id: ot_mbedtls - id: ot_stack_features_config from: ot-efr32 + - id: ot_vendor_extension + from: ot-efr32 - id: uartdrv_usart instance: - vcom diff --git a/slc/platform_projects/openthread-efr32-soc.slcp b/slc/platform_projects/openthread-efr32-soc.slcp index 3d995ea3..d397c926 100644 --- a/slc/platform_projects/openthread-efr32-soc.slcp +++ b/slc/platform_projects/openthread-efr32-soc.slcp @@ -6,11 +6,14 @@ category: OpenThread Examples quality: production component: + - id: ot_crash_handler - id: ot_platform_abstraction_core - id: ot_psa_crypto - id: ot_mbedtls - id: ot_stack_features_config from: ot-efr32 + - id: ot_vendor_extension + from: ot-efr32 - id: uartdrv_usart instance: - vcom diff --git a/src/openthread/core/vendor_extension.cpp b/src/openthread/core/vendor_extension.cpp new file mode 100644 index 00000000..34d5e309 --- /dev/null +++ b/src/openthread/core/vendor_extension.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2024, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements a OpenThread vendor extension for EFR32 + */ + +#include "openthread-core-config.h" + +#include +#include + +#include "common/code_utils.hpp" +#include "common/new.hpp" + +#include "instance/extension.hpp" + +#if defined(SL_COMPONENT_CATALOG_PRESENT) +#include "sl_component_catalog.h" +#endif + +extern "C" void efr32PrintResetInfo(void); + +namespace ot { +namespace Extension { + +/** + * Defines the vendor extension object. + * + */ +class Extension : public ExtensionBase +{ +public: + explicit Extension(Instance &aInstance) + : ExtensionBase(aInstance) + { + } +}; + +// ---------------------------------------------------------------------------- +// `ExtensionBase` API +// ---------------------------------------------------------------------------- + +static OT_DEFINE_ALIGNED_VAR(sExtensionRaw, sizeof(Extension), uint64_t); + +ExtensionBase &ExtensionBase::Init(Instance &aInstance) +{ + ExtensionBase *ext = reinterpret_cast(&sExtensionRaw); + + VerifyOrExit(!ext->mIsInitialized); + + ext = new (&sExtensionRaw) Extension(aInstance); + +exit: + return *ext; +} + +void ExtensionBase::SignalInstanceInit(void) +{ + // OpenThread instance is initialized and ready. + +#if defined(SL_CATALOG_OT_CRASH_HANDLER_PRESENT) + efr32PrintResetInfo(); +#endif +} + +void ExtensionBase::SignalNcpInit(Ncp::NcpBase &aNcpBase) +{ + // NCP instance is initialized and ready. + OT_UNUSED_VARIABLE(aNcpBase); + +#if defined(SL_CATALOG_OT_CRASH_HANDLER_PRESENT) + efr32PrintResetInfo(); +#endif +} + +void ExtensionBase::HandleNotifierEvents(Events aEvents) +{ + OT_UNUSED_VARIABLE(aEvents); +} + +} // namespace Extension +} // namespace ot