Skip to content

Commit 2f0554f

Browse files
committed
single lane scrambler
1 parent 8bbb885 commit 2f0554f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/main/scala/Scrambler.scala

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package edu.berkeley.cs.ucie.digital
2+
3+
import chisel3._
4+
import chisel3.util._
5+
import chisel3.util.random._
6+
7+
//
8+
9+
class Scrambler extends Module {
10+
val io = IO(new Bundle {
11+
val L0_in = Input(UInt(16.W))
12+
val valid = Input(Bool())
13+
val rst = Input(Bool())
14+
val L0_out = Output(UInt(16.W))
15+
})
16+
val L0_LFSR = Module(new FibonacciLFSR(23, Set(23,21,18,15,7,2,1), Some(BigInt(1949628)), XOR, 16, false))
17+
L0_LFSR.io.increment := io.valid
18+
L0_LFSR.io.seed.bits := VecInit(1949628.U(23.W).asBools)
19+
L0_LFSR.io.seed.valid := (reset.asBool || io.rst)
20+
21+
val L0_LFSR_result = L0_LFSR.io.out
22+
printf(cf"$L0_LFSR_result.asUInt")
23+
io.L0_out := L0_LFSR_result.asUInt ^ io.L0_in
24+
}
25+

src/test/scala/Scrambler.scala

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package edu.berkeley.cs.ucie.digital
2+
3+
import chisel3._
4+
import chiseltest._
5+
import org.scalatest.funspec.AnyFunSpec
6+
7+
class ScramblerTest extends AnyFunSpec with ChiselScalatestTester {
8+
describe("Scrambler") {
9+
it("should scramble one lane") {
10+
test(new Scrambler()) { c =>
11+
c.io.rst.poke(true.B)
12+
c.clock.step()
13+
c.clock.step()
14+
c.io.rst.poke(false.B)
15+
c.clock.step()
16+
c.io.valid.poke(true.B)
17+
c.io.L0_in.poke(9628)
18+
c.io.L0_out.expect(39456)
19+
c.clock.step()
20+
c.io.L0_in.poke(13458)
21+
c.io.L0_out.expect(48271)
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)