Skip to main content

sparreal_kernel/os/
cpu.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2#[repr(usize)]
3pub enum CpuOnStatus {
4    Ok = 0,
5    NotSupported = 1,
6    AlreadyOn = 2,
7    InvalidParameters = 3,
8    Other = 4,
9}
10
11impl CpuOnStatus {
12    pub fn is_started(self) -> bool {
13        matches!(self, Self::Ok | Self::AlreadyOn)
14    }
15}
16
17impl From<usize> for CpuOnStatus {
18    fn from(value: usize) -> Self {
19        match value {
20            0 => Self::Ok,
21            1 => Self::NotSupported,
22            2 => Self::AlreadyOn,
23            3 => Self::InvalidParameters,
24            _ => Self::Other,
25        }
26    }
27}
28
29pub fn cpu_count() -> usize {
30    crate::hal::al::cpu::cpu_count()
31}
32
33pub fn current_cpu_id() -> usize {
34    crate::hal::al::cpu::current_cpu_id()
35}
36
37pub fn cpu_on(cpu_idx: usize) -> CpuOnStatus {
38    crate::hal::al::cpu::cpu_on(cpu_idx).into()
39}