Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrambler Module #57

Merged
merged 11 commits into from
Feb 2, 2024
67 changes: 67 additions & 0 deletions src/main/scala/Scrambler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package edu.berkeley.cs.ucie.digital
package interfaces

import chisel3._
import chisel3.util.random._

class Scrambler(
afeParams: AfeParams,
width: Int,
seed: BigInt,
) extends Module {
val io = IO(new Bundle {
val data_in = Input(UInt(afeParams.mbSerializerRatio.W))
val valid = Input(Bool())
val seed = Input(UInt(23.W))
val data_out = Output(UInt(afeParams.mbSerializerRatio.W))
})
val LFSR = Module(
new FibonacciLFSR(
23,
Set(23, 21, 18, 15, 7, 2, 1),
Some(seed),
XOR,
width,
false,
),
)
LFSR.io.increment := io.valid
LFSR.io.seed.bits := VecInit(io.seed.asBools)
LFSR.io.seed.valid := (reset.asBool)
val LFSR_result = LFSR.io.out
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need this? does LFSR.io.out.asUInt not work?

// printf(cf"$LFSR_result.asUInt")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this line

io.data_out := LFSR_result.asUInt ^ io.data_in
}

class UCIeScrambler(
afeParams: AfeParams,
width: Int,
numLanes: Int,
) extends Module {
val io = IO(new Bundle {
val data_in = Input(Vec(numLanes, UInt(afeParams.mbSerializerRatio.W)))
val valid = Input(Bool())
val data_out = Output(Vec(numLanes, UInt(afeParams.mbSerializerRatio.W)))
})
val UCIe_seeds = List(
"1dbfbc",
"0607bb",
"1ec760",
"18c0db",
"010f12",
"19cfc9",
"0277ce",
"1bb807",
)
val seeds = (for (i <- 0 until numLanes) yield UCIe_seeds(i % 8)).toList
val scramblers =
seeds.map(seed => Module(new Scrambler(afeParams, width, BigInt(seed, 16))))
for (i <- 0 until scramblers.length) {
scramblers(i).io.data_in := io.data_in(i)
scramblers(i).io.valid := io.valid
scramblers(i).reset := reset
scramblers(i).clock := clock
scramblers(i).io.seed := ("h" + seeds(i)).U(23.W)
io.data_out(i) := scramblers(i).io.data_out
}
}
32 changes: 32 additions & 0 deletions src/test/scala/Scrambler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package edu.berkeley.cs.ucie.digital
package interfaces

import chisel3._
import chiseltest._
import org.scalatest.funspec.AnyFunSpec

class ScramblerTest extends AnyFunSpec with ChiselScalatestTester {

describe("Scrambler") {
it("4 lane scrambler test") {
test(new UCIeScrambler(new AfeParams(), 16, 4)) { c =>
c.reset.poke(true.B)
c.clock.step()
c.clock.step()
c.reset.poke(false.B)
c.clock.step()
c.io.valid.poke(true.B)

c.io.data_in(0).poke(1.U(16.W))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to add a few more clock steps to the test

c.io.data_in(1).poke(1012.U(16.W))
c.io.data_in(2).poke(823.U(16.W))
c.io.data_in(3).poke(134.U(16.W))
c.io.data_out(0).expect(49085.U(16.W))
c.io.data_out(1).expect(1103.U(16.W))
c.io.data_out(2).expect(50263.U(16.W))
c.io.data_out(3).expect(49245.U(16.W))

}
}
}
}