|
| 1 | +# axklib |
| 2 | + |
| 3 | +[](https://crates.io/crates/axklib) |
| 4 | +[](https://numpy1314.github.io/axklib) |
| 5 | +[](https://github.com/numpy1314/axklib/blob/main/LICENSE) |
| 6 | + |
| 7 | +**axklib** — Small kernel-helper abstractions used across the ArceOS microkernel. |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +This crate exposes a tiny, `no_std`-compatible trait (`Klib`) that the platform/board layer must implement. The trait provides a handful of common kernel helpers such as: |
| 12 | + |
| 13 | +- Memory mapping helpers |
| 14 | +- Timing utilities (busy-wait) |
| 15 | +- IRQ registration and enabling/disabling |
| 16 | + |
| 17 | +The implementation is typically supplied by the platform layer (e.g., `modules/axklib-impl`) and consumed by drivers and other modules. |
| 18 | + |
| 19 | +The crate also provides small convenience modules (`mem`, `time`, `irq`) that re-export the trait methods with shorter names to make call sites more ergonomic. |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +Add this to your `Cargo.toml`: |
| 24 | + |
| 25 | +```toml |
| 26 | +[dependencies] |
| 27 | +axklib = "0.2.0" |
| 28 | +``` |
| 29 | + |
| 30 | +## Example |
| 31 | + |
| 32 | +```rust |
| 33 | +// 1. Map 4K of device MMIO at physical address `paddr` |
| 34 | +// Returns axerrno::AxResult<VirtAddr> |
| 35 | +let vaddr = axklib::mem::iomap(paddr, 0x1000)?; |
| 36 | + |
| 37 | +// 2. Busy-wait for 100 microseconds |
| 38 | +axklib::time::busy_wait(core::time::Duration::from_micros(100)); |
| 39 | + |
| 40 | +// 3. Register an IRQ handler |
| 41 | +// Returns bool indicating success |
| 42 | +axklib::irq::register(32, my_irq_handler); |
| 43 | + |
| 44 | +fn my_irq_handler() { |
| 45 | + // Handle interrupt... |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +## License |
| 50 | +This project is licensed under either of |
| 51 | + |
| 52 | +- GNU General Public License, Version 3.0 or later (LICENSE-GPL |
| 53 | + or https://www.gnu.org/licenses/gpl-3.0.html |
| 54 | +) |
| 55 | + |
| 56 | +- Apache License, Version 2.0 (LICENSE-APACHE |
| 57 | + or http://www.apache.org/licenses/LICENSE-2.0 |
| 58 | +) |
| 59 | + |
| 60 | +- Mulan Permissive Software License, Version 2.0 (LICENSE-MULAN |
| 61 | + or https://license.coscl.org.cn/MulanPSL2/ |
| 62 | +) |
| 63 | + |
| 64 | +at your option. |
0 commit comments