From fcc6951c707144ba423b81e03bc2f34b6cfa7286 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 23 Sep 2019 12:45:09 -0400 Subject: Mark pipe descriptor register memory as volatile. Most of the values in the descriptor memory can be modified by the hardware, so we need to tell Rust that. Also, refactor the common register setup code into `register.rs`. --- src/pipe/ctrl_pipe.rs | 60 +++++++-------------------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) (limited to 'src/pipe/ctrl_pipe.rs') diff --git a/src/pipe/ctrl_pipe.rs b/src/pipe/ctrl_pipe.rs index 360a0e7..5db00c1 100644 --- a/src/pipe/ctrl_pipe.rs +++ b/src/pipe/ctrl_pipe.rs @@ -1,57 +1,20 @@ +use super::register::{Readable, Register, Writable, R as GenR, W as GenW}; + /// Host Control Pipe. /// /// Offset: 0x0c /// Reset: 0xXXXX /// Property: PAC Write-Protection, Write-Synchronized, Read-Synchronized -#[derive(Clone, Copy, Debug)] -#[repr(C, packed)] -pub struct CtrlPipe(u16); - -pub struct R { - bits: u16, -} - -pub struct W { - bits: u16, -} - -impl CtrlPipe { - pub fn read(self) -> R { - R { bits: self.0 } - } - - pub fn write(&mut self, f: F) - where - F: FnOnce(&mut W) -> &mut W, - { - let mut w = W { bits: self.0 }; - f(&mut w); - self.0 = w.bits; - } +pub type CtrlPipe = Register; +impl Readable for CtrlPipe {} +impl Writable for CtrlPipe {} - pub fn modify(&mut self, f: F) - where - for<'w> F: FnOnce(&R, &'w mut W) -> &'w mut W, - { - let r = R { bits: self.0 }; - let mut w = W { bits: self.0 }; - f(&r, &mut w); - self.0 = w.bits; - } -} +pub type R = GenR; +pub type W = GenW; -impl From for CtrlPipe { - fn from(v: u16) -> Self { - Self(v) - } -} +pub struct _CtrlPipe; impl R { - /// Value in raw bits. - pub fn bits(&self) -> u16 { - self.bits - } - pub fn permax(&self) -> PErMaxR { let bits = { const POS: u8 = 12; @@ -115,13 +78,6 @@ impl PDAddrR { } impl W { - /// Write raw bits. - - pub unsafe fn bits(&mut self, v: u16) -> &mut Self { - self.bits = v; - self - } - pub fn permax(&mut self) -> PErMaxW { PErMaxW { w: self } } -- cgit v1.2.3