usbcore.rx package¶
Submodules¶
usbcore.rx.bitstuff module¶
-
class
usbcore.rx.bitstuff.
RxBitstuffRemover
(*args, **kwargs)[source]¶ Bases:
usbcore.rx.bitstuff.RxBitstuffRemover
RX Bitstuff Removal
Long sequences of 1’s would cause the receiver to lose it’s lock on the transmitter’s clock. USB solves this with bitstuffing. A ‘0’ is stuffed after every 6 consecutive 1’s. This extra bit is required to recover the clock, but it should not be passed on to higher layers in the device.
https://www.pjrc.com/teensy/beta/usb20.pdf, USB2 Spec, 7.1.9 https://en.wikipedia.org/wiki/Bit_stuffing
usb_12 : 12MHz
- i_valid : Signal(1)
- Qualifier for all of the input signals. Indicates one bit of valid data is present on the inputs.
- i_data : Signal(1)
- Decoded data bit from USB bus. Qualified by valid.
- o_data : Signal(1)
- Decoded data bit from USB bus.
- o_stall : Signal(1)
- Indicates the bit stuffer just removed an extra bit, so no data available.
- o_error : Signal(1)
- Indicates there has been a bitstuff error. A bitstuff error occurs when there should be a stuffed ‘0’ after 6 consecutive 1’s; but instead of a ‘0’, there is an additional ‘1’. This is normal during IDLE, but should never happen within a packet. Qualified by valid.
-
get_fragment
()¶
usbcore.rx.bitstuff_test module¶
usbcore.rx.clock module¶
-
class
usbcore.rx.clock.
RxClockDataRecovery
(usbp_raw, usbn_raw)[source]¶ Bases:
migen.fhdl.module.Module
RX Clock Data Recovery module.
RxClockDataRecovery synchronizes the USB differential pair with the FPGAs clocks, de-glitches the differential pair, and recovers the incoming clock and data.
usb_48 : 48MHz
Input ports are passed in via the constructor.
- usbp_raw : Signal(1)
- Raw USB+ input from the FPGA IOs, no need to synchronize.
- usbn_raw : Signal(1)
- Raw USB- input from the FPGA IOs, no need to synchronize.
Output ports are data members of the module. All output ports are flopped. The line_state_dj/dk/se0/se1 outputs are 1-hot encoded.
- line_state_valid : Signal(1)
- Asserted for one clock when the output line state is ready to be sampled.
- line_state_dj : Signal(1)
- Represents Full Speed J-state on the incoming USB data pair. Qualify with line_state_valid.
- line_state_dk : Signal(1)
- Represents Full Speed K-state on the incoming USB data pair. Qualify with line_state_valid.
- line_state_se0 : Signal(1)
- Represents SE0 on the incoming USB data pair. Qualify with line_state_valid.
- line_state_se1 : Signal(1)
- Represents SE1 on the incoming USB data pair. Qualify with line_state_valid.
usbcore.rx.clock_test module¶
usbcore.rx.crc module¶
-
class
usbcore.rx.crc.
RxCrcChecker
(*args, **kwargs)[source]¶ Bases:
usbcore.rx.crc.RxCrcChecker
CRC Checker
Checks the CRC of a serial stream of data.
https://www.pjrc.com/teensy/beta/usb20.pdf, USB2 Spec, 8.3.5 https://en.wikipedia.org/wiki/Cyclic_redundancy_check
Parameters: - are passed in via the constructor. (Parameters) –
- width (int) – Width of the CRC.
- polynomial (int) – CRC polynomial in integer form.
- initial (int) – Initial value of the CRC register before data starts shifting in.
- residual (int) – Value of the CRC register if all the shifted in data is valid.
- Ports (Output) –
- ------------ –
- i_data (Signal(1)) – Decoded data bit from USB bus. Qualified by valid.
- i_reset (Signal(1)) – Resets the CRC calculation back to the initial state.
- i_valid (Signal(1)) – Indicate that i_data is valid and a CRC should be calculated
- Ports –
- ------------ –
- o_crc_good (Signal()) – CRC value is good.
-
get_fragment
()¶
usbcore.rx.crc_test module¶
usbcore.rx.detect module¶
-
class
usbcore.rx.detect.
RxPacketDetect
(*args, **kwargs)[source]¶ Bases:
usbcore.rx.detect.RxPacketDetect
Packet Detection
Full Speed packets begin with the following sequence:
KJKJKJKKThis raw sequence corresponds to the following data:
00000001The bus idle condition is signaled with the J state:
JJJJJJJJThis translates to a series of ‘1’s since there are no transitions. Given this information, it is easy to detect the beginning of a packet by looking for 00000001.
The end of a packet is even easier to detect. The end of a packet is signaled with two SE0 and one J. We can just look for the first SE0 to detect the end of the packet.
Packet detection can occur in parallel with bitstuff removal.
https://www.pjrc.com/teensy/beta/usb20.pdf, USB2 Spec, 7.1.10
- i_valid : Signal(1)
- Qualifier for all of the input signals. Indicates one bit of valid data is present on the inputs.
- i_data : Signal(1)
- Decoded data bit from USB bus. Qualified by valid.
- i_se0 : Signal(1)
- Indicator for SE0 from USB bus. Qualified by valid.
- o_pkt_start : Signal(1)
- Asserted for one clock on the last bit of the sync.
- o_pkt_active : Signal(1)
- Asserted while in the middle of a packet.
- o_pkt_end : Signal(1)
- Asserted for one clock after the last data bit of a packet was received.
-
get_fragment
()¶
usbcore.rx.detect_test module¶
usbcore.rx.nrzi module¶
-
class
usbcore.rx.nrzi.
RxNRZIDecoder
[source]¶ Bases:
migen.fhdl.module.Module
RX NRZI decoder.
In order to ensure there are enough bit transitions for a receiver to recover the clock usb uses NRZI encoding. This module processes the incoming dj, dk, se0, and valid signals and decodes them to data values. It also pipelines the se0 signal and passes it through unmodified.
https://www.pjrc.com/teensy/beta/usb20.pdf, USB2 Spec, 7.1.8 https://en.wikipedia.org/wiki/Non-return-to-zero
usb_48 : 48MHz
Input ports are passed in via the constructor.
- i_valid : Signal(1)
- Qualifier for all of the input signals. Indicates one bit of valid data is present on the inputs.
- i_dj : Signal(1)
- Indicates the bus is currently in a Full-Speed J-state. Qualified by valid.
- i_dk : Signal(1)
- Indicates the bus is currently in a Full-Speed K-state. Qualified by valid.
- i_se0 : Signal(1)
- Indicates the bus is currently in a SE0 state. Qualified by valid.
Output ports are data members of the module. All output ports are flopped.
- o_valid : Signal(1)
- Qualifier for all of the output signals. Indicates one bit of valid data is present on the outputs.
- o_data : Signal(1)
- Decoded data bit from USB bus. Qualified by valid.
- o_se0 : Signal(1)
- Indicates the bus is currently in a SE0 state. Qualified by valid.
usbcore.rx.nrzi_test module¶
usbcore.rx.pipeline module¶
usbcore.rx.pipeline_test module¶
usbcore.rx.shifter module¶
-
class
usbcore.rx.shifter.
RxShifter
(*args, **kwargs)[source]¶ Bases:
usbcore.rx.shifter.RxShifter
RX Shifter
A shifter is responsible for shifting in serial bits and presenting them as parallel data. The shifter knows how many bits to shift and has controls for resetting the shifter.
usb_12 : 12MHz
Parameters: - are passed in via the constructor. (Parameters) –
- width (int) – Number of bits to shift in.
- Ports (Output) –
- ----------- –
- i_valid (Signal(1)) – Qualifier for all of the input signals. Indicates one bit of valid data is present on the inputs.
- i_data (Signal(1)) – Serial input data. Qualified by valid.
- Ports –
- ------------ –
- o_data (Signal(width)) – Shifted in data.
- o_put (Signal(1)) – Asserted for one clock once the register is full.
-
get_fragment
()¶