vex_sdk/
system.rs

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
//! VEXos System Functions

#[cfg(any(target_env = "v5", target_env = "exp", doc))]
use crate::{map_jump_table, JUMP_TABLE_START};
#[cfg(any(target_env = "v5", target_env = "exp", doc))]
use core::ffi::c_void;

/// Code Signature
///
/// The first 16 bytes of a user code binary should contain the user code
/// signature.  For simple user code programs this will be created by the
/// startup code in the runtime library, certain types of user code,
/// for example a virtual machine, may override the default settings to cause
/// the V5 system code to enable custom functionality yet TBD.
#[repr(C, packed)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct vcodesig {
    /// Magic, must be 'VXV5' 0x35565856 le
    pub magic: u32,

    /// Program type
    pub r#type: u32,

    /// Program originator
    pub owner: u32,

    /// Program options
    pub options: u32,
}

impl Default for vcodesig {
    fn default() -> Self {
        vcodesig {
            magic: V5_SIG_MAGIC,
            r#type: Default::default(),
            owner: Default::default(),
            options: Default::default(),
        }
    }
}

pub const V5_SIG_MAGIC: u32 = 0x35585658;
pub const EX_SIG_MAGIC: u32 = 0x45585658;

pub const V5_SIG_TYPE_USER: u32 = 0;
pub const V5_SIG_OWNER_SYS: u32 = 0;
pub const V5_SIG_OWNER_VEX: u32 = 1;
pub const V5_SIG_OWNER_PARTNER: u32 = 2;
pub const V5_SIG_OPTIONS_NONE: u32 = 0;
/// Invert default graphics colors
pub const V5_SIG_OPTIONS_INDG: u32 = 1 << 0;
/// Kill threads when main exits
pub const V5_SIG_OPTIONS_EXIT: u32 = 1 << 1;
/// Invert graphics based on theme
pub const V5_SIG_OPTIONS_THDG: u32 = 1 << 2;

#[repr(C)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct time {
    /// Hours
    pub ti_hour: u8,
    /// Minutes
    pub ti_min: u8,
    /// Seconds
    pub ti_sec: u8,
    /// Hundredths of seconds
    pub ti_hund: u8,
}

#[repr(C)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct date {
    /// Year - 1980
    pub da_year: u16,
    /// Day of the month
    pub da_day: u8,
    /// Month (1 = Jan)
    pub da_mon: u8,
}

#[cfg(any(target_env = "v5", target_env = "exp", doc))]
map_jump_table! {
    0x10 => pub fn vexStdlibMismatchError(param_1: u32, param_2: u32),
    0x01c =>
        /// special use only ! Talk to James.
        pub fn vexScratchMemoryPtr(ptr: *mut *mut core::ffi::c_void) -> i32,
    0x998 => pub fn vexScratchMemoryLock() -> bool,
    0x99c => pub fn vexScratchMemoryUnock(),
    0x118 =>
        /// Gets the time since program start with millisecond precision.
        pub fn vexSystemTimeGet() -> u32,
    0x11c => pub fn vexGettime() -> time,
    0x120 => pub fn vexGetdate() -> date,
    0x124 => pub fn vexSystemMemoryDump(),
    0x128 => pub fn vexSystemDigitalIO(pin: u32, value: u32),
    0x12c => pub fn vexSystemStartupOptions() -> u32,
    0x130 =>
        /// Exits the current user program, returning to the main program screen.
        pub fn vexSystemExitRequest(),
    0x134 =>
        /// Gets the time since program start with microsecond precision.
        pub fn vexSystemHighResTimeGet() -> u64,
    0x138 =>
        /// Gets the time since power on with microsecond precision.
        pub fn vexSystemPowerupTimeGet() -> u64,
    0x13c =>
        /// Gets the address in memory of a linked file to the current user program, or `0`, if no file is linked.
        ///
        /// VEXos's internal filesystem structure allows user programs to "link" other external binary packages =>
        /// similar
        pub fn vexSystemLinkAddrGet() -> u32,
    0x174 => pub fn vexSystemUsbStatus() -> u32,
    0x8c0 => pub fn vexSystemTimerStop(),
    0x8c4 => pub fn vexSystemTimerClearInterrupt(),
    0x8c8 => pub fn vexSystemTimerReinitForRtos(priority: u32, handler: extern "aapcs" fn(data: *mut c_void)) -> i32,
    0x8cc => pub fn vexSystemApplicationIRQHandler(ulICCIAR: u32),
    0x8d0 => pub fn vexSystemWatchdogReinitRtos() -> i32,
    0x8d4 => pub fn vexSystemWatchdogGet() -> u32,
    0x910 => pub fn vexSystemBoot(),
    0x914 => pub fn vexSystemUndefinedException(),
    0x918 => pub fn vexSystemFIQInterrupt(),
    0x91c => pub fn vexSystemIQRQnterrupt(),
    0x920 => pub fn vexSystemSWInterrupt(),
    0x924 => pub fn vexSystemDataAbortInterrupt(),
    0x928 => pub fn vexSystemPrefetchAbortInterrupt(),
}

#[cfg(any(target_env = "v5", target_env = "exp", doc))]
pub unsafe extern "aapcs" fn vexSystemVersion() -> u32 {
    unsafe { core::ptr::read_volatile((JUMP_TABLE_START + 0x1000) as *const u32) }
}

#[cfg(any(target_env = "v5", target_env = "exp", doc))]
pub unsafe extern "aapcs" fn vexStdlibVersion() -> u32 {
    unsafe { core::ptr::read_volatile((JUMP_TABLE_START + 0x1004) as *const u32) }
}