diff --git a/crates/examples/microkit/http-server/pds/pl031-driver/interface-types/src/lib.rs b/crates/examples/microkit/http-server/pds/pl031-driver/interface-types/src/lib.rs index 07b48d1d6..064117713 100644 --- a/crates/examples/microkit/http-server/pds/pl031-driver/interface-types/src/lib.rs +++ b/crates/examples/microkit/http-server/pds/pl031-driver/interface-types/src/lib.rs @@ -17,5 +17,5 @@ pub enum Request { #[derive(Debug, Serialize, Deserialize)] pub struct NowResponse { - pub micros: Seconds, + pub unix_time: Seconds, } diff --git a/crates/examples/microkit/http-server/pds/pl031-driver/src/config.rs b/crates/examples/microkit/http-server/pds/pl031-driver/src/config.rs index 723e4845d..eff7034a2 100644 --- a/crates/examples/microkit/http-server/pds/pl031-driver/src/config.rs +++ b/crates/examples/microkit/http-server/pds/pl031-driver/src/config.rs @@ -4,6 +4,8 @@ // SPDX-License-Identifier: BSD-2-Clause // +#![allow(dead_code)] + pub mod channels { use sel4_microkit::Channel; diff --git a/crates/examples/microkit/http-server/pds/pl031-driver/src/main.rs b/crates/examples/microkit/http-server/pds/pl031-driver/src/main.rs index aa454e78c..eaedb9531 100644 --- a/crates/examples/microkit/http-server/pds/pl031-driver/src/main.rs +++ b/crates/examples/microkit/http-server/pds/pl031-driver/src/main.rs @@ -8,8 +8,6 @@ #![no_main] #![feature(never_type)] -use core::time::Duration; - use sel4_microkit::{memory_region_symbol, protection_domain, Channel, Handler, MessageInfo}; use sel4_microkit_message::MessageInfoExt as _; @@ -22,9 +20,7 @@ use config::channels; #[protection_domain] fn init() -> HandlerImpl { - let mut driver = - unsafe { Driver::new(memory_region_symbol!(pl031_mmio_vaddr: *mut ()).as_ptr()) }; - sel4_microkit::debug_println!("XXX {:?}", driver.now()); + let driver = unsafe { Driver::new(memory_region_symbol!(pl031_mmio_vaddr: *mut ()).as_ptr()) }; HandlerImpl { driver } } @@ -35,50 +31,27 @@ struct HandlerImpl { impl Handler for HandlerImpl { type Error = !; - // fn notified(&mut self, channel: Channel) -> Result<(), Self::Error> { - // match channel { - // channels::DEVICE => { - // self.driver.handle_interrupt(); - // channels::DEVICE.irq_ack().unwrap(); - // channels::CLIENT.notify(); - // } - // _ => { - // unreachable!() - // } - // } - // Ok(()) - // } - - // fn protected( - // &mut self, - // channel: Channel, - // msg_info: MessageInfo, - // ) -> Result { - // Ok(match channel { - // channels::CLIENT => match msg_info.recv_using_postcard::() { - // Ok(req) => match req { - // Request::Now => { - // let now = self.driver.now(); - // MessageInfo::send_using_postcard(NowResponse { - // micros: now.as_micros().try_into().unwrap(), - // }) - // .unwrap() - // } - // Request::SetTimeout { relative_micros } => { - // self.driver - // .set_timeout(Duration::from_micros(relative_micros)); - // MessageInfo::send_empty() - // } - // Request::ClearTimeout => { - // self.driver.clear_timeout(); - // MessageInfo::send_empty() - // } - // }, - // Err(_) => MessageInfo::send_unspecified_error(), - // }, - // _ => { - // unreachable!() - // } - // }) - // } + fn protected( + &mut self, + channel: Channel, + msg_info: MessageInfo, + ) -> Result { + Ok(match channel { + channels::CLIENT => match msg_info.recv_using_postcard::() { + Ok(req) => match req { + Request::Now => { + let now = self.driver.now(); + MessageInfo::send_using_postcard(NowResponse { + unix_time: now.as_secs().try_into().unwrap(), + }) + .unwrap() + } + }, + Err(_) => MessageInfo::send_unspecified_error(), + }, + _ => { + unreachable!() + } + }) + } } diff --git a/crates/examples/microkit/http-server/pds/server/core/src/lib.rs b/crates/examples/microkit/http-server/pds/server/core/src/lib.rs index 18b5518e1..c574244bb 100644 --- a/crates/examples/microkit/http-server/pds/server/core/src/lib.rs +++ b/crates/examples/microkit/http-server/pds/server/core/src/lib.rs @@ -39,12 +39,10 @@ use server::Server; const HTTP_PORT: u16 = 80; const HTTPS_PORT: u16 = 443; -// TODO -const NOW: u64 = 1704284617; - pub async fn run_server< T: BlockIO + Clone + 'static, >( + now_unix_time: Duration, now_fn: impl 'static + Send + Sync + Fn() -> Instant, _timers_ctx: TimerManager, network_ctx: ManagedInterface, @@ -66,7 +64,7 @@ pub async fn run_server< } }); - let tls_config = Arc::new(mk_tls_config(cert_pem, priv_pem, now_fn)); + let tls_config = Arc::new(mk_tls_config(cert_pem, priv_pem, now_unix_time, now_fn)); let use_socket_for_https_closure: SocketUser = Box::new({ move |server, socket| { @@ -153,6 +151,7 @@ async fn use_socket_for_https Instant, ) -> ServerConfig { let cert_der = match rustls_pemfile::read_one_from_slice(cert_pem.as_bytes()) @@ -180,7 +179,7 @@ fn mk_tls_config( .with_single_cert(vec![cert_der], key_der) .unwrap(); config.time_provider = TimeProvider::new(GetCurrentTimeImpl::new( - UnixTime::since_unix_epoch(Duration::from_secs(NOW)), + UnixTime::since_unix_epoch(now_unix_time), now_fn, )); diff --git a/crates/examples/microkit/http-server/pds/server/src/main.rs b/crates/examples/microkit/http-server/pds/server/src/main.rs index c87c8c026..d7a939bc3 100644 --- a/crates/examples/microkit/http-server/pds/server/src/main.rs +++ b/crates/examples/microkit/http-server/pds/server/src/main.rs @@ -43,12 +43,14 @@ mod block_client; mod config; mod handler; mod net_client; +mod rtc_client; mod timer_client; use block_client::BlockClient; use config::channels; use handler::HandlerImpl; use net_client::NetClient; +use rtc_client::RTCClient; use timer_client::TimerClient; const BLOCK_CACHE_SIZE_IN_BLOCKS: usize = 128; @@ -77,11 +79,17 @@ static LOGGER: Logger = LoggerBuilder::const_default() fn init() -> impl Handler { LOGGER.set().unwrap(); - let timer_client = TimerClient::new(channels::TIMER_DRIVER); + let rtc_client = RTCClient::new(channels::RTC_DRIVER); + let timer_client = Arc::new(TimerClient::new(channels::TIMER_DRIVER)); let net_client = NetClient::new(channels::NET_DRIVER); let block_client = BlockClient::new(channels::BLOCK_DRIVER); - let timer_client = Arc::new(timer_client); + let now_unix_time = Duration::from_secs(rtc_client.now().into()); + + let now_fn = { + let timer_client = timer_client.clone(); + move || Instant::ZERO + Duration::from_micros(timer_client.now()) + }; let notify_net: fn() = || channels::NET_DRIVER.notify(); let notify_block: fn() = || channels::BLOCK_DRIVER.notify(); @@ -158,11 +166,6 @@ fn init() -> impl Handler { ) }; - let now_fn = { - let timer_client = timer_client.clone(); - move || Instant::ZERO + Duration::from_micros(timer_client.now()) - }; - HandlerImpl::new( channels::TIMER_DRIVER, channels::NET_DRIVER, @@ -179,6 +182,7 @@ fn init() -> impl Handler { let fs_block_io = disk.partition_using_mbr(&entry); let fs_block_io = Rc::new(fs_block_io); run_server( + now_unix_time, now_fn, timers_ctx, network_ctx, diff --git a/crates/examples/microkit/http-server/pds/server/src/rtc_client.rs b/crates/examples/microkit/http-server/pds/server/src/rtc_client.rs new file mode 100644 index 000000000..b230af8b7 --- /dev/null +++ b/crates/examples/microkit/http-server/pds/server/src/rtc_client.rs @@ -0,0 +1,30 @@ +// +// Copyright 2023, Colias Group, LLC +// +// SPDX-License-Identifier: BSD-2-Clause +// + +use sel4_microkit::MessageInfo; +use sel4_microkit_message::MessageInfoExt as _; + +use microkit_http_server_example_pl031_driver_interface_types::*; + +pub struct RTCClient { + channel: sel4_microkit::Channel, +} + +impl RTCClient { + pub fn new(channel: sel4_microkit::Channel) -> Self { + Self { channel } + } + + pub fn now(&self) -> Seconds { + let req = Request::Now; + let resp: NowResponse = self + .channel + .pp_call(MessageInfo::send_using_postcard(req).unwrap()) + .recv_using_postcard() + .unwrap(); + resp.unix_time + } +}