-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crates/sel4/bitfield-types: Move Bitfield type into sel4-sys
Signed-off-by: Nick Spinale <[email protected]>
- Loading branch information
Showing
5 changed files
with
49 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
use core::fmt; | ||
|
||
use sel4_bitfield_types::Bitfield; | ||
pub(crate) mod types; | ||
|
||
use types::Bitfield; | ||
|
||
include!(concat!(env!("OUT_DIR"), "/types.rs")); | ||
include!(concat!(env!("OUT_DIR"), "/shared_types.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use core::ops::Range; | ||
|
||
use sel4_bitfield_types::{get_bits, set_bits, UnsignedPrimInt}; | ||
|
||
#[repr(C)] | ||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] | ||
pub struct Bitfield<T, const N: usize> { | ||
arr: [T; N], | ||
} | ||
|
||
impl<T, const N: usize> Bitfield<T, N> | ||
where | ||
T: UnsignedPrimInt, | ||
{ | ||
pub fn from_arr(arr: [T; N]) -> Self { | ||
Self { arr } | ||
} | ||
|
||
pub fn into_arr(self) -> [T; N] { | ||
self.arr | ||
} | ||
|
||
pub fn as_arr(&self) -> &[T; N] { | ||
&self.arr | ||
} | ||
|
||
pub fn as_mut_arr(&mut self) -> &mut [T; N] { | ||
&mut self.arr | ||
} | ||
|
||
pub fn zeroed() -> Self { | ||
Self::from_arr([T::zero(); N]) | ||
} | ||
|
||
pub fn get_bits(&self, range: Range<usize>) -> T { | ||
get_bits(&self.arr, range) | ||
} | ||
|
||
pub fn set_bits(&mut self, range: Range<usize>, bits: T) { | ||
set_bits(&mut self.arr, range, bits) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use sel4_bitfield_types::Bitfield; | ||
use crate::bf::types::Bitfield; | ||
|
||
use crate::{seL4_MessageInfo, seL4_Word}; | ||
|
||
|