1extern crate core;
6use core::ffi::*;
7use core::ptr;
8use core::cmp::{PartialOrd, Ordering};
9
10use crate::types::*;
11
12extern "C" {
13 fn xwrustffi_pm_set_op(cpuid: XwId,
14 resume_periph: PmOperation,
15 suspend_periph: PmOperation,
16 wakeup_cpu: PmOperation,
17 sleep_cpu: PmOperation,
18 arg: *mut c_void);
19 fn xwrustffi_pm_suspend();
20 fn xwrustffi_pm_resume();
21 fn xwrustffi_pm_get_stage() -> XwSq;
22}
23
24pub type PmOperation = extern "C" fn(*mut c_void);
26
27pub fn set_op(cpuid: XwId,
37 resume_periph: PmOperation,
38 suspend_periph: PmOperation,
39 wakeup_cpu: PmOperation,
40 sleep_cpu: PmOperation) {
41 unsafe {
42 xwrustffi_pm_set_op(cpuid,
43 resume_periph,
44 suspend_periph,
45 wakeup_cpu,
46 sleep_cpu,
47 ptr::null_mut());
48 }
49}
50
51pub fn suspend() {
59 unsafe {
60 xwrustffi_pm_suspend();
61 }
62}
63
64pub fn resume() {
77 unsafe {
78 xwrustffi_pm_resume();
79 }
80}
81
82pub struct PmStage(XwSq);
83
84impl PmStage {
85 pub const SUSPENDED: PmStage = PmStage(0);
87 pub const SUSPENDING: PmStage = PmStage(1);
89 pub const RESUMING: PmStage = PmStage(1);
91 pub const FREEZING: PmStage = PmStage(3);
93 pub const THAWING: PmStage = PmStage(3);
95 pub const RUNNING: PmStage = PmStage(4);
97}
98
99pub fn get_stage() -> PmStage {
105 unsafe {
106 PmStage(xwrustffi_pm_get_stage())
107 }
108}
109
110impl PartialEq for PmStage {
111 fn eq(&self, other: &Self) -> bool {
112 self.0 == other.0
113 }
114}
115
116impl PartialOrd for PmStage {
117 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
118 if self.0 < other.0 {
119 Some(Ordering::Less)
120 } else if self.0 > other.0 {
121 Some(Ordering::Greater)
122 } else {
123 Some(Ordering::Equal)
124 }
125 }
126}