|
| 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 | +} |
0 commit comments