Skip to content

Commit 57651af

Browse files
committed
Add types and test for implementing ringbuffer abstractions in rust
1 parent 7d224e4 commit 57651af

9 files changed

Lines changed: 598 additions & 0 deletions

File tree

bittide-instances/tests/Wishbone/ScatterGather.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,31 @@ case_scatter_gather_c_test = do
7373
where
7474
msg = "Received the following from the CPU over UART:\n" <> simResultC
7575

76+
-- Aligned ringbuffer test simulation
77+
simAlignedRingbuffer :: IO ()
78+
simAlignedRingbuffer = putStr simResultAlignedRingbuffer
79+
80+
simResultAlignedRingbuffer :: (HasCallStack) => String
81+
simResultAlignedRingbuffer = chr . fromIntegral <$> catMaybes uartStream
82+
where
83+
uartStream = sampleC def{timeoutAfter = 200_000} dutNoMM
84+
85+
dutNoMM :: (HasCallStack) => Circuit () (Df System (BitVector 8))
86+
dutNoMM = circuit $ do
87+
mm <- ignoreMM
88+
uartTx <-
89+
withClockResetEnable clockGen (resetGenN d2) enableGen
90+
$ (dutWithBinary "aligned_ringbuffer_test")
91+
-< mm
92+
idC -< uartTx
93+
94+
case_aligned_ringbuffer_test :: Assertion
95+
case_aligned_ringbuffer_test = do
96+
assertBool
97+
msg
98+
("*** ALL TESTS PASSED ***" `isInfixOf` simResultAlignedRingbuffer)
99+
where
100+
msg = "Received the following from the CPU over UART:\n" <> simResultAlignedRingbuffer
101+
76102
tests :: TestTree
77103
tests = $(testGroupGenerator)

firmware-binaries/Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firmware-binaries/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ members = [
1616
"examples/c_hello",
1717
"examples/smoltcp_client",
1818

19+
"sim-tests/aligned_ringbuffer_test",
1920
"sim-tests/axi_stream_self_test",
2021
"sim-tests/registerwb_test",
2122
"sim-tests/capture_ugn_test",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2025 Google LLC
2+
#
3+
# SPDX-License-Identifier: CC0-1.0
4+
5+
[package]
6+
name = "aligned_ringbuffer_test"
7+
version = "0.1.0"
8+
edition = "2021"
9+
license = "Apache-2.0"
10+
authors = ["Google LLC"]
11+
12+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+
14+
[dependencies]
15+
riscv-rt = "0.11.0"
16+
bittide-sys = { path = "../../../firmware-support/bittide-sys" }
17+
bittide-hal = { path = "../../../firmware-support/bittide-hal" }
18+
ufmt = "0.2.0"
19+
20+
[build-dependencies]
21+
memmap-generate = { path = "../../../firmware-support/memmap-generate" }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-FileCopyrightText: 2025 Google LLC
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
use memmap_generate::build_utils::standard_memmap_build;
6+
7+
fn main() {
8+
standard_memmap_build("ScatterGatherPe.json", "DataMemory", "InstructionMemory");
9+
println!("cargo:rerun-if-changed=build.rs");
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
SPDX-FileCopyrightText: 2025 Google LLC
3+
4+
SPDX-License-Identifier: CC0-1.0
5+
*/
6+
7+
MEMORY
8+
{
9+
IMEM : ORIGIN = 0x80000000, LENGTH = 64K
10+
DMEM : ORIGIN = 0x20000000, LENGTH = 32K
11+
}
12+
13+
REGION_ALIAS("REGION_TEXT", IMEM);
14+
REGION_ALIAS("REGION_RODATA", DMEM);
15+
REGION_ALIAS("REGION_DATA", DMEM);
16+
REGION_ALIAS("REGION_BSS", DMEM);
17+
REGION_ALIAS("REGION_HEAP", DMEM);
18+
REGION_ALIAS("REGION_STACK", DMEM);

0 commit comments

Comments
 (0)