-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.rs
109 lines (91 loc) · 2.02 KB
/
main.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
#![allow(improper_ctypes)]
#![no_std]
#![feature(lang_items)]
#![feature(no_std)]
#![feature(intrinsics)]
#![feature(core)]
#![feature(start)]
extern crate core;
mod runtime;
extern "rust-intrinsic" { pub fn volatile_load<T>(src: *const T) -> T; }
extern "rust-intrinsic" { pub fn volatile_store<T>(src: *mut T, value: T); }
const RAM_ADDR: u32 = 0x1e000000;
#[repr(packed)]
struct resource_table
{
ver: u32,
num: u32,
reserved: [u32; 2],
offset: [u32; 1],
}
#[repr(u8)]
enum fw_resource_type
{
RSC_CARVEOUT = 0,
RSC_DEVMEM = 1,
RSC_TRACE = 2,
RSC_VDEV = 3,
RSC_MMU = 4,
RSC_LAST = 5,
}
#[repr(packed)]
struct fw_rsc_carveout
{
type_: u32,
da: u32,
pa: u32,
len: u32,
flags: u32,
reserved: u32,
name: [u8; 32], // TODO: not sure if the type is right
}
pub struct rproc_resource
{
base: resource_table,
code_cout: fw_rsc_carveout,
}
#[link_section=".rtable"]
pub static mut ti_ipc_remoteproc_ResourceTable: rproc_resource = rproc_resource {
base: resource_table { ver: 1, num: 1, reserved: [0, 0], offset: [20], rproc_resource, code_cout) }
},
code_cout: fw_rsc_carveout { type_: fw_resource_type::RSC_CARVEOUT as u32, da: RAM_ADDR, pa: RAM_ADDR, len: 1<<19,
flags: 0, reserved: 0, name: *b"APP_CPU1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
},
};
#[no_mangle]
pub fn set_led(led_port: *mut u32, led_pin: u32) {
unsafe {
*led_port |= 1 << led_pin;
}
}
#[no_mangle]
pub fn clear_led(led_port: *mut u32, led_pin: u32) {
unsafe {
*led_port &= !(1 << led_pin);
}
}
#[no_mangle]
pub fn toogle_led(led_port: *mut u32, led_pin: u32) {
unsafe {
*led_port ^= 1 << led_pin;
}
}
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
main();
return 0;
}
pub fn main() {
unsafe {
volatile_load(&ti_ipc_remoteproc_ResourceTable);
}
let led_port: *mut u32 = 0x40000030 as *mut u32;
loop {
let mut i: u32 = 0;
while i < 10000000u32 { i += 1; }
i = 0;
while i < 10000000u32 { i += 1; }
toogle_led(led_port, 2);
toogle_led(led_port, 4);
}
}