parent
ac5f032cd9
commit
990470bedd
|
|
@ -1,8 +1,11 @@
|
|||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#![feature(asm)]
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
|
||||
/// Create aliases for FFI types for esp32c3, which doesn't have std.
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod ffi {
|
||||
|
|
@ -31,6 +34,19 @@ pub extern "C" fn add_in_rust(x: i32, y: i32) -> i32 {
|
|||
x + y
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_in_rust_inline_asm(mut x: i32, y: i32) -> i32 {
|
||||
unsafe {
|
||||
sys::validate_param_in_c(0, x);
|
||||
sys::validate_param_in_c(1, y);
|
||||
}
|
||||
unsafe {
|
||||
// more detail available: https://doc.rust-lang.org/beta/unstable-book/library-features/asm.html
|
||||
asm!("add {0}, {0}, {1}", inout(reg) x, in(reg) y);
|
||||
}
|
||||
x
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ void app_main(void)
|
|||
int sum = add_in_rust(x, y);
|
||||
printf("Rust calculated %d + %d = %d\n\n", x, y, sum);
|
||||
|
||||
x = 9;
|
||||
y = 10;
|
||||
sum = add_in_rust_inline_asm(x, y);
|
||||
printf("Rust calculated (using asm!) %d + %d = %d\n\n", x, y, sum);
|
||||
|
||||
for (int i = 10; i >= 0; i--) {
|
||||
printf("Restarting in %d seconds...\n", i);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
|
|
|||
Loading…
Reference in New Issue