You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-07-12 09:10:40 +02:00
Start writing about MMIO.
This commit is contained in:
@ -256,7 +256,7 @@
|
|||||||
# Bare Metal Rust: Afternoon
|
# Bare Metal Rust: Afternoon
|
||||||
|
|
||||||
- [Application processors]()
|
- [Application processors]()
|
||||||
- [MMIO]()
|
- [MMIO](bare-metal/aps/mmio.md)
|
||||||
- [Let's write a UART driver]()
|
- [Let's write a UART driver]()
|
||||||
- [Logging]()
|
- [Logging]()
|
||||||
- [Useful crates]()
|
- [Useful crates]()
|
||||||
|
17
src/bare-metal/aps/mmio.md
Normal file
17
src/bare-metal/aps/mmio.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Volatile memory access for MMIO
|
||||||
|
|
||||||
|
* Use `pointer::read_volatile` and `pointer::write_volatile`.
|
||||||
|
* Never hold a reference.
|
||||||
|
* `addr_of!` lets you get fields of structs without creating an intermediate reference.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
* Volatile access: read or write operations may have side-effects, so prevent the compiler or
|
||||||
|
hardware from reordering, duplicating or eliding them.
|
||||||
|
* Usually if you write and then read, e.g. via a mutable reference, the compiler may assume that
|
||||||
|
the value read is the same as the value just written, and not bother actually reading memory.
|
||||||
|
* Some existing crates for volatile access to hardware do hold references, but this is unsound.
|
||||||
|
Whenever a reference exist, the compiler may choose to dereference it.
|
||||||
|
* Use the `addr_of!` macro to get struct field pointers from a pointer to the struct.
|
||||||
|
|
||||||
|
</details>
|
Reference in New Issue
Block a user