use crate::{bag::Bag, closure::Closure, kernel::raw, time::Duration, utils::PhantomInvariant};
#[const_trait]
pub unsafe trait CfgBase {
type System: raw::KernelBase;
fn num_task_priority_levels(&mut self, new_value: usize);
fn startup_hook_define(&mut self, func: fn());
}
#[const_trait]
pub unsafe trait CfgTask: ~const CfgBase {
fn task_define<Properties: ~const Bag>(
&mut self,
descriptor: TaskDescriptor<Self::System>,
properties: Properties,
) -> <Self::System as raw::KernelBase>::RawTaskId;
}
#[derive(Debug)]
pub struct TaskDescriptor<System> {
pub phantom: PhantomInvariant<System>,
pub start: Closure,
pub active: bool,
pub priority: usize,
pub stack_size: Option<usize>,
}
#[const_trait]
pub unsafe trait CfgEventGroup: ~const CfgBase<System: raw::KernelEventGroup> {
fn event_group_define<Properties: ~const Bag>(
&mut self,
descriptor: EventGroupDescriptor<Self::System>,
properties: Properties,
) -> <Self::System as raw::KernelEventGroup>::RawEventGroupId;
}
#[derive(Debug)]
pub struct EventGroupDescriptor<System> {
pub phantom: PhantomInvariant<System>,
pub initial_bits: raw::EventGroupBits,
pub queue_order: raw::QueueOrder,
}
#[const_trait]
pub unsafe trait CfgMutex: ~const CfgBase<System: raw::KernelMutex> {
fn mutex_define<Properties: ~const Bag>(
&mut self,
descriptor: MutexDescriptor<Self::System>,
properties: Properties,
) -> <Self::System as raw::KernelMutex>::RawMutexId;
}
#[derive(Debug)]
pub struct MutexDescriptor<System> {
pub phantom: PhantomInvariant<System>,
pub protocol: raw::MutexProtocol,
}
#[const_trait]
pub unsafe trait CfgSemaphore: ~const CfgBase<System: raw::KernelSemaphore> {
fn semaphore_define<Properties: ~const Bag>(
&mut self,
descriptor: SemaphoreDescriptor<Self::System>,
properties: Properties,
) -> <Self::System as raw::KernelSemaphore>::RawSemaphoreId;
}
#[derive(Debug)]
pub struct SemaphoreDescriptor<System> {
pub phantom: PhantomInvariant<System>,
pub initial: raw::SemaphoreValue,
pub maximum: raw::SemaphoreValue,
pub queue_order: raw::QueueOrder,
}
#[const_trait]
pub unsafe trait CfgTimer: ~const CfgBase<System: raw::KernelTimer> {
fn timer_define<Properties: ~const Bag>(
&mut self,
descriptor: TimerDescriptor<Self::System>,
properties: Properties,
) -> <Self::System as raw::KernelTimer>::RawTimerId;
}
#[derive(Debug)]
pub struct TimerDescriptor<System> {
pub phantom: PhantomInvariant<System>,
pub start: Closure,
pub active: bool,
pub delay: Option<Duration>,
pub period: Option<Duration>,
}
#[const_trait]
pub unsafe trait CfgInterruptLine: ~const CfgBase<System: raw::KernelInterruptLine> {
fn interrupt_line_define<Properties: ~const Bag>(
&mut self,
descriptor: InterruptLineDescriptor<Self::System>,
properties: Properties,
);
}
#[derive(Debug)]
pub struct InterruptLineDescriptor<System> {
pub phantom: PhantomInvariant<System>,
pub line: raw::InterruptNum,
pub priority: Option<raw::InterruptPriority>,
pub start: Option<raw::InterruptHandlerFn>,
pub enabled: bool,
}