diff options
Diffstat (limited to 'components/rust/core/src')
| -rw-r--r-- | components/rust/core/src/api/mod.rs | 2 | ||||
| -rw-r--r-- | components/rust/core/src/api/queue.rs | 11 | ||||
| -rw-r--r-- | components/rust/core/src/bindings/librt.rs | 3 | ||||
| -rw-r--r-- | components/rust/core/src/bindings/mod.rs | 3 | ||||
| -rw-r--r-- | components/rust/core/src/fs.rs | 2 | ||||
| -rw-r--r-- | components/rust/core/src/lib.rs | 3 |
6 files changed, 16 insertions, 8 deletions
diff --git a/components/rust/core/src/api/mod.rs b/components/rust/core/src/api/mod.rs index 8fc2ba2301..cf3d0bbc0c 100644 --- a/components/rust/core/src/api/mod.rs +++ b/components/rust/core/src/api/mod.rs @@ -14,6 +14,7 @@ pub mod thread; pub mod mutex; pub mod sem; pub mod queue; +#[cfg(feature = "libdl")] pub mod libloading; @@ -24,4 +25,5 @@ pub use thread::*; pub use mutex::*; pub use sem::*; pub use queue::*; +#[cfg(feature = "libdl")] pub use libloading::*; diff --git a/components/rust/core/src/api/queue.rs b/components/rust/core/src/api/queue.rs index 96665e47f2..8a77374b90 100644 --- a/components/rust/core/src/api/queue.rs +++ b/components/rust/core/src/api/queue.rs @@ -20,7 +20,7 @@ pub type APIRawQueue = rt_mq_t; pub(crate) fn queue_create(name: &str, len: u64, message_size: u64) -> Option<APIRawQueue> { let s = CString::new(name).unwrap(); let raw; - unsafe { raw = rt_mq_create(s.as_ptr(), message_size, len, 0) } + unsafe { raw = rt_mq_create(s.as_ptr(), message_size as rt_size_t, len as rt_size_t, 0) } if raw == ptr::null_mut() { None } else { @@ -35,7 +35,7 @@ pub(crate) fn queue_send_wait( msg_size: u64, tick: i32, ) -> RttCResult { - unsafe { rt_mq_send_wait(handle, msg, msg_size, tick).into() } + unsafe { rt_mq_send_wait(handle, msg, msg_size as rt_size_t, tick).into() } } #[inline] @@ -45,7 +45,12 @@ pub(crate) fn queue_receive_wait( msg_size: u64, tick: i32, ) -> RttCResult { - unsafe { rt_mq_recv(handle, msg, msg_size, tick).into() } + let ret = unsafe { rt_mq_recv(handle, msg, msg_size as rt_size_t, tick) }; + if ret >= 0 { + RttCResult::Ok + } else { + ret.into() + } } #[inline] diff --git a/components/rust/core/src/bindings/librt.rs b/components/rust/core/src/bindings/librt.rs index 3f16c014fd..a39ed07c22 100644 --- a/components/rust/core/src/bindings/librt.rs +++ b/components/rust/core/src/bindings/librt.rs @@ -26,6 +26,7 @@ pub type rt_int32_t = c_int; pub type rt_uint8_t = c_uchar; pub type rt_tick_t = rt_uint32_t; pub type rt_size_t = rt_ubase_t; +pub type rt_ssize_t = rt_base_t; pub type rt_thread_t = *mut c_void; pub type rt_sem_t = *mut c_void; @@ -94,7 +95,7 @@ unsafe extern "C" { pub fn rt_mq_create(name: *const c_char, msg_size: rt_size_t, max_msgs: rt_size_t, flag: rt_uint8_t) -> rt_mq_t; pub fn rt_mq_send(mq: rt_mq_t, buffer: *const c_void, size: rt_size_t) -> rt_err_t; pub fn rt_mq_send_wait(mq: rt_mq_t, buffer: *const c_void, size: rt_size_t, timeout: rt_int32_t) -> rt_err_t; - pub fn rt_mq_recv(mq: rt_mq_t, buffer: *mut c_void, size: rt_size_t, timeout: rt_int32_t) -> rt_base_t; + pub fn rt_mq_recv(mq: rt_mq_t, buffer: *mut c_void, size: rt_size_t, timeout: rt_int32_t) -> rt_ssize_t; pub fn rt_mq_delete(mq: rt_mq_t) -> rt_err_t; pub fn rt_mq_detach(mq: rt_mq_t) -> rt_err_t; } diff --git a/components/rust/core/src/bindings/mod.rs b/components/rust/core/src/bindings/mod.rs index ae2610e9c8..cad651a1dd 100644 --- a/components/rust/core/src/bindings/mod.rs +++ b/components/rust/core/src/bindings/mod.rs @@ -46,8 +46,7 @@ pub use librt::{ /* Memory management functions */ pub use librt::{ - rt_malloc, rt_free, rt_realloc, rt_calloc, rt_malloc_align, rt_free_align, - rt_safe_malloc, rt_safe_free + rt_malloc, rt_free, rt_realloc, rt_calloc, rt_malloc_align, rt_free_align }; /* Device management functions */ diff --git a/components/rust/core/src/fs.rs b/components/rust/core/src/fs.rs index 6ad02037ab..9a8d1afa8d 100644 --- a/components/rust/core/src/fs.rs +++ b/components/rust/core/src/fs.rs @@ -98,7 +98,7 @@ impl File { pub fn seek(&self, offset: i64) -> RTResult<i64> { let n = unsafe { libc::lseek(self.fd, offset as libc::off_t, libc::SEEK_SET) }; - if n < 0 { Err(FileSeekErr) } else { Ok(n) } + if n < 0 { Err(FileSeekErr) } else { Ok(n.into()) } } pub fn flush(&self) -> RTResult<()> { diff --git a/components/rust/core/src/lib.rs b/components/rust/core/src/lib.rs index 01e4b34102..0b94f81427 100644 --- a/components/rust/core/src/lib.rs +++ b/components/rust/core/src/lib.rs @@ -17,7 +17,6 @@ and device interfaces. Designed for embedded devices running RT-Thread. */ #![no_std] -#![feature(alloc_error_handler)] #![feature(linkage)] #![allow(dead_code)] @@ -33,6 +32,7 @@ pub mod init; pub mod allocator; pub mod mutex; pub mod out; +#[cfg(feature = "fs")] pub mod fs; pub mod panic; pub mod param; @@ -40,6 +40,7 @@ pub mod queue; pub mod sem; pub mod thread; pub mod time; +#[cfg(feature = "libdl")] pub mod libloader; mod prelude; |
