summaryrefslogtreecommitdiffstats
path: root/library/std/src/os/xous/services/systime.rs
blob: bbb875c69426ec9623d7ee16e4afd946227ad1d5 (plain)
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
use crate::os::xous::ffi::{connect, Connection};
use core::sync::atomic::{AtomicU32, Ordering};

pub(crate) enum SystimeScalar {
    GetUtcTimeMs,
}

impl Into<[usize; 5]> for SystimeScalar {
    fn into(self) -> [usize; 5] {
        match self {
            SystimeScalar::GetUtcTimeMs => [3, 0, 0, 0, 0],
        }
    }
}

/// Return a `Connection` to the systime server. This server is used for reporting the
/// realtime clock.
pub(crate) fn systime_server() -> Connection {
    static SYSTIME_SERVER_CONNECTION: AtomicU32 = AtomicU32::new(0);
    let cid = SYSTIME_SERVER_CONNECTION.load(Ordering::Relaxed);
    if cid != 0 {
        return cid.into();
    }

    let cid = connect("timeserverpublic".try_into().unwrap()).unwrap();
    SYSTIME_SERVER_CONNECTION.store(cid.into(), Ordering::Relaxed);
    cid
}