Skip to content

Commit e666c0b

Browse files
author
Jorge Aparicio
committed
make ITM functions operate on Stim
push synchronization duties to the caller
1 parent 6db72a5 commit e666c0b

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

src/exception.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use ctxt::Context;
44
use Reserved;
55

6-
/// Kind of exception
6+
/// Enumeration of all exceptions
77
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
88
pub enum Exception {
99
/// i.e. currently not servicing an exception

src/interrupt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub unsafe trait Nr {
3434

3535
unsafe impl<T> Sync for Mutex<T> {}
3636

37-
/// Disable interrupts, globally
37+
/// Disables all interrupts
3838
#[inline(always)]
3939
pub fn disable() {
4040
match () {
@@ -51,7 +51,7 @@ pub fn disable() {
5151
}
5252
}
5353

54-
/// Enable interrupts, globally
54+
/// Enables all the interrupts
5555
#[inline(always)]
5656
pub fn enable() {
5757
match () {

src/itm.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,39 +43,35 @@ unsafe fn write_words(stim: &Stim, bytes: &[u32]) {
4343
}
4444
}
4545

46-
struct Itm {
47-
port: u8,
48-
}
46+
struct Port<'p>(&'p Stim);
4947

50-
impl fmt::Write for Itm {
48+
impl<'p> fmt::Write for Port<'p> {
5149
fn write_str(&mut self, s: &str) -> fmt::Result {
52-
write_all(self.port, s.as_bytes());
50+
write_all(self.0, s.as_bytes());
5351
Ok(())
5452
}
5553
}
5654

5755
/// Writes a `buffer` to the ITM `port`
58-
pub fn write_all(port: u8, buffer: &[u8]) {
59-
let stim = unsafe { &(*::peripheral::ITM.get()).stim[port as usize] };
60-
56+
pub fn write_all(port: &Stim, buffer: &[u8]) {
6157
if buffer.len() < 7 {
62-
write_bytes(stim, buffer);
58+
write_bytes(port, buffer);
6359
} else {
6460
let (head, body, tail) = unsafe { split(buffer) };
65-
write_bytes(stim, head);
66-
unsafe { write_words(stim, body) }
67-
write_bytes(stim, tail);
61+
write_bytes(port, head);
62+
unsafe { write_words(port, body) }
63+
write_bytes(port, tail);
6864
}
6965
}
7066

7167
/// Writes `fmt::Arguments` to the ITM `port`
72-
pub fn write_fmt(port: u8, args: fmt::Arguments) {
68+
pub fn write_fmt(port: &Stim, args: fmt::Arguments) {
7369
use core::fmt::Write;
7470

75-
Itm { port }.write_fmt(args).ok();
71+
Port(port).write_fmt(args).ok();
7672
}
7773

7874
/// Writes a string to the ITM `port`
79-
pub fn write_str(port: u8, string: &str) {
75+
pub fn write_str(port: &Stim, string: &str) {
8076
write_all(port, string.as_bytes())
8177
}

0 commit comments

Comments
 (0)