URL
https://opencores.org/ocsvn/myhdl_lfsr/myhdl_lfsr/trunk
Subversion Repositories myhdl_lfsr
[/] [myhdl_lfsr/] [trunk/] [lfsr_logic.py] - Rev 2
Compare with Previous | Blame | View Log
from myhdl import * from lfsr_tap_table import * import random #Author: Shawn Rainey # rainey.shawn@gmail.com #init_value must not be 0 def get_lfsr(width=32, init_value=1): if init_value == 0: raise SystemExit("LFSR May not be instantiated with initial zero value") tap_const = intbv(0)[width:] for i in lfsr_tap_table[width]: tap_const[i-1] = 1 def lfsr_module(reset, clock, lfsr_out): reg_internal = Signal(intbv(init_value)[width:]) @always_comb def assign_out(): lfsr_out.next = reg_internal @always_seq(clock.posedge, reset=reset) def lfsr_logic(): if reg_internal[0] == 1: #use of _val here may not be forward or backward compatible #with other versions of MyHDL #works with MyHDL 0.9.0 reg_internal.next = (reg_internal >> 1) ^ tap_const._val else: reg_internal.next = reg_internal >> 1 return instances() return lfsr_module