Source code for usbcore.tx.shifter

#!/usr/bin/env python3

import unittest

from migen import *

from migen.fhdl.decorators import CEInserter, ResetInserter

from ..utils.packet import b
from ..test.common import BaseUsbTestCase


[docs]@ResetInserter() @CEInserter() class TxShifter(Module): """Transmit Shifter TxShifter accepts parallel data and shifts it out serially. Parameters ---------- Parameters are passed in via the constructor. width : int Width of the data to be shifted. Input Ports ----------- Input ports are passed in via the constructor. i_data : Signal(width) Data to be transmitted. Output Ports ------------ Output ports are data members of the module. All outputs are flopped. o_data : Signal(1) Serial data output. o_empty : Signal(1) Asserted the cycle before the shifter loads in more i_data. o_get : Signal(1) Asserted the cycle after the shifter loads in i_data. """ def __init__(self, width): self.i_data = Signal(width) self.o_get = Signal(1) self.o_empty = Signal(1) self.o_data = Signal(1) shifter = Signal(width) pos = Signal(width, reset=0b1) empty = Signal(1) self.sync += [ pos.eq(pos >> 1), shifter.eq(shifter >> 1), If(empty, shifter.eq(self.i_data), pos.eq(1 << (width-1)), ), self.o_get.eq(empty), ] self.comb += [ empty.eq(pos[0]), self.o_empty.eq(empty), self.o_data.eq(shifter[0]), ]