Skip to content

Commit e511041

Browse files
committed
tock-registers: add trait-based manipulator methods to registers
Replace the individual implementations of common methods on registers (e.g. get, set, read, modify) by traits which represent the respective access level (Readable, Writeable, ReadWriteable). This significantly reduces code duplication found in tock-registers by providing default implementations for most methods, as well as allowing to implement custom register types adhering to the tock-registers interface. Furthermore, generic implementations of peripherals can be designed to take trait objects instead of concrete register types, to be agnostic over their actual register (e.g. some register mapped to either a RISC-V CSR or a memory location). The Readable, Writeable and ReadWriteable manipulation traits have associated type parameters specifying the underlying integer type and RegisterLongName. Associated type parameters are used, as every monomorphized register over precise IntLike and RegisterLongName types should have at most a single implementation of the respective manipulation traits. If generic traits were used, multiple manipulation traits could be implemented on a single monomorphized register type. Every readable register type implements Readable, which requires the get-method to be implemented manually. Every writeable register type implements Writeable, which requires the set-method to be implemented manually. Registers which implement both Readable and Writeable, and have the same associated IntLike and RegisterLongName types for both of their Readable and Writeable implementations also implement ReadWriteable. For Aliased registers (where read and write operations correspond to different registers), ReadWriteable is therefore in general not implemented. Potential drawbacks of this approach include - requiring to import Readable, Writeable and ReadWriteable to be able to use the respective methods - having a standard interface, which does not allow deviation from Signed-off-by: Leon Schuermann <[email protected]>
1 parent cde3ff8 commit e511041

File tree

1 file changed

+185
-216
lines changed

1 file changed

+185
-216
lines changed

0 commit comments

Comments
 (0)