Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/twister.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
west config --global update.narrow true
west update --path-cache /github/cache/zephyrproject 2>&1 1> west.update.log || west update --path-cache /github/cache/zephyrproject 2>&1 1> west.update.log || ( rm -rf ../modules ../bootloader ../tools && west update --path-cache /github/cache/zephyrproject)
west forall -c 'git reset --hard HEAD'
pip3 install pigweed

- name: Generate Test Plan with Twister
if: github.event_name == 'pull_request_target'
Expand Down Expand Up @@ -166,7 +167,7 @@ jobs:
git log --pretty=oneline | head -n 10
fi
echo "$HOME/.local/bin" >> $GITHUB_PATH

pip3 install pigweed
west init -l . || true
west config --global update.narrow true
west update --path-cache /github/cache/zephyrproject 2>&1 1> west.update.log || west update --path-cache /github/cache/zephyrproject 2>&1 1> west.update.log || ( rm -rf ../modules ../bootloader ../tools && west update --path-cache /github/cache/zephyrproject)
Expand Down
3 changes: 3 additions & 0 deletions modules/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ comment "zcbor module not available."
comment "CHRE module not available."
depends on !ZEPHYR_CHRE_MODULE

comment "Pigweed module not available."
depends on !ZEPHYR_PIGWEED_MODULE

# This ensures that symbols are available in Kconfig for dependency checking
# and referencing, while keeping the settings themselves unavailable when the
# modules are not present in the workspace
Expand Down
32 changes: 32 additions & 0 deletions samples/modules/pigweed/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Pigweed
************

Pigweed is a broad open source collection of embedded-targeted libraries.
These libraries are called modules inside Pigweed. Pigweed is intergrated into Zephyr as a single Zephyr module.
Individual Pigweed modules can be enabled with Kconfig flags (e.g. `CONFIG_PIGWEED_ASSERT`).
Not every module can be expected to work with Zephyr out of the box.
Only pigweed modules with Zephyr samples are expected to work reliably.

For detailed documentation on individual Pigweed modules, refer to `Pigweed.dev <https://pigweed.dev/module_guides.html>`_.

Requirements
************

* The pigweed python module (included in `requirements-extra.txt`)
* The `pw_rpc` sample depends on the :ref:`nanopb<nanopb_sample>` module.

Building
************

To build the samples use the following west command:

.. zephyr-app-commands::
:zephyr-app: samples/modules/pigweed/<pigweed_module_sample>
:board: native_posix
:goals: build

Maintenance
************

Bug fixes and feature changes should be sent to the upstream `Pigweed repository <https://pigweed.googlesource.com/pigweed/pigweed/>`_.
Pigweed APIs are subject to change, users should pin to specific revision in west.yml to ensure compatibility.
36 changes: 36 additions & 0 deletions samples/modules/pigweed/pw_rpc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2023 Google LLC
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(rpc_demo)

add_definitions(-DVERSION=5)
add_definitions(-DCONFIG_RPC_BUFFER_SIZE=1024)
add_definitions(-DPW_LOG_LEVEL=PW_LOG_LEVEL_INFO)
add_definitions(-DPW_LOG_SHOW_MODULE=1)

# Define the proto library
include($ENV{PW_ROOT}/pw_protobuf_compiler/proto.cmake)
pw_proto_library(
rpc_demo.protos
SOURCES proto/demo.proto
)

file(GLOB app_sources src/*.cpp)
target_sources(app
PRIVATE
${app_sources}
)
zephyr_include_directories(include)
zephyr_link_libraries(
rpc_demo.protos.nanopb
rpc_demo.protos.nanopb_rpc
)
target_link_libraries(app
PRIVATE
rpc_demo.protos.nanopb
rpc_demo.protos.nanopb_rpc
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <pw_hdlc/rpc_channel.h>
#include <pw_hdlc/rpc_packets.h>
#include <pw_rpc/client.h>
#include <pw_stream/stream.h>

#include <array>
#include <atomic>

namespace rpc_demo {

class ClientReader {
public:
ClientReader(pw::stream::Reader& rx, pw::rpc::Client* rpc_client);
bool ParsePacket();

private:
pw::stream::Reader& rx_;
pw::rpc::Client* rpc_client_;
std::array<std::byte, CONFIG_RPC_BUFFER_SIZE> decode_buffer_;
pw::hdlc::Decoder decoder_;
};

} // namespace rpc_demo
25 changes: 25 additions & 0 deletions samples/modules/pigweed/pw_rpc/include/rpc_demo/deque_stream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <pw_stream/stream.h>
#include <pw_sync/mutex.h>

#include <deque>

class DequeReadWriter : public pw::stream::NonSeekableReaderWriter {
public:
DequeReadWriter() = default;

protected:
pw::StatusWithSize DoRead(pw::ByteSpan destination) override;
pw::Status DoWrite(pw::ConstByteSpan data) override;

private:
std::deque<std::byte> buff_;
pw::sync::Mutex mutex_;
};
19 changes: 19 additions & 0 deletions samples/modules/pigweed/pw_rpc/include/rpc_demo/rxtx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2023 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <pw_stream/stream.h>

/**
* @return The ReaderWriter stream used for client-to-service communication.
*/
pw::stream::ReaderWriter& ClientToServiceStream();

/**
* @return The ReaderWriter stream used for service-to-client communication.
*/
pw::stream::ReaderWriter& ServiceToClientStream();
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "proto/demo.rpc.pb.h"

namespace rpc_demo {

class DemoService : public pw_rpc::nanopb::DemoService::Service<DemoService> {
public:
::pw::Status GetVersion(const ::rpc_demo_Empty& request,
::rpc_demo_GetVersionResponse& response);

::pw::Status GetSensorList(const ::rpc_demo_Empty& request,
::rpc_demo_GetSensorListResponse& response);

::pw::Status UpdateSensorFrequency(
const ::rpc_demo_UpdateSensorFrequencyRequest& request,
::rpc_demo_UpdateSensorFrequencyResponse& response);

::pw::Status GetSensorSamples(
const ::rpc_demo_GetSensorSamplesRequest& request,
::rpc_demo_GetSensorSamplesResponse& response);
};

} // namespace rpc_demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <pw_hdlc/rpc_channel.h>
#include <pw_span/span.h>
#include <pw_stream/stream.h>

#include <atomic>
#include <thread>

#include "rpc_demo/service/demo_service.h"

namespace rpc_demo {

class ServiceReader {
public:
ServiceReader(pw::stream::Reader* reader,
pw::stream::Writer* writer,
pw::hdlc::RpcChannelOutput* output,
pw::span<pw::rpc::Channel> channels);

bool ParsePacket();

private:
pw::stream::Reader* reader_;
pw::stream::Writer* writer_;
pw::hdlc::RpcChannelOutput* output_;
pw::span<pw::rpc::Channel> channels_;
};

} // namespace rpc_demo
36 changes: 36 additions & 0 deletions samples/modules/pigweed/pw_rpc/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2023 Google LLC
# SPDX-License-Identifier: Apache-2.0

CONFIG_ASSERT=y
CONFIG_NANOPB=y
CONFIG_BOARD_NATIVE_POSIX_64BIT=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4

CONFIG_PIGWEED_ASSERT=y
CONFIG_PIGWEED_BYTES=y
CONFIG_PIGWEED_CHECKSUM=y
CONFIG_PIGWEED_CHRONO_SYSTEM_CLOCK=y
CONFIG_PIGWEED_CONTAINERS=y
CONFIG_PIGWEED_FUNCTION=y
CONFIG_PIGWEED_HDLC=y
CONFIG_PIGWEED_INTERRUPT_CONTEXT=y
CONFIG_PIGWEED_LOG=y
CONFIG_PIGWEED_POLYFILL=y
CONFIG_PIGWEED_POLYFILL_OVERRIDES=y
CONFIG_PIGWEED_PREPROCESSOR=y
CONFIG_PIGWEED_RESULT=y
CONFIG_PIGWEED_ROUTER_PACKET_PARSER=y
CONFIG_PIGWEED_RPC_COMMON=y
CONFIG_PIGWEED_SPAN=y
CONFIG_PIGWEED_STATUS=y
CONFIG_PIGWEED_STREAM=y
CONFIG_PIGWEED_STRING=y
CONFIG_PIGWEED_SYNC_MUTEX=y
CONFIG_PIGWEED_SYS_IO=y
CONFIG_PIGWEED_VARINT=y

CONFIG_CPLUSPLUS=y
CONFIG_STD_CPP17=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_CPP_MAIN=y
67 changes: 67 additions & 0 deletions samples/modules/pigweed/pw_rpc/proto/demo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2023 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

syntax = "proto3";

package rpc_demo;

message GetVersionResponse {
uint32 version_number = 1;
}

message ThreeAxisData {
float x = 1;
float y = 2;
float z = 3;
}

message SensorInfo {
string name = 1;
enum Type {
ACCEL = 0;
GYRO = 1;
MAG = 2;
}
Type type = 2;
uint32 sample_frequency_hz = 3;
}

message GetSensorListResponse {
repeated SensorInfo sensors = 1;
}

message UpdateSensorFrequencyRequest {
uint32 sensor_index = 1;
uint32 sample_frequency_hz = 2;
}

message UpdateSensorFrequencyResponse {
uint32 sample_frequency_hz = 1;
}

message GetSensorSamplesRequest {
uint32 sensor_index = 1;
}

message GetSensorSamplesResponse {
repeated ThreeAxisData data = 1;
}

message Empty {}

enum RpcClientChannelId {
UNASSIGNED = 0;
DEFAULT = 1;
}

service DemoService {
rpc GetVersion(Empty) returns (GetVersionResponse) {}
rpc GetSensorList(Empty) returns (GetSensorListResponse) {}
rpc UpdateSensorFrequency(UpdateSensorFrequencyRequest)
returns (UpdateSensorFrequencyResponse) {}
rpc GetSensorSamples(GetSensorSamplesRequest)
returns (GetSensorSamplesResponse) {}
}
23 changes: 23 additions & 0 deletions samples/modules/pigweed/pw_rpc/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sample:
description: A simple sample of the Pigweed pw_rpc sub module.
name: pw_rpc sample
tests:
sample.modules.pw_rpc:
tags: pw_rpc
platform_allow: native_posix
timeout: 10
modules:
- pigweed
harness: console
harness_config:
type: multi_line
ordered: true
regex:
- "(.*)Starting RPC demo(.*)"
- "(.*)Service waiting for data(.*)"
- "(.*)Starting pw_rpc service(.*)"
- "(.*)Service got packet!(.*)"
- "(.*)Client waiting for response(.*)"
- "(.*)Reading bytes(.*)"
- "(.*)Client got packet!(.*)"
- "(.*)Received version #5(.*)"
Loading