diff options
| author | zhang san <[email protected]> | 2025-12-08 18:34:25 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-08 18:34:25 +0800 |
| commit | 69980f8b9d29b38dbd4ddf6373b4b45f3a138409 (patch) | |
| tree | 21dd9a8ce80e3d30192e9ffa56ea39a199bae309 /components/rust/core/src/api/queue.rs | |
| parent | cd1d47b87c5d47e131730e5506eb3ad77d357653 (diff) | |
Adding Rust Language Support for RT-Thread #10910
Diffstat (limited to 'components/rust/core/src/api/queue.rs')
| -rw-r--r-- | components/rust/core/src/api/queue.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/components/rust/core/src/api/queue.rs b/components/rust/core/src/api/queue.rs new file mode 100644 index 0000000000..96665e47f2 --- /dev/null +++ b/components/rust/core/src/api/queue.rs @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2006-2025, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author notes + * 2025-10-10 foxglove Queue API + */ + +use crate::api::RttCResult; +use core::ffi::c_void; +use crate::bindings::*; +use core::ptr; +use alloc::ffi::CString; + +pub type APIRawQueue = rt_mq_t; + +#[inline] +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) } + if raw == ptr::null_mut() { + None + } else { + Some(raw) + } +} + +#[inline] +pub(crate) fn queue_send_wait( + handle: APIRawQueue, + msg: *const c_void, + msg_size: u64, + tick: i32, +) -> RttCResult { + unsafe { rt_mq_send_wait(handle, msg, msg_size, tick).into() } +} + +#[inline] +pub(crate) fn queue_receive_wait( + handle: APIRawQueue, + msg: *mut c_void, + msg_size: u64, + tick: i32, +) -> RttCResult { + unsafe { rt_mq_recv(handle, msg, msg_size, tick).into() } +} + +#[inline] +pub(crate) fn queue_delete(handle: APIRawQueue) { + unsafe { + rt_mq_delete(handle); + } +} |
