forked from ROMEO/obsw
rust lib
This commit is contained in:
parent
a4bcbf64cc
commit
e0527bf91b
@ -97,6 +97,7 @@ add_subdirectory(fsfw)
|
||||
add_subdirectory(common)
|
||||
|
||||
add_subdirectory(${MISSION_PATH})
|
||||
add_subdirectory(mission_rust)
|
||||
|
||||
# ##############################################################################
|
||||
# Post-Sources preparation
|
||||
@ -105,7 +106,7 @@ add_subdirectory(${MISSION_PATH})
|
||||
# Add libraries for all sources.
|
||||
target_link_libraries(lwip PUBLIC freertos_kernel)
|
||||
target_link_libraries(fsfw PUBLIC lwip)
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC fsfw lwip)
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC fsfw lwip mission_rust)
|
||||
|
||||
target_include_directories(
|
||||
${TARGET_NAME} PUBLIC ${BSP_PATH})
|
||||
|
@ -189,10 +189,16 @@ int main(void) {
|
||||
|
||||
void testIp();
|
||||
|
||||
extern "C" {
|
||||
void rust_main(double i);
|
||||
}
|
||||
|
||||
void mission(void *){
|
||||
|
||||
printf("Starting Mission\n");
|
||||
|
||||
rust_main(123456879123456789);
|
||||
|
||||
testIp();
|
||||
|
||||
sif::debug << "OStreams working" << std::endl;
|
||||
|
5
mission_rust/.cargo/config.toml
Normal file
5
mission_rust/.cargo/config.toml
Normal file
@ -0,0 +1,5 @@
|
||||
[build]
|
||||
target = "armv7a-none-eabihf"
|
||||
|
||||
[unstable]
|
||||
build-std = ["core"]
|
1
mission_rust/.gitignore
vendored
Normal file
1
mission_rust/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
target/
|
11
mission_rust/CMakeLists.txt
Normal file
11
mission_rust/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
add_custom_target(
|
||||
mission_rust_internal
|
||||
COMMAND cargo build $<$<CONFIG:Release>:--release>
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
add_library(mission_rust INTERFACE)
|
||||
|
||||
add_dependencies(mission_rust mission_rust_internal)
|
||||
|
||||
target_link_libraries(mission_rust INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/target/armv7a-none-eabihf/$<IF:$<CONFIG:Release>,release,debug>/libmission_rust.a)
|
16
mission_rust/Cargo.lock
generated
Normal file
16
mission_rust/Cargo.lock
generated
Normal file
@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cty"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
||||
|
||||
[[package]]
|
||||
name = "mission_rust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cty",
|
||||
]
|
12
mission_rust/Cargo.toml
Normal file
12
mission_rust/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "mission_rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
cty = "0.2.2"
|
43
mission_rust/src/lib.rs
Normal file
43
mission_rust/src/lib.rs
Normal file
@ -0,0 +1,43 @@
|
||||
#![no_std]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_panic: &PanicInfo<'_>) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn outbyte(c: cty::c_char);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_main(i: cty::c_double) {
|
||||
mission(i);
|
||||
}
|
||||
|
||||
struct Outbytes {}
|
||||
|
||||
use core::fmt::{Error, Write};
|
||||
|
||||
impl Write for Outbytes {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||
for c in s.as_bytes() {
|
||||
unsafe {
|
||||
outbyte(*c);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn mission(i: f64) {
|
||||
for byte in "abcd\n".bytes() {
|
||||
unsafe {
|
||||
outbyte(byte);
|
||||
}
|
||||
}
|
||||
let mut stdout = Outbytes {};
|
||||
|
||||
let _ok = writeln!(&mut stdout, "I got {}!", i);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user