Skip to content

Commit 606ed52

Browse files
committed
Cargo update embedded_cfu_protocol in embedded-services and examples,
and fix breaking changes in CFU
1 parent 8468515 commit 606ed52

File tree

14 files changed

+131
-236
lines changed

14 files changed

+131
-236
lines changed

Cargo.lock

Lines changed: 2 additions & 2 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ embassy-sync = { git = "https://github.com/embassy-rs/embassy" }
4444
embassy-time = { git = "https://github.com/embassy-rs/embassy" }
4545
embassy-time-driver = { git = "https://github.com/embassy-rs/embassy" }
4646
embedded-batteries-async = "0.1.0"
47-
embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu", version = "0.1.0" }
47+
embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu" }
4848
embedded-hal = "1.0"
4949
embedded-hal-async = "1.0"
5050
embedded-hal-nb = "1.0"

cfu-service/src/buffer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::future::pending;
55

66
use embassy_futures::select::{Either3, select3};
77
use embassy_sync::{
8-
channel::{DynamicReceiver, DynamicSender},
8+
channel::{SendDynamicReceiver, SendDynamicSender},
99
mutex::Mutex,
1010
};
1111
use embassy_time::{Duration, TimeoutError, with_timeout};
@@ -57,10 +57,10 @@ pub struct Buffer<'a> {
5757
state: Mutex<GlobalRawMutex, State>,
5858
/// Component ID to buffer requests for
5959
buffered_id: ComponentId,
60-
/// Sender for the buffer
61-
buffer_sender: DynamicSender<'a, FwUpdateContentCommand>,
62-
/// Receiver for the buffer
63-
buffer_receiver: DynamicReceiver<'a, FwUpdateContentCommand>,
60+
/// Sender for the buffer. Must be used with a channel with an underlying Mutex that is Send and Sync.
61+
buffer_sender: SendDynamicSender<'a, FwUpdateContentCommand>,
62+
/// Receiver for the buffer. Must be used with a channel with an underlying Mutex that is Send and Sync.
63+
buffer_receiver: SendDynamicReceiver<'a, FwUpdateContentCommand>,
6464
/// Configuration for the buffer
6565
config: Config,
6666
}
@@ -81,8 +81,8 @@ impl<'a> Buffer<'a> {
8181
pub fn new(
8282
external_id: ComponentId,
8383
buffered_id: ComponentId,
84-
buffer_sender: DynamicSender<'a, FwUpdateContentCommand>,
85-
buffer_receiver: DynamicReceiver<'a, FwUpdateContentCommand>,
84+
buffer_sender: SendDynamicSender<'a, FwUpdateContentCommand>,
85+
buffer_receiver: SendDynamicReceiver<'a, FwUpdateContentCommand>,
8686
config: Config,
8787
) -> Self {
8888
Self {

cfu-service/src/host.rs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,39 @@ use core::future::Future;
33
use embedded_cfu_protocol::components::CfuComponentTraits;
44
use embedded_cfu_protocol::host::{CfuHostStates, CfuUpdater};
55
use embedded_cfu_protocol::protocol_definitions::*;
6-
use embedded_cfu_protocol::{CfuImage, CfuWriter, CfuWriterDefault, CfuWriterError};
6+
use embedded_cfu_protocol::{
7+
CfuImage,
8+
writer::{CfuWriterAsync, CfuWriterError, CfuWriterNop},
9+
};
710
use heapless::Vec;
811

912
use crate::CfuError;
1013

1114
/// All host side Cfu traits, in some cases this will originate from a OS driver for CFU
12-
pub trait CfuHost: CfuHostStates {
15+
pub trait CfuHost<W>: CfuHostStates<W> {
1316
/// Get all images
1417
fn get_cfu_images<I: CfuImage>(&self) -> impl Future<Output = Result<Vec<I, MAX_CMPT_COUNT>, CfuError>>;
1518
/// Gets the firmware version of all components
16-
fn get_all_fw_versions<T: CfuWriter>(
19+
fn get_all_fw_versions(
1720
self,
18-
writer: &mut T,
21+
writer: &mut W,
1922
primary_cmpt: ComponentId,
2023
) -> impl Future<Output = Result<GetFwVersionResponse, CfuError>>;
2124
/// Goes through the offer list and returns a slice of offer responses
22-
fn process_cfu_offers<'a, T: CfuWriter>(
25+
fn process_cfu_offers<'a>(
2326
offer_commands: &'a [FwUpdateOffer],
24-
writer: &mut T,
27+
writer: &mut W,
2528
) -> impl Future<Output = Result<&'a [FwUpdateOfferResponse], CfuError>>;
2629
/// For a specific component, update its content
27-
fn update_cfu_content<T: CfuWriter>(
28-
writer: &mut T,
29-
) -> impl Future<Output = Result<FwUpdateContentResponse, CfuError>>;
30+
fn update_cfu_content(writer: &mut W) -> impl Future<Output = Result<FwUpdateContentResponse, CfuError>>;
3031
/// For a specific image that was updated, validate its content
3132
fn is_cfu_image_valid<I: CfuImage>(image: I) -> impl Future<Output = Result<bool, CfuError>>;
3233
}
3334

3435
pub struct CfuHostInstance<I: CfuImage, C: CfuComponentTraits> {
3536
pub updater: CfuUpdater,
3637
pub images: heapless::Vec<I, MAX_CMPT_COUNT>,
37-
pub writer: CfuWriterDefault,
38+
pub writer: CfuWriterNop,
3839
pub primary_cmpt: C,
3940
pub host_token: HostToken,
4041
}
@@ -45,15 +46,15 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHostInstance<I, C> {
4546
Self {
4647
updater: CfuUpdater {},
4748
images: Vec::new(),
48-
writer: CfuWriterDefault::default(),
49+
writer: CfuWriterNop,
4950
primary_cmpt,
5051
host_token: HostToken::Driver,
5152
}
5253
}
5354
}
5455

55-
impl<I: CfuImage, C: CfuComponentTraits> CfuHostStates for CfuHostInstance<I, C> {
56-
async fn start_transaction<T: CfuWriter>(self, _writer: &mut T) -> Result<FwUpdateOfferResponse, CfuProtocolError> {
56+
impl<I: CfuImage, C: CfuComponentTraits, W: CfuWriterAsync> CfuHostStates<W> for CfuHostInstance<I, C> {
57+
async fn start_transaction(self, _writer: &mut W) -> Result<FwUpdateOfferResponse, CfuProtocolError> {
5758
let _mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new(
5859
HostToken::Driver,
5960
SpecialComponentIds::Info,
@@ -62,10 +63,7 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHostStates for CfuHostInstance<I, C>
6263
let mockresponse = FwUpdateOfferResponse::default();
6364
Ok(mockresponse)
6465
}
65-
async fn notify_start_offer_list<T: CfuWriter>(
66-
self,
67-
writer: &mut T,
68-
) -> Result<FwUpdateOfferResponse, CfuProtocolError> {
66+
async fn notify_start_offer_list(self, writer: &mut W) -> Result<FwUpdateOfferResponse, CfuProtocolError> {
6967
// Serialize FwUpdateOfferInformation to bytes
7068
let mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new(
7169
HostToken::Driver,
@@ -89,10 +87,7 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHostStates for CfuHostInstance<I, C>
8987
}
9088
}
9189

92-
async fn notify_end_offer_list<T: CfuWriter>(
93-
self,
94-
writer: &mut T,
95-
) -> Result<FwUpdateOfferResponse, CfuProtocolError> {
90+
async fn notify_end_offer_list(self, writer: &mut W) -> Result<FwUpdateOfferResponse, CfuProtocolError> {
9691
let mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new(
9792
HostToken::Driver,
9893
SpecialComponentIds::Info,
@@ -128,14 +123,14 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHostStates for CfuHostInstance<I, C>
128123
}
129124
}
130125

131-
impl<I: CfuImage, C: CfuComponentTraits> CfuHost for CfuHostInstance<I, C> {
126+
impl<I: CfuImage, C: CfuComponentTraits, W: CfuWriterAsync> CfuHost<W> for CfuHostInstance<I, C> {
132127
async fn get_cfu_images<T: CfuImage>(&self) -> Result<Vec<T, MAX_CMPT_COUNT>, CfuError> {
133128
Err(CfuError::BadImage)
134129
}
135130

136-
async fn get_all_fw_versions<T: CfuWriter>(
131+
async fn get_all_fw_versions(
137132
self,
138-
_writer: &mut T,
133+
_writer: &mut W,
139134
primary_cmpt: ComponentId,
140135
) -> Result<GetFwVersionResponse, CfuError> {
141136
let mut component_count: u8 = 0;
@@ -172,15 +167,15 @@ impl<I: CfuImage, C: CfuComponentTraits> CfuHost for CfuHostInstance<I, C> {
172167
}
173168
}
174169

175-
async fn process_cfu_offers<'a, T: CfuWriter>(
170+
async fn process_cfu_offers<'a>(
176171
_offer_commands: &'a [FwUpdateOffer],
177-
_writer: &mut T,
172+
_writer: &mut W,
178173
) -> Result<&'a [FwUpdateOfferResponse], CfuError> {
179174
// TODO
180175
Err(CfuError::BadImage)
181176
}
182177

183-
async fn update_cfu_content<T: CfuWriter>(_writer: &mut T) -> Result<FwUpdateContentResponse, CfuError> {
178+
async fn update_cfu_content(_writer: &mut W) -> Result<FwUpdateContentResponse, CfuError> {
184179
Err(CfuError::ProtocolError(CfuProtocolError::WriterError(
185180
CfuWriterError::Other,
186181
)))

cfu-service/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#![no_std]
2+
23
use embassy_sync::once_lock::OnceLock;
34
use embedded_cfu_protocol::client::CfuReceiveContent;
5+
use embedded_cfu_protocol::components::CfuComponentTraits;
46
use embedded_cfu_protocol::protocol_definitions::*;
57
use embedded_services::cfu::component::*;
68
use embedded_services::cfu::{CfuError, ContextToken};
7-
use embedded_services::{comms, error, info};
9+
use embedded_services::{comms, error, info, trace};
810

911
pub mod buffer;
1012
pub mod host;
@@ -17,8 +19,21 @@ pub struct CfuClient {
1719
tp: comms::Endpoint,
1820
}
1921

20-
/// use default "do-nothing" implementations
21-
impl<T, C, E: Default> CfuReceiveContent<T, C, E> for CfuClient {}
22+
impl<T, C> CfuReceiveContent<T, C, ()> for CfuClient {
23+
async fn process_command(&self, _args: Option<T>, _cmd: C) -> Result<(), ()> {
24+
trace!("CfuClient CfuReceiveContent::process_command do nothing implementation.");
25+
Ok(())
26+
}
27+
28+
async fn prepare_components(
29+
&self,
30+
_args: Option<T>,
31+
_primary_component: impl CfuComponentTraits,
32+
) -> Result<(), ()> {
33+
trace!("CfuClient CfuReceiveContent::prepare_components do nothing implementation.");
34+
Ok(())
35+
}
36+
}
2237

2338
impl CfuClient {
2439
/// Create a new Cfu Client

embedded-service/src/cfu/component.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use embassy_sync::channel::Channel;
55
use embassy_sync::mutex::Mutex;
66
use embedded_cfu_protocol::components::{CfuComponentInfo, CfuComponentStorage, CfuComponentTraits};
77
use embedded_cfu_protocol::protocol_definitions::*;
8-
use embedded_cfu_protocol::{CfuWriter, CfuWriterError};
8+
use embedded_cfu_protocol::writer::{CfuWriterAsync, CfuWriterError};
99
use heapless::Vec;
1010

1111
use super::CfuError;
@@ -173,7 +173,7 @@ impl CfuDevice {
173173
}
174174

175175
/// Example for CFU Component
176-
pub struct CfuComponentDefault<W: CfuWriter> {
176+
pub struct CfuComponentDefault<W> {
177177
device: CfuDevice,
178178
is_dual_bank: bool,
179179
is_primary: bool,
@@ -182,19 +182,19 @@ pub struct CfuComponentDefault<W: CfuWriter> {
182182
writer: Mutex<GlobalRawMutex, W>,
183183
}
184184

185-
impl<W: CfuWriter + Default> Default for CfuComponentDefault<W> {
185+
impl<W: CfuWriterAsync + Default> Default for CfuComponentDefault<W> {
186186
fn default() -> Self {
187187
Self::new(1, false, [None; MAX_SUBCMPT_COUNT], W::default())
188188
}
189189
}
190190

191-
impl<W: CfuWriter> CfuDeviceContainer for CfuComponentDefault<W> {
191+
impl<W: CfuWriterAsync> CfuDeviceContainer for CfuComponentDefault<W> {
192192
fn get_cfu_component_device(&self) -> &CfuDevice {
193193
&self.device
194194
}
195195
}
196196

197-
impl<W: CfuWriter> CfuComponentDefault<W> {
197+
impl<W: CfuWriterAsync> CfuComponentDefault<W> {
198198
/// Constructor
199199
pub fn new(
200200
id: ComponentId,
@@ -283,7 +283,7 @@ impl<W: CfuWriter> CfuComponentDefault<W> {
283283
}
284284
}
285285

286-
impl<W: CfuWriter> CfuComponentInfo for CfuComponentDefault<W> {
286+
impl<W: CfuWriterAsync> CfuComponentInfo for CfuComponentDefault<W> {
287287
fn get_component_id(&self) -> ComponentId {
288288
self.device.component_id()
289289
}
@@ -304,25 +304,29 @@ impl<W: CfuWriter> CfuComponentInfo for CfuComponentDefault<W> {
304304
}
305305
}
306306

307-
impl<W: CfuWriter> CfuWriter for CfuComponentDefault<W> {
308-
async fn cfu_write(&self, mem_offset: Option<usize>, data: &[u8]) -> Result<(), CfuWriterError> {
307+
impl<W: CfuWriterAsync> CfuWriterAsync for CfuComponentDefault<W> {
308+
async fn cfu_write(&mut self, mem_offset: Option<usize>, data: &[u8]) -> Result<(), CfuWriterError> {
309309
self.writer.lock().await.cfu_write(mem_offset, data).await
310310
}
311311
async fn cfu_write_read(
312-
&self,
312+
&mut self,
313313
mem_offset: Option<usize>,
314314
data: &[u8],
315315
read: &mut [u8],
316316
) -> Result<(), CfuWriterError> {
317317
self.writer.lock().await.cfu_write_read(mem_offset, data, read).await
318318
}
319319

320-
async fn cfu_read(&self, mem_offset: Option<usize>, read: &mut [u8]) -> Result<(), CfuWriterError> {
320+
async fn cfu_read(&mut self, mem_offset: Option<usize>, read: &mut [u8]) -> Result<(), CfuWriterError> {
321321
self.writer.lock().await.cfu_read(mem_offset, read).await
322322
}
323+
324+
async fn cfu_storage(&mut self, mem_offset: usize, read: &[u8]) -> Result<(), CfuWriterError> {
325+
self.writer.lock().await.cfu_storage(mem_offset, read).await
326+
}
323327
}
324328

325-
impl<W: CfuWriter> CfuComponentStorage for CfuComponentDefault<W> {
329+
impl<W: CfuWriterAsync> CfuComponentStorage for CfuComponentDefault<W> {
326330
fn get_storage_offset(&self) -> usize {
327331
self.storage_offset
328332
}
@@ -344,7 +348,7 @@ async fn default_get_fw_version() -> Result<FwVersion, CfuProtocolError> {
344348
Ok(FwVersion::default())
345349
}
346350

347-
impl<W: CfuWriter + Default> CfuComponentTraits for CfuComponentDefault<W> {}
351+
impl<W: CfuWriterAsync + Default> CfuComponentTraits for CfuComponentDefault<W> {}
348352

349353
/// Example Wrapper for CFU Component
350354
/// Takes type which implements `CFUComponentTraits` and `CfuDeviceContainer`

0 commit comments

Comments
 (0)