blob: 9b07c4e3b42dcd26bfb58ffbf5ad8d46d5eccb6d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/*
* Sets bits in the register pointed to by 'reg'.
*
* reg: raw pointer to the register to manipulate.
* mask: the bits to change in the register. The binary of mask should follow
* the regex 0*1*0* (i.e. all the 1's should be contiguous).
* val: The value to write to the bits referenced by 'mask'
*/
pub fn regset(reg: *mut u32, mask: u32, val: u32) -> () {
unsafe {
reg.write_volatile((reg.read_volatile() & !mask) | (val << mask.trailing_zeros()));
}
}
/*
* Returns bits in the register pointed to by 'reg'.
*
* reg: raw pointer to the register to read
* mask: the bits to retrieve.
*/
pub fn regget(reg: *mut u32, mask: u32) -> u32 {
unsafe {
(reg.read_volatile() & mask) >> mask.trailing_zeros()
}
}
|