lib: fix accessors so they actually work

We were taking an address of the address, rather than transmuting the
address itself.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-09-27 11:51:17 +08:00
parent 03bfd901f8
commit fe68f64446

View File

@ -85,14 +85,14 @@ where
CSR { base }
}
pub fn r(&mut self, field: Field) -> T {
let usize_base: *mut usize = unsafe { core::mem::transmute(&self.base) };
let usize_base: *mut usize = unsafe { core::mem::transmute(self.base) };
((unsafe { usize_base.add(field.register.offset).read_volatile() } >> field.offset)
& field.mask)
.try_into()
.unwrap_or_default()
}
pub fn rw(&mut self, field: Field, value: T) {
let usize_base: *mut usize = unsafe { core::mem::transmute(&self.base) };
let usize_base: *mut usize = unsafe { core::mem::transmute(self.base) };
let value_as_usize: usize = value.try_into().unwrap_or_default() << field.offset;
let previous =
unsafe { usize_base.add(field.register.offset).read_volatile() } & !field.mask;
@ -103,7 +103,7 @@ where
};
}
pub fn ow(&mut self, field: Field, value: T) {
let usize_base: *mut usize = unsafe { core::mem::transmute(&self.base) };
let usize_base: *mut usize = unsafe { core::mem::transmute(self.base) };
let value_as_usize: usize = value.try_into().unwrap_or_default() << field.offset;
unsafe {
usize_base