tpu-sg2002 0.1.0

TPU driver in Rust for SG2002 SoC.
Documentation
//! Kernel function abstractions for TPU device layer.

/// Physical address type.
pub type PhysAddr = u64;

/// Time type for timestamps (microseconds).
pub type TimeStamp = u64;

/// Log levels.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogLevel {
    Error,
    Warn,
    Info,
    Debug,
}

/// Kernel functions required by the TPU device layer.
pub trait KernelFns {
    /// Sleep for the given number of milliseconds.
    ///
    /// Optional hook. The current SG2002 fast path no longer relies on this,
    /// but it is retained for portability and future backoff strategies.
    fn sleep_ms(&self, _ms: u32) {}

    /// Return a monotonic timestamp in microseconds.
    fn now_us(&self) -> TimeStamp;

    /// Logging hook.
    fn log(&self, level: LogLevel, msg: &str);

    /// Enable TPU clocks.
    fn enable_clocks(&self) {}

    /// Disable TPU clocks.
    fn disable_clocks(&self) {}

    /// Reset TPU hardware.
    fn reset(&self) {}

    /// Clean data cache for DMA buffer before device access.
    fn dma_sync_for_device(&self, _paddr: PhysAddr, _size: usize) {}

    /// Invalidate data cache for DMA buffer after device access.
    fn dma_sync_for_cpu(&self, _paddr: PhysAddr, _size: usize) {}
}