Skip to content
Merged
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
21 changes: 14 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ members = [
"power-button-service",
"power-policy-service",
"time-alarm-service",
"time-alarm-service-messages",
"time-alarm-service-interface",
"time-alarm-service-relay",
"type-c-service",
"debug-service",
"debug-service-messages",
Expand Down Expand Up @@ -105,7 +106,8 @@ serde = { version = "1.0.*", default-features = false }
static_cell = "2.1.0"
toml = { version = "0.8", default-features = false }
thermal-service-messages = { path = "./thermal-service-messages" }
time-alarm-service-messages = { path = "./time-alarm-service-messages" }
time-alarm-service-interface = { path = "./time-alarm-service-interface" }
time-alarm-service-relay = { path = "./time-alarm-service-relay" }
type-c-interface = { path = "./type-c-interface" }
syn = "2.0"
tps6699x = { git = "https://github.com/OpenDevicePartnership/tps6699x" }
Expand Down
22 changes: 11 additions & 11 deletions embedded-service/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub mod mctp {
fn process_request<'a>(
&'a self,
request: Self::RequestType,
) -> impl core::future::Future<Output = Self::ResultType> + Send + 'a;
) -> impl core::future::Future<Output = Self::ResultType> + 'a;
}

// Traits below this point are intended for consumption by relay services (e.g. the eSPI service), not individual services that want their messages relayed.
Expand Down Expand Up @@ -168,7 +168,7 @@ pub mod mctp {
fn process_request<'a>(
&'a self,
message: Self::RequestEnumType,
) -> impl core::future::Future<Output = Self::ResultEnumType> + Send + 'a;
) -> impl core::future::Future<Output = Self::ResultEnumType> + 'a;
}

/// This macro generates a relay type over a collection of message types, which can be used by a relay service to
Expand All @@ -195,9 +195,9 @@ pub mod mctp {
/// ```ignore
///
/// impl_odp_mctp_relay_handler!(
/// MyRelayHanderType;
/// Battery, 0x9, battery_service::Service<'static>;
/// TimeAlarm, 0xB, time_alarm_service::Service<'static>;
/// MyRelayHandlerType;
/// Battery, 0x9, battery_service_relay::RelayHandler<battery_service::Service<'static>>;
/// TimeAlarm, 0xB, time_alarm_service_relay::RelayHandler<time_alarm_service::Service<'static>>;
/// );
Comment thread
williampMSFT marked this conversation as resolved.
Resolved
///
/// let relay_handler = MyRelayHandlerType::new(battery_service_instance, time_alarm_service_instance);
Expand Down Expand Up @@ -448,16 +448,16 @@ pub mod mctp {
}


pub struct $relay_type_name<'hw> {
pub struct $relay_type_name {
$(
[<$service_name:snake _handler>]: &'hw $service_handler_type,
[<$service_name:snake _handler>]: $service_handler_type,
)+
}

impl<'hw> $relay_type_name<'hw> {
impl $relay_type_name {
pub fn new(
$(
[<$service_name:snake _handler>]: &'hw $service_handler_type,
[<$service_name:snake _handler>]: $service_handler_type,
)+
) -> Self {
Self {
Expand All @@ -468,7 +468,7 @@ pub mod mctp {
}
}

impl<'hw> $crate::relay::mctp::RelayHandler for $relay_type_name<'hw> {
impl $crate::relay::mctp::RelayHandler for $relay_type_name {
type ServiceIdType = OdpService;
type HeaderType = OdpHeader;
type RequestEnumType = HostRequest;
Expand All @@ -477,7 +477,7 @@ pub mod mctp {
fn process_request<'a>(
&'a self,
message: HostRequest,
) -> impl core::future::Future<Output = HostResult> + Send + 'a {
) -> impl core::future::Future<Output = HostResult> + 'a {
async move {
match message {
$(
Expand Down
19 changes: 15 additions & 4 deletions examples/rt685s-evk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion examples/rt685s-evk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ embedded-usb-pd = { git = "https://github.com/OpenDevicePartnership/embedded-usb
type-c-service = { path = "../../type-c-service", features = ["defmt"] }
type-c-interface = { path = "../../type-c-interface", features = ["defmt"] }
time-alarm-service = { path = "../../time-alarm-service", features = ["defmt"] }
time-alarm-service-messages = { path = "../../time-alarm-service-messages", features = [
time-alarm-service-interface = { path = "../../time-alarm-service-interface", features = [
"defmt",
] }
time-alarm-service-relay = { path = "../../time-alarm-service-relay", features = [
"defmt",
] }

Expand Down
16 changes: 12 additions & 4 deletions examples/rt685s-evk/src/bin/time_alarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ use embedded_mcu_hal::{
};
use embedded_services::info;
use static_cell::StaticCell;
use time_alarm_service_messages::{AcpiDaylightSavingsTimeStatus, AcpiTimeZone, AcpiTimeZoneOffset, AcpiTimestamp};
use time_alarm_service_interface::{
AcpiDaylightSavingsTimeStatus, AcpiTimeZone, AcpiTimeZoneOffset, AcpiTimestamp, TimeAlarmService,
};
use {defmt_rtt as _, panic_probe as _};

// Type aliases to make it easier to use the service and relay handler types without needing to write out all the generic parameters every time.
// This is especially helpful for the relay handler, which has a lot of generic parameters due to the traits it needs to implement.
//
type TimeAlarmServiceType = time_alarm_service::Service<'static>;
type TimeAlarmServiceRelayHandlerType = time_alarm_service_relay::TimeAlarmServiceRelayHandler<TimeAlarmServiceType>;

#[embassy_executor::main]
async fn main(spawner: embassy_executor::Spawner) {
let p = embassy_imxrt::init(Default::default());
Expand All @@ -25,7 +33,7 @@ async fn main(spawner: embassy_executor::Spawner) {

let time_service = odp_service_common::spawn_service!(
spawner,
time_alarm_service::Service<'static>,
TimeAlarmServiceType,
time_alarm_service::InitParams {
backing_clock: dt_clock,
tz_storage: tz,
Expand All @@ -40,10 +48,10 @@ async fn main(spawner: embassy_executor::Spawner) {
use embedded_services::relay::mctp::impl_odp_mctp_relay_handler;
impl_odp_mctp_relay_handler!(
EspiRelayHandler;
TimeAlarm, 0x0B, time_alarm_service::Service<'static>;
TimeAlarm, 0x0B, crate::TimeAlarmServiceRelayHandlerType;
);

let _relay_handler = EspiRelayHandler::new(&time_service);
let _relay_handler = EspiRelayHandler::new(TimeAlarmServiceRelayHandlerType::new(time_service));

// Here, you'd normally pass _relay_handler to your relay service (e.g. eSPI service).
// In this example, we're not leveraging a relay service, so we'll just demonstrate some direct calls.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "time-alarm-service-messages"
description = "Time and Alarm service message definitions"
name = "time-alarm-service-interface"
version.workspace = true
edition.workspace = true
license.workspace = true
Expand All @@ -11,13 +10,12 @@ bitfield.workspace = true
defmt = { workspace = true, optional = true }
log = { workspace = true, optional = true }
embedded-mcu-hal.workspace = true
embedded-services.workspace = true
num_enum.workspace = true
zerocopy = { workspace = true, features = ["derive"] }

[features]
defmt = ["dep:defmt", "embedded-mcu-hal/defmt"]
log = ["dep:log", "embedded-services/log"]
log = ["dep:log"]

[lints]
workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl From<&AcpiTimestamp> for RawAcpiTimestamp {

// -------------------------------------------------

/// The current daylight savings time status of the timer.
#[derive(Clone, Copy, Debug, PartialEq, num_enum::IntoPrimitive, num_enum::TryFromPrimitive)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
Expand All @@ -77,13 +78,15 @@ pub enum AcpiDaylightSavingsTimeStatus {

// -------------------------------------------------

/// The time offset from UTC of the system's time zone, expressed in minutes
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct AcpiTimeZoneOffset {
minutes_from_utc: i16, // minutes from UTC
}

impl AcpiTimeZoneOffset {
/// Constructs a time zone offset with the given number of minutes from UTC. Valid values are -1440 to 1440 (inclusive).
pub fn new(minutes_from_utc: i16) -> Result<Self, DatetimeClockError> {
if !(-1440..=1440).contains(&minutes_from_utc) {
Err(DatetimeClockError::UnsupportedDatetime)
Expand All @@ -92,11 +95,13 @@ impl AcpiTimeZoneOffset {
}
}

/// The number of minutes that the time zone is offset from UTC.
pub fn minutes_from_utc(&self) -> i16 {
self.minutes_from_utc
}
}

/// The time zone of the system, either unknown or specified as a number of minutes from UTC.
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum AcpiTimeZone {
Expand Down Expand Up @@ -130,6 +135,7 @@ impl From<AcpiTimeZone> for i16 {

// -------------------------------------------------

/// A timestamp as specified in the ACPI spec, including time zone and daylight savings time status.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AcpiTimestamp {
Expand All @@ -139,6 +145,7 @@ pub struct AcpiTimestamp {
}

impl AcpiTimestamp {
/// Converts this timestamp into the raw byte format specified in the ACPI spec version 6.4, section 9.18.3 (_GRT), with the Valid bit set.
pub fn as_bytes(&self) -> [u8; core::mem::size_of::<RawAcpiTimestamp>()] /* 16 */ {
// Size is guaranteed to be correct by zerocopy, but zerocopy returns as a slice rather than an array,
// and we need to return an owned array, so we need to convert.
Expand All @@ -150,6 +157,7 @@ impl AcpiTimestamp {
.expect("Size is guaranteed to be the size of RawAcpiTimestamp")
}

/// Attempt to parse an ACPI timestamp from a byte slice. Returns an error if the slice does not represent a valid ACPI timestamp as specified in ACPI spec version 6.4, section 9.18.4 (_SRT).
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self, DatetimeClockError> {
let raw = RawAcpiTimestamp::ref_from_bytes(
bytes
Expand Down
Loading
Loading