Skip to content

Commit 2a14cf8

Browse files
committed
tock-register-interface: update crate::registers doc comment
Move the previous documentation comment of crate::registers to the top-level module, as it not only describes the register types but also Fields and macros. Introduce a new documentation comment, providing an overview of the included register types. Signed-off-by: Leon Schuermann <leon@is.currently.online>
1 parent 107fb22 commit 2a14cf8

File tree

2 files changed

+65
-52
lines changed

2 files changed

+65
-52
lines changed

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,60 @@
11
//! Tock Register Interface
22
//!
3+
//! Provides efficient mechanisms to express and use type-checked
4+
//! memory mapped registers and bitfields.
35
//!
6+
//! ```rust
7+
//! # fn main() {}
8+
//!
9+
//! use tock_registers::registers::{ReadOnly, ReadWrite};
10+
//! use tock_registers::register_bitfields;
11+
//!
12+
//! // Register maps are specified like this:
13+
//! #[repr(C)]
14+
//! struct Registers {
15+
//! // Control register: read-write
16+
//! cr: ReadWrite<u32, Control::Register>,
17+
//! // Status register: read-only
18+
//! s: ReadOnly<u32, Status::Register>,
19+
//! }
20+
//!
21+
//! // Register fields and definitions look like this:
22+
//! register_bitfields![u32,
23+
//! // Simpler bitfields are expressed concisely:
24+
//! Control [
25+
//! /// Stop the Current Transfer
26+
//! STOP 8,
27+
//! /// Software Reset
28+
//! SWRST 7,
29+
//! /// Master Disable
30+
//! MDIS 1,
31+
//! /// Master Enable
32+
//! MEN 0
33+
//! ],
34+
//!
35+
//! // More complex registers can express subtypes:
36+
//! Status [
37+
//! TXCOMPLETE OFFSET(0) NUMBITS(1) [],
38+
//! TXINTERRUPT OFFSET(1) NUMBITS(1) [],
39+
//! RXCOMPLETE OFFSET(2) NUMBITS(1) [],
40+
//! RXINTERRUPT OFFSET(3) NUMBITS(1) [],
41+
//! MODE OFFSET(4) NUMBITS(3) [
42+
//! FullDuplex = 0,
43+
//! HalfDuplex = 1,
44+
//! Loopback = 2,
45+
//! Disabled = 3
46+
//! ],
47+
//! ERRORCOUNT OFFSET(6) NUMBITS(3) []
48+
//! ]
49+
//! ];
50+
//! ```
51+
//!
52+
//! Author
53+
//! ------
54+
//! - Shane Leonard <shanel@stanford.edu>
455
556
#![feature(const_fn_trait_bound)]
657
#![no_std]
7-
858
// If we don't build any actual register types, we don't need unsafe
959
// code in this crate
1060
#![cfg_attr(not(feature = "register_types"), forbid(unsafe_code))]

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

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,20 @@
1-
//! Implementation of registers and bitfields.
1+
//! Implementation of included register types.
22
//!
3-
//! Provides efficient mechanisms to express and use type-checked memory mapped
4-
//! registers and bitfields.
3+
//! This module provides a standard set of register types, which can
4+
//! describe different access levels:
55
//!
6-
//! ```rust
7-
//! # fn main() {}
6+
//! - [`ReadWrite`] for registers which can be read and written to
7+
//! - [`ReadOnly`] for registers which can only be read
8+
//! - [`WriteOnly`] for registers which can only be written to
9+
//! - [`Aliased`] for registers which can be both read and written,
10+
//! but represent different registers depending on the operation
11+
//! - [`InMemoryRegister`] provide a register-type in RAM using
12+
//! volatile operations
813
//!
9-
//! use tock_registers::registers::{ReadOnly, ReadWrite};
10-
//! use tock_registers::register_bitfields;
11-
//!
12-
//! // Register maps are specified like this:
13-
//! #[repr(C)]
14-
//! struct Registers {
15-
//! // Control register: read-write
16-
//! cr: ReadWrite<u32, Control::Register>,
17-
//! // Status register: read-only
18-
//! s: ReadOnly<u32, Status::Register>,
19-
//! }
20-
//!
21-
//! // Register fields and definitions look like this:
22-
//! register_bitfields![u32,
23-
//! // Simpler bitfields are expressed concisely:
24-
//! Control [
25-
//! /// Stop the Current Transfer
26-
//! STOP 8,
27-
//! /// Software Reset
28-
//! SWRST 7,
29-
//! /// Master Disable
30-
//! MDIS 1,
31-
//! /// Master Enable
32-
//! MEN 0
33-
//! ],
34-
//!
35-
//! // More complex registers can express subtypes:
36-
//! Status [
37-
//! TXCOMPLETE OFFSET(0) NUMBITS(1) [],
38-
//! TXINTERRUPT OFFSET(1) NUMBITS(1) [],
39-
//! RXCOMPLETE OFFSET(2) NUMBITS(1) [],
40-
//! RXINTERRUPT OFFSET(3) NUMBITS(1) [],
41-
//! MODE OFFSET(4) NUMBITS(3) [
42-
//! FullDuplex = 0,
43-
//! HalfDuplex = 1,
44-
//! Loopback = 2,
45-
//! Disabled = 3
46-
//! ],
47-
//! ERRORCOUNT OFFSET(6) NUMBITS(3) []
48-
//! ]
49-
//! ];
50-
//! ```
51-
//!
52-
//! Author
53-
//! ------
54-
//! - Shane Leonard <shanel@stanford.edu>
14+
//! These types can be disabled by removing the `register_types` crate
15+
//! feature (part of the default features). This is useful if this
16+
//! crate should be used only as an interface library, or if all
17+
//! unsafe code should be disabled.
5518
5619
use core::cell::UnsafeCell;
5720
use core::marker::PhantomData;

0 commit comments

Comments
 (0)