File: random_generator.py

package info (click to toggle)
myhdl 0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,728 kB
  • sloc: python: 25,033; ansic: 2,203; makefile: 243; sh: 206
file content (59 lines) | stat: -rw-r--r-- 1,526 bytes parent folder | download | duplicates (2)
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
from __future__ import absolute_import
import myhdl
from myhdl import *

def random_generator(random_word, enable, clock, reset):

    W = len(random_word)

    @instance
    def logic():
        lfsr = modbv(0)[64:]
        word =  modbv(0)[W:]
        while True:
            yield clock.posedge, reset.posedge
            if reset == 1:
                random_word.next = 0
                lfsr[:] = 1
            else:
                if enable:
                    for i in range(W):
                        word[i] = lfsr[63]
                        tmp0 = lfsr[63] ^ lfsr[62] ^ lfsr[60] ^ lfsr[59]
                        lfsr <<= 1
                        lfsr[0] = tmp0
                    random_word.next = word

    return logic



                    
# def random_generator(random_word, enable, clock, reset):

#     W = len(random_word)

#     @instance
#     def logic():
#         lfsr = intbv(0)[64:]
#         word =  intbv(0)[W:]
#         while True:
#             yield clock.posedge, reset.posedge
#             if reset == 1:
#                 random_word.next = 0
#                 lfsr[:] = 0
#                 lfsr[63] = 1
#             else:
#                 if enable:
#                     for i in range(W):
#                         word[i] = lfsr[0]
#                         tmp63 = lfsr[0] ^ lfsr[1] ^ lfsr[3] ^ lfsr[4]
#                         lfsr >>= 1
#                         lfsr[63] = tmp63
#                     random_word.next = word

#     return logic