1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use core::num::NonZeroUsize;
use r3_core::kernel::{
    raw_cfg::{CfgEventGroup, EventGroupDescriptor},
    EventGroupBits,
};

use crate::{cfg::CfgBuilder, event_group, klock::CpuLockCell, wait, KernelTraits, Port};

unsafe impl<Traits: KernelTraits> const CfgEventGroup for CfgBuilder<Traits> {
    fn event_group_define<Properties: ~const r3_core::bag::Bag>(
        &mut self,
        EventGroupDescriptor {
            phantom: _,
            initial_bits,
            queue_order,
        }: EventGroupDescriptor<Self::System>,
        _properties: Properties,
    ) -> event_group::EventGroupId {
        self.event_groups.push(CfgBuilderEventGroup {
            initial_bits,
            queue_order: wait::QueueOrder::from(queue_order),
        });

        unsafe { NonZeroUsize::new_unchecked(self.event_groups.len()) }
    }
}

#[doc(hidden)]
pub struct CfgBuilderEventGroup {
    initial_bits: EventGroupBits,
    queue_order: wait::QueueOrder,
}

impl Clone for CfgBuilderEventGroup {
    fn clone(&self) -> Self {
        Self {
            initial_bits: self.initial_bits,
            queue_order: self.queue_order,
        }
    }
}

impl Copy for CfgBuilderEventGroup {}

impl CfgBuilderEventGroup {
    pub const fn to_state<Traits: Port>(&self) -> event_group::EventGroupCb<Traits> {
        event_group::EventGroupCb {
            bits: CpuLockCell::new(self.initial_bits),
            wait_queue: wait::WaitQueue::new(self.queue_order),
        }
    }
}