-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathErrorCounter.scala
81 lines (72 loc) · 2.31 KB
/
ErrorCounter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package edu.berkeley.cs.ucie.digital
package logphy
import chisel3._
import chisel3.util._
import interfaces.AfeParams
/** TODO: need to do per-lane, not just aggregate */
class ErrorCounter(afeParams: AfeParams) extends Module {
val io = IO(new Bundle {
val req = Flipped(Valid(new Bundle {
val pattern = TransmitPattern()
val input = Input(
Vec(afeParams.mbLanes, UInt(afeParams.mbSerializerRatio.W)),
)
}))
val errorCount = Output(
Vec(afeParams.mbLanes, UInt(log2Ceil(afeParams.mbSerializerRatio + 1).W)),
)
})
val lfsr = Module(
new UCIeScrambler(afeParams = afeParams, numLanes = afeParams.mbLanes),
)
lfsr.io.valid := io.req.valid && io.req.bits.pattern === TransmitPattern.LFSR
lfsr.io.data_in := VecInit(
Seq.fill(afeParams.mbLanes)(0.U(afeParams.mbSerializerRatio.W)),
)
val expected = WireInit(
VecInit(
Seq.fill(afeParams.mbLanes)(0.U(afeParams.mbSerializerRatio.W)),
),
)
/** Assign expected value */
switch(io.req.bits.pattern) {
is(TransmitPattern.CLOCK) {
assert(!io.req.valid, "Cannot do error count with sideband clock pattern")
}
is(TransmitPattern.LFSR) {
expected := lfsr.io.data_out
}
is(TransmitPattern.PER_LANE_ID) {
val perLaneId = VecInit(Seq.fill(afeParams.mbLanes)(0.U(16.W)))
for (i <- 0 until afeParams.mbLanes) {
perLaneId(i) := Cat("b1010".U(4.W), i.U(8.W), "b1010".U(4.W))
}
val ratio16 = afeParams.mbSerializerRatio / 16
val patternVec = VecInit.tabulate(afeParams.mbLanes, ratio16) { (_, _) =>
0.U(16.W)
}
for (i <- 0 until afeParams.mbLanes) {
for (j <- 0 until ratio16) {
patternVec(i)(j) := perLaneId(i)
}
}
expected := patternVec.asTypeOf(expected)
}
is(TransmitPattern.VALTRAIN) {
val valtrain = VecInit(
Seq.fill(afeParams.mbLanes * afeParams.mbSerializerRatio / 8)(
"b1111_0000".U(8.W),
),
)
expected := valtrain.asTypeOf(expected)
}
}
/** count errors */
val diffVec = Wire(
Vec(afeParams.mbLanes, Vec(afeParams.mbSerializerRatio, UInt(1.W))),
)
for (i <- 0 until afeParams.mbLanes) {
diffVec(i) := (expected(i) ^ io.req.bits.input(i)).asTypeOf(diffVec(i))
io.errorCount(i) := diffVec(i).reduceTree(_ +& _)
}
}