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:
parent
03bfd901f8
commit
fe68f64446
@ -85,14 +85,14 @@ where
|
|||||||
CSR { base }
|
CSR { base }
|
||||||
}
|
}
|
||||||
pub fn r(&mut self, field: Field) -> T {
|
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)
|
((unsafe { usize_base.add(field.register.offset).read_volatile() } >> field.offset)
|
||||||
& field.mask)
|
& field.mask)
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
pub fn rw(&mut self, field: Field, value: T) {
|
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 value_as_usize: usize = value.try_into().unwrap_or_default() << field.offset;
|
||||||
let previous =
|
let previous =
|
||||||
unsafe { usize_base.add(field.register.offset).read_volatile() } & !field.mask;
|
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) {
|
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;
|
let value_as_usize: usize = value.try_into().unwrap_or_default() << field.offset;
|
||||||
unsafe {
|
unsafe {
|
||||||
usize_base
|
usize_base
|
||||||
|
Loading…
Reference in New Issue
Block a user