Skip to content

Commit 1e78d16

Browse files
committed
Merge Add async feature gate, blocking serial
PR #40 mctp-estack: Add async feature gate, add blocking serial transport binding from https://github.com/OpenPRoT/mctp-rs/tree/sync-features
2 parents 4930b8b + fafe92f commit 1e78d16

File tree

14 files changed

+229
-50
lines changed

14 files changed

+229
-50
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defmt = "0.3"
1616
deku = { git = "https://github.com/CodeConstruct/deku.git", tag = "cc/deku-v0.19.1/no-alloc-3", default-features = false }
1717
embedded-io-adapters = { version = "0.6", features = ["std", "futures-03"] }
1818
embedded-io-async = "0.6"
19+
embedded-io = "0.6"
1920
enumset = "1.1"
2021
env_logger = "0.11.3"
2122
heapless = "0.8"

ci/runtests.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -v
44
set -e
@@ -15,7 +15,7 @@ cargo fmt -- --check
1515

1616
# Check everything first
1717
cargo check --all-targets --locked
18-
if [ -z "NO_CLIPPY" ]; then
18+
if [ -z "$NO_CLIPPY" ]; then
1919
cargo clippy --all-targets
2020
fi
2121

@@ -27,14 +27,14 @@ cargo test
2727
NOSTD_CRATES="mctp pldm pldm-fw pldm-platform pldm-file"
2828
for c in $NOSTD_CRATES; do
2929
(
30-
cd $c
30+
cd "$c"
3131
cargo build --target thumbv7em-none-eabihf --no-default-features
3232
)
3333
done
3434
ALLOC_CRATES="pldm pldm-platform pldm-file"
3535
for c in $ALLOC_CRATES; do
3636
(
37-
cd $c
37+
cd "$c"
3838
cargo build --target thumbv7em-none-eabihf --no-default-features --features alloc
3939
)
4040
done
@@ -53,6 +53,25 @@ cargo build --target thumbv7em-none-eabihf --features defmt --no-default-feature
5353
cargo build --features log
5454
)
5555

56-
cargo doc
56+
FEATURES_ASYNC="async"
57+
FEATURES_SYNC=""
58+
59+
declare -a FEATURES=(
60+
"$FEATURES_SYNC"
61+
"$FEATURES_ASYNC"
62+
)
63+
64+
# mctp-estack, sync an async
65+
(
66+
cd mctp-estack
67+
for feature in "${FEATURES[@]}"; do
68+
cargo test --features="$feature"
69+
done;
70+
)
71+
72+
# run cargo doc tests
73+
for feature in "${FEATURES[@]}"; do
74+
cargo doc --features="$feature"
75+
done;
5776

5877
echo success

mctp-estack/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ rust-version = "1.85"
1111
[dependencies]
1212
crc = { workspace = true }
1313
defmt = { workspace = true, optional = true }
14-
embassy-sync = "0.7"
15-
embedded-io-async = { workspace = true }
14+
embassy-sync = { version = "0.7", optional = true }
15+
embedded-io.workspace = true
16+
embedded-io-async.workspace = true
1617
heapless = { workspace = true }
1718
log = { workspace = true, optional = true }
1819
mctp = { workspace = true }
@@ -29,7 +30,8 @@ smol = { workspace = true }
2930

3031

3132
[features]
32-
default = ["log"]
33+
default = ["log", "async"]
3334
std = ["mctp/std"]
3435
log = ["dep:log"]
3536
defmt = ["mctp/defmt", "dep:defmt" ]
37+
async = ["dep:embassy-sync"]

mctp-estack/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
[API docs](https://docs.rs/mctp-estack)
44

55
This is a MCTP stack suitable for embedded devices.
6+
A `async` Router for [Embassy](https://embassy.dev/) (or other _async runtime_)
7+
based applications is available through the `async` feature.
68

79
A `Router` instance handles feeding MCTP packets to and from user
810
provided MCTP transports, and handles sending receiving MCTP messages
9-
from applications using the `mctp` crate async traits.
11+
from applications using the `mctp` crate _async_ traits.
1012

1113
Applications using MCTP can create `RouterAsyncListener` and
1214
`RouterAsyncReqChannel` instances.
@@ -16,3 +18,6 @@ MCTP bridging between ports is supported by the `Router`.
1618
The core `Stack` handles IO-less MCTP message reassembly and fragmentation,
1719
and MCTP tag tracking. MCTP transport binding packet encoding and decoding is
1820
provided for I2C, USB, and serial.
21+
22+
## Features
23+
- `async`: _async_ router implementing `mctp` crate _async_ traits

mctp-estack/src/control.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
//! MCTP Control Protocol implementation
88
99
use crate::fmt::*;
10+
#[cfg(feature = "async")]
1011
use crate::Router;
11-
use mctp::{AsyncRespChannel, Eid, Error, Listener, MsgIC, MsgType};
12+
#[cfg(feature = "async")]
13+
use mctp::{AsyncRespChannel, MsgIC};
14+
use mctp::{Eid, Error, Listener, MsgType};
1215
use uuid::Uuid;
1316

1417
/// A `Result` with a MCTP control completion code as error.
@@ -191,7 +194,9 @@ pub struct MctpControlMsg<'a> {
191194
work: [u8; 2],
192195
}
193196

197+
#[cfg(feature = "async")]
194198
const MAX_MSG_SIZE: usize = 20; /* largest is Get Endpoint UUID */
199+
#[cfg(feature = "async")]
195200
const MAX_MSG_TYPES: usize = 8;
196201

197202
impl<'a> MctpControlMsg<'a> {
@@ -424,13 +429,15 @@ where
424429
}
425430

426431
/// A Control Message handler.
432+
#[cfg(feature = "async")]
427433
pub struct MctpControl<'g, 'r> {
428434
rsp_buf: [u8; MAX_MSG_SIZE],
429435
types: heapless::Vec<MsgType, MAX_MSG_TYPES>,
430436
uuid: Option<Uuid>,
431437
router: &'g Router<'r>,
432438
}
433439

440+
#[cfg(feature = "async")]
434441
impl<'g, 'r> MctpControl<'g, 'r> {
435442
/// Create a new instance.
436443
pub fn new(router: &'g Router<'r>) -> Self {

mctp-estack/src/fragment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Fragmenter {
147147
rest = &mut rest[1..];
148148
}
149149

150-
let Ok(n) = self.reader.read(payload, &mut rest) else {
150+
let Ok(n) = self.reader.read(payload, rest) else {
151151
return SendOutput::failure(Error::BadArgument, self);
152152
};
153153
let rest = &rest[n..];

mctp-estack/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55

66
//! # MCTP Stack
77
//!
8-
//! This crate provides a MCTP stack that can be embedded in other programs
9-
//! or devices.
8+
//! This crate provides a MCTP stack and transport bindings,
9+
//! that can be embedded in other programs or devices.
1010
//!
11-
//! A [`Router`] object lets programs use a [`Stack`] with
12-
//! MCTP transport binding links. Each *Port* handles transmitting and receiving
11+
//! The IO-less [`Stack`] handles MCTP message formatting and parsing, independent
12+
//! of any particular MCTP transport binding.
13+
//!
14+
//! A Router for *async* applications is available
15+
//! through the `async` feature.
16+
//! The async `Router` lets programs use a `Stack`
17+
//! by providing implementations for the standard [`mctp` crate](mctp) async traits.
18+
//! Transport bindings are provided by *Ports* which handle transmitting and receiving
1319
//! packets independently. Messages destined for the stack's own EID will
1420
//! be passed to applications.
1521
//!
16-
//! Applications can create [`router::RouterAsyncListener`] and [`router::RouterAsyncReqChannel`]
17-
//! instances to communicate over MCTP. Those implement the standard [`mctp` crate](mctp)
18-
//! async traits.
19-
//!
20-
//! The IO-less [`Stack`] handles MCTP message formatting and parsing, independent
21-
//! of any particular MCTP transport binding.
22+
//! ## Features
23+
//! - `async`: _async_ router implementing [`mctp` crate](mctp) _async_ traits
2224
//!
2325
//! ## Configuration
2426
//!
@@ -35,6 +37,7 @@
3537
// those reworked when using the log crate either.
3638
#![allow(clippy::uninlined_format_args)]
3739
#![warn(clippy::unused_async)]
40+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3841

3942
#[cfg(test)]
4043
#[macro_use]
@@ -61,19 +64,22 @@ pub mod control;
6164
pub mod fragment;
6265
pub mod i2c;
6366
mod reassemble;
67+
#[cfg(feature = "async")]
6468
pub mod router;
6569
pub mod serial;
6670
pub mod usb;
6771
#[macro_use]
6872
mod util;
6973
mod proto;
7074

75+
#[cfg(feature = "async")]
7176
#[rustfmt::skip]
7277
#[allow(clippy::needless_lifetimes)]
7378
mod zerocopy_channel;
7479

7580
use fragment::{Fragmenter, SendOutput};
7681
use reassemble::Reassembler;
82+
#[cfg(feature = "async")]
7783
pub use router::Router;
7884

7985
use crate::fmt::*;

0 commit comments

Comments
 (0)