|
1 |
| -//! Implementation of registers and bitfields. |
| 1 | +//! Implementation of included register types. |
2 | 2 | //!
|
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: |
5 | 5 | //!
|
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 |
8 | 13 | //!
|
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. |
55 | 18 |
|
56 | 19 | use core::cell::UnsafeCell;
|
57 | 20 | use core::marker::PhantomData;
|
|
0 commit comments