new feature: Add RT-Thread platform support#1012
new feature: Add RT-Thread platform support#1012clolckliang wants to merge 1 commit intoeclipse-zenoh:mainfrom
Conversation
|
PR missing one of the required labels: {'internal', 'breaking-change', 'bug', 'documentation', 'enhancement', 'new feature', 'dependencies'} |
- Implement platform abstraction layer for RT-Thread RTOS - Add network layer with TCP/UDP unicast/multicast support - Integrate with RT-Thread build system (SCons, Kconfig) - Provide comprehensive examples and documentation - Support RT-Thread 4.0+ with lwIP network stack - Memory optimized for embedded environments (16-32KB RAM) Features implemented: - Multi-threading with RT-Thread primitives - Memory management using RT-Thread allocators - Network communication (TCP/UDP unicast/multicast) - Time management and sleep functions - Synchronization primitives (mutexes, condition variables) - Random number generation - MSH command integration for examples - Kconfig-based configuration - SCons build system integration Testing completed: - Basic functionality (memory, threads, mutexes, time) - Network operations (TCP/UDP sockets, multicast) - Zenoh protocol (sessions, pub/sub, query/reply) - Integration with RT-Thread build system
b9728e8 to
83c2d09
Compare
|
PR missing one of the required labels: {'breaking-change', 'bug', 'new feature', 'dependencies', 'documentation', 'enhancement', 'internal'} |
|
This workflow requires one of the following labels: internal, breaking-change, bug, documentation, enhancement, new feature, dependencies. |
|
Could you please add the "new feature" label to this PR? This adds RT-Thread platform support to zenoh-pico. @eclipse-zenoh/maintainers |
There was a problem hiding this comment.
Pylintpython3 (reported by Codacy) found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
There was a problem hiding this comment.
Markdownlint (reported by Codacy) found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
|
Dear @clolckliang, thanks for your contribution and sorry for the long reply! |
There was a problem hiding this comment.
Pull request overview
This PR adds a new RT-Thread platform port for zenoh-pico, including RTOS system primitives, a POSIX/lwIP-based networking backend, RT-Thread packaging/build integration (SCons/Kconfig/package.json), plus RT-Thread-specific examples and documentation.
Changes:
- Added RT-Thread platform abstraction (tasks/mutex/condvar/time/memory/random) and a new RT-Thread network backend.
- Integrated RT-Thread platform selection via
ZENOH_RTTHREAD, plus RT-Thread config defaults and RT-Thread package/build files. - Added RT-Thread examples and a substantial set of RT-Thread-focused docs/guides/scripts.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 31 comments.
Show a summary per file
| File | Description |
|---|---|
| submit_pr.py | Helper script for submitting PRs from a local environment (hardcoded paths/username). |
| src/system/rtthread/system.c | RT-Thread implementation of random/memory/threading/sync/time APIs. |
| src/system/rtthread/network.c | RT-Thread TCP/UDP socket implementation (POSIX-style). |
| package.json | RT-Thread package descriptor metadata. |
| include/zenoh-pico/system/platform/rtthread.h | RT-Thread platform type definitions (tasks/mutex/condvar/sockets). |
| include/zenoh-pico/system/common/platform.h | Adds ZENOH_RTTHREAD include branch. |
| include/zenoh-pico/config_rtthread.h | RT-Thread default feature flags and sizing/timeouts. |
| include/zenoh-pico/config.h | Adds ZENOH_RTTHREAD config include. |
| examples/rtthread/z_pub.c | RT-Thread publisher example + MSH export. |
| examples/rtthread/z_sub.c | RT-Thread subscriber example + MSH export. |
| examples/rtthread/z_get.c | RT-Thread GET/query example + MSH export. |
| examples/rtthread/z_put.c | RT-Thread PUT example + MSH export. |
| examples/rtthread/z_test.c | RT-Thread basic functionality test + MSH export. |
| copy_files.bat | Local Windows copy helper for moving RT-Thread files into another checkout. |
| check_rtthread_files.py | Local validation script to check presence of RT-Thread-related files. |
| SUBMIT_PR_GUIDE.md | Detailed PR submission guide (Chinese). |
| SIMPLE_PR_GUIDE.md | Simplified PR submission guide (Chinese). |
| SConscript | RT-Thread SCons build integration for the package. |
| RTTHREAD_ADAPTATION_SUMMARY.md | Technical summary of the RT-Thread port (Chinese). |
| README_RTTHREAD.md | RT-Thread usage documentation and examples. |
| PR_READY_SUMMARY.md | Summary/checklist-style “ready” status doc. |
| PR_DESCRIPTION.md | PR description template content. |
| PR_CHECKLIST.md | PR checklist for the RT-Thread port. |
| MANUAL_PR_STEPS.md | Manual PR submission steps guide (Chinese). |
| Kconfig | RT-Thread menuconfig options for zenoh-pico package. |
| COMMIT_MESSAGES.md | Commit message templates for the RT-Thread PR. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| // Start read and lease tasks for zenoh-pico | ||
| if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { |
There was a problem hiding this comment.
zp_start_read_task() / zp_start_lease_task() take a mutable loaned session, but this example passes z_loan(s) instead of z_loan_mut(s). Please use z_loan_mut(s) for task helpers.
| if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { | |
| if (zp_start_read_task(z_loan_mut(s), NULL) < 0 || zp_start_lease_task(z_loan_mut(s), NULL) < 0) { |
| echo 🚀 RT-Thread 适配文件复制脚本 | ||
| echo ================================ | ||
|
|
||
| set SOURCE_DIR=E:\Programing\Embedded_Drivers_And_Tools\modules\zenoh-pico |
There was a problem hiding this comment.
SOURCE_DIR is hardcoded to a specific local path (E:\Programing\...), making this script non-portable and not useful to other contributors. Consider removing it from the upstream PR or parameterizing the source directory.
| set SOURCE_DIR=E:\Programing\Embedded_Drivers_And_Tools\modules\zenoh-pico | |
| rem 如果未预先设置 SOURCE_DIR,则默认使用当前脚本所在目录 | |
| if not defined SOURCE_DIR ( | |
| set "SOURCE_DIR=%~dp0" | |
| ) |
| z_get_options_default(&opts); | ||
| z_owned_bytes_t payload; | ||
| if (value != NULL) { | ||
| z_bytes_from_str(&payload, value); |
There was a problem hiding this comment.
z_bytes_from_str() does not have a 2-argument form. For a constant string, use z_bytes_copy_from_str(), or if you want to transfer ownership provide deleter/context per the API. As written, this won’t compile.
| z_bytes_from_str(&payload, value); | |
| z_bytes_copy_from_str(&payload, value); |
| z_bytes_from_str(&payload, value); | ||
| z_put(z_loan(s), z_loan(ke), z_move(payload), NULL); | ||
|
|
||
| z_close(z_move(s), NULL); |
There was a problem hiding this comment.
z_close() expects a loaned session (z_loan_mut(s)) and the owned session should then be dropped. Calling z_close(z_move(s), ...) uses the wrong argument kind and doesn’t drop the session.
| z_close(z_move(s), NULL); | |
| z_close(z_loan_mut(s), NULL); | |
| z_drop(z_move(s)); |
| // Start read and lease tasks for zenoh-pico | ||
| if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { | ||
| printf("Unable to start read and lease tasks\n"); | ||
| z_close(z_move(s), NULL); | ||
| return -1; |
There was a problem hiding this comment.
z_close() expects a loaned session (z_loan_mut(s)) and then the owned session should be dropped. Calling z_close(z_move(s), ...) uses the wrong argument kind and doesn’t drop s. Please change to z_close(z_loan_mut(s), ...); z_drop(z_move(s));.
| z_owned_publisher_t pub; | ||
| z_view_keyexpr_t ke; | ||
| z_view_keyexpr_from_str_unchecked(&ke, "demo/example"); | ||
| z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL); |
There was a problem hiding this comment.
The publisher snippet calls z_declare_publisher() with the wrong argument order. The API is z_declare_publisher(session, &pub, keyexpr, options) (see include/zenoh-pico/api/primitives.h), but the snippet passes (&pub, session, ...), which won’t compile.
| z_declare_publisher(&pub, z_loan(s), z_loan(ke), NULL); | |
| z_declare_publisher(z_loan(s), &pub, z_loan(ke), NULL); |
| z_owned_subscriber_t sub; | ||
| z_view_keyexpr_t ke; | ||
| z_view_keyexpr_from_str_unchecked(&ke, "demo/example"); | ||
| z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL); |
There was a problem hiding this comment.
The subscriber example calls z_declare_subscriber() with the wrong argument order (it should be z_declare_subscriber(session, &sub, keyexpr, &callback, options)). As written, this snippet won’t compile against the current API.
| z_declare_subscriber(&sub, z_loan(s), z_loan(ke), z_move(callback), NULL); | |
| z_declare_subscriber(z_loan(s), &sub, z_loan(ke), z_move(callback), NULL); |
| printf("Elapsed time: %lu ms\n", elapsed_ms); | ||
|
|
||
| z_time_t time_now = z_time_now(); | ||
| printf("Time now: %lu\n", time_now.time); |
There was a problem hiding this comment.
z_time_t is struct timeval on this platform, so it doesn’t have a .time field. This won’t compile; use tv_sec / tv_usec or format via z_time_now_as_str().
| printf("Time now: %lu\n", time_now.time); | |
| printf("Time now: %ld.%06ld\n", (long)time_now.tv_sec, (long)time_now.tv_usec); |
| zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, mode); | ||
| if (locator != NULL) { | ||
| zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, locator); |
There was a problem hiding this comment.
zp_config_insert() expects a mutable loaned config (z_loaned_config_t*), but this example passes z_loan(config) instead of z_loan_mut(config). Please use the mutable loan macro when inserting/modifying config values.
| zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, mode); | |
| if (locator != NULL) { | |
| zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, locator); | |
| zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, mode); | |
| if (locator != NULL) { | |
| zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, locator); |
| zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, mode); | ||
| if (locator != NULL) { | ||
| zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, locator); |
There was a problem hiding this comment.
This example mutates the config via zp_config_insert() but uses z_loan(config) instead of z_loan_mut(config). Please use z_loan_mut(config) when inserting config values.
| zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, mode); | |
| if (locator != NULL) { | |
| zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, locator); | |
| zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, mode); | |
| if (locator != NULL) { | |
| zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, locator); |
Add RT-Thread Platform Support
Summary
This PR adds comprehensive support for the RT-Thread real-time operating system to zenoh-pico, enabling zenoh communication capabilities on RT-Thread-based embedded devices.
Changes Overview
🎯 Platform Abstraction Layer
Platform Header:
include/zenoh-pico/system/platform/rtthread.hSystem Implementation:
src/system/rtthread/system.crt_tick_get()rt_malloc/rt_realloc/rt_freeNetwork Implementation:
src/system/rtthread/network.c⚙️ Configuration System
RT-Thread Config:
include/zenoh-pico/config_rtthread.hBuild Integration:
SConscript- SCons build script for RT-Thread projectsKconfig- Configuration options for RT-Thread menuconfigpackage.json- RT-Thread package descriptorPlatform Detection: Updated
include/zenoh-pico/config.handinclude/zenoh-pico/system/platform.h📚 Examples and Documentation
Example Programs:
examples/rtthread/z_pub.c- Publisher exampleexamples/rtthread/z_sub.c- Subscriber exampleexamples/rtthread/z_get.c- GET query exampleexamples/rtthread/z_put.c- PUT exampleexamples/rtthread/z_test.c- Basic functionality testDocumentation:
README_RTTHREAD.md- Comprehensive usage guideFeatures Implemented
✅ Core Functionality
✅ RT-Thread Integration
✅ Network Protocols
Testing
Basic Functionality Tests
Network Tests
Zenoh Protocol Tests
Compatibility
RT-Thread Versions
Network Stack
Memory Requirements
Performance Characteristics
Usage Example
Integration Instructions
Add to RT-Thread Project:
# Copy to RT-Thread packages directory cp -r zenoh-pico /path/to/rtthread/packages/iot/Configure Features:
scons --menuconfig # Navigate to: RT-Thread online packages -> IoT -> zenoh-picoBuild and Run:
scons # In RT-Thread MSH: zenoh_test, zenoh_pub, zenoh_subBreaking Changes
None. This is a new platform addition that doesn't affect existing platforms.
Checklist
Related Issues
This PR addresses the need for RT-Thread support in zenoh-pico, enabling zenoh communication on one of the most popular Chinese RTOS platforms used in IoT and embedded applications.
Future Enhancements