Skip to content

Commit

Permalink
Implement add ops for AxiAddr
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Heymans <[email protected]>
  • Loading branch information
ArthurHeymans committed Dec 19, 2024
1 parent 173003e commit 55790bd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions drivers/src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use caliptra_registers::axi_dma::{
enums::{RdRouteE, WrRouteE},
AxiDmaReg,
};
use core::ops::Add;
use zerocopy::AsBytes;

pub enum DmaReadTarget {
Expand All @@ -39,6 +40,22 @@ impl From<u64> for AxiAddr {
}
}
}
impl From<AxiAddr> for u64 {
fn from(addr: AxiAddr) -> Self {
(addr.hi as u64) << 32 | (addr.lo as u64)
}
}

impl Add for AxiAddr {
type Output = Self;

fn add(self, rhs: Self) -> Self {
let self_u64: u64 = self.into();
let rhs_u64: u64 = rhs.into();
let sum = self_u64 + rhs_u64;
sum.into()
}
}

pub struct DmaReadTransaction {
pub read_addr: AxiAddr,
Expand Down

0 comments on commit 55790bd

Please sign in to comment.