diff options
author | 2017-03-11 19:47:57 -0500 | |
---|---|---|
committer | 2017-03-11 19:47:57 -0500 | |
commit | e666c0b79eb520e16c75bef4cfc085c1dfe72b06 (patch) | |
tree | 7e95c28e539793dbd4cf8f1385ad8f2f0b823c0a /src | |
parent | 6db72a50f302f6bd3974488a9d681dac26cd72c2 (diff) | |
download | cortex-m-e666c0b79eb520e16c75bef4cfc085c1dfe72b06.tar.gz cortex-m-e666c0b79eb520e16c75bef4cfc085c1dfe72b06.tar.zst cortex-m-e666c0b79eb520e16c75bef4cfc085c1dfe72b06.zip |
make ITM functions operate on `Stim`
push synchronization duties to the caller
Diffstat (limited to 'src')
-rw-r--r-- | src/exception.rs | 2 | ||||
-rw-r--r-- | src/interrupt.rs | 4 | ||||
-rw-r--r-- | src/itm.rs | 26 |
3 files changed, 14 insertions, 18 deletions
diff --git a/src/exception.rs b/src/exception.rs index 2c4b1be..451332e 100644 --- a/src/exception.rs +++ b/src/exception.rs @@ -3,7 +3,7 @@ use ctxt::Context; use Reserved; -/// Kind of exception +/// Enumeration of all exceptions #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Exception { /// i.e. currently not servicing an exception diff --git a/src/interrupt.rs b/src/interrupt.rs index 2aff77e..6c84301 100644 --- a/src/interrupt.rs +++ b/src/interrupt.rs @@ -34,7 +34,7 @@ pub unsafe trait Nr { unsafe impl<T> Sync for Mutex<T> {} -/// Disable interrupts, globally +/// Disables all interrupts #[inline(always)] pub fn disable() { match () { @@ -51,7 +51,7 @@ pub fn disable() { } } -/// Enable interrupts, globally +/// Enables all the interrupts #[inline(always)] pub fn enable() { match () { @@ -43,39 +43,35 @@ unsafe fn write_words(stim: &Stim, bytes: &[u32]) { } } -struct Itm { - port: u8, -} +struct Port<'p>(&'p Stim); -impl fmt::Write for Itm { +impl<'p> fmt::Write for Port<'p> { fn write_str(&mut self, s: &str) -> fmt::Result { - write_all(self.port, s.as_bytes()); + write_all(self.0, s.as_bytes()); Ok(()) } } /// Writes a `buffer` to the ITM `port` -pub fn write_all(port: u8, buffer: &[u8]) { - let stim = unsafe { &(*::peripheral::ITM.get()).stim[port as usize] }; - +pub fn write_all(port: &Stim, buffer: &[u8]) { if buffer.len() < 7 { - write_bytes(stim, buffer); + write_bytes(port, buffer); } else { let (head, body, tail) = unsafe { split(buffer) }; - write_bytes(stim, head); - unsafe { write_words(stim, body) } - write_bytes(stim, tail); + write_bytes(port, head); + unsafe { write_words(port, body) } + write_bytes(port, tail); } } /// Writes `fmt::Arguments` to the ITM `port` -pub fn write_fmt(port: u8, args: fmt::Arguments) { +pub fn write_fmt(port: &Stim, args: fmt::Arguments) { use core::fmt::Write; - Itm { port }.write_fmt(args).ok(); + Port(port).write_fmt(args).ok(); } /// Writes a string to the ITM `port` -pub fn write_str(port: u8, string: &str) { +pub fn write_str(port: &Stim, string: &str) { write_all(port, string.as_bytes()) } |