sel4_driver_interfaces/
rtc.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

use core::cell::RefCell;
use core::ops::Deref;

use lock_api::{Mutex, RawMutex};

use crate::{WrappedMutex, WrappedRefCell, WrappedRefCellError};

pub use rtcc::{DateTime, DateTimeAccess, Datelike, NaiveDate, NaiveDateTime, NaiveTime, Timelike};

impl<T: Deref<Target = RefCell<U>>, U: DateTimeAccess> DateTimeAccess for &WrappedRefCell<T> {
    type Error = WrappedRefCellError<U::Error>;

    fn datetime(&mut self) -> Result<NaiveDateTime, Self::Error> {
        self.with_mut(|this| this.datetime())
    }

    fn set_datetime(&mut self, datetime: &NaiveDateTime) -> Result<(), Self::Error> {
        self.with_mut(|this| this.set_datetime(datetime))
    }
}

impl<R: RawMutex, T: Deref<Target = Mutex<R, U>>, U: DateTimeAccess> DateTimeAccess
    for &WrappedMutex<T>
{
    type Error = U::Error;

    fn datetime(&mut self) -> Result<NaiveDateTime, Self::Error> {
        self.with_mut(|this| this.datetime())
    }

    fn set_datetime(&mut self, datetime: &NaiveDateTime) -> Result<(), Self::Error> {
        self.with_mut(|this| this.set_datetime(datetime))
    }
}