tpu_sg2002/lib.rs
1//! Minimal TPU device layer for SG2002.
2//!
3//! Bare-metal, OS-agnostic TPU driver for the CVITEK SG2002 SoC.
4//!
5//! # Usage
6//!
7//! ```ignore
8//! use tpu_sg2002::{TpuDevice, TpuConfig, KernelFns, LogLevel, TimeStamp};
9//! use core::ptr::NonNull;
10//!
11//! struct MyKernelFns;
12//! impl KernelFns for MyKernelFns {
13//! fn sleep_ms(&self, ms: u32) { /* ... */ }
14//! fn now_us(&self) -> TimeStamp { /* ... */ }
15//! fn log(&self, level: LogLevel, msg: &str) { /* ... */ }
16//! }
17//!
18//! let tdma_base = NonNull::new(0x0C00_0000 as *mut u8).unwrap();
19//! let tiu_base = NonNull::new(0x0C01_0000 as *mut u8).unwrap();
20//! let mut tpu = TpuDevice::new(tdma_base, tiu_base, TpuConfig::default(), MyKernelFns);
21//! tpu.platform_init().expect("TPU init failed");
22//! ```
23
24#![no_std]
25
26mod device;
27mod kernel_fns;
28mod types;
29pub mod ioctrl;
30pub mod platform;
31pub mod pmu;
32pub mod registers;
33
34// Error type
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum TpuError {
37 InvalidParameter,
38 Timeout,
39 DeviceError,
40}
41
42// Core types
43pub use types::{CpuSyncDesc, DmabufView, DmaHeader, TpuConfig, TpuTdmaPioInfo, parse_dmabuf_view};
44pub use device::TpuDevice;
45pub use kernel_fns::{PhysAddr, TimeStamp, LogLevel, KernelFns};
46
47// Re-export essential platform types
48pub use platform::{TdmaReg, TpuRegBackup, TdmaSyncStatus, TiuCtrlStatus, TIMEOUT_US};
49pub use pmu::{TpuPmu, TpuPmuEvent, PmuSummary};
50pub use registers::TiuLaneNum;