about summary refs log tree commit diff
path: root/library/std/src/os/xous/services/systime.rs
blob: e54cffdc4c018d3380fb9d513d284401b9d9e330 (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
29
use core::sync::atomic::{Atomic, AtomicU32, Ordering};

use crate::os::xous::ffi::{Connection, connect};

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],
        }
    }
}

/// Returns 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: Atomic<u32> = 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
}