Advertisement
Guest User

Untitled

a guest
Apr 13th, 2020
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. class Rotator(Elaboratable):
  2. def __init__(self, datain, dataout, rotation=0, comb=True):
  3. assert len(datain) == len(dataout)
  4.  
  5. self.datain = datain
  6. self.dataout = dataout
  7. self.rotation = rotation
  8. self.comb = comb
  9.  
  10. self.ports = [
  11. self.datain,
  12. self.dataout,
  13. self.rotation,
  14. ]
  15.  
  16. def elaborate(self, platform):
  17. m = Module()
  18.  
  19. length = len(self.datain)
  20. with m.Switch(self.rotation):
  21. for i in range(length):
  22. with m.Case(i):
  23. if self.comb:
  24. m.d.comb += self.dataout.eq(Cat(self.datain[i:length], self.datain[0:i]))
  25. else:
  26. m.d.sync += self.dataout.eq(Cat(self.datain[i:length], self.datain[0:i]))
  27.  
  28. return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement