Skip to content

Commit e882870

Browse files
committed
tock-register-interface: hint at the trait interfaces in README
Hint at the presence of the Readable, Writeable and ReadWriteable traits in the crate's README, while still focusing on the included types operating on memory-mapped registers. Furthermore, refer to the proper trait documentation for more information. Signed-off-by: Leon Schuermann <leon@is.currently.online>
1 parent d43156f commit e882870

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

libraries/tock-register-interface/README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Tock Register Interface
22

3-
This crate provides an interface for defining and manipulating memory mapped
4-
registers and bitfields.
3+
This crate provides an interface and types for defining and
4+
manipulating registers and bitfields.
55

66
## Defining registers
77

88
The crate provides three types for working with memory mapped registers:
99
`ReadWrite`, `ReadOnly`, and `WriteOnly`, providing read-write, read-only, and
10-
write-only functionality, respectively.
10+
write-only functionality, respectively. These types implement the `Readable`,
11+
`Writeable` and `ReadWriteable` traits.
1112

1213
Defining the registers is done with the `register_structs` macro, which expects
1314
for each register an offset, a field name, and a type. Registers must be
@@ -198,10 +199,12 @@ register_bitfields! [
198199
## Register Interface Summary
199200

200201
There are four types provided by the register interface: `ReadOnly`,
201-
`WriteOnly`, `ReadWrite`, and `Aliased`. They provide the following functions:
202+
`WriteOnly`, `ReadWrite`, and `Aliased`. They expose the following
203+
methods, through the implementations of the `Readable`, `Writeable`
204+
and `ReadWriteable` traits respectively:
202205

203206
```rust
204-
ReadOnly<T: IntLike, R: RegisterLongName = ()>
207+
ReadOnly<T: IntLike, R: RegisterLongName = ()>: Readable
205208
.get() -> T // Get the raw register value
206209
.read(field: Field<T, R>) -> T // Read the value of the given field
207210
.read_as_enum<E>(field: Field<T, R>) -> Option<E> // Read value of the given field as a enum member
@@ -210,11 +213,11 @@ ReadOnly<T: IntLike, R: RegisterLongName = ()>
210213
.matches_all(value: FieldValue<T, R>) -> bool // Check if all specified parts of a field match
211214
.extract() -> LocalRegisterCopy<T, R> // Make local copy of register
212215

213-
WriteOnly<T: IntLike, R: RegisterLongName = ()>
216+
WriteOnly<T: IntLike, R: RegisterLongName = ()>: Writeable
214217
.set(value: T) // Set the raw register value
215218
.write(value: FieldValue<T, R>) // Write the value of one or more fields,
216219
// overwriting other fields to zero
217-
ReadWrite<T: IntLike, R: RegisterLongName = ()>
220+
ReadWrite<T: IntLike, R: RegisterLongName = ()>: Readable + Writeable + ReadWriteable
218221
.get() -> T // Get the raw register value
219222
.set(value: T) // Set the raw register value
220223
.read(field: Field<T, R>) -> T // Read the value of the given field
@@ -231,7 +234,7 @@ ReadWrite<T: IntLike, R: RegisterLongName = ()>
231234
.matches_all(value: FieldValue<T, R>) -> bool // Check if all specified parts of a field match
232235
.extract() -> LocalRegisterCopy<T, R> // Make local copy of register
233236

234-
Aliased<T: IntLike, R: RegisterLongName = (), W: RegisterLongName = ()>
237+
Aliased<T: IntLike, R: RegisterLongName = (), W: RegisterLongName = ()>: Readable + Writeable
235238
.get() -> T // Get the raw register value
236239
.set(value: T) // Set the raw register value
237240
.read(field: Field<T, R>) -> T // Read the value of the given field
@@ -453,3 +456,14 @@ register_bitfields! [
453456
]
454457
]
455458
```
459+
460+
## Implementing custom register types
461+
462+
The `Readable`, `Writeable` and `ReadWriteable` traits make it
463+
possible to implement custom register types, even outside of this
464+
crate. A particularly useful application area for this are CPU
465+
registers, such as ARM SPSRs or RISC-V CSRs. It is sufficient to
466+
implement the `Readable::get` and `Writeable::set` methods for the
467+
rest of the API to be automatically implemented by the crate-provided
468+
traits. For more in-depth documentation on how this works, refer to
469+
the `interfaces` module documentation.

0 commit comments

Comments
 (0)