vex_sdk/
system.rs

1//! VEXos System Functions
2
3use core::ffi::{c_char, c_void};
4
5/// Code Signature
6///
7/// The first 16 bytes of a user code binary should contain the user code
8/// signature.  For simple user code programs this will be created by the
9/// startup code in the runtime library, certain types of user code,
10/// for example a virtual machine, may override the default settings to cause
11/// the V5 system code to enable custom functionality yet TBD.
12#[repr(C, packed)]
13#[derive(Copy, Clone, Eq, PartialEq, Debug)]
14pub struct vcodesig {
15    /// Magic, must be 'VXV5' 0x35565856 le
16    pub magic: u32,
17
18    /// Program type
19    pub r#type: u32,
20
21    /// Program originator
22    pub owner: u32,
23
24    /// Program options
25    pub options: u32,
26}
27
28impl Default for vcodesig {
29    fn default() -> Self {
30        vcodesig {
31            magic: V5_SIG_MAGIC,
32            r#type: Default::default(),
33            owner: Default::default(),
34            options: Default::default(),
35        }
36    }
37}
38
39pub const V5_SIG_MAGIC: u32 = 0x35585658;
40pub const EX_SIG_MAGIC: u32 = 0x45585658;
41
42pub const V5_SIG_TYPE_USER: u32 = 0;
43pub const V5_SIG_OWNER_SYS: u32 = 0;
44pub const V5_SIG_OWNER_VEX: u32 = 1;
45pub const V5_SIG_OWNER_PARTNER: u32 = 2;
46pub const V5_SIG_OPTIONS_NONE: u32 = 0;
47/// Invert default graphics colors
48pub const V5_SIG_OPTIONS_INDG: u32 = 1 << 0;
49/// Kill threads when main exits
50pub const V5_SIG_OPTIONS_EXIT: u32 = 1 << 1;
51/// Invert graphics based on theme
52pub const V5_SIG_OPTIONS_THDG: u32 = 1 << 2;
53
54#[repr(C)]
55#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
56pub struct time {
57    /// Hours
58    pub ti_hour: u8,
59    /// Minutes
60    pub ti_min: u8,
61    /// Seconds
62    pub ti_sec: u8,
63    /// Hundredths of seconds
64    pub ti_hund: u8,
65}
66
67#[repr(C)]
68#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
69pub struct date {
70    /// Year - 1980
71    pub da_year: u16,
72    /// Day of the month
73    pub da_day: u8,
74    /// Month (1 = Jan)
75    pub da_mon: u8,
76}
77
78unsafe extern "system" {
79    pub fn vexScratchMemoryPtr(ptr: *mut *mut core::ffi::c_void) -> i32;
80    pub fn vexScratchMemoryLock() -> bool;
81    pub fn vexScratchMemoryUnlock();
82    pub fn vexSystemTimeGet() -> u32;
83    pub fn vexGettime() -> time;
84    pub fn vexGetdate() -> date;
85    pub fn vexSystemMemoryDump();
86    pub fn vexSystemDigitalIO(pin: u32, value: u32);
87    pub fn vexSystemStartupOptions() -> u32;
88    pub fn vexSystemExitRequest();
89    pub fn vexSystemHighResTimeGet() -> u64;
90    pub fn vexSystemPowerupTimeGet() -> u64;
91    pub fn vexSystemLinkAddrGet() -> u32;
92    pub fn vexSystemUsbStatus() -> u32;
93    pub fn vexSystemTimerStop();
94    pub fn vexSystemTimerClearInterrupt();
95    pub fn vexSystemTimerReinitForRtos(
96        priority: u32,
97        handler: extern "system" fn(data: *mut c_void),
98    ) -> i32;
99    pub fn vexSystemApplicationIRQHandler(ulICCIAR: u32);
100    pub fn vexSystemWatchdogReinitRtos() -> i32;
101    pub fn vexSystemWatchdogGet() -> u32;
102    pub fn vexSystemBoot();
103    pub fn vexSystemUndefinedException();
104    pub fn vexSystemFIQInterrupt();
105    pub fn vexSystemIQRQnterrupt();
106    pub fn vexSystemSWInterrupt();
107    pub fn vexSystemDataAbortInterrupt();
108    pub fn vexSystemPrefetchAbortInterrupt();
109    pub fn vexSystemVersion() -> u32;
110    pub fn vexStdlibVersion() -> u32;
111}
112
113unsafe extern "C" {
114    pub fn vex_printf(format: *const c_char, ...) -> i32;
115    pub fn vex_sprintf(out: *mut c_char, format: *const c_char, ...) -> i32;
116    pub fn vex_snprintf(out: *mut c_char, max_len: u32, format: *const c_char, ...) -> i32;
117}