diff --git a/chips/nrf51/src/clock.rs b/chips/nrf51/src/clock.rs index 4ee9a7da13..5461bd5b62 100644 --- a/chips/nrf51/src/clock.rs +++ b/chips/nrf51/src/clock.rs @@ -11,7 +11,7 @@ //! * Philip Levis //! * Date: August 18, 2016 -use core::cell::Cell; +use kernel::common::cells::OptionalCell; use kernel::common::cells::VolatileCell; use kernel::common::StaticRef; @@ -98,19 +98,19 @@ pub trait ClockClient { /// Clock struct pub struct Clock { registers: StaticRef, - client: Cell>, + client: OptionalCell<&'static ClockClient>, } impl Clock { pub const fn new() -> Clock { Clock { registers: CLOCK_BASE, - client: Cell::new(None), + client: OptionalCell::empty(), } } pub fn set_client(&self, client: &'static ClockClient) { - self.client.set(Some(client)); + self.client.set(client); } pub fn interrupt_enable(&self, interrupt: InterruptField) { diff --git a/chips/nrf51/src/i2c.rs b/chips/nrf51/src/i2c.rs index 0798134161..0608a883a1 100644 --- a/chips/nrf51/src/i2c.rs +++ b/chips/nrf51/src/i2c.rs @@ -4,6 +4,7 @@ use core::cell::Cell; use core::cmp; +use kernel::common::cells::OptionalCell; use kernel::common::cells::TakeCell; use kernel::common::regs::{FieldValue, ReadOnly, ReadWrite, WriteOnly}; use kernel::common::StaticRef; @@ -16,7 +17,7 @@ use {nrf5x, nrf5x::gpio, nrf5x::pinmux::Pinmux}; /// additional data necessary to implement an asynchronous interface. pub struct TWIM { registers: StaticRef, - client: Cell>, + client: OptionalCell<&'static i2c::I2CHwMasterClient>, tx_len: Cell, rx_len: Cell, pos: Cell, @@ -27,7 +28,7 @@ impl TWIM { const fn new(instance: usize) -> TWIM { TWIM { registers: TWIM_BASE[instance], - client: Cell::new(None), + client: OptionalCell::empty(), tx_len: Cell::new(0), rx_len: Cell::new(0), pos: Cell::new(0), @@ -36,8 +37,8 @@ impl TWIM { } pub fn set_client(&self, client: &'static i2c::I2CHwMasterClient) { - debug_assert!(self.client.get().is_none()); - self.client.set(Some(client)); + debug_assert!(self.client.is_none()); + self.client.set(client); } /// Configures an already constructed `TWIM`. @@ -94,7 +95,7 @@ impl TWIM { } fn reply(&self, result: i2c::Error) { - self.client.get().map(|client| { + self.client.map(|client| { self.buf.take().map(|buf| { client.command_complete(buf, result); }); diff --git a/chips/nrf51/src/radio.rs b/chips/nrf51/src/radio.rs index 5556c69624..e2668725d8 100644 --- a/chips/nrf51/src/radio.rs +++ b/chips/nrf51/src/radio.rs @@ -13,6 +13,7 @@ use core::cell::Cell; use core::convert::TryFrom; use kernel; +use kernel::common::cells::OptionalCell; use kernel::common::cells::VolatileCell; use kernel::common::StaticRef; use kernel::hil::ble_advertising; @@ -117,8 +118,8 @@ const RADIO_BASE: StaticRef = pub struct Radio { registers: StaticRef, tx_power: Cell, - rx_client: Cell>, - tx_client: Cell>, + rx_client: OptionalCell<&'static ble_advertising::RxClient>, + tx_client: OptionalCell<&'static ble_advertising::TxClient>, } impl Radio { @@ -126,8 +127,8 @@ impl Radio { Radio { registers: RADIO_BASE, tx_power: Cell::new(TxPower::ZerodBm), - rx_client: Cell::new(None), - tx_client: Cell::new(None), + rx_client: OptionalCell::empty(), + tx_client: OptionalCell::empty(), } } @@ -296,9 +297,7 @@ impl Radio { | nrf5x::constants::RADIO_STATE_TXDISABLE | nrf5x::constants::RADIO_STATE_TX => { self.radio_off(); - self.tx_client - .get() - .map(|client| client.transmit_event(result)); + self.tx_client.map(|client| client.transmit_event(result)); } nrf5x::constants::RADIO_STATE_RXRU | nrf5x::constants::RADIO_STATE_RXIDLE @@ -306,7 +305,7 @@ impl Radio { | nrf5x::constants::RADIO_STATE_RX => { self.radio_off(); unsafe { - self.rx_client.get().map(|client| { + self.rx_client.map(|client| { // Length is: S0 (1 Byte) + Length (1 Byte) + S1 (0 Bytes) + Payload // And because the length field is directly read from the packet // We need to add 2 to length to get the total length @@ -369,11 +368,11 @@ impl ble_advertising::BleAdvertisementDriver for Radio { } fn set_receive_client(&self, client: &'static ble_advertising::RxClient) { - self.rx_client.set(Some(client)); + self.rx_client.set(client); } fn set_transmit_client(&self, client: &'static ble_advertising::TxClient) { - self.tx_client.set(Some(client)); + self.tx_client.set(client); } } diff --git a/chips/nrf51/src/uart.rs b/chips/nrf51/src/uart.rs index 0248d6f2cf..b77f92a19a 100644 --- a/chips/nrf51/src/uart.rs +++ b/chips/nrf51/src/uart.rs @@ -1,4 +1,5 @@ use core::cell::Cell; +use kernel::common::cells::OptionalCell; use kernel::common::cells::TakeCell; use kernel::common::regs::{ReadWrite, WriteOnly}; use kernel::common::StaticRef; @@ -149,7 +150,7 @@ const UART_BASE: StaticRef = pub struct UART { registers: StaticRef, - client: Cell>, + client: OptionalCell<&'static uart::Client>, buffer: TakeCell<'static, [u8]>, len: Cell, index: Cell, @@ -164,7 +165,7 @@ impl UART { pub const fn new() -> UART { UART { registers: UART_BASE, - client: Cell::new(None), + client: OptionalCell::empty(), buffer: TakeCell::empty(), len: Cell::new(0), index: Cell::new(0), @@ -244,7 +245,7 @@ impl UART { regs.task_stoptx.write(Task::ENABLE::SET); // Signal client write done - self.client.get().map(|client| { + self.client.map(|client| { self.buffer.take().map(|buffer| { client.transmit_complete(buffer, uart::Error::CommandComplete); }); @@ -287,7 +288,7 @@ impl UART { impl uart::UART for UART { fn set_client(&self, client: &'static uart::Client) { - self.client.set(Some(client)); + self.client.set(client); } fn init(&self, params: uart::UARTParams) {