Skip to content

Commit 1b08d7b

Browse files
committed
Fix large cluster read and writes
1 parent ba28ee7 commit 1b08d7b

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

integration/src/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ fn test_case<T: PartialEq + std::fmt::Debug>(test_case_name: &str, actual: T, ex
2626
}
2727
}
2828

29+
#[cfg(target_arch = "arm")]
30+
const RESOURCE: &str = "RIO0";
31+
32+
#[cfg(not(target_arch = "arm"))]
33+
const RESOURCE: &str = "rio://172.22.11.2/RIO0";
34+
2935
#[allow(overflowing_literals)]
3036
fn main() -> Result<(), ni_fpga::Error> {
3137
let mut tmp_bitfile = NamedTempFile::new().unwrap();
@@ -34,7 +40,7 @@ fn main() -> Result<(), ni_fpga::Error> {
3440
let session = Session::open(
3541
tmp_bitfile.path().to_str().unwrap(),
3642
"D08F17F77A45A5692FA2342C6B86E0EE",
37-
"RIO0",
43+
RESOURCE,
3844
)?;
3945

4046
test_case("read plain U8", session.read::<u8>(98306)?, 0b00000001);
@@ -98,15 +104,12 @@ fn main() -> Result<(), ni_fpga::Error> {
98104
session.read::<TestCluster>(98360)?,
99105
TestCluster { b: false, u: 1337 },
100106
);
101-
// TODO: Investigate cluster array memory layout in order to fix this test.
102-
// The expected array may be incorrect here, I don't exactly remember what I used for the
103-
// fixture bitfile before my LabView FPGA trial expired.
104107
test_case(
105108
"read cluster array",
106-
session.read::<[TestCluster; 2]>(98360)?,
109+
session.read::<[TestCluster; 2]>(98364)?,
107110
[
108-
TestCluster { b: true, u: 255 },
109-
TestCluster { b: false, u: 1337 },
111+
TestCluster { b: true, u: 1234 },
112+
TestCluster { b: false, u: 5678 },
110113
],
111114
);
112115

ni-fpga/src/session.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ impl Session {
4444
)
4545
});
4646
match status {
47-
Status::Success => Ok(Datatype::unpack(
48-
&FpgaBits::from_slice(&buffer)
49-
[((T::SIZE_IN_BITS - 1) / 8 + 1) * 8 - T::SIZE_IN_BITS..],
50-
)?),
47+
Status::Success => {
48+
let slice_start = if (T::SIZE_IN_BITS - 1) / 8 < 4 {
49+
((T::SIZE_IN_BITS - 1) / 8 + 1) * 8 - T::SIZE_IN_BITS
50+
} else {
51+
0
52+
};
53+
Ok(Datatype::unpack(
54+
&FpgaBits::from_slice(&buffer)[slice_start..],
55+
)?)
56+
}
5157
_ => Err(Error::FPGA(status)),
5258
}
5359
}
@@ -56,9 +62,13 @@ impl Session {
5662
[u8; (T::SIZE_IN_BITS - 1) / 8 + 1]: Sized,
5763
{
5864
let mut buffer = [0u8; (T::SIZE_IN_BITS - 1) / 8 + 1];
65+
let slice_start = if (T::SIZE_IN_BITS - 1) / 8 < 4 {
66+
((T::SIZE_IN_BITS - 1) / 8 + 1) * 8 - T::SIZE_IN_BITS
67+
} else {
68+
0
69+
};
5970
Datatype::pack(
60-
&mut FpgaBits::from_slice_mut(&mut buffer)
61-
[((T::SIZE_IN_BITS - 1) / 8 + 1) * 8 - T::SIZE_IN_BITS..],
71+
&mut FpgaBits::from_slice_mut(&mut buffer)[slice_start..],
6272
data,
6373
)?;
6474
let status = Status::from(unsafe {

0 commit comments

Comments
 (0)