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

class usbcore.rx.bitstuff_test.TestRxBitstuffRemover(methodName='runTest')[source]

Bases: usbcore.test.common.BaseUsbTestCase

bitstuff_test(vector, short_name)[source]
test_no_bit_stuff()[source]
test_bit_stuff()[source]
test_bit_stuff_after_reset()[source]
test_bit_stuff_error()[source]
test_bit_stuff_error_after_reset()[source]
test_multiple_bit_stuff_scenario()[source]
test_mixed_bit_stuff_error()[source]
test_idle_packet_idle()[source]
test_idle_packet_idle_packet_idle()[source]
test_captured_setup_packet_no_stuff()[source]
test_valid_idle_packet_idle_packet_idle()[source]
test_valid_captured_setup_packet_no_stuff()[source]

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

class usbcore.rx.clock_test.TestRxClockDataRecovery(methodName='runTest')[source]

Bases: usbcore.test.common.BaseUsbTestCase

test_j()[source]
test_k()[source]
test_0()[source]
test_1()[source]
test_jk01()[source]
test_jjjkj0j1kjkkk0k10j0k00011j1k1011()[source]
test_kkkkk0k0kjjjk0kkkkjjjkjkjkjjj0kj()[source]
basic_recovery_test(seq, short_test=True)[source]

This test covers basic clock and data recovery.

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

class usbcore.rx.crc_test.TestRxCrcChecker(methodName='runTest')[source]

Bases: usbcore.test.common.BaseUsbTestCase

shifter_test(i, vector)[source]
test_usb2_token_with_good_crc5()[source]
test_usb2_token_with_good_crc5_and_pipeline_stalls()[source]
test_usb2_token_with_bad_crc5()[source]
test_usb2_token_with_good_crc5_2()[source]
test_usb2_token_with_bad_crc5_2()[source]
test_usb2_token_with_good_crc5_1_2()[source]
test_usb2_data_with_good_crc16()[source]
test_usb2_data_with_bad_crc16()[source]

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:

KJKJKJKK

This raw sequence corresponds to the following data:

00000001

The bus idle condition is signaled with the J state:

JJJJJJJJ

This 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

class usbcore.rx.detect_test.TestRxPacketDetect(methodName='runTest')[source]

Bases: usbcore.test.common.BaseUsbTestCase

packet_detect_test(vector, short_name)[source]
test_se0_idle()[source]
test_idle_packet_idle()[source]
test_idle_packet_idle_stall()[source]
test_idle_packet_idle_stalls()[source]
test_idle_packet_idle_packet_idle()[source]
test_idle_sync_idle()[source]
test_idle_glitch()[source]
test_valid_idle_packet_idle_packet_idle()[source]

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

class usbcore.rx.nrzi_test.TestRxNRZIDecoder(methodName='runTest')[source]

Bases: usbcore.test.common.BaseUsbTestCase

nrzi_test(vector, short_name)[source]
test_usb2_spec_7_1_8()[source]
test_usb2_spec_7_1_9_1()[source]
test_usb2_spec_7_1_9_1_stalls()[source]
test_usb2_spec_7_1_9_1_stalls_2()[source]
test_usb2_spec_7_1_9_1_stalls_3()[source]
test_usb2_spec_7_1_9_1_stalls_se0_glitch()[source]
test_captured_setup_packet()[source]
test_captured_setup_packet_stalls()[source]

usbcore.rx.pipeline module

class usbcore.rx.pipeline.RxPipeline[source]

Bases: migen.fhdl.module.Module

usbcore.rx.pipeline_test module

class usbcore.rx.pipeline_test.TestRxPipeline(methodName='runTest')[source]

Bases: usbcore.test.common.BaseUsbTestCase

pkt_decode_test(vector, name)[source]
test_usb2_sof_stuffed_mid()[source]
test_usb2_sof_stuffed_end()[source]
test_usb2_sof_token()[source]
test_usb2_sof_token_1()[source]
test_usb2_sof_token_eop_dribble_1()[source]
test_usb2_sof_token_eop_dribble_6()[source]
test_usb2_sof_token_bad_pid()[source]
test_usb2_sof_token_bad_crc5()[source]
test_usb2_ack_handshake()[source]
test_usb2_ack_handshake_pid_error()[source]
test_usb2_ack_handshake_eop_dribble_1()[source]
test_usb2_ack_handshake_eop_dribble_6()[source]
test_usb2_data_with_good_crc16()[source]
test_usb2_data_with_good_crc16_1_eop_dribble()[source]
test_usb2_data_with_good_crc16_6_eop_dribble()[source]
test_usb2_data_with_bad_crc16()[source]

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()

usbcore.rx.shifter_test module

class usbcore.rx.shifter_test.TestRxShifter(methodName='runTest')[source]

Bases: usbcore.test.common.BaseUsbTestCase

shifter_test(vector, short_name)[source]
test_basic_shift_in()[source]
test_basic_shift_in_1()[source]
test_basic_shift_in_2()[source]
test_basic_shift_in_3()[source]
test_basic_shift_in_4()[source]
test_basic_shift_in_5()[source]
test_basic_shift_in_6()[source]
test_basic_shift_in_7()[source]
test_basic_shift_in_2_bytes()[source]
test_multiple_resets()[source]
test_multiple_resets_tight_timing()[source]

Module contents