2019-04-30 13:58:31 +00:00
|
|
|
[![Build Status](https://travis-ci.com/olagrottvik/encdec8b10b.svg?token=jVu3gMDvjaqfNCVgNVai&branch=master)](https://travis-ci.com/olagrottvik/encdec8b10b)
|
|
|
|
|
2019-04-28 15:11:06 +00:00
|
|
|
# encdec8b10b
|
|
|
|
|
|
|
|
Encode and decode 8B10B encoding
|
|
|
|
|
2019-04-30 16:10:33 +00:00
|
|
|
## Get
|
|
|
|
|
|
|
|
```
|
|
|
|
python3 -m pip install encdec8b10b
|
|
|
|
```
|
|
|
|
|
2019-04-28 15:11:06 +00:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
### Encode Data Byte
|
|
|
|
```
|
|
|
|
from encdec8b10b import EncDec8B10B
|
|
|
|
|
|
|
|
running_disp = 0
|
|
|
|
byte_to_enc = 0xf
|
|
|
|
running_disp, encoded = EncDec8B10B.enc_8b10b(byte_to_enc, running_disp)
|
|
|
|
print(hex(encoded))
|
2019-04-28 15:15:02 +00:00
|
|
|
Output >> 0xba
|
2019-04-28 15:11:06 +00:00
|
|
|
```
|
|
|
|
### Encode Control Byte
|
|
|
|
```
|
|
|
|
from encdec8b10b import EncDec8B10B
|
|
|
|
|
|
|
|
running_disp = 0
|
|
|
|
byte_to_enc = 0xbc # comma
|
|
|
|
ctrl = 1
|
|
|
|
running_disp, encoded = EncDec8B10B.enc_8b10b(byte_to_enc, running_disp, ctrl)
|
|
|
|
print(hex(encoded))
|
2019-04-28 15:15:02 +00:00
|
|
|
Output >> 0x17c
|
2019-04-28 15:11:06 +00:00
|
|
|
```
|
|
|
|
### Decode Data Byte
|
|
|
|
```
|
|
|
|
from encdec8b10b import EncDec8B10B
|
|
|
|
|
|
|
|
byte_to_dec = 0xba
|
|
|
|
ctrl, decoded = EncDec8B10B.dec_8b10b(byte_to_dec)
|
|
|
|
print(hex(decoded))
|
2019-04-28 15:15:02 +00:00
|
|
|
Output >> 0xf
|
2019-04-28 15:11:06 +00:00
|
|
|
# ctrl variable confirm that it was a data byte
|
|
|
|
print(ctrl)
|
2019-04-28 15:15:02 +00:00
|
|
|
Output >> 0
|
2019-04-28 15:11:06 +00:00
|
|
|
```
|
|
|
|
### Decode Control Byte
|
|
|
|
```
|
|
|
|
from encdec8b10b import EncDec8B10B
|
|
|
|
|
|
|
|
byte_to_dec = 0x17c # comma encoded
|
|
|
|
ctrl, decoded = EncDec8B10B.dec_8b10b(byte_to_dec)
|
|
|
|
print(hex(decoded))
|
2019-04-28 15:15:02 +00:00
|
|
|
Output >> 0xbc
|
2019-04-28 15:11:06 +00:00
|
|
|
# ctrl variable confirm that it was a control byte
|
|
|
|
print(ctrl)
|
2019-04-28 15:15:02 +00:00
|
|
|
Output >> 1
|
2019-04-28 15:11:06 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Verbosity
|
|
|
|
Both functions have a verbose-mode to make it easier to confirm everything that's happening:
|
|
|
|
```
|
|
|
|
from encdec8b10b import EncDec8B10B
|
|
|
|
|
|
|
|
running_disp = 0
|
|
|
|
byte_to_enc = 0xA0
|
|
|
|
running_disp, encoded = EncDec8B10B.enc_8b10b(byte_to_enc, running_disp, verbose=True)
|
2019-04-28 15:15:02 +00:00
|
|
|
|
|
|
|
Output >> Encoder - In: A0 - Encoded: 146 - Running Disparity: 0
|
2019-04-28 15:11:06 +00:00
|
|
|
|
|
|
|
ctrl, decoded = EncDec8B10B.dec_8b10b(encoded, verbose=True)
|
2019-04-28 15:15:02 +00:00
|
|
|
|
|
|
|
Output >> Decoded: A0 - Control: 0
|
2019-04-28 15:11:06 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 8B10B
|
|
|
|
8B10B Encoding were implemented by Al Widmer and Peter Franaszek in 1983. It is still widely used in high-speed electronics.
|
|
|
|
|
|
|
|
- [Original article](https://ieeexplore.ieee.org/document/5390392)
|
|
|
|
- [Wikipedia](https://en.wikipedia.org/wiki/8b/10b_encoding)
|
|
|
|
|
|
|
|
|
|
|
|
### Thanks
|
|
|
|
- [Ryu Shinhyung](https://opencores.org/projects/async_8b10b_encoder_decoder) for creating the tables used in this module
|
2019-04-28 15:15:02 +00:00
|
|
|
- [Chuck Benz](http://asics.chuckbenz.com/) for creating awesome combinational 8B10B modules
|
2019-04-28 15:11:06 +00:00
|
|
|
- [Alex Forencich](http://www.alexforencich.com/wiki/en/scripts/matlab/enc8b10b) for his 8B10B Matlab script
|