Skip to content

Commit eaee959

Browse files
committed
zephyr: Implement Debug for Semaphore
It just prints the type, but allows other structs containing Semaphores to be printed. Signed-off-by: David Brown <[email protected]>
1 parent ff176b9 commit eaee959

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

zephyr/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub mod time;
1919

2020
pub use error::{Error, Result};
2121

22+
/// Re-exported for local macro use.
23+
pub use paste::paste;
24+
2225
// Bring in the generated kconfig module
2326
pub mod kconfig {
2427
//! Zephyr Kconfig values.

zephyr/src/object.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ use crate::sync::atomic::{AtomicUsize, Ordering};
4444
/// be properly registered in Zephyr as kernel objects. The object has the underlying Zephyr type
4545
/// T, and the wrapper type W.
4646
///
47+
/// TODO: Can we avoid the public fields with a const new method?
48+
///
4749
/// TODO: Handling const-defined alignment for these.
4850
pub struct StaticKernelObject<T> {
4951
#[allow(dead_code)]
5052
/// The underlying zephyr kernel object.
51-
pub(crate) value: UnsafeCell<T>,
53+
pub value: UnsafeCell<T>,
5254
/// Initialization status of this object. Most objects will start uninitialized and be
5355
/// initialized manually.
54-
pub(crate) init: AtomicUsize,
56+
pub init: AtomicUsize,
5557
}
5658

5759
/// Each can be wrapped appropriately. The wrapped type is the instance that holds the raw pointer.
@@ -205,20 +207,20 @@ macro_rules! _kobj_rule {
205207
#[macro_export]
206208
macro_rules! _kobj_stack {
207209
($v:vis, $name: ident, $size:expr) => {
208-
::paste::paste! {
210+
$crate::paste! {
209211
// The actual stack itself goes into the no-init linker section. We'll use the user_name,
210212
// with _REAL appended, to indicate the real stack.
211213
#[link_section = concat!(".noinit.", stringify!($name), ".", file!(), line!())]
212-
$v static [< $name _REAL >] $crate::sys::thread::RealThreadStack<{$crate::sys::thread::stack_len($size)}> =
214+
$v static [< $name _REAL >]: $crate::sys::thread::RealStaticThreadStack<{$crate::sys::thread::stack_len($size)}> =
213215
unsafe { ::core::mem::zeroed() };
214216

215217
// The proxy object used to ensure initialization is placed in initialized memory.
216-
$v static $name: $crate::object::StaticKernelObject<$crate::object::StaticThreadStack> = StaticKernelObject {
217-
value: ::core::cell::UnsafeCell::new($crate::object::StaticThreadStack {
218+
$v static $name: $crate::object::StaticKernelObject<$crate::sys::thread::StaticThreadStack> = $crate::object::StaticKernelObject {
219+
value: ::core::cell::UnsafeCell::new($crate::sys::thread::StaticThreadStack {
218220
base: [< $name _REAL >].data.get() as *mut $crate::raw::z_thread_stack_element,
219221
size: $size,
220222
}),
221-
init: $crate::atomic::AtomicUsize::new(0),
223+
init: $crate::sync::atomic::AtomicUsize::new(0),
222224
};
223225
}
224226
};

zephyr/src/sys/sync.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//! from a pool, although the objects will still be statically allocated.
3232
3333
use core::ffi::c_uint;
34+
use core::fmt;
3435

3536
use crate::{
3637
error::{Result, to_result_void},
@@ -129,3 +130,9 @@ impl Wrapped for StaticKernelObject<k_sem> {
129130
}
130131
}
131132
}
133+
134+
impl fmt::Debug for Semaphore {
135+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
136+
write!(f, "sys::Semaphore")
137+
}
138+
}

0 commit comments

Comments
 (0)