|
| 1 | +<div id="header" align="center"> |
| 2 | + |
| 3 | + <b>[volatile_table]</b> |
| 4 | + |
| 5 | + (A zero-cost, type-safe DSL for MMIO and volatile register mapping with compile-time access control (RO/RW/WO).) |
| 6 | + </br></br> |
| 7 | + |
| 8 | +<div id="badges"> |
| 9 | + <a href="./LICENSE"> |
| 10 | + <img src="https://github.com/UlinProject/img/blob/main/short_32/apache2.png?raw=true" alt="apache2"/> |
| 11 | + </a> |
| 12 | + <a href="https://crates.io/crates/volatile_table"> |
| 13 | + <img src="https://github.com/UlinProject/img/blob/main/short_32/cratesio.png?raw=true" alt="cratesio"/> |
| 14 | + </a> |
| 15 | + <a href="https://docs.rs/volatile_table"> |
| 16 | + <img src="https://github.com/UlinProject/img/blob/main/short_32/docrs.png?raw=true" alt="docrs"/> |
| 17 | + </a> |
| 18 | + <a href="https://github.com/denisandroid"> |
| 19 | + <img src="https://github.com/UlinProject/img/blob/main/short_32/uproject.png?raw=true" alt="uproject"/> |
| 20 | + </a> |
| 21 | + |
| 22 | + [](https://github.com/UlinProject/volatile_table/actions/workflows/CI.yml) |
| 23 | + |
| 24 | + |
| 25 | +</div> |
| 26 | +</div> |
| 27 | + |
| 28 | +## Why volatile_table? |
| 29 | +- Type-Safe Access: Compiler-enforced RO/RW/WO rights. |
| 30 | +- Hardware-Friendly DSL: Use byte offsets (+=) directly from datasheets. |
| 31 | +- Zero-Overhead: No runtime cost, just direct volatile instructions. |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +Add this to your Cargo.toml: |
| 36 | + |
| 37 | +```toml |
| 38 | +[dependencies] |
| 39 | +volatile_table = "0.0.1" |
| 40 | +``` |
| 41 | + |
| 42 | +and this to your source code: |
| 43 | + |
| 44 | +```rust |
| 45 | +use volatile_table::volatile_table; |
| 46 | +``` |
| 47 | + |
| 48 | +## Example |
| 49 | + |
| 50 | +```rust |
| 51 | +use volatile_table::volatile_table; |
| 52 | + |
| 53 | +volatile_table! { |
| 54 | + map[rw <u32> AO_BASE = 0xC81004C0]: { |
| 55 | + wo <u32> AO_WFIFO += 0 << 2; // Write FIFO |
| 56 | + ro <u32> AO_RFIFO += 1 << 2; // Read FIFO |
| 57 | + rw <u32> AO_CONTROL += 2 << 2; // Control Register |
| 58 | + ro <u32> AO_STATUS += 3 << 2; // Status Register |
| 59 | + rw <u32> AO_MISC += 4 << 2; // Misc Settings |
| 60 | + } |
| 61 | +} |
| 62 | +const TX_FIFO_FULL: u32 = 0x200000; |
| 63 | + |
| 64 | +pub fn write_byte(a: u8) { |
| 65 | + // Note: .read() and .write() operations are unsafe because they perform direct memory access, |
| 66 | + // which is necessary for hardware interaction. |
| 67 | + unsafe { |
| 68 | + while (AO_STATUS.read() & TX_FIFO_FULL) != 0 {} // (busy-wait loop) |
| 69 | + AO_WFIFO.write(a as _); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +pub fn print_message(msg: &str) { |
| 74 | + for byte in msg.as_bytes() { |
| 75 | + write_byte(*byte); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +pub fn main() { |
| 80 | + print_message("Hello, world!\r\n"); |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +<a href="./examples"> |
| 85 | + See all |
| 86 | +</a> |
| 87 | + |
| 88 | +## License |
| 89 | + |
| 90 | +This project has a single license (LICENSE-APACHE-2.0). |
| 91 | + |
| 92 | +<div align="left"> |
| 93 | + <a href="https://github.com/denisandroid"> |
| 94 | + <img align="left" src="https://github.com/UlinProject/img/blob/main/block_220_100/uproject.png?raw=true" alt="uproject"/> |
| 95 | + </a> |
| 96 | + <b> Copyright (c) 2026 #UlinProject</b> |
| 97 | + |
| 98 | + <b> (Denis Kotlyarov).</b> |
| 99 | + </br></br></br> |
| 100 | +</div> |
| 101 | + |
| 102 | +### Apache License |
| 103 | +<div align="left"> |
| 104 | + <a href="./LICENSE"> |
| 105 | + <img align="left" src="https://github.com/UlinProject/img/blob/main/block_220_100/apache2.png?raw=true" alt="apache2"/> |
| 106 | + |
| 107 | + </a> |
| 108 | + <b> Licensed under the Apache License, Version 2.0.</b> |
| 109 | + </br></br></br></br> |
| 110 | +</div> |
0 commit comments