Skip to content

Commit

Permalink
[Telink] RPC implementation added (#23740)
Browse files Browse the repository at this point in the history
Basic RPC functionaliy.

Signed-off-by: Maciej Bojczuk <[email protected]>

Signed-off-by: Maciej Bojczuk <[email protected]>
  • Loading branch information
bojczmac authored and pull[bot] committed May 19, 2023
1 parent 5c534ee commit 1096487
Show file tree
Hide file tree
Showing 18 changed files with 937 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/telink/app/enable-gnu-std.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
#

add_library(gnu17 INTERFACE)
target_compile_options(gnu17 INTERFACE -std=gnu++17 -D_SYS__PTHREADTYPES_H_)
target_compile_options(gnu17 INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17> -D_SYS__PTHREADTYPES_H_)
target_link_libraries(app PRIVATE gnu17)
13 changes: 9 additions & 4 deletions config/telink/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ macro(chip_gn_arg ARG VALUE)
string(APPEND CHIP_GN_ARGS "--arg\n${ARG}\n${VALUE}\n")
endmacro()


# ==============================================================================
# Prepare CHIP configuration based on the project Kconfig configuration
# ==============================================================================
Expand Down Expand Up @@ -128,10 +129,6 @@ if (CONFIG_CHIP_LIB_SHELL)
list(APPEND CHIP_LIBRARIES -lCHIPShell)
endif()

if (CONFIG_CHIP_PW_RPC)
list(APPEND CHIP_LIBRARIES -lPwRpc)
endif()

if (CONFIG_TELINK_BLE_LIB)
list(APPEND CHIP_LIBRARIES -lB91_ble_lib)
endif()
Expand Down Expand Up @@ -226,6 +223,14 @@ if (CHIP_PROJECT_CONFIG)
chip_gn_arg_string("chip_project_config_include" ${CHIP_PROJECT_CONFIG})
chip_gn_arg_string("chip_system_project_config_include" ${CHIP_PROJECT_CONFIG})
endif()

if (CONFIG_CHIP_PW_RPC)
set(PIGWEED_DIR "//third_party/pigweed/repo")
chip_gn_arg_string("pw_assert_BACKEND" ${PIGWEED_DIR}/pw_assert_log:check_backend)
chip_gn_arg_string("pw_log_BACKEND" ${PIGWEED_DIR}/pw_log_basic)
chip_gn_arg("pw_build_LINK_DEPS" [\"${PIGWEED_DIR}/pw_assert:impl\",\ \"${PIGWEED_DIR}/pw_log:impl\"])
endif()

if (CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER)
chip_gn_arg_bool("chip_build_example_providers" "true")
list(APPEND CHIP_LIBRARIES -lMatterDeviceInfoProviderExample)
Expand Down
27 changes: 27 additions & 0 deletions examples/common/pigweed/telink/PigweedLoggerMutex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "PigweedLoggerMutex.h"

namespace chip {
namespace rpc {

PigweedLoggerMutex logger_mutex;

} // namespace rpc
} // namespace chip
52 changes: 52 additions & 0 deletions examples/common/pigweed/telink/PigweedLoggerMutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "PigweedLogger.h"
#include "pigweed/RpcService.h"
#include <zephyr/zephyr.h>

namespace chip {
namespace rpc {
class PigweedLoggerMutex : public ::chip::rpc::Mutex
{
public:
PigweedLoggerMutex() {}
void Lock() override
{
k_sem * sem = PigweedLogger::GetSemaphore();
if (sem)
{
k_sem_take(sem, K_FOREVER);
}
}
void Unlock() override
{
k_sem * sem = PigweedLogger::GetSemaphore();
if (sem)
{
k_sem_give(sem);
}
}
};

extern PigweedLoggerMutex logger_mutex;

} // namespace rpc
} // namespace chip
159 changes: 159 additions & 0 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,162 @@ chip_configure_data_model(app
if(CONFIG_CHIP_OTA_REQUESTOR)
target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp)
endif()

# Fix for unused swap parameter in: zephyr/include/zephyr/arch/riscv/irq.h:70
add_compile_options(-Wno-error=unused-parameter)

if (CONFIG_CHIP_PW_RPC)

# Make all targets created below depend on zephyr_interface to inherit MCU-related compilation flags
link_libraries($<BUILD_INTERFACE:zephyr_interface>)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)

pw_set_module_config(pw_rpc_CONFIG pw_rpc.disable_global_mutex_config)
pw_set_backend(pw_log pw_log_basic)
pw_set_backend(pw_assert.check pw_assert_log.check_backend)
pw_set_backend(pw_assert.assert pw_assert.assert_compatibility_backend)
pw_set_backend(pw_sys_io pw_sys_io.telink)
pw_set_backend(pw_trace pw_trace_tokenized)
set(dir_pw_third_party_nanopb "${CHIP_ROOT}/third_party/nanopb/repo" CACHE STRING "" FORCE)

add_subdirectory(third_party/connectedhomeip/third_party/pigweed/repo)
add_subdirectory(third_party/connectedhomeip/third_party/nanopb/repo)
add_subdirectory(third_party/connectedhomeip/examples/platform/telink/pw_sys_io)

pw_proto_library(attributes_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/attributes_service.proto
INPUTS
${CHIP_ROOT}/examples/common/pigweed/protos/attributes_service.options
PREFIX
attributes_service
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_proto
)

pw_proto_library(button_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/button_service.proto
PREFIX
button_service
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_proto
)

pw_proto_library(descriptor_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/descriptor_service.proto
PREFIX
descriptor_service
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_proto
)

pw_proto_library(device_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.proto
INPUTS
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.options
PREFIX
device_service
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
DEPS
pw_protobuf.common_proto
)

pw_proto_library(lighting_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/lighting_service.proto
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
PREFIX
lighting_service
DEPS
pw_protobuf.common_proto
)

pw_proto_library(ot_cli_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/ot_cli_service.proto
INPUTS
${CHIP_ROOT}/examples/common/pigweed/protos/ot_cli_service.options
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
PREFIX
ot_cli_service
DEPS
pw_protobuf.common_proto
)

pw_proto_library(thread_service
SOURCES
${CHIP_ROOT}/examples/common/pigweed/protos/thread_service.proto
INPUTS
${CHIP_ROOT}/examples/common/pigweed/protos/thread_service.options
STRIP_PREFIX
${CHIP_ROOT}/examples/common/pigweed/protos
PREFIX
thread_service
DEPS
pw_protobuf.common_proto
)

target_sources(app PRIVATE
../../common/pigweed/RpcService.cpp
../../common/pigweed/telink/PigweedLoggerMutex.cpp
${TELINK_COMMON}/Rpc.cpp
${TELINK_COMMON}/util/src/PigweedLogger.cpp
)

target_include_directories(app PRIVATE
${PIGWEED_ROOT}/pw_sys_io/public
${CHIP_ROOT}/src/lib/support
${CHIP_ROOT}/src/system
${TELINK_COMMON}
../../common
../../common/pigweed
../../common/pigweed/telink)

target_compile_options(app PRIVATE
"-DPW_RPC_ATTRIBUTE_SERVICE=1"
"-DPW_RPC_BUTTON_SERVICE=1"
"-DPW_RPC_DESCRIPTOR_SERVICE=1"
"-DPW_RPC_DEVICE_SERVICE=1"
"-DPW_RPC_LIGHTING_SERVICE=1"
"-DPW_RPC_THREAD_SERVICE=1"
"-DPW_RPC_TRACING_SERVICE=1"
"-DPW_TRACE_BACKEND_SET=1")

target_link_libraries(app PRIVATE
attributes_service.nanopb_rpc
button_service.nanopb_rpc
descriptor_service.nanopb_rpc
device_service.nanopb_rpc
lighting_service.nanopb_rpc
thread_service.nanopb_rpc
pw_checksum
pw_hdlc
pw_log
pw_rpc.server
pw_trace_tokenized
pw_trace_tokenized.trace_buffer
pw_trace_tokenized.rpc_service
pw_trace_tokenized.protos.nanopb_rpc
)

target_link_options(app
PUBLIC
"-T${PIGWEED_ROOT}/pw_tokenizer/pw_tokenizer_linker_sections.ld"
)

endif(CONFIG_CHIP_PW_RPC)
12 changes: 12 additions & 0 deletions examples/lighting-app/telink/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,15 @@ Usage of OTA:
Once the transfer is complete, OTA requestor sends ApplyUpdateRequest command to
OTA provider for applying the image. Device will restart on successful
application of OTA image.

### Building with Pigweed RPCs

The RPCs in `lighting-common/lighting_service/lighting_service.proto` can be
used to control various functionalities of the lighting app from a USB-connected
host computer. To build the example with the RPC server, run the following
command with _build-target_ replaced with the build target name of the Nordic
Semiconductor's kit you own:
```
$ west build -b tlsr9518adk80d -- -DOVERLAY_CONFIG=rpc.overlay
```
16 changes: 16 additions & 0 deletions examples/lighting-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <platform/telink/FactoryDataProvider.h>
#endif

#ifdef CONFIG_CHIP_PW_RPC
#include "Rpc.h"
#endif

#include <cstdint>

struct k_timer;
Expand All @@ -40,7 +44,18 @@ class AppTask
void PostEvent(AppEvent * event);
void UpdateClusterState();

enum ButtonId_t
{
kButtonId_LightingAction = 1,
kButtonId_FactoryReset,
kButtonId_StartThread,
kButtonId_StartBleAdv
} ButtonId;

private:
#ifdef CONFIG_CHIP_PW_RPC
friend class chip::rpc::TelinkButton;
#endif
friend AppTask & GetAppTask(void);
CHIP_ERROR Init();

Expand All @@ -62,6 +77,7 @@ class AppTask
static void LightingActionEventHandler(AppEvent * aEvent);
static void StartBleAdvHandler(AppEvent * aEvent);

static void ButtonEventHandler(ButtonId_t btnId, bool btnPressed);
static void InitButtons(void);

static void ThreadProvisioningHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
Expand Down
47 changes: 47 additions & 0 deletions examples/lighting-app/telink/rpc.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This file should be used as a configuration overlay to build Pigweed RPCs to
# lighting-app.

# Enable Pigweed RPC
CONFIG_CHIP_PW_RPC=y

# Add support for C++17 to build Pigweed components
CONFIG_STD_CPP14=n
CONFIG_STD_CPP17=y

# Add support for Zephyr console component to use it for Pigweed console purposes
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y
CONFIG_CONSOLE_PUTCHAR_BUFSIZE=256

# Disable features which may interfere with Pigweed HDLC transport
CONFIG_SHELL=n
CONFIG_OPENTHREAD_SHELL=n
CONFIG_BOOT_BANNER=n

# Configure Zephyr logger with defaults backends disabled as the app provides its own,
# based on Pigweed HDLC.
CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=n
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_LOG_BACKEND_RTT=n
CONFIG_LOG_OUTPUT=y

# Increase zephyr tty rx buffer
CONFIG_CONSOLE_GETCHAR_BUFSIZE=128
Loading

0 comments on commit 1096487

Please sign in to comment.