Skip to content

Commit b35fad8

Browse files
authored
Merge pull request tock#4824 from tock/dev/lpc55s69-uart-no-optionalcell
lpc55s6x: use static refs, not optionalcells
2 parents afebaaf + 48b7e39 commit b35fad8

4 files changed

Lines changed: 36 additions & 33 deletions

File tree

boards/lpc55s69-evk/src/io.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ impl IoWrite for Writer {
111111
fn write(&mut self, buf: &[u8]) -> usize {
112112
self.uart.map_or_else(
113113
|| {
114-
let uart = Uart::new_uart0();
114+
let clocks = lpc55s6x::clocks::Clock::new();
115+
let flexcomm = lpc55s6x::flexcomm::Flexcomm::new(0);
116+
117+
let uart = Uart::new_uart0(&clocks, &flexcomm);
115118
self.configure_uart(&uart);
116119
self.write_to_uart(&uart, buf);
117120
},

boards/lpc55s69-evk/src/main.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ fn system_init() {
3434
clocks.start_timer_clocks();
3535
}
3636

37-
unsafe fn get_peripherals() -> &'static mut Lpc55s69DefaultPeripheral<'static> {
38-
static_init!(Lpc55s69DefaultPeripheral, Lpc55s69DefaultPeripheral::new())
37+
unsafe fn get_peripherals(
38+
clocks: &'static Clock,
39+
flexcomm: &'static flexcomm::Flexcomm,
40+
) -> &'static Lpc55s69DefaultPeripheral<'static> {
41+
static_init!(
42+
Lpc55s69DefaultPeripheral,
43+
Lpc55s69DefaultPeripheral::new(clocks, flexcomm)
44+
)
3945
}
4046

4147
const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
@@ -134,7 +140,9 @@ unsafe fn start() -> (
134140

135141
system_init();
136142

137-
let peripherals = get_peripherals();
143+
let clock = static_init!(clocks::Clock, clocks::Clock::new());
144+
let flexcomm0 = static_init!(flexcomm::Flexcomm, flexcomm::Flexcomm::new_id(0).unwrap());
145+
let peripherals = get_peripherals(clock, flexcomm0);
138146

139147
peripherals.pins.init();
140148

@@ -282,16 +290,11 @@ unsafe fn start() -> (
282290

283291
peripherals.pins.pint.configure_interrupt(0, Edge::Rising);
284292

285-
let clock = static_init!(clocks::Clock, clocks::Clock::new());
286-
let flexcomm0 = static_init!(flexcomm::Flexcomm, flexcomm::Flexcomm::new_id(0).unwrap());
287-
288293
clock.setup_uart_clock(FrgId::Frg0, FrgClockSource::Fro96Mhz);
289294

290295
let uart = &peripherals.uart;
291296

292297
uart.set_clock_source(FrgClockSource::Fro96Mhz);
293-
uart.set_clocks(clock);
294-
uart.set_flexcomm(flexcomm0);
295298

296299
peripherals.pins.iocon.configure_pin(
297300
LPCPin::P0_29,

chips/lpc55s6x/src/chip.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use cortexm33::{CortexM33, CortexMVariant};
1010
use kernel::platform::chip::Chip;
1111
use kernel::platform::chip::InterruptService;
1212

13+
use crate::clocks::Clock;
1314
use crate::ctimer0::LPCTimer;
15+
use crate::flexcomm::Flexcomm;
1416
use crate::gpio::Pins;
1517
use crate::interrupts;
1618
use crate::uart::Uart;
@@ -93,11 +95,11 @@ pub struct Lpc55s69DefaultPeripheral<'a> {
9395
}
9496

9597
impl Lpc55s69DefaultPeripheral<'_> {
96-
pub fn new() -> Self {
98+
pub fn new(clocks: &'static Clock, flexcomm: &'static Flexcomm) -> Self {
9799
Self {
98100
pins: Pins::new(),
99101
ctimer0: LPCTimer::new(),
100-
uart: Uart::new_uart0(),
102+
uart: Uart::new_uart0(clocks, flexcomm),
101103
}
102104
}
103105
}

chips/lpc55s6x/src/uart.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ const USART4_BASE: StaticRef<UsartRegisters> =
562562
pub struct Uart<'a> {
563563
registers: StaticRef<UsartRegisters>,
564564
instance: u8,
565-
clocks: OptionalCell<&'a Clock>,
566-
flexcomm: OptionalCell<&'a Flexcomm>,
565+
clocks: &'a Clock,
566+
flexcomm: &'a Flexcomm,
567567

568568
uart_clock_source: Cell<FrgClockSource>,
569569

@@ -582,12 +582,17 @@ pub struct Uart<'a> {
582582
}
583583

584584
impl<'a> Uart<'a> {
585-
pub fn new(registers: StaticRef<UsartRegisters>, instance: u8) -> Self {
585+
pub fn new(
586+
registers: StaticRef<UsartRegisters>,
587+
instance: u8,
588+
clocks: &'a Clock,
589+
flexcomm: &'a Flexcomm,
590+
) -> Self {
586591
Self {
587592
registers,
588593
instance,
589-
clocks: OptionalCell::empty(),
590-
flexcomm: OptionalCell::empty(),
594+
clocks,
595+
flexcomm,
591596

592597
uart_clock_source: Cell::new(FrgClockSource::Fro12Mhz),
593598

@@ -605,20 +610,12 @@ impl<'a> Uart<'a> {
605610
rx_status: Cell::new(UARTStateRX::Idle),
606611
}
607612
}
608-
pub fn new_uart0() -> Self {
609-
Self::new(USART0_BASE, 0)
613+
pub fn new_uart0(clocks: &'a Clock, flexcomm: &'a Flexcomm) -> Self {
614+
Self::new(USART0_BASE, 0, clocks, flexcomm)
610615
}
611616

612-
pub fn new_uart4() -> Self {
613-
Self::new(USART4_BASE, 4)
614-
}
615-
616-
pub fn set_clocks(&self, clocks: &'a Clock) {
617-
self.clocks.set(clocks);
618-
}
619-
620-
pub fn set_flexcomm(&self, flexcomm: &'a Flexcomm) {
621-
self.flexcomm.set(flexcomm);
617+
pub fn new_uart4(clocks: &'a Clock, flexcomm: &'a Flexcomm) -> Self {
618+
Self::new(USART4_BASE, 4, clocks, flexcomm)
622619
}
623620

624621
pub fn set_clock_source(&self, source: FrgClockSource) {
@@ -836,17 +833,15 @@ impl<'a> Uart<'a> {
836833

837834
impl Configure for Uart<'_> {
838835
fn configure(&self, params: Parameters) -> Result<(), ErrorCode> {
839-
let clocks = self.clocks.get().ok_or(ErrorCode::OFF)?;
840-
let flexcomm = self.flexcomm.get().ok_or(ErrorCode::OFF)?;
841836
let clock_source = self.uart_clock_source.get();
842837
let frg_id = FrgId::from_u32(self.instance.into()).ok_or(ErrorCode::INVAL)?;
843-
clocks.setup_uart_clock(frg_id, clock_source);
844-
flexcomm.configure_for_uart();
838+
self.clocks.setup_uart_clock(frg_id, clock_source);
839+
self.flexcomm.configure_for_uart();
845840

846841
// --- Disable USART before configuration ---
847842
self.registers.cfg.modify(CFG::ENABLE::CLEAR);
848843

849-
let clk = clocks.get_frg_clock_frequency(clock_source);
844+
let clk = self.clocks.get_frg_clock_frequency(clock_source);
850845
let brg_val = (clk / (16 * params.baud_rate)).saturating_sub(1);
851846
if brg_val > 0xFFFF {
852847
return Err(ErrorCode::INVAL); // Baud rate not possible

0 commit comments

Comments
 (0)