[][src]Module tock_registers::registers

Implementation of registers and bitfields.

Provides efficient mechanisms to express and use type-checked memory mapped registers and bitfields.


use tock_registers::registers::{ReadOnly, ReadWrite};
use tock_registers::register_bitfields;

// Register maps are specified like this:
#[repr(C)]
struct Registers {
    // Control register: read-write
    cr: ReadWrite<u32, Control::Register>,
    // Status register: read-only
    s: ReadOnly<u32, Status::Register>,
}

// Register fields and definitions look like this:
register_bitfields![u32,
    // Simpler bitfields are expressed concisely:
    Control [
        /// Stop the Current Transfer
        STOP 8,
        /// Software Reset
        SWRST 7,
        /// Master Disable
        MDIS 1,
        /// Master Enable
        MEN 0
    ],

    // More complex registers can express subtypes:
    Status [
        TXCOMPLETE  OFFSET(0) NUMBITS(1) [],
        TXINTERRUPT OFFSET(1) NUMBITS(1) [],
        RXCOMPLETE  OFFSET(2) NUMBITS(1) [],
        RXINTERRUPT OFFSET(3) NUMBITS(1) [],
        MODE        OFFSET(4) NUMBITS(3) [
            FullDuplex = 0,
            HalfDuplex = 1,
            Loopback = 2,
            Disabled = 3
        ],
        ERRORCOUNT OFFSET(6) NUMBITS(3) []
    ]
];

Author

Structs

Field

Specific section of a register.

FieldValue

Values for the specific register fields.

InMemoryRegister

In memory volatile register.

LocalRegisterCopy

This behaves very similarly to a read-only register, but instead of doing a volatile read to MMIO to get the value for each function call, a copy of the register contents are stored locally in memory. This allows a peripheral to do a single read on a register, and then check which bits are set without having to do a full MMIO read each time. It also allows the value of the register to be "cached" in case the peripheral driver needs to clear the register in hardware yet still be able to check the bits.

ReadOnly

Read-only registers.

ReadWrite

Read/Write registers.

WriteOnly

Write-only registers.

Traits

IntLike

IntLike properties needed to read/write/modify a register.

RegisterLongName

Descriptive name for each register.

TryFromValue

Conversion of raw register value into enumerated values member. Implemented inside register_bitfields! macro for each bit field.