|
|
@@ -3,9 +3,10 @@ |
|
|
|
import re |
|
|
|
|
|
|
|
class ControlSymbol(int): |
|
|
|
pass |
|
|
|
def __repr__(self): |
|
|
|
return 'ControlSymbol(%#x)' % self |
|
|
|
|
|
|
|
class EncDec_8B10B(object): |
|
|
|
class EncDec8B10B(object): |
|
|
|
# Table 36-3 of 802.3-2018 has symbols for 1000Base-X coding |
|
|
|
|
|
|
|
COMMA = ControlSymbol(0xbc) |
|
|
@@ -2117,7 +2118,7 @@ class EncDec_8B10B(object): |
|
|
|
If a control byte is received, it is returned by itself as an |
|
|
|
instance of ControlSymbol. |
|
|
|
|
|
|
|
Note that it needs to receive an EncDec_8B10B.COMMA control byte |
|
|
|
Note that it needs to receive an EncDec8B10B.COMMA control byte |
|
|
|
first to establish sync, and then will data after that. |
|
|
|
''' |
|
|
|
|
|
|
@@ -2192,7 +2193,7 @@ class EncDec_8B10B(object): |
|
|
|
'''Encode a single byte to 10 bits.''' |
|
|
|
|
|
|
|
assert data_in <= 0xFF, "Data in must be maximum one byte" |
|
|
|
encoded = int(EncDec_8B10B.enc_lookup[( |
|
|
|
encoded = int(EncDec8B10B.enc_lookup[( |
|
|
|
ctrl << 9) + (running_disparity << 8) + data_in], 2) |
|
|
|
new_disparity = (encoded >> 10) & 1 |
|
|
|
encoded = encoded & 0x3FF |
|
|
@@ -2205,7 +2206,7 @@ class EncDec_8B10B(object): |
|
|
|
'''Decode 10 bits into a byte.''' |
|
|
|
|
|
|
|
assert data_in <= 0x3FF, "Data in must be maximum 10 bits" |
|
|
|
decoded = EncDec_8B10B.dec_lookup[(data_in)] |
|
|
|
decoded = EncDec8B10B.dec_lookup[(data_in)] |
|
|
|
if decoded == "DEC8b10bERR": |
|
|
|
raise Exception( |
|
|
|
"Input to 8B10B Decoder is not a 8B10B Encoded Word") |
|
|
|