diff options
author | 2018-01-11 14:28:51 +0000 | |
---|---|---|
committer | 2018-01-11 14:28:51 +0000 | |
commit | 6a5a789b60f88c50bb8712fd35dfcb3339018cb0 (patch) | |
tree | 166503af50042e80b3f044caac4be587689dc5da /src/peripheral/mod.rs | |
parent | bdc7ca96c5593e410c8f49025d2b0fced7607a4d (diff) | |
parent | ee21e7d66a2975aa358f9a69185defa9fa5e4e85 (diff) | |
download | cortex-m-6a5a789b60f88c50bb8712fd35dfcb3339018cb0.tar.gz cortex-m-6a5a789b60f88c50bb8712fd35dfcb3339018cb0.tar.zst cortex-m-6a5a789b60f88c50bb8712fd35dfcb3339018cb0.zip |
Auto merge of #73 - japaric:itm, r=japaric
make `Stim::write_*` methods take `&mut self` instead of `&self`
this prevents people from overlapping non-atomic write operations on the same stimulus port when
working with generators (cooperative tasks).
For example, with this change the following code won't compile
``` rust
let stim = &mut ITM.stim[0];
let a = || {
loop {
// ..
for byte in b"Hello, world!".iter() {
while !stim.is_fifo_ready() { yield }
stim.write_u8(*byte);
}
// ..
}
};
let b = || {
loop {
// ..
for byte in b"The quick brown fox jumps over the lazy dog".iter() {
while !stim.is_fifo_ready() { yield }
stim.write_u8(*byte);
}
// ..
}
};
```
A possible fix for the above code is to use different stimulus ports in each task (generator).
Diffstat (limited to 'src/peripheral/mod.rs')
-rw-r--r-- | src/peripheral/mod.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/peripheral/mod.rs b/src/peripheral/mod.rs index d462bdb..bd658a4 100644 --- a/src/peripheral/mod.rs +++ b/src/peripheral/mod.rs @@ -9,7 +9,7 @@ #![allow(private_no_mangle_statics)] use core::marker::PhantomData; -use core::ops::Deref; +use core::ops::{Deref, DerefMut}; use interrupt; @@ -262,8 +262,8 @@ pub struct ITM { impl ITM { /// Returns a pointer to the register block - pub fn ptr() -> *const itm::RegisterBlock { - 0xE000_0000 as *const _ + pub fn ptr() -> *mut itm::RegisterBlock { + 0xE000_0000 as *mut _ } } @@ -275,6 +275,12 @@ impl Deref for ITM { } } +impl DerefMut for ITM { + fn deref_mut(&mut self) -> &mut Self::Target { + unsafe { &mut *Self::ptr() } + } +} + /// Memory Protection Unit pub struct MPU { _marker: PhantomData<*const ()>, |