hal_api/
stack.rs

1use crate::{Result, mem::PhysAddr};
2use core::{ffi::c_void, num::NonZero};
3
4pub type EntryFn = extern "C" fn();
5pub type FinFn = extern "C" fn() -> !;
6
7pub struct Descriptor {
8    pub top: PhysAddr,
9    pub size: NonZero<usize>,
10    pub entry: EntryFn,
11    pub fin: Option<FinFn>,
12}
13
14pub trait Stacklike {
15    type ElemSize: Copy;
16    type StackPtr;
17
18    unsafe fn new(desc: Descriptor) -> Result<Self>
19    where
20        Self: Sized;
21
22    fn create_sp(&self, ptr: *mut c_void) -> Result<Self::StackPtr>;
23    fn set_sp(&mut self, sp: Self::StackPtr);
24
25    fn sp(&self) -> *mut c_void;
26
27    //fn push_tinit<F, const N: usize>(&mut self, init: &ThreadInitializer<F, N, Self::ElemSize>) -> Result<CtxPtr>;
28
29    // Pushes a function context onto the stack, which will be executed when the IRQ returns.
30    //fn push_irq_ret_fn(&mut self, f: fn(), fin: Option<fn() -> !>) -> Result<Self::StackPtr>;
31}
32
33pub trait ThreadArgument: Send + 'static {}
34
35impl<T> ThreadArgument for T where T: Send + 'static {}
36
37/*
38macro_rules! impl_thread_arg {
39    ($($t:ty),+) => { $(unsafe impl ThreadArgument for $t {})+ };
40}
41
42macro_rules! impl_thread_arg_tuples {
43    ( $( $len:literal ),* $(,)? ) => {
44        $(
45            seq!(I in 0..$len {
46                unsafe impl<#(T~I: ThreadArgument,)*> ThreadArgument for (#(T~I,)*) {}
47            });
48        )*
49    }
50}
51
52impl_thread_arg!(u8,u16,u32,u64,u128,usize,i8,i16,i32,i64,i128,isize,bool,char);
53impl_thread_arg_tuples!(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
54
55
56pub struct ThreadInitializer<F, const N: usize> {
57     pub func: F,
58     pub finalizer: Option<fn()>,
59     pub args: [ElemSize; N],
60}
61
62impl<F, const N: usize, ElemSize: Copy + Into<usize>> ThreadInitializer<F, N, ElemSize> {
63    pub fn new(func: F, finalizer: Option<fn()>, args: &[ElemSize; N]) -> Self {
64        Self { func, finalizer, args: *args }
65    }
66}
67*/