Skip to content

Commit 8286951

Browse files
committed
fixing components
1 parent 9f6679b commit 8286951

9 files changed

Lines changed: 147 additions & 22 deletions

File tree

boards/components/src/adc.rs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
77
use capsules_core::adc::AdcDedicated;
88
use capsules_core::adc::AdcVirtualized;
9+
use capsules_core::virtualizers::selection_policy::SelectionPolicy;
910
use capsules_core::virtualizers::virtual_adc::{AdcDevice, MuxAdc};
11+
use core::marker::PhantomData;
1012
use core::mem::MaybeUninit;
1113
use kernel::capabilities;
1214
use kernel::component::Component;
@@ -57,19 +59,32 @@ macro_rules! adc_dedicated_component_static {
5759
};};
5860
}
5961

60-
pub struct AdcMuxComponent<A: 'static + adc::Adc<'static>> {
62+
pub struct AdcMuxComponent<
63+
A: 'static + adc::Adc<'static>,
64+
P: 'static + SelectionPolicy<&'static AdcDevice<'static, A, P>>,
65+
> {
6166
adc: &'static A,
67+
phantom: PhantomData<P>,
6268
}
6369

64-
impl<A: 'static + adc::Adc<'static>> AdcMuxComponent<A> {
70+
impl<
71+
A: 'static + adc::Adc<'static>,
72+
P: 'static + SelectionPolicy<&'static AdcDevice<'static, A, P>>,
73+
> AdcMuxComponent<A, P>
74+
{
6575
pub fn new(adc: &'static A) -> Self {
66-
AdcMuxComponent { adc }
76+
AdcMuxComponent {
77+
adc,
78+
phantom: PhantomData,
79+
}
6780
}
6881
}
6982

70-
impl<A: 'static + adc::Adc<'static>> Component for AdcMuxComponent<A> {
71-
type StaticInput = &'static mut MaybeUninit<MuxAdc<'static, A>>;
72-
type Output = &'static MuxAdc<'static, A>;
83+
impl<A: 'static + adc::Adc<'static>, P: SelectionPolicy<&'static AdcDevice<'static, A, P>>>
84+
Component for AdcMuxComponent<A, P>
85+
{
86+
type StaticInput = &'static mut MaybeUninit<MuxAdc<'static, A, P>>;
87+
type Output = &'static MuxAdc<'static, A, P>;
7388

7489
fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
7590
let adc_mux = static_buffer.write(MuxAdc::new(self.adc));
@@ -80,23 +95,32 @@ impl<A: 'static + adc::Adc<'static>> Component for AdcMuxComponent<A> {
8095
}
8196
}
8297

83-
pub struct AdcComponent<A: 'static + adc::Adc<'static>> {
84-
adc_mux: &'static MuxAdc<'static, A>,
98+
pub struct AdcComponent<
99+
A: 'static + adc::Adc<'static>,
100+
P: 'static + SelectionPolicy<&'static AdcDevice<'static, A, P>>,
101+
> {
102+
adc_mux: &'static MuxAdc<'static, A, P>,
85103
channel: A::Channel,
86104
}
87105

88-
impl<A: 'static + adc::Adc<'static>> AdcComponent<A> {
89-
pub fn new(mux: &'static MuxAdc<'static, A>, channel: A::Channel) -> Self {
106+
impl<
107+
A: 'static + adc::Adc<'static>,
108+
P: 'static + SelectionPolicy<&'static AdcDevice<'static, A, P>>,
109+
> AdcComponent<A, P>
110+
{
111+
pub fn new(mux: &'static MuxAdc<'static, A, P>, channel: A::Channel) -> Self {
90112
AdcComponent {
91113
adc_mux: mux,
92114
channel,
93115
}
94116
}
95117
}
96118

97-
impl<A: 'static + adc::Adc<'static>> Component for AdcComponent<A> {
98-
type StaticInput = &'static mut MaybeUninit<AdcDevice<'static, A>>;
99-
type Output = &'static AdcDevice<'static, A>;
119+
impl<A: 'static + adc::Adc<'static>, P: SelectionPolicy<&'static AdcDevice<'static, A, P>>>
120+
Component for AdcComponent<A, P>
121+
{
122+
type StaticInput = &'static mut MaybeUninit<AdcDevice<'static, A, P>>;
123+
type Output = &'static AdcDevice<'static, A, P>;
100124

101125
fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
102126
let adc_device = static_buffer.write(AdcDevice::new(self.adc_mux, self.channel));

boards/components/src/bus.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//! );
2525
//! ```
2626
27+
use capsules_core::virtualizers::selection_policy::SelectionPolicy;
2728
use capsules_core::virtualizers::virtual_i2c::{I2CDevice, MuxI2C};
2829
use capsules_core::virtualizers::virtual_spi::MuxSpiMaster;
2930
use capsules_core::virtualizers::virtual_spi::VirtualSpiMasterDevice;
@@ -72,6 +73,18 @@ macro_rules! i2c_master_bus_component_static {
7273
>
7374
);
7475

76+
(bus, i2c_device, address_buffer)
77+
};};
78+
($D:ty, $P:ty $(,)?) => {{
79+
let address_buffer = kernel::static_buf!([u8; 1]);
80+
let bus = kernel::static_buf!(capsules_extra::bus::I2CMasterBus<'static, $D, $P>);
81+
let i2c_device = kernel::static_buf!(
82+
capsules_core::virtualizers::virtual_i2c::I2CDevice<
83+
'static,
84+
capsules_extra::bus::I2CMasterBus<'static, $D, $P>,
85+
>
86+
);
87+
7588
(bus, i2c_device, address_buffer)
7689
};};
7790
}
@@ -98,22 +111,29 @@ impl<B: 'static + bus8080::Bus8080<'static>> Component for Bus8080BusComponent<B
98111
}
99112
}
100113

101-
pub struct SpiMasterBusComponent<S: 'static + spi::SpiMaster<'static>> {
102-
spi_mux: &'static MuxSpiMaster<'static, S>,
114+
pub struct SpiMasterBusComponent<
115+
S: 'static + spi::SpiMaster<'static>,
116+
P: 'static + SelectionPolicy<&'static VirtualSpiMasterDevice<'static, S, P>>,
117+
> {
118+
spi_mux: &'static MuxSpiMaster<'static, S, P>,
103119
chip_select: S::ChipSelect,
104120
baud_rate: u32,
105121
clock_phase: ClockPhase,
106122
clock_polarity: ClockPolarity,
107123
}
108124

109-
impl<S: 'static + spi::SpiMaster<'static>> SpiMasterBusComponent<S> {
125+
impl<
126+
S: 'static + spi::SpiMaster<'static>,
127+
P: 'static + SelectionPolicy<&'static VirtualSpiMasterDevice<'static, S, P>>,
128+
> SpiMasterBusComponent<S, P>
129+
{
110130
pub fn new(
111-
spi_mux: &'static MuxSpiMaster<'static, S>,
131+
spi_mux: &'static MuxSpiMaster<'static, S, P>,
112132
chip_select: S::ChipSelect,
113133
baud_rate: u32,
114134
clock_phase: ClockPhase,
115135
clock_polarity: ClockPolarity,
116-
) -> SpiMasterBusComponent<S> {
136+
) -> SpiMasterBusComponent<S, P> {
117137
SpiMasterBusComponent {
118138
spi_mux,
119139
chip_select,
@@ -124,13 +144,17 @@ impl<S: 'static + spi::SpiMaster<'static>> SpiMasterBusComponent<S> {
124144
}
125145
}
126146

127-
impl<S: 'static + spi::SpiMaster<'static>> Component for SpiMasterBusComponent<S> {
147+
impl<
148+
S: 'static + spi::SpiMaster<'static>,
149+
P: 'static + SelectionPolicy<&'static VirtualSpiMasterDevice<'static, S, P>>,
150+
> Component for SpiMasterBusComponent<S, P>
151+
{
128152
type StaticInput = (
129-
&'static mut MaybeUninit<VirtualSpiMasterDevice<'static, S>>,
130-
&'static mut MaybeUninit<SpiMasterBus<'static, VirtualSpiMasterDevice<'static, S>>>,
153+
&'static mut MaybeUninit<VirtualSpiMasterDevice<'static, S, P>>,
154+
&'static mut MaybeUninit<SpiMasterBus<'static, VirtualSpiMasterDevice<'static, S, P>>>,
131155
&'static mut MaybeUninit<[u8; core::mem::size_of::<usize>()]>,
132156
);
133-
type Output = &'static SpiMasterBus<'static, VirtualSpiMasterDevice<'static, S>>;
157+
type Output = &'static SpiMasterBus<'static, VirtualSpiMasterDevice<'static, S, P>>;
134158

135159
fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
136160
let spi_device = static_buffer

capsules/core/src/virtualizers/virtual_adc.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ impl<'a, A: hil::adc::Adc<'a>, P: SelectionPolicy<&'a AdcDevice<'a, A, P>>> MuxA
5454
}
5555
}
5656

57+
pub fn new_with_policy(adc: &'a A, selection_policy: P) -> MuxAdc<'a, A, P> {
58+
MuxAdc {
59+
adc,
60+
devices: List::new(),
61+
inflight: OptionalCell::empty(),
62+
selection_policy,
63+
}
64+
}
65+
5766
fn do_next_op(&self) {
5867
if self.inflight.is_none() {
5968
let mnode = self

capsules/core/src/virtualizers/virtual_aes_ccm.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ impl<
167167
}
168168
}
169169

170+
pub fn new_with_policy(aes: &'a A, selection_policy: P) -> MuxAES128CCM<'a, A, P> {
171+
aes.enable(); // enable the hardware, in case it's forgotten elsewhere
172+
MuxAES128CCM {
173+
aes,
174+
client: OptionalCell::empty(),
175+
ccm_clients: List::new(),
176+
inflight: OptionalCell::empty(),
177+
deferred_call: DeferredCall::new(),
178+
selection_policy,
179+
}
180+
}
181+
170182
/// Asynchronously executes the next operation, if any. Used by calls
171183
/// to trigger do_next_op such that it will execute after the call
172184
/// returns.

capsules/core/src/virtualizers/virtual_flash.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ impl<'a, F: hil::flash::Flash, P: SelectionPolicy<&'a FlashUser<'a, F, P>>> MuxF
101101
}
102102
}
103103

104+
pub fn new_with_policy(flash: &'a F, selection_policy: P) -> MuxFlash<'a, F, P> {
105+
MuxFlash {
106+
flash,
107+
users: List::new(),
108+
inflight: OptionalCell::empty(),
109+
selection_policy,
110+
}
111+
}
112+
104113
/// Scan the list of users and find the first user that has a pending
105114
/// request, then issue that request to the flash hardware.
106115
fn do_next_op(&self) {

capsules/core/src/virtualizers/virtual_i2c.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ impl<
8383
}
8484
}
8585

86+
pub fn new_with_policy(
87+
i2c: &'a I,
88+
smbus: Option<&'a S>,
89+
i2c_selection_policy: PI,
90+
smbus_selection_policy: PS,
91+
) -> MuxI2C<'a, I, S, PI, PS> {
92+
MuxI2C {
93+
i2c,
94+
smbus,
95+
i2c_devices: List::new(),
96+
smbus_devices: List::new(),
97+
enabled: Cell::new(0),
98+
i2c_inflight: OptionalCell::empty(),
99+
smbus_inflight: OptionalCell::empty(),
100+
deferred_call: DeferredCall::new(),
101+
i2c_selection_policy,
102+
smbus_selection_policy,
103+
}
104+
}
105+
86106
fn enable(&self) {
87107
let enabled = self.enabled.get();
88108
self.enabled.set(enabled + 1);

capsules/core/src/virtualizers/virtual_pwm.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ impl<'a, P: hil::pwm::Pwm, SP: SelectionPolicy<&'a PwmPinUser<'a, P, SP>>> MuxPw
5050
}
5151
}
5252

53+
pub fn new_with_policy(pwm: &'a P, selection_policy: SP) -> MuxPwm<'a, P, SP> {
54+
MuxPwm {
55+
pwm,
56+
devices: List::new(),
57+
inflight: OptionalCell::empty(),
58+
selection_policy,
59+
}
60+
}
61+
5362
/// If we are not currently doing anything, scan the list of devices for
5463
/// one with an outstanding operation and run that.
5564
fn do_next_op(&self) {

capsules/core/src/virtualizers/virtual_rng.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ impl<'a, P: SelectionPolicy<&'a VirtualRngMasterDevice<'a, P>>> MuxRngMaster<'a,
4040
}
4141
}
4242

43+
pub fn new_with_policy(rng: &'a dyn Rng<'a>, selection_policy: P) -> MuxRngMaster<'a, P> {
44+
MuxRngMaster {
45+
rng,
46+
devices: List::new(),
47+
inflight: OptionalCell::empty(),
48+
selection_policy,
49+
}
50+
}
51+
4352
fn do_next_op(&self) -> Result<(), ErrorCode> {
4453
if self.inflight.is_none() {
4554
let mnode = self

capsules/core/src/virtualizers/virtual_spi.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ impl<
6868
deferred_call: DeferredCall::new(),
6969
}
7070
}
71+
pub fn new_with_policy(spi: &'a Spi, selection_policy: P) -> MuxSpiMaster<'a, Spi, P> {
72+
MuxSpiMaster {
73+
spi,
74+
devices: List::new(),
75+
inflight: OptionalCell::empty(),
76+
selection_policy,
77+
deferred_call: DeferredCall::new(),
78+
}
79+
}
7180

7281
fn do_next_op(&self) {
7382
if self.inflight.is_none() {

0 commit comments

Comments
 (0)