Replace regular memory read/writes with volatile memory read/writes
Fixes #21.
This commit is contained in:
parent
c7dfee4617
commit
3868326bca
|
@ -31,14 +31,14 @@ pub trait Register : Sized {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn write<V>(value: V) where V: Into<Self::T> {
|
fn write<V>(value: V) where V: Into<Self::T> {
|
||||||
unsafe {
|
unsafe {
|
||||||
*Self::ADDRESS = value.into();
|
core::ptr::write_volatile(Self::ADDRESS, value.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads the value of the register.
|
/// Reads the value of the register.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn read() -> Self::T {
|
fn read() -> Self::T {
|
||||||
unsafe { *Self::ADDRESS }
|
unsafe { core::ptr::read_volatile(Self::ADDRESS) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets a set of bits to `1` in the register.
|
/// Sets a set of bits to `1` in the register.
|
||||||
|
@ -69,7 +69,7 @@ pub trait Register : Sized {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn unset_mask_raw(mask: Self::T) {
|
fn unset_mask_raw(mask: Self::T) {
|
||||||
unsafe {
|
unsafe {
|
||||||
*Self::ADDRESS &= !mask;
|
core::ptr::write_volatile(Self::ADDRESS, core::ptr::read_volatile(Self::ADDRESS) & !mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ pub trait Register : Sized {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn toggle_raw(mask: Self::T) {
|
fn toggle_raw(mask: Self::T) {
|
||||||
unsafe {
|
unsafe {
|
||||||
*Self::ADDRESS ^= mask;
|
core::ptr::write_volatile(Self::ADDRESS, core::ptr::read_volatile(Self::ADDRESS) ^ mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ pub trait Register : Sized {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn is_mask_set_raw(mask: Self::T) -> bool {
|
fn is_mask_set_raw(mask: Self::T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*Self::ADDRESS & mask) == mask
|
(core::ptr::read_volatile(Self::ADDRESS) & mask) == mask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ pub trait Register : Sized {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn is_clear_raw(mask: Self::T) -> bool {
|
fn is_clear_raw(mask: Self::T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*Self::ADDRESS & mask) == Self::T::from(0)
|
(core::ptr::read_volatile(Self::ADDRESS) & mask) == Self::T::from(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue