Skip to content

Commit 61ee6ed

Browse files
committed
itm: bitfield LSR; add has_software_lock, locked; amend docs
Related to rust-embedded#392.
1 parent 570ce0a commit 61ee6ed

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

Diff for: CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
Also fixes `VectActive::from` to take a `u16` and subtract `16` for
1313
`VectActive::Interrupt`s to match `SBC::vect_active()` (#373).
1414
- DWT: add `configure` API for address, cycle count comparison (#342, #367).
15-
- ITM: add `configure` API; `lock`, `unlock`, and `busy` functions (#342, #383).
15+
- ITM: add `configure` API; `lock`, `unlock`, `busy`, `locked` functions (#342, #383).
1616
- TPIU: add API for *Formatter and Flush Control* (FFCR) and *Selected Pin Control* (SPPR) registers (#342).
1717
- Add `std` and `serde` crate features for improved host-side ITM decode functionality when working with the downstream `itm`, `cargo-rtic-scope` crates (#363, #366).
1818

Diff for: src/peripheral/itm.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct RegisterBlock {
3434
/// Lock Access
3535
pub lar: WO<u32>,
3636
/// Lock Status
37-
pub lsr: RO<u32>,
37+
pub lsr: RO<Lsr>,
3838
}
3939

4040
bitfield! {
@@ -53,6 +53,15 @@ bitfield! {
5353
busy, _: 23;
5454
}
5555

56+
bitfield! {
57+
/// Software Lock Status Register
58+
#[repr(C)]
59+
#[derive(Copy, Clone)]
60+
pub struct Lsr(u32);
61+
sli, _: 0;
62+
slk, _: 1;
63+
}
64+
5665
/// Stimulus Port
5766
pub struct Stim {
5867
register: UnsafeCell<u32>,
@@ -200,7 +209,9 @@ pub enum ITMConfigurationError {
200209
}
201210

202211
impl ITM {
203-
/// Removes the software lock on the [`ITM`]. Must be called before any other [`ITM`] functions.
212+
/// Removes the software lock on the [`ITM`]. Must be called before
213+
/// any mutating [`ITM`] functions if a software lock mechanism is
214+
/// implemented. See [`has_software_lock`].
204215
///
205216
/// See (coresight, B2.3.10).
206217
#[inline]
@@ -209,7 +220,7 @@ impl ITM {
209220
unsafe { self.lar.write(0xC5AC_CE55) }
210221
}
211222

212-
/// Adds the software lock on the [`ITM`]. Should be called after any other [`ITM`] functions.
223+
/// Adds the software lock on the [`ITM`]. Should be called after any other mutating [`ITM`] functions.
213224
///
214225
/// See (coresight, B2.3.10).
215226
#[inline]
@@ -218,6 +229,24 @@ impl ITM {
218229
unsafe { self.lar.write(0) }
219230
}
220231

232+
/// Checks whether the target implements the software lock
233+
/// mechanism. If `true`, [`unlock`] must be called before any other
234+
/// mutating [`ITM`] functions.
235+
///
236+
/// See (coresight, B2.3.10).
237+
#[inline]
238+
pub fn has_software_lock(&self) -> bool {
239+
self.lsr.read().sli()
240+
}
241+
242+
/// Checks whether the peripheral is locked.
243+
///
244+
/// See (coresight, B2.3.10).
245+
#[inline]
246+
pub fn locked(&self) -> bool {
247+
self.lsr.read().slk()
248+
}
249+
221250
/// Indicates whether the [`ITM`] is currently processing events.
222251
/// Returns `true` if [`ITM`] events are present and are being drained.
223252
#[inline]

0 commit comments

Comments
 (0)