Skip to content

Commit b6eb23f

Browse files
Merge pull request #57 from ucb-ucie/scrambler
Scrambler Module
2 parents e35cf75 + 4a6bfc5 commit b6eb23f

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

src/main/scala/Scrambler.scala

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package edu.berkeley.cs.ucie.digital
2+
package interfaces
3+
4+
import chisel3._
5+
import chisel3.util.random._
6+
7+
class Scrambler(
8+
afeParams: AfeParams,
9+
width: Int,
10+
seed: BigInt,
11+
) extends Module {
12+
val io = IO(new Bundle {
13+
val data_in = Input(UInt(afeParams.mbSerializerRatio.W))
14+
val valid = Input(Bool())
15+
val seed = Input(UInt(23.W))
16+
val data_out = Output(UInt(afeParams.mbSerializerRatio.W))
17+
})
18+
val LFSR = Module(
19+
new FibonacciLFSR(
20+
23,
21+
Set(23, 21, 18, 15, 7, 2, 1),
22+
Some(seed),
23+
XOR,
24+
width,
25+
false,
26+
),
27+
)
28+
LFSR.io.increment := io.valid
29+
LFSR.io.seed.bits := VecInit(io.seed.asBools)
30+
LFSR.io.seed.valid := (reset.asBool)
31+
io.data_out := LFSR.io.out.asUInt ^ io.data_in
32+
}
33+
34+
class UCIeScrambler(
35+
afeParams: AfeParams,
36+
width: Int,
37+
numLanes: Int,
38+
) extends Module {
39+
val io = IO(new Bundle {
40+
val data_in = Input(Vec(numLanes, UInt(afeParams.mbSerializerRatio.W)))
41+
val valid = Input(Bool())
42+
val data_out = Output(Vec(numLanes, UInt(afeParams.mbSerializerRatio.W)))
43+
})
44+
val UCIe_seeds = List(
45+
"1dbfbc",
46+
"0607bb",
47+
"1ec760",
48+
"18c0db",
49+
"010f12",
50+
"19cfc9",
51+
"0277ce",
52+
"1bb807",
53+
)
54+
val seeds = (for (i <- 0 until numLanes) yield UCIe_seeds(i % 8)).toList
55+
val scramblers =
56+
seeds.map(seed => Module(new Scrambler(afeParams, width, BigInt(seed, 16))))
57+
for (i <- 0 until scramblers.length) {
58+
scramblers(i).io.data_in := io.data_in(i)
59+
scramblers(i).io.valid := io.valid
60+
scramblers(i).reset := reset
61+
scramblers(i).clock := clock
62+
scramblers(i).io.seed := ("h" + seeds(i)).U(23.W)
63+
io.data_out(i) := scramblers(i).io.data_out
64+
}
65+
}

src/test/scala/Scrambler.scala

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package edu.berkeley.cs.ucie.digital
2+
package interfaces
3+
4+
import chisel3._
5+
import chiseltest._
6+
import org.scalatest.funspec.AnyFunSpec
7+
8+
class ScramblerTest extends AnyFunSpec with ChiselScalatestTester {
9+
10+
describe("Scrambler") {
11+
it("4 lane scrambler test") {
12+
test(new UCIeScrambler(new AfeParams(), 16, 4)) { c =>
13+
c.reset.poke(true.B)
14+
c.clock.step()
15+
c.clock.step()
16+
c.reset.poke(false.B)
17+
c.clock.step()
18+
c.io.valid.poke(true.B)
19+
20+
c.io.data_in(0).poke(1.U(16.W))
21+
c.io.data_in(1).poke(1012.U(16.W))
22+
c.io.data_in(2).poke(823.U(16.W))
23+
c.io.data_in(3).poke(134.U(16.W))
24+
c.io.data_out(0).expect(49085.U(16.W))
25+
c.io.data_out(1).expect(1103.U(16.W))
26+
c.io.data_out(2).expect(50263.U(16.W))
27+
c.io.data_out(3).expect(49245.U(16.W))
28+
c.clock.step()
29+
c.io.data_in(0).poke(203.U(16.W))
30+
c.io.data_in(1).poke(176.U(16.W))
31+
c.io.data_in(2).poke(21.U(16.W))
32+
c.io.data_in(3).poke(5847.U(16.W))
33+
c.io.data_out(0).expect(65321.U(16.W))
34+
c.io.data_out(1).expect(56489.U(16.W))
35+
c.io.data_out(2).expect(11245.U(16.W))
36+
c.io.data_out(3).expect(57654.U(16.W))
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)