Skip to content

Commit 4e0595e

Browse files
committed
Update to use AcpiCommsMsg
1 parent dcd6d97 commit 4e0595e

7 files changed

Lines changed: 69 additions & 39 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ syn = "2.0"
7171
tps6699x = { git = "https://github.com/OpenDevicePartnership/tps6699x" }
7272
tokio = { version = "1.42.0" }
7373
zerocopy = "0.8.26"
74-
uuid = { version = "1.17.0", default-features = false }
74+
uuid = { version = "=1.17.0", default-features = false }

examples/std/Cargo.lock

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

examples/std/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ log = "0.4.14"
4949
heapless = "0.8.0"
5050
static_cell = "2"
5151
embedded-hal-async = "1.0.0"
52-
embedded-hal = "1.0.0"
5352
embedded-hal-mock = { version = "0.11.1", features = ["embedded-hal-async"] }
5453

5554
critical-section = { version = "1.1", features = ["std"] }

thermal-service/src/context.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,34 @@ use crate::mptf;
44
use crate::{Error, Event, fan, sensor};
55
use embassy_sync::channel::Channel;
66
use embedded_services::GlobalRawMutex;
7+
use embedded_services::buffer::OwnedRef;
78
use embedded_services::{error, intrusive_list};
89

9-
pub(crate) struct Context {
10+
embedded_services::define_static_buffer!(mctp_buf, u8, [0u8; 69]);
11+
12+
pub(crate) struct Context<'a> {
1013
// Registered temperature sensors
1114
sensors: intrusive_list::IntrusiveList,
1215
// Registered fans
1316
fans: intrusive_list::IntrusiveList,
1417
// MPTF Request Queue
1518
mptf: Channel<GlobalRawMutex, mptf::Request, 10>,
1619
// Raw MCTP Payload Queue
17-
mctp: Channel<GlobalRawMutex, mctp::Payload, 10>,
20+
mctp: Channel<GlobalRawMutex, mctp::AcpiMsgComms<'a>, 10>,
21+
// MCTP message buffer
22+
mctp_buf: OwnedRef<'a, u8>,
1823
// Event queue
1924
events: Channel<GlobalRawMutex, Event, 10>,
2025
}
2126

22-
impl Context {
27+
impl<'a> Context<'a> {
2328
pub(crate) fn new() -> Self {
2429
Self {
2530
sensors: intrusive_list::IntrusiveList::new(),
2631
fans: intrusive_list::IntrusiveList::new(),
2732
mptf: Channel::new(),
2833
mctp: Channel::new(),
34+
mctp_buf: mctp_buf::get_mut().unwrap(),
2935
events: Channel::new(),
3036
}
3137
}
@@ -105,15 +111,19 @@ impl Context {
105111
self.mptf.receive().await
106112
}
107113

108-
pub(crate) fn send_mctp_payload(&self, msg: mctp::Payload) -> Result<(), Error> {
114+
pub(crate) fn send_mctp_payload(&self, msg: mctp::AcpiMsgComms<'a>) -> Result<(), Error> {
109115
self.mctp.try_send(msg).map_err(|_| Error)?;
110116
Ok(())
111117
}
112118

113-
pub(crate) async fn wait_mctp_payload(&self) -> mctp::Payload {
119+
pub(crate) async fn wait_mctp_payload(&self) -> mctp::AcpiMsgComms<'_> {
114120
self.mctp.receive().await
115121
}
116122

123+
pub(crate) fn get_mctp_buf(&self) -> &OwnedRef<'a, u8> {
124+
&self.mctp_buf
125+
}
126+
117127
pub(crate) async fn send_event(&self, event: Event) {
118128
self.events.send(event).await
119129
}

thermal-service/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use embassy_sync::once_lock::OnceLock;
55
use embedded_sensors_hal_async::temperature::DegreesCelsius;
6+
use embedded_services::buffer::OwnedRef;
67
use embedded_services::{comms, error, info, intrusive_list};
78

89
mod context;
@@ -31,12 +32,12 @@ pub enum Event {
3132
FanFailure(fan::DeviceId, fan::Error),
3233
}
3334

34-
struct Service {
35-
context: context::Context,
35+
struct Service<'a> {
36+
context: context::Context<'a>,
3637
endpoint: comms::Endpoint,
3738
}
3839

39-
impl Service {
40+
impl<'a> Service<'a> {
4041
fn new() -> Self {
4142
Self {
4243
context: context::Context::new(),
@@ -45,12 +46,12 @@ impl Service {
4546
}
4647
}
4748

48-
impl comms::MailboxDelegate for Service {
49+
impl<'a> comms::MailboxDelegate for Service<'a> {
4950
fn receive(&self, message: &comms::Message) -> Result<(), comms::MailboxDelegateError> {
5051
// Queue for later processing
51-
if let Some(&msg) = message.data.get::<mctp::Payload>() {
52+
if let Some(msg) = message.data.get::<mctp::AcpiMsgComms>() {
5253
self.context
53-
.send_mctp_payload(msg)
54+
.send_mctp_payload(msg.clone())
5455
.map_err(|_| comms::MailboxDelegateError::BufferFull)
5556
} else if let Some(&msg) = message.data.get::<mptf::Request>() {
5657
self.context
@@ -99,10 +100,14 @@ pub async fn wait_mptf_request() -> mptf::Request {
99100
}
100101

101102
/// Wait for a MCTP payload
102-
pub async fn wait_mctp_payload() -> mctp::Payload {
103+
pub async fn wait_mctp_payload<'a>() -> mctp::AcpiMsgComms<'a> {
103104
SERVICE.get().await.context.wait_mctp_payload().await
104105
}
105106

107+
pub fn get_mctp_buf<'a>() -> &'a OwnedRef<'a, u8> {
108+
SERVICE.try_get().unwrap().context.get_mctp_buf()
109+
}
110+
106111
/// Send a thermal event
107112
pub async fn send_event(event: Event) {
108113
SERVICE.get().await.context.send_event(event).await

thermal-service/src/mctp.rs

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::mptf::*;
2+
use core::borrow::{Borrow, BorrowMut};
3+
pub use embedded_services::{comms, ec_type::message::AcpiMsgComms};
24

35
pub const CURRENT_VERSION: u8 = 1;
46

5-
/// Raw MCTP Payload
6-
pub type Payload = ([u8; 69], usize);
7-
87
/// MCTP Payload Error
98
pub struct PayloadError {
109
command: u8,
@@ -17,16 +16,18 @@ impl PayloadError {
1716
}
1817
}
1918

20-
impl TryFrom<Payload> for Request {
19+
impl TryFrom<AcpiMsgComms<'_>> for Request {
2120
type Error = PayloadError;
22-
fn try_from(payload: Payload) -> Result<Self, Self::Error> {
23-
let payload_len = payload.1;
21+
fn try_from(acpi: AcpiMsgComms<'_>) -> Result<Self, Self::Error> {
22+
let access = acpi.payload.borrow();
23+
let payload: &[u8] = access.borrow();
24+
2425
let (version, _rsvd, _status, command, data) = (
25-
payload.0[0],
26-
payload.0[1],
27-
payload.0[2],
28-
payload.0[3],
29-
&payload.0[4..payload_len],
26+
payload[0],
27+
payload[1],
28+
payload[2],
29+
payload[3],
30+
&payload[4..acpi.payload_len],
3031
);
3132
if version != CURRENT_VERSION {
3233
return Err(PayloadError::new(command, Status::UnsupportedRevision));
@@ -109,15 +110,17 @@ impl TryFrom<Payload> for Request {
109110
}
110111
}
111112

112-
impl From<Response> for Payload {
113+
impl From<Response> for AcpiMsgComms<'_> {
113114
fn from(response: Response) -> Self {
114-
let mut payload = [0; 69];
115-
payload[0] = CURRENT_VERSION; // Version
116-
payload[1] = 0; // Reserved
117-
payload[2] = u8::from(response.status); // Status
118-
payload[3] = response.data.into(); // Command
119-
115+
let mut access = crate::get_mctp_buf().borrow_mut();
116+
let payload: &mut [u8] = access.borrow_mut();
120117
let (header, data) = payload.split_at_mut(4);
118+
119+
header[0] = CURRENT_VERSION; // Version
120+
header[1] = 0; // Reserved
121+
header[2] = u8::from(response.status); // Status
122+
header[3] = response.data.into(); // Command
123+
121124
let header_len = header.len();
122125

123126
let data_len = match response.data {
@@ -151,17 +154,28 @@ impl From<Response> for Payload {
151154
}
152155
};
153156

154-
(payload, header_len + data_len)
157+
AcpiMsgComms {
158+
payload: crate::context::mctp_buf::get(),
159+
payload_len: header_len + data_len,
160+
endpoint: comms::EndpointID::Internal(comms::Internal::Thermal),
161+
}
155162
}
156163
}
157164

158-
impl From<PayloadError> for Payload {
165+
impl From<PayloadError> for AcpiMsgComms<'_> {
159166
fn from(mctp_error: PayloadError) -> Self {
160-
let mut payload = [0; 69];
167+
let mut access = crate::get_mctp_buf().borrow_mut();
168+
let payload: &mut [u8] = access.borrow_mut();
169+
161170
payload[0] = CURRENT_VERSION; // Version
162171
payload[1] = 0; // Reserved
163172
payload[2] = u8::from(mctp_error.error); // Status
164173
payload[3] = mctp_error.command; // Command
165-
(payload, 4)
174+
175+
AcpiMsgComms {
176+
payload: crate::context::mctp_buf::get(),
177+
payload_len: 4,
178+
endpoint: comms::EndpointID::Internal(comms::Internal::Thermal),
179+
}
166180
}
167181
}

thermal-service/src/mptf.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,13 @@ pub async fn handle_requests() {
362362
// Packet is OK
363363
Ok(request) => {
364364
let response = process_request(request).await;
365-
mctp::Payload::from(response)
365+
mctp::AcpiMsgComms::from(response)
366366
}
367367
// Packet is malformed
368-
Err(payload_error) => mctp::Payload::from(payload_error),
368+
Err(payload_error) => {
369+
error!("Thermal received malformed packet");
370+
mctp::AcpiMsgComms::from(payload_error)
371+
}
369372
};
370373
ts::send_service_msg(comms::EndpointID::External(comms::External::Host), &response).await
371374
}

0 commit comments

Comments
 (0)