register-interface

Crates.ioregister-interface
lib.rsregister-interface
version0.1.0
created_at2022-11-19 23:56:25.697696+00
updated_at2022-11-19 23:56:25.697696+00
descriptionA register interface, bitfield and memory mapping library
homepage
repositoryhttps://github.com/Istar-Eldritch/register-interface
max_upload_size
id718755
size5,106
Ruben Paz (Istar-Eldritch)

documentation

README

This crate adds two proc macros:

  • field: Allows to represent a bitfield of a register.
  • register: Allows to represent a register on a register map.

Usage

To represent a new register type, define a new struct and anotate its differnet bitfield sections:

// (name_of_field, position from, position to)
#[field(data, 0, 7)]
#[field(full, 31, 31)]
pub struct TxData {
    addr: *mut usize,
}

To represent a device register map, define a new struct and anotate its didfferent registers.

// (name of register, type of register, offset from base address)
#[register(txdata, TxData, 0x0)]
#[register(rxdata, RxData, 0x4)]
#[register(txctrl, TxCtrl, 0x08)]
#[register(rxctrl, RxCtrl, 0x0C)]
#[register(ie, InterruptRegister, 0x10)]
#[register(ip, InterruptRegister, 0x14)]
#[register(div, Div, 0x18)]
pub struct Uart {
    addr: *mut usize,
}

To access the fields you can then:

let mut uart = Uart::new(&mut reg_ptr);
let data = uart.rxdata.data();
uart.rxdata().set_data(data + 1);

Overhead

Both reads and writes perform two bitwise operations, a mask and a bitshift on top of the read / write operations.

Commit count: 1

cargo fmt