Skip to content

Commit de2d5fc

Browse files
bors[bot]ppannuto
andauthored
Merge #2642
2642: Tock reg UIntLike r=lschuermann a=ppannuto ### Pull Request Overview tock-registers: Rename `IntLike` to `UIntLike` This better captures the semantics of this interfaces. Closes #2641. Depends on #2618. ### Testing Strategy This pull request was tested by compiling. ### TODO or Help Wanted N/A. ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Pat Pannuto <pat.pannuto@gmail.com>
2 parents c2fbb2c + 1365373 commit de2d5fc

File tree

6 files changed

+60
-60
lines changed

6 files changed

+60
-60
lines changed

libraries/tock-register-interface/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ methods, through the implementations of the `Readable`, `Writeable`
204204
and `ReadWriteable` traits respectively:
205205

206206
```rust
207-
ReadOnly<T: IntLike, R: RegisterLongName = ()>: Readable
207+
ReadOnly<T: UIntLike, R: RegisterLongName = ()>: Readable
208208
.get() -> T // Get the raw register value
209209
.read(field: Field<T, R>) -> T // Read the value of the given field
210210
.read_as_enum<E>(field: Field<T, R>) -> Option<E> // Read value of the given field as a enum member
@@ -213,11 +213,11 @@ ReadOnly<T: IntLike, R: RegisterLongName = ()>: Readable
213213
.matches_all(value: FieldValue<T, R>) -> bool // Check if all specified parts of a field match
214214
.extract() -> LocalRegisterCopy<T, R> // Make local copy of register
215215

216-
WriteOnly<T: IntLike, R: RegisterLongName = ()>: Writeable
216+
WriteOnly<T: UIntLike, R: RegisterLongName = ()>: Writeable
217217
.set(value: T) // Set the raw register value
218218
.write(value: FieldValue<T, R>) // Write the value of one or more fields,
219219
// overwriting other fields to zero
220-
ReadWrite<T: IntLike, R: RegisterLongName = ()>: Readable + Writeable + ReadWriteable
220+
ReadWrite<T: UIntLike, R: RegisterLongName = ()>: Readable + Writeable + ReadWriteable
221221
.get() -> T // Get the raw register value
222222
.set(value: T) // Set the raw register value
223223
.read(field: Field<T, R>) -> T // Read the value of the given field
@@ -234,7 +234,7 @@ ReadWrite<T: IntLike, R: RegisterLongName = ()>: Readable + Writeable + ReadWrit
234234
.matches_all(value: FieldValue<T, R>) -> bool // Check if all specified parts of a field match
235235
.extract() -> LocalRegisterCopy<T, R> // Make local copy of register
236236

237-
Aliased<T: IntLike, R: RegisterLongName = (), W: RegisterLongName = ()>: Readable + Writeable
237+
Aliased<T: UIntLike, R: RegisterLongName = (), W: RegisterLongName = ()>: Readable + Writeable
238238
.get() -> T // Get the raw register value
239239
.set(value: T) // Set the raw register value
240240
.read(field: Field<T, R>) -> T // Read the value of the given field
@@ -250,7 +250,7 @@ Aliased<T: IntLike, R: RegisterLongName = (), W: RegisterLongName = ()>: Readabl
250250
The `Aliased` type represents cases where read-only and write-only registers,
251251
with different meanings, are aliased to the same memory location.
252252

253-
The first type parameter (the `IntLike` type) is `u8`, `u16`, `u32`,
253+
The first type parameter (the `UIntLike` type) is `u8`, `u16`, `u32`,
254254
`u64`, `u128` or `usize`.
255255

256256
## Example: Using registers and bitfields

libraries/tock-register-interface/src/fields.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//!
1010
//! A specific section (bitfield) in a register is described by the
1111
//! [`Field`] type, consisting of an unshifted bitmask over the base
12-
//! register [`IntLike`](crate::IntLike) type, and a shift
12+
//! register [`UIntLike`](crate::UIntLike) type, and a shift
1313
//! parameter. It is further associated with a specific
1414
//! [`RegisterLongName`], which can prevent its use with incompatible
1515
//! registers.
@@ -68,18 +68,18 @@
6868
use core::marker::PhantomData;
6969
use core::ops::{Add, AddAssign};
7070

71-
use crate::{IntLike, RegisterLongName};
71+
use crate::{RegisterLongName, UIntLike};
7272

7373
/// Specific section of a register.
7474
///
7575
/// For the Field, the mask is unshifted, ie. the LSB should always be set.
76-
pub struct Field<T: IntLike, R: RegisterLongName> {
76+
pub struct Field<T: UIntLike, R: RegisterLongName> {
7777
pub mask: T,
7878
pub shift: usize,
7979
associated_register: PhantomData<R>,
8080
}
8181

82-
impl<T: IntLike, R: RegisterLongName> Field<T, R> {
82+
impl<T: UIntLike, R: RegisterLongName> Field<T, R> {
8383
pub const fn new(mask: T, shift: usize) -> Field<T, R> {
8484
Field {
8585
mask: mask,
@@ -113,7 +113,7 @@ impl<T: IntLike, R: RegisterLongName> Field<T, R> {
113113
//
114114
// #[automatically_derived]
115115
// #[allow(unused_qualifications)]
116-
// impl<T: ::core::marker::Copy + IntLike,
116+
// impl<T: ::core::marker::Copy + UIntLike,
117117
// R: ::core::marker::Copy + RegisterLongName>
118118
// ::core::marker::Copy for Field<T, R> {}
119119
//
@@ -122,7 +122,7 @@ impl<T: IntLike, R: RegisterLongName> Field<T, R> {
122122
// Manually implementing Clone and Copy works around this issue.
123123
//
124124
// Relevant Rust issue: https://github.com/rust-lang/rust/issues/26925
125-
impl<T: IntLike, R: RegisterLongName> Clone for Field<T, R> {
125+
impl<T: UIntLike, R: RegisterLongName> Clone for Field<T, R> {
126126
fn clone(&self) -> Self {
127127
Field {
128128
mask: self.mask,
@@ -131,7 +131,7 @@ impl<T: IntLike, R: RegisterLongName> Clone for Field<T, R> {
131131
}
132132
}
133133
}
134-
impl<T: IntLike, R: RegisterLongName> Copy for Field<T, R> {}
134+
impl<T: UIntLike, R: RegisterLongName> Copy for Field<T, R> {}
135135

136136
macro_rules! Field_impl_for {
137137
($type:ty) => {
@@ -155,7 +155,7 @@ Field_impl_for!(usize);
155155
/// For the FieldValue, the masks and values are shifted into their actual
156156
/// location in the register.
157157
#[derive(Copy, Clone)]
158-
pub struct FieldValue<T: IntLike, R: RegisterLongName> {
158+
pub struct FieldValue<T: UIntLike, R: RegisterLongName> {
159159
mask: T,
160160
pub value: T,
161161
associated_register: PhantomData<R>,
@@ -193,7 +193,7 @@ FieldValue_impl_for!(u64);
193193
FieldValue_impl_for!(u128);
194194
FieldValue_impl_for!(usize);
195195

196-
impl<T: IntLike, R: RegisterLongName> FieldValue<T, R> {
196+
impl<T: UIntLike, R: RegisterLongName> FieldValue<T, R> {
197197
/// Get the raw bitmask represented by this FieldValue.
198198
#[inline]
199199
pub fn mask(&self) -> T {
@@ -225,7 +225,7 @@ impl<T: IntLike, R: RegisterLongName> FieldValue<T, R> {
225225
}
226226

227227
// Combine two fields with the addition operator
228-
impl<T: IntLike, R: RegisterLongName> Add for FieldValue<T, R> {
228+
impl<T: UIntLike, R: RegisterLongName> Add for FieldValue<T, R> {
229229
type Output = Self;
230230

231231
#[inline]
@@ -239,7 +239,7 @@ impl<T: IntLike, R: RegisterLongName> Add for FieldValue<T, R> {
239239
}
240240

241241
// Combine two fields with the += operator
242-
impl<T: IntLike, R: RegisterLongName> AddAssign for FieldValue<T, R> {
242+
impl<T: UIntLike, R: RegisterLongName> AddAssign for FieldValue<T, R> {
243243
#[inline]
244244
fn add_assign(&mut self, rhs: FieldValue<T, R>) {
245245
self.mask |= rhs.mask;

libraries/tock-register-interface/src/interfaces.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//!
88
//! Each trait has two associated type parameters, namely:
99
//!
10-
//! - `T`: [`IntLike`](crate::IntLike), indicating the underlying
10+
//! - `T`: [`UIntLike`](crate::UIntLike), indicating the underlying
1111
//! integer type used to represent the register's raw contents.
1212
//!
1313
//! - `R`: [`RegisterLongName`](crate::RegisterLongName), functioning
@@ -148,7 +148,7 @@
148148
//! ```
149149
150150
use crate::fields::{Field, FieldValue, TryFromValue};
151-
use crate::{IntLike, LocalRegisterCopy, RegisterLongName};
151+
use crate::{LocalRegisterCopy, RegisterLongName, UIntLike};
152152

153153
/// Readable register
154154
///
@@ -161,7 +161,7 @@ use crate::{IntLike, LocalRegisterCopy, RegisterLongName};
161161
/// [`Readable`] is the same as that of [`Writeable`] (i.e. not for
162162
/// [`Aliased`](crate::registers::Aliased) registers).
163163
pub trait Readable {
164-
type T: IntLike;
164+
type T: UIntLike;
165165
type R: RegisterLongName;
166166

167167
/// Get the raw register value
@@ -218,7 +218,7 @@ pub trait Readable {
218218
/// [`Readable`] is the same as that of [`Writeable`] (i.e. not for
219219
/// [`Aliased`](crate::registers::Aliased) registers).
220220
pub trait Writeable {
221-
type T: IntLike;
221+
type T: UIntLike;
222222
type R: RegisterLongName;
223223

224224
/// Set the raw register value
@@ -252,14 +252,14 @@ pub trait Writeable {
252252
/// and [`Writeable`], as long as [`Readable::R`] == [`Writeable::R`]
253253
/// (i.e. not for [`Aliased`](crate::registers::Aliased) registers).
254254
pub trait ReadWriteable {
255-
type T: IntLike;
255+
type T: UIntLike;
256256
type R: RegisterLongName;
257257

258258
/// Write the value of one or more fields, leaving the other fields unchanged
259259
fn modify(&self, field: FieldValue<Self::T, Self::R>);
260260
}
261261

262-
impl<T: IntLike, R: RegisterLongName, S> ReadWriteable for S
262+
impl<T: UIntLike, R: RegisterLongName, S> ReadWriteable for S
263263
where
264264
S: Readable<T = T, R = R> + Writeable<T = T, R = R>,
265265
{

libraries/tock-register-interface/src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ use core::ops::{BitAnd, BitOr, BitOrAssign, Not, Shl, Shr};
7373

7474
/// Trait representing the base type of registers.
7575
///
76-
/// IntLike defines basic properties of types required to
76+
/// UIntLike defines basic properties of types required to
7777
/// read/write/modify a register through its methods and supertrait
7878
/// requirements.
7979
///
80-
/// It features a range of default implementations for common integer
81-
/// types, such as [`u8`], [`u16`], [`u32`], [`u64`], [`u128`] and
82-
/// [`usize`].
83-
pub trait IntLike:
80+
/// It features a range of default implementations for common unsigned
81+
/// integer types, such as [`u8`], [`u16`], [`u32`], [`u64`], [`u128`],
82+
/// and [`usize`].
83+
pub trait UIntLike:
8484
BitAnd<Output = Self>
8585
+ BitOr<Output = Self>
8686
+ BitOrAssign
@@ -94,32 +94,32 @@ pub trait IntLike:
9494
/// Return the representation of the value `0` in the implementing
9595
/// type.
9696
///
97-
/// This can be used to acquire values of the [`IntLike`] type,
97+
/// This can be used to acquire values of the [`UIntLike`] type,
9898
/// even in generic implementations. For instance, to get the
99-
/// value `1`, one can use `<T as IntLike>::zero() + 1`. To get
99+
/// value `1`, one can use `<T as UIntLike>::zero() + 1`. To get
100100
/// the largest representable value, use a bitwise negation: `~(<T
101-
/// as IntLike>::zero())`.
101+
/// as UIntLike>::zero())`.
102102
fn zero() -> Self;
103103
}
104104

105-
// Helper macro for implementing the IntLike trait on differrent
105+
// Helper macro for implementing the UIntLike trait on differrent
106106
// types.
107-
macro_rules! IntLike_impl_for {
107+
macro_rules! UIntLike_impl_for {
108108
($type:ty) => {
109-
impl IntLike for $type {
109+
impl UIntLike for $type {
110110
fn zero() -> Self {
111111
0
112112
}
113113
}
114114
};
115115
}
116116

117-
IntLike_impl_for!(u8);
118-
IntLike_impl_for!(u16);
119-
IntLike_impl_for!(u32);
120-
IntLike_impl_for!(u64);
121-
IntLike_impl_for!(u128);
122-
IntLike_impl_for!(usize);
117+
UIntLike_impl_for!(u8);
118+
UIntLike_impl_for!(u16);
119+
UIntLike_impl_for!(u32);
120+
UIntLike_impl_for!(u64);
121+
UIntLike_impl_for!(u128);
122+
UIntLike_impl_for!(usize);
123123

124124
/// Descriptive name for each register.
125125
pub trait RegisterLongName {}

libraries/tock-register-interface/src/local_register.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::fmt;
55
use core::marker::PhantomData;
66

77
use crate::fields::{Field, FieldValue, TryFromValue};
8-
use crate::{IntLike, RegisterLongName};
8+
use crate::{RegisterLongName, UIntLike};
99

1010
/// A read-write copy of register contents.
1111
///
@@ -28,12 +28,12 @@ use crate::{IntLike, RegisterLongName};
2828
/// [`Writeable`](crate::interfaces::Writeable) and
2929
/// [`ReadWriteable`](crate::interfaces::ReadWriteable).
3030
#[derive(Copy, Clone)]
31-
pub struct LocalRegisterCopy<T: IntLike, R: RegisterLongName = ()> {
31+
pub struct LocalRegisterCopy<T: UIntLike, R: RegisterLongName = ()> {
3232
value: T,
3333
associated_register: PhantomData<R>,
3434
}
3535

36-
impl<T: IntLike, R: RegisterLongName> LocalRegisterCopy<T, R> {
36+
impl<T: UIntLike, R: RegisterLongName> LocalRegisterCopy<T, R> {
3737
pub const fn new(value: T) -> Self {
3838
LocalRegisterCopy {
3939
value: value,
@@ -103,14 +103,14 @@ impl<T: IntLike, R: RegisterLongName> LocalRegisterCopy<T, R> {
103103
}
104104
}
105105

106-
impl<T: IntLike + fmt::Debug, R: RegisterLongName> fmt::Debug for LocalRegisterCopy<T, R> {
106+
impl<T: UIntLike + fmt::Debug, R: RegisterLongName> fmt::Debug for LocalRegisterCopy<T, R> {
107107
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
108108
write!(f, "{:?}", self.value)
109109
}
110110
}
111111

112-
// Helper macro to implement From<LocalRegisterCopy<T: IntLike>, R>>
113-
// for <T: IntLike>
112+
// Helper macro to implement From<LocalRegisterCopy<T: UIntLike>, R>>
113+
// for <T: UIntLike>
114114
macro_rules! From_impl_for {
115115
($type:ty) => {
116116
impl<R: RegisterLongName> From<LocalRegisterCopy<$type, R>> for $type {

0 commit comments

Comments
 (0)