forked from m-labs/drtio_transceiver_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprbs.py
42 lines (31 loc) · 1.14 KB
/
prbs.py
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
from operator import xor, add
from functools import reduce
from migen import *
class PRBSGenerator(Module):
def __init__(self, n_out, n_state=23, taps=[17, 22]):
self.o = Signal(n_out)
# # #
state = Signal(n_state, reset=1)
curval = [state[i] for i in range(n_state)]
curval += [0]*(n_out - n_state)
for i in range(n_out):
nv = reduce(xor, [curval[tap] for tap in taps])
curval.insert(0, nv)
curval.pop()
self.sync += [
state.eq(Cat(*curval[:n_state])),
self.o.eq(Cat(*curval))
]
class PRBSChecker(Module):
def __init__(self, n_in, n_state=23, taps=[17, 22]):
self.i = Signal(n_in)
self.errors = Signal(n_in)
# # #
state = Signal(n_state, reset=1)
curval = [state[i] for i in range(n_state)]
for i in reversed(range(n_in)):
correctv = reduce(xor, [curval[tap] for tap in taps])
self.sync += self.errors[i].eq(self.i[i] != correctv)
curval.insert(0, self.i[i])
curval.pop()
self.sync += state.eq(Cat(*curval[:n_state]))