|
1 | 1 | mod atomic {
|
| 2 | + use super::*; |
2 | 3 | use portable_atomic::Ordering;
|
3 | 4 |
|
4 | 5 | pub trait AtomicOperations {
|
@@ -35,67 +36,66 @@ mod atomic {
|
35 | 36 | // Enable 64-bit atomics for 64-bit RISCV
|
36 | 37 | #[cfg(any(target_pointer_width = "64", target_has_atomic = "64"))]
|
37 | 38 | impl_atomics!(u64, portable_atomic::AtomicU64);
|
38 |
| -} |
39 |
| -use atomic::AtomicOperations; |
40 | 39 |
|
41 |
| -impl<REG: Readable + Writable> Reg<REG> |
42 |
| -where |
43 |
| - REG::Ux: AtomicOperations + Default + core::ops::Not<Output = REG::Ux>, |
44 |
| -{ |
45 |
| - /// Set high every bit in the register that was set in the write proxy. Leave other bits |
46 |
| - /// untouched. The write is done in a single atomic instruction. |
47 |
| - /// |
48 |
| - /// # Safety |
49 |
| - /// |
50 |
| - /// The resultant bit pattern may not be valid for the register. |
51 |
| - #[inline(always)] |
52 |
| - pub unsafe fn set_bits<F>(&self, f: F) |
| 40 | + impl<REG: Readable + Writable> Reg<REG> |
53 | 41 | where
|
54 |
| - F: FnOnce(&mut REG::Writer) -> &mut W<REG>, |
| 42 | + REG::Ux: AtomicOperations + Default + core::ops::Not<Output = REG::Ux>, |
55 | 43 | {
|
56 |
| - let bits = f(&mut REG::Writer::from(W { |
57 |
| - bits: Default::default(), |
58 |
| - _reg: marker::PhantomData, |
59 |
| - })) |
60 |
| - .bits; |
61 |
| - REG::Ux::atomic_or(self.register.as_ptr(), bits); |
62 |
| - } |
| 44 | + /// Set high every bit in the register that was set in the write proxy. Leave other bits |
| 45 | + /// untouched. The write is done in a single atomic instruction. |
| 46 | + /// |
| 47 | + /// # Safety |
| 48 | + /// |
| 49 | + /// The resultant bit pattern may not be valid for the register. |
| 50 | + #[inline(always)] |
| 51 | + pub unsafe fn set_bits<F>(&self, f: F) |
| 52 | + where |
| 53 | + F: FnOnce(&mut REG::Writer) -> &mut W<REG>, |
| 54 | + { |
| 55 | + let bits = f(&mut REG::Writer::from(W { |
| 56 | + bits: Default::default(), |
| 57 | + _reg: marker::PhantomData, |
| 58 | + })) |
| 59 | + .bits; |
| 60 | + REG::Ux::atomic_or(self.register.as_ptr(), bits); |
| 61 | + } |
63 | 62 |
|
64 |
| - /// Clear every bit in the register that was cleared in the write proxy. Leave other bits |
65 |
| - /// untouched. The write is done in a single atomic instruction. |
66 |
| - /// |
67 |
| - /// # Safety |
68 |
| - /// |
69 |
| - /// The resultant bit pattern may not be valid for the register. |
70 |
| - #[inline(always)] |
71 |
| - pub unsafe fn clear_bits<F>(&self, f: F) |
72 |
| - where |
73 |
| - F: FnOnce(&mut REG::Writer) -> &mut W<REG>, |
74 |
| - { |
75 |
| - let bits = f(&mut REG::Writer::from(W { |
76 |
| - bits: !REG::Ux::default(), |
77 |
| - _reg: marker::PhantomData, |
78 |
| - })) |
79 |
| - .bits; |
80 |
| - REG::Ux::atomic_and(self.register.as_ptr(), bits); |
81 |
| - } |
| 63 | + /// Clear every bit in the register that was cleared in the write proxy. Leave other bits |
| 64 | + /// untouched. The write is done in a single atomic instruction. |
| 65 | + /// |
| 66 | + /// # Safety |
| 67 | + /// |
| 68 | + /// The resultant bit pattern may not be valid for the register. |
| 69 | + #[inline(always)] |
| 70 | + pub unsafe fn clear_bits<F>(&self, f: F) |
| 71 | + where |
| 72 | + F: FnOnce(&mut REG::Writer) -> &mut W<REG>, |
| 73 | + { |
| 74 | + let bits = f(&mut REG::Writer::from(W { |
| 75 | + bits: !REG::Ux::default(), |
| 76 | + _reg: marker::PhantomData, |
| 77 | + })) |
| 78 | + .bits; |
| 79 | + REG::Ux::atomic_and(self.register.as_ptr(), bits); |
| 80 | + } |
82 | 81 |
|
83 |
| - /// Toggle every bit in the register that was set in the write proxy. Leave other bits |
84 |
| - /// untouched. The write is done in a single atomic instruction. |
85 |
| - /// |
86 |
| - /// # Safety |
87 |
| - /// |
88 |
| - /// The resultant bit pattern may not be valid for the register. |
89 |
| - #[inline(always)] |
90 |
| - pub unsafe fn toggle_bits<F>(&self, f: F) |
91 |
| - where |
92 |
| - F: FnOnce(&mut REG::Writer) -> &mut W<REG>, |
93 |
| - { |
94 |
| - let bits = f(&mut REG::Writer::from(W { |
95 |
| - bits: Default::default(), |
96 |
| - _reg: marker::PhantomData, |
97 |
| - })) |
98 |
| - .bits; |
99 |
| - REG::Ux::atomic_xor(self.register.as_ptr(), bits); |
| 82 | + /// Toggle every bit in the register that was set in the write proxy. Leave other bits |
| 83 | + /// untouched. The write is done in a single atomic instruction. |
| 84 | + /// |
| 85 | + /// # Safety |
| 86 | + /// |
| 87 | + /// The resultant bit pattern may not be valid for the register. |
| 88 | + #[inline(always)] |
| 89 | + pub unsafe fn toggle_bits<F>(&self, f: F) |
| 90 | + where |
| 91 | + F: FnOnce(&mut REG::Writer) -> &mut W<REG>, |
| 92 | + { |
| 93 | + let bits = f(&mut REG::Writer::from(W { |
| 94 | + bits: Default::default(), |
| 95 | + _reg: marker::PhantomData, |
| 96 | + })) |
| 97 | + .bits; |
| 98 | + REG::Ux::atomic_xor(self.register.as_ptr(), bits); |
| 99 | + } |
100 | 100 | }
|
101 | 101 | }
|
0 commit comments