|
54 | 54 | //! - Shane Leonard <shanel@stanford.edu>
|
55 | 55 |
|
56 | 56 | use core::cell::UnsafeCell;
|
57 |
| -use core::fmt; |
58 | 57 | use core::marker::PhantomData;
|
59 | 58 |
|
60 |
| -use crate::fields::{Field, FieldValue, TryFromValue}; |
61 | 59 | use crate::interfaces::{Readable, Writeable};
|
62 | 60 | use crate::{IntLike, RegisterLongName};
|
63 | 61 |
|
@@ -219,122 +217,6 @@ impl<T: IntLike, R: RegisterLongName> Writeable for InMemoryRegister<T, R> {
|
219 | 217 | }
|
220 | 218 | }
|
221 | 219 |
|
222 |
| -/// A read-write copy of register contents. |
223 |
| -/// |
224 |
| -/// This behaves very similarly to a read-write register, but instead of doing a |
225 |
| -/// volatile read to MMIO to get the value for each function call, a copy of the |
226 |
| -/// register contents are stored locally in memory. This allows a peripheral |
227 |
| -/// to do a single read on a register, and then check which bits are set without |
228 |
| -/// having to do a full MMIO read each time. It also allows the value of the |
229 |
| -/// register to be "cached" in case the peripheral driver needs to clear the |
230 |
| -/// register in hardware yet still be able to check the bits. |
231 |
| -/// You can write to a local register, which will modify the stored value, but |
232 |
| -/// will not modify any hardware because it operates only on local copy. |
233 |
| -/// |
234 |
| -/// This type does not implement the [`Readable`] and [`Writeable`] |
235 |
| -/// traits because it requires a mutable reference to modify the |
236 |
| -/// contained value. It still mirrors the interface which would be |
237 |
| -/// exposed by a type implementing [`Readable`], [`Writeable`] and |
238 |
| -/// [`ReadWriteable`](crate::interfaces::ReadWriteable). |
239 |
| -#[derive(Copy, Clone)] |
240 |
| -pub struct LocalRegisterCopy<T: IntLike, R: RegisterLongName = ()> { |
241 |
| - value: T, |
242 |
| - associated_register: PhantomData<R>, |
243 |
| -} |
244 |
| - |
245 |
| -impl<T: IntLike, R: RegisterLongName> LocalRegisterCopy<T, R> { |
246 |
| - pub const fn new(value: T) -> Self { |
247 |
| - LocalRegisterCopy { |
248 |
| - value: value, |
249 |
| - associated_register: PhantomData, |
250 |
| - } |
251 |
| - } |
252 |
| - |
253 |
| - /// Get the raw register value |
254 |
| - #[inline] |
255 |
| - pub fn get(&self) -> T { |
256 |
| - self.value |
257 |
| - } |
258 |
| - |
259 |
| - /// Set the raw register value |
260 |
| - #[inline] |
261 |
| - pub fn set(&mut self, value: T) { |
262 |
| - self.value = value; |
263 |
| - } |
264 |
| - |
265 |
| - /// Read the value of the given field |
266 |
| - #[inline] |
267 |
| - pub fn read(&self, field: Field<T, R>) -> T { |
268 |
| - field.read(self.get()) |
269 |
| - } |
270 |
| - |
271 |
| - /// Read value of the given field as an enum member |
272 |
| - #[inline] |
273 |
| - pub fn read_as_enum<E: TryFromValue<T, EnumType = E>>(&self, field: Field<T, R>) -> Option<E> { |
274 |
| - field.read_as_enum(self.get()) |
275 |
| - } |
276 |
| - |
277 |
| - /// Write the value of one or more fields, overwriting the other fields with zero |
278 |
| - #[inline] |
279 |
| - pub fn write(&mut self, field: FieldValue<T, R>) { |
280 |
| - self.set(field.value); |
281 |
| - } |
282 |
| - |
283 |
| - /// Write the value of one or more fields, leaving the other fields unchanged |
284 |
| - #[inline] |
285 |
| - pub fn modify(&mut self, field: FieldValue<T, R>) { |
286 |
| - self.set(field.modify(self.get())); |
287 |
| - } |
288 |
| - |
289 |
| - /// Check if one or more bits in a field are set |
290 |
| - #[inline] |
291 |
| - pub fn is_set(&self, field: Field<T, R>) -> bool { |
292 |
| - field.is_set(self.get()) |
293 |
| - } |
294 |
| - |
295 |
| - /// Check if any specified parts of a field match |
296 |
| - #[inline] |
297 |
| - pub fn matches_any(&self, field: FieldValue<T, R>) -> bool { |
298 |
| - field.matches_any(self.get()) |
299 |
| - } |
300 |
| - |
301 |
| - /// Check if all specified parts of a field match |
302 |
| - #[inline] |
303 |
| - pub fn matches_all(&self, field: FieldValue<T, R>) -> bool { |
304 |
| - field.matches_all(self.get()) |
305 |
| - } |
306 |
| - |
307 |
| - /// Do a bitwise AND operation of the stored value and the passed in value |
308 |
| - /// and return a new LocalRegisterCopy. |
309 |
| - #[inline] |
310 |
| - pub fn bitand(&self, rhs: T) -> LocalRegisterCopy<T, R> { |
311 |
| - LocalRegisterCopy::new(self.value & rhs) |
312 |
| - } |
313 |
| -} |
314 |
| - |
315 |
| -impl<T: IntLike + fmt::Debug, R: RegisterLongName> fmt::Debug for LocalRegisterCopy<T, R> { |
316 |
| - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
317 |
| - write!(f, "{:?}", self.value) |
318 |
| - } |
319 |
| -} |
320 |
| - |
321 |
| -macro_rules! From_impl_for { |
322 |
| - ($type:ty) => { |
323 |
| - impl<R: RegisterLongName> From<LocalRegisterCopy<$type, R>> for $type { |
324 |
| - fn from(r: LocalRegisterCopy<$type, R>) -> $type { |
325 |
| - r.value |
326 |
| - } |
327 |
| - } |
328 |
| - }; |
329 |
| -} |
330 |
| - |
331 |
| -From_impl_for!(u8); |
332 |
| -From_impl_for!(u16); |
333 |
| -From_impl_for!(u32); |
334 |
| -From_impl_for!(u64); |
335 |
| -From_impl_for!(u128); |
336 |
| -From_impl_for!(usize); |
337 |
| - |
338 | 220 | #[cfg(not(feature = "no_std_unit_tests"))]
|
339 | 221 | #[cfg(test)]
|
340 | 222 | mod tests {
|
@@ -376,8 +258,8 @@ mod tests {
|
376 | 258 | }
|
377 | 259 |
|
378 | 260 | mod field {
|
379 |
| - use super::super::{Field, TryFromValue}; |
380 | 261 | use super::Foo;
|
| 262 | + use crate::fields::{Field, TryFromValue}; |
381 | 263 |
|
382 | 264 | #[test]
|
383 | 265 | fn test_new() {
|
@@ -446,7 +328,7 @@ mod tests {
|
446 | 328 | }
|
447 | 329 |
|
448 | 330 | mod field_value {
|
449 |
| - use super::super::Field; |
| 331 | + use crate::fields::Field; |
450 | 332 |
|
451 | 333 | #[test]
|
452 | 334 | fn test_from() {
|
|
0 commit comments