Skip to content

Commit 8065e5e

Browse files
committed
Some adjustments for utick and sleep
1 parent 96b8796 commit 8065e5e

File tree

8 files changed

+66
-69
lines changed

8 files changed

+66
-69
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ view-rtfm-expansion:
66
rustfmt target/rtfm-expansion.rs
77
vi target/rtfm-expansion.rs
88

9+
# turn off the LEDs and whatnot
10+
darkness:
11+
gdb-multiarch -q -x darkness.gdb > /dev/null 2> /dev/null
12+
913
#
1014
# External documentation
1115
#

darkness.gdb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# source .gdb-dashboard
2+
3+
set history save on
4+
set confirm off
5+
6+
target extended-remote :2331
7+
monitor reset
8+
quit

examples/aes.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use cortex_m_semihosting::dbg;
1919

2020
#[entry]
2121
fn main() -> ! {
22-
// let _dp = hal::raw::Peripherals::take().unwrap();
23-
2422
// AES-xxx variants have key sizes of xxx bits
2523
let key = GenericArray::from_slice(&[0u8; 32]);
2624
// AES always has block size of 128 bits
@@ -36,10 +34,10 @@ fn main() -> ! {
3634
cipher.encrypt_block(&mut block);
3735
let after = hal::get_cycle_count();
3836
dbg!("encrypting took {} cycles", after - before);
39-
// dbg!(block);
37+
dbg!(block);
4038
// And decrypt it back
4139
cipher.decrypt_block(&mut block);
42-
// dbg!(block);
40+
dbg!(block);
4341
assert_eq!(block, block_copy);
4442

4543
// // We can encrypt 8 blocks simultaneously using

examples/baby_usb.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
///
5+
/// Compare also with: https://github.com/Ko-/aes-armcortexm
6+
///
7+
extern crate panic_halt;
8+
use cortex_m::asm;
9+
use cortex_m_rt::entry;
10+
use cortex_m_semihosting::dbg;
11+
12+
use hal::prelude::*;
13+
#[allow(unused_imports)]
14+
use lpc55s6x_hal as hal;
15+
16+
17+
#[entry]
18+
fn main() -> ! {
19+
let mut dp = hal::raw::Peripherals::take().unwrap();
20+
let mut syscon = hal::syscon::wrap(dp.SYSCON);
21+
22+
syscon.enable_clock(&mut dp.USB0);
23+
24+
// returns 0x0, 0x0 if clock is not enabled...
25+
// UM says: (5, 1) <-- probly swapped
26+
// We get: (1, 6)
27+
dbg!(dp.USB0.info.read().majrev().bits());
28+
dbg!(dp.USB0.info.read().minrev().bits());
29+
dbg!(dp.USB0.info.read().frame_nr().bits());
30+
dbg!(dp.USB0.info.read().err_code().bits());
31+
32+
loop {
33+
asm::wfi();
34+
}
35+
}

examples/led.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn main() -> ! {
4343
clock: &clock,
4444
}; // 500 ms = 0.5 s
4545

46-
let mut sleep = hal::sleep::Busy::prepare(&mut utick);
46+
let mut sleep = hal::sleep::Busy::wrap(&mut utick);
4747

4848
loop {
4949
sleep.sleep(delay);

examples/led_utick.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
// extern crate panic_semihosting; // 4004 bytes
55
extern crate panic_halt; // 672 bytes
66

7-
use cortex_m::asm;
7+
// use cortex_m::asm;
88
use cortex_m_rt::entry;
9+
// use nb::block;
910

1011
use hal::{gpio::Level, prelude::*};
1112
use lpc55s6x_hal as hal;
@@ -45,23 +46,18 @@ fn main() -> ! {
4546
loop {
4647
red.set_low().unwrap();
4748
utick.start(1_000_000u32);
48-
while let Err(nb::Error::WouldBlock) = utick.wait() {
49-
asm::nop();
50-
}
49+
// block!(utick.wait()).unwrap();
50+
utick.blocking_wait();
5151
red.set_high().unwrap();
5252

5353
green.set_low().unwrap();
5454
utick.start(1_000_000u32);
55-
while let Err(nb::Error::WouldBlock) = utick.wait() {
56-
asm::nop();
57-
}
55+
utick.blocking_wait();
5856
green.set_high().unwrap();
5957

6058
blue.set_low().unwrap();
6159
utick.start(1_000_000u32);
62-
while let Err(nb::Error::WouldBlock) = utick.wait() {
63-
asm::nop();
64-
}
60+
utick.blocking_wait();
6561
blue.set_high().unwrap();
6662
}
6763
}

src/sleep.rs

+2-29
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,7 @@ where
4343
/// Provides a [`Sleep`] implementation based on busy waiting and uses the [UTICK]
4444
/// to measure the time. An interrupt handler is not required.
4545
///
46-
/// Only clocks that the UTICK supports can be used. See [`utick::Clock`] for more
47-
/// details.
48-
///
49-
/// Since this sleep mode waits busily, which is very energy-inefficient, it is
50-
/// only suitable for simple examples, or very short wait times.
51-
///
52-
/// # Examples
53-
///
54-
/// ``` no_run
55-
/// use lpc82x_hal::prelude::*;
56-
/// use lpc82x_hal::{
57-
/// sleep,
58-
/// Peripherals,
59-
/// };
60-
/// use lpc82x_hal::clock::Ticks;
61-
///
62-
/// let mut p = Peripherals::take().unwrap();
63-
///
64-
/// let mut syscon = p.SYSCON.split();
65-
/// let mut utick = p.UTICK.enable(&mut syscon.handle);
66-
///
67-
/// let clock = syscon.irc_derived_clock;
68-
///
69-
/// let mut sleep = sleep::Busy::prepare(&mut utick);
70-
///
71-
/// let delay = Ticks { value: 750_000, clock: &clock }; // 1000 ms
72-
/// sleep.sleep(delay);
73-
/// ```
46+
/// Examples: led_utick.rs
7447
pub struct Busy<'utick, 'fro1mhz> {
7548
utick: &'utick mut EnabledUtick<'fro1mhz>,
7649
}
@@ -84,7 +57,7 @@ impl<'utick, 'fro1mhz> Busy<'utick, 'fro1mhz> {
8457
/// Requires a mutable reference to [`UTICK`]. The reference will be borrowed
8558
/// for as long as the `sleep::Busy` instance exists, as it will be needed
8659
/// to count down the time in every call to [`Sleep::sleep`].
87-
pub fn prepare(utick: &'utick mut EnabledUtick<'fro1mhz>) -> Self {
60+
pub fn wrap(utick: &'utick mut EnabledUtick<'fro1mhz>) -> Self {
8861
Busy { utick }
8962
}
9063
}

src/utick.rs

+8-25
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,7 @@
55
//! The UTICK peripheral is described in the user manual, chapter 26.
66
//! It is driven by the FRO 1Mhz clock and has a microsecond resolution.
77
//!
8-
//! # Examples
9-
//!
10-
//! ``` no_run
11-
//! extern crate lpc55S6x_hal;
12-
//! extern crate nb;
13-
//!
14-
//! use lpc55S6x_hal::prelude::*;
15-
//! use lpc55S6x_hal::Peripherals;
16-
//!
17-
//! let mut p = Peripherals::take().unwrap();
18-
//!
19-
//! let mut syscon = p.SYSCON.split();
20-
//! let mut timer = p.UTICK.enable(&mut syscon.handle);
21-
//!
22-
//! // Start the timer at 1_000_000. Sine the UTICK tuner 1 MHz,
23-
//! // this translates to a one second wait.
24-
//! timer.start(1_000_000u32);
25-
//!
26-
//! while let Err(nb::Error::WouldBlock) = timer.wait() {
27-
//! // do stuff
28-
//! }
29-
//! ```
30-
//!
31-
//! Please refer to the [examples in the repository] for more example code.
8+
//! # Examples: led.rs, led_utick.rs
329
3310
use embedded_hal::timer;
3411
use nb;
@@ -162,11 +139,17 @@ impl timer::CountDown for EnabledUtick<'_> {
162139
}
163140
}
164141

142+
impl EnabledUtick<'_> {
143+
pub fn blocking_wait(&mut self) {
144+
while self.raw.stat.read().active().bit_is_set() {}
145+
}
146+
}
147+
165148
/// A clock that is usable by the micro-tick timer (UTICK)
166149
///
167150
/// This trait is implemented for all clocks that are supported by the UTICK,
168151
/// which is just FRO1MHZ.
169152
/// The user shouldn't need to implement this trait themselves.
170153
pub trait Clock {}
171154

172-
impl<State> Clock for Fro1MhzUtickClock<State> {}
155+
impl Clock for Fro1MhzUtickClock<init_state::Enabled> {}

0 commit comments

Comments
 (0)