Skip to content

Commit 0639e0a

Browse files
committed
zephyr: Add kobj_define support for Threads and stack
Add support to the `kobj_define` macro for creating kernel stacks and kernel threads. Signed-off-by: David Brown <[email protected]>
1 parent 2e66e84 commit 0639e0a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

zephyr/src/object.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,46 @@ macro_rules! _kobj_rule {
179179
// [$crate::sys::sync::StaticMutex::new(); $size];
180180
unsafe { ::core::mem::zeroed() };
181181
};
182+
183+
($v:vis, $name:ident, StaticThread) => {
184+
// Since the static object has an atomic that we assume is initialized, let the compiler put
185+
// this in the data section it finds appropriate (probably .bss if it is initialized to zero).
186+
// This only matters when the objects are being checked.
187+
// TODO: This doesn't seem to work with the config.
188+
// #[cfg_attr(not(CONFIG_RUST_CHECK_KOBJ_INIT),
189+
// link_section = concat!(".noinit.", stringify!($name), ".", file!(), line!()))]
190+
$v static $name: $crate::sys::thread::StaticThread =
191+
$crate::sys::thread::StaticThread::new();
192+
};
193+
194+
($v:vis , $name:ident, [StaticThread; $size:expr]) => {
195+
$v static $name: [$crate::sys::thread::StaticThread; $size] =
196+
// See above for the zereod reason.
197+
unsafe { ::core::mem::zeroed() };
198+
};
199+
200+
// Stack expressions have the same syntax ambiguities that they do. We allow an identifier
201+
// (const), a numeric literal, or an expression in braces.
202+
($v:vis, $name:ident, ThreadStack<$size:literal>) => {
203+
$crate::_kobj_stack!($v, $name, $size);
204+
};
205+
($v:vis, $name:ident, ThreadStack<$size:ident>) => {
206+
$crate::_kobj_stack!($v, $name, $size);
207+
};
208+
($v:vis, $name:ident, ThreadStack<{$size:expr}>) => {
209+
$crate::_kobj_stack!($v, $name, $size);
210+
};
211+
212+
// Array of stack object versions.
213+
($v:vis, $name:ident, [ThreadStack<$size:literal>; $asize:expr]) => {
214+
$crate::_kobj_stack!($v, $name, $size, $asize);
215+
};
216+
($v:vis, $name:ident, [ThreadStack<$size:ident>; $asize:expr]) => {
217+
$crate::_kobj_stack!($v, $name, $size, $asize);
218+
};
219+
($v:vis, $name:ident, [ThreadStack<{$size:expr}>; $asize:expr]) => {
220+
$crate::_kobj_stack!($v, $name, $size, $asize);
221+
};
182222
}
183223

184224
#[doc(hidden)]

0 commit comments

Comments
 (0)