summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/itron/abi.rs
blob: 5eb14bb7e534be11226565e0b243a987bec50588 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//! ABI for μITRON derivatives
pub type int_t = crate::os::raw::c_int;
pub type uint_t = crate::os::raw::c_uint;
pub type bool_t = int_t;

/// Kernel object ID
pub type ID = int_t;

/// The current task.
pub const TSK_SELF: ID = 0;

/// Relative time
pub type RELTIM = u32;

/// Timeout (a valid `RELTIM` value or `TMO_FEVR`)
pub type TMO = u32;

/// The infinite timeout value
pub const TMO_FEVR: TMO = TMO::MAX;

/// The maximum valid value of `RELTIM`
pub const TMAX_RELTIM: RELTIM = 4_000_000_000;

/// System time
pub type SYSTIM = u64;

/// Error code type
pub type ER = int_t;

/// Error code type, `ID` on success
pub type ER_ID = int_t;

/// Service call operational mode
pub type MODE = uint_t;

/// OR waiting condition for an eventflag
pub const TWF_ORW: MODE = 0x01;

/// Object attributes
pub type ATR = uint_t;

/// FIFO wait order
pub const TA_FIFO: ATR = 0;
/// Only one task is allowed to be in the waiting state for the eventflag
pub const TA_WSGL: ATR = 0;
/// The eventflag’s bit pattern is cleared when a task is released from the
/// waiting state for that eventflag.
pub const TA_CLR: ATR = 0x04;

/// Bit pattern of an eventflag
pub type FLGPTN = uint_t;

/// Task or interrupt priority
pub type PRI = int_t;

/// The special value of `PRI` representing the current task's priority.
pub const TPRI_SELF: PRI = 0;

/// Use the priority inheritance protocol
#[cfg(target_os = "solid_asp3")]
pub const TA_INHERIT: ATR = 0x02;

/// Activate the task on creation
pub const TA_ACT: ATR = 0x01;

/// The maximum count of a semaphore
pub const TMAX_MAXSEM: uint_t = uint_t::MAX;

/// Callback parameter
pub type EXINF = isize;

/// Task entrypoint
pub type TASK = Option<unsafe extern "C" fn(EXINF)>;

// Error codes
pub const E_OK: ER = 0;
pub const E_SYS: ER = -5;
pub const E_NOSPT: ER = -9;
pub const E_RSFN: ER = -10;
pub const E_RSATR: ER = -11;
pub const E_PAR: ER = -17;
pub const E_ID: ER = -18;
pub const E_CTX: ER = -25;
pub const E_MACV: ER = -26;
pub const E_OACV: ER = -27;
pub const E_ILUSE: ER = -28;
pub const E_NOMEM: ER = -33;
pub const E_NOID: ER = -34;
pub const E_NORES: ER = -35;
pub const E_OBJ: ER = -41;
pub const E_NOEXS: ER = -42;
pub const E_QOVR: ER = -43;
pub const E_RLWAI: ER = -49;
pub const E_TMOUT: ER = -50;
pub const E_DLT: ER = -51;
pub const E_CLS: ER = -52;
pub const E_RASTER: ER = -53;
pub const E_WBLK: ER = -57;
pub const E_BOVR: ER = -58;
pub const E_COMM: ER = -65;

#[derive(Clone, Copy)]
#[repr(C)]
pub struct T_CSEM {
    pub sematr: ATR,
    pub isemcnt: uint_t,
    pub maxsem: uint_t,
}

#[derive(Clone, Copy)]
#[repr(C)]
pub struct T_CFLG {
    pub flgatr: ATR,
    pub iflgptn: FLGPTN,
}

#[derive(Clone, Copy)]
#[repr(C)]
pub struct T_CMTX {
    pub mtxatr: ATR,
    pub ceilpri: PRI,
}

#[derive(Clone, Copy)]
#[repr(C)]
pub struct T_CTSK {
    pub tskatr: ATR,
    pub exinf: EXINF,
    pub task: TASK,
    pub itskpri: PRI,
    pub stksz: usize,
    pub stk: *mut u8,
}

extern "C" {
    #[link_name = "__asp3_acre_tsk"]
    pub fn acre_tsk(pk_ctsk: *const T_CTSK) -> ER_ID;
    #[link_name = "__asp3_get_tid"]
    pub fn get_tid(p_tskid: *mut ID) -> ER;
    #[link_name = "__asp3_dly_tsk"]
    pub fn dly_tsk(dlytim: RELTIM) -> ER;
    #[link_name = "__asp3_ter_tsk"]
    pub fn ter_tsk(tskid: ID) -> ER;
    #[link_name = "__asp3_del_tsk"]
    pub fn del_tsk(tskid: ID) -> ER;
    #[link_name = "__asp3_get_pri"]
    pub fn get_pri(tskid: ID, p_tskpri: *mut PRI) -> ER;
    #[link_name = "__asp3_rot_rdq"]
    pub fn rot_rdq(tskpri: PRI) -> ER;
    #[link_name = "__asp3_slp_tsk"]
    pub fn slp_tsk() -> ER;
    #[link_name = "__asp3_tslp_tsk"]
    pub fn tslp_tsk(tmout: TMO) -> ER;
    #[link_name = "__asp3_wup_tsk"]
    pub fn wup_tsk(tskid: ID) -> ER;
    #[link_name = "__asp3_unl_cpu"]
    pub fn unl_cpu() -> ER;
    #[link_name = "__asp3_dis_dsp"]
    pub fn dis_dsp() -> ER;
    #[link_name = "__asp3_ena_dsp"]
    pub fn ena_dsp() -> ER;
    #[link_name = "__asp3_sns_dsp"]
    pub fn sns_dsp() -> bool_t;
    #[link_name = "__asp3_get_tim"]
    pub fn get_tim(p_systim: *mut SYSTIM) -> ER;
    #[link_name = "__asp3_acre_flg"]
    pub fn acre_flg(pk_cflg: *const T_CFLG) -> ER_ID;
    #[link_name = "__asp3_del_flg"]
    pub fn del_flg(flgid: ID) -> ER;
    #[link_name = "__asp3_set_flg"]
    pub fn set_flg(flgid: ID, setptn: FLGPTN) -> ER;
    #[link_name = "__asp3_clr_flg"]
    pub fn clr_flg(flgid: ID, clrptn: FLGPTN) -> ER;
    #[link_name = "__asp3_wai_flg"]
    pub fn wai_flg(flgid: ID, waiptn: FLGPTN, wfmode: MODE, p_flgptn: *mut FLGPTN) -> ER;
    #[link_name = "__asp3_twai_flg"]
    pub fn twai_flg(
        flgid: ID,
        waiptn: FLGPTN,
        wfmode: MODE,
        p_flgptn: *mut FLGPTN,
        tmout: TMO,
    ) -> ER;
    #[link_name = "__asp3_acre_mtx"]
    pub fn acre_mtx(pk_cmtx: *const T_CMTX) -> ER_ID;
    #[link_name = "__asp3_del_mtx"]
    pub fn del_mtx(tskid: ID) -> ER;
    #[link_name = "__asp3_loc_mtx"]
    pub fn loc_mtx(mtxid: ID) -> ER;
    #[link_name = "__asp3_ploc_mtx"]
    pub fn ploc_mtx(mtxid: ID) -> ER;
    #[link_name = "__asp3_tloc_mtx"]
    pub fn tloc_mtx(mtxid: ID, tmout: TMO) -> ER;
    #[link_name = "__asp3_unl_mtx"]
    pub fn unl_mtx(mtxid: ID) -> ER;
    pub fn exd_tsk() -> ER;
}