usbcore.tx package¶
Submodules¶
usbcore.tx.bitstuff module¶
-
class
usbcore.tx.bitstuff.
TxBitstuffer
(*args, **kwargs)[source]¶ Bases:
usbcore.tx.bitstuff.TxBitstuffer
Bitstuff Insertion
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.
The TxBitstuffer is the only component in the transmit pipeline that can delay transmission of serial data. It is therefore responsible for generating the bit_strobe signal that keeps the pipe moving forward.
https://www.pjrc.com/teensy/beta/usb20.pdf, USB2 Spec, 7.1.9 https://en.wikipedia.org/wiki/Bit_stuffing
usb_12 : 48MHz
- i_data : Signal(1)
- Data bit to be transmitted on USB.
- o_data : Signal(1)
- Data bit to be transmitted on USB.
- o_stall : Signal(1)
- Used to apply backpressure on the tx pipeline.
-
get_fragment
()¶
usbcore.tx.bitstuff_test module¶
-
class
usbcore.tx.bitstuff_test.
TestTxBitstuffer
(methodName='runTest')[source]¶ Bases:
usbcore.test.common.BaseUsbTestCase
-
do
(**test_args)¶
-
usbcore.tx.crc module¶
-
class
usbcore.tx.crc.
TxSerialCrcGenerator
(*args, **kwargs)[source]¶ Bases:
usbcore.tx.crc.TxSerialCrcGenerator
Transmit CRC Generator
TxSerialCrcGenerator generates a running CRC.
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.
- Ports (Output) –
- ------------ –
- i_data (Signal(1)) – Serial data to generate CRC for.
- Ports –
- ------------ –
- o_crc (Signal(width)) – Current CRC value.
-
get_fragment
()¶
-
usbcore.tx.crc.
bytes_to_int
(d)[source]¶ Convert a list of bytes to an int
Bytes are in LSB first.
>>> hex(bytes_to_int([0, 1])) '0x100' >>> hex(bytes_to_int([1, 2])) '0x201'
-
usbcore.tx.crc.
cols
(rows)[source]¶ >>> a = [ ... [1, 2], ... ['a', 'b'], ... [4, 5], ... ] >>> for c in cols(a): ... print(c) [1, 'a', 4] [2, 'b', 5] >>> a = [ ... [1, 2, 3], ... ['a', 'b', 'c'], ... ] >>> for c in cols(a): ... print(c) [1, 'a'] [2, 'b'] [3, 'c']
-
usbcore.tx.crc.
lfsr_serial_shift_crc
(lfsr_poly, lfsr_cur, data)[source]¶ shift_by == num_data_bits len(data_cur) == num_data_bits >>> for i in range(5): … l = [0]*5; l[i] = 1 … r = lfsr_serial_shift_crc( … lfsr_poly=[0,0,1,0,1], # (5, 2, 0) … lfsr_cur=l, … data=[0,0,0,0], … ) … print(“Min[%i] =” % i, r) Min[0] = [1, 0, 0, 0, 0] Min[1] = [0, 0, 1, 0, 1] Min[2] = [0, 1, 0, 1, 0] Min[3] = [1, 0, 1, 0, 0] Min[4] = [0, 1, 1, 0, 1] >>> for i in range(4): … d = [0]*4; d[i] = 1 … r = lfsr_serial_shift_crc( … lfsr_poly=[0,0,1,0,1], # (5, 2, 0) … lfsr_cur=[0,0,0,0,0], … data=d, … ) … print(“Nin[%i] =” % i, r) Nin[0] = [0, 0, 1, 0, 1] Nin[1] = [0, 1, 0, 1, 0] Nin[2] = [1, 0, 1, 0, 0] Nin[3] = [0, 1, 1, 0, 1]
-
usbcore.tx.crc.
print_matrix
(crc_width, cols_nin, cols_min)[source]¶ >>> crc_width = 5 >>> data_width = 4 >>> poly_list = [0, 0, 1, 0, 1] >>> _, cols_nin, cols_min = build_matrix(poly_list, data_width) >>> print_matrix(crc_width, cols_nin, cols_min) 0 d[ 0], , , d[ 3], , c[ 1], , , c[ 4] 1 , d[ 1], , , , , c[ 2], , 2 d[ 0], , d[ 2], d[ 3], , c[ 1], , c[ 3], c[ 4] 3 , d[ 1], , d[ 3], , , c[ 2], , c[ 4] 4 , , d[ 2], , c[ 0], , , c[ 3],
-
usbcore.tx.crc.
build_matrix
(lfsr_poly, data_width)[source]¶ >>> print("\n".join(build_matrix([0,0,1,0,1], 4)[0])) lfsr([0, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0]) = [0, 0, 1, 0, 1] lfsr([0, 0, 1, 0, 1], [0, 0, 0, 0, 0], [0, 1, 0, 0]) = [0, 1, 0, 1, 0] lfsr([0, 0, 1, 0, 1], [0, 0, 0, 0, 0], [0, 0, 1, 0]) = [1, 0, 1, 0, 0] lfsr([0, 0, 1, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 1]) = [0, 1, 1, 0, 1] <BLANKLINE> lfsr([0, 0, 1, 0, 1], [1, 0, 0, 0, 0], [0, 0, 0, 0]) = [1, 0, 0, 0, 0] lfsr([0, 0, 1, 0, 1], [0, 1, 0, 0, 0], [0, 0, 0, 0]) = [0, 0, 1, 0, 1] lfsr([0, 0, 1, 0, 1], [0, 0, 1, 0, 0], [0, 0, 0, 0]) = [0, 1, 0, 1, 0] lfsr([0, 0, 1, 0, 1], [0, 0, 0, 1, 0], [0, 0, 0, 0]) = [1, 0, 1, 0, 0] lfsr([0, 0, 1, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0]) = [0, 1, 1, 0, 1] <BLANKLINE> Mout[4] = [0, 0, 1, 0] [1, 0, 0, 1, 0] Mout[3] = [0, 1, 0, 1] [0, 0, 1, 0, 1] Mout[2] = [1, 0, 1, 1] [0, 1, 0, 1, 1] Mout[1] = [0, 1, 0, 0] [0, 0, 1, 0, 0] Mout[0] = [1, 0, 0, 1] [0, 1, 0, 0, 1]
-
class
usbcore.tx.crc.
TxParallelCrcGenerator
(*args, **kwargs)[source]¶ Bases:
usbcore.tx.crc.TxParallelCrcGenerator
Transmit CRC Generator
TxParallelCrcGenerator generates a running CRC.
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.
- Ports (Output) –
- ------------ –
- i_data_payload (Signal(8)) – Byte wide data to generate CRC for.
- i_data_strobe (Signal(1)) – Strobe signal for the payload.
- Ports –
- ------------ –
- o_crc (Signal(width)) – Current CRC value.
-
get_fragment
()¶
usbcore.tx.crc_test module¶
-
class
usbcore.tx.crc_test.
TestTxSerialCrcGenerator
(methodName='runTest')[source]¶ Bases:
usbcore.test.common.BaseUsbTestCase
-
do
(**test_args)¶
-
-
class
usbcore.tx.crc_test.
TestCrcPipeline
(methodName='runTest')[source]¶ Bases:
usbcore.test.common.BaseUsbTestCase
-
maxDiff
= None¶
-
usbcore.tx.nrzi module¶
-
class
usbcore.tx.nrzi.
TxNRZIEncoder
[source]¶ Bases:
migen.fhdl.module.Module
NRZI Encode
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
- i_valid : Signal(1)
- Qualifies oe, data, and se0.
- i_oe : Signal(1)
- Indicates that the transmit pipeline should be driving USB.
- i_data : Signal(1)
- Data bit to be transmitted on USB. Qualified by o_valid.
- i_se0 : Signal(1)
- Overrides value of o_data when asserted and indicates that SE0 state should be asserted on USB. Qualified by o_valid.
- o_usbp : Signal(1)
- Raw value of USB+ line.
- o_usbn : Signal(1)
- Raw value of USB- line.
- o_oe : Signal(1)
- When asserted it indicates that the tx pipeline should be driving USB.
usbcore.tx.nrzi_test module¶
usbcore.tx.pipeline module¶
usbcore.tx.pipeline_test module¶
-
class
usbcore.tx.pipeline_test.
TestTxPipeline
(methodName='runTest')[source]¶ Bases:
usbcore.test.common.BaseUsbTestCase
-
maxDiff
= None¶
-
usbcore.tx.shifter module¶
-
class
usbcore.tx.shifter.
TxShifter
(*args, **kwargs)[source]¶ Bases:
usbcore.tx.shifter.TxShifter
Transmit Shifter
TxShifter accepts parallel data and shifts it out serially.
Parameters: - are passed in via the constructor. (Parameters) –
- width (int) – Width of the data to be shifted.
- Ports (Output) –
- ----------- –
- ports are passed in via the constructor. (Input) –
- i_data (Signal(width)) – Data to be transmitted.
- Ports –
- ------------ –
- ports are data members of the module. All outputs are flopped. (Output) –
- 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.
-
get_fragment
()¶