Add the code and some other stuff

This commit is contained in:
ogre 2019-04-28 17:11:06 +02:00
parent 6f7c8b50e1
commit 1d0f5ccf51
5 changed files with 2267 additions and 1 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.idea
__pycache__
build/

79
README.md Normal file → Executable file
View File

@ -1 +1,78 @@
# encdec_8b10b
# encdec8b10b
Encode and decode 8B10B encoding
## 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))
0xba
```
### 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))
0x17c
```
### Decode Data Byte
```
from encdec8b10b import EncDec8B10B
byte_to_dec = 0xba
ctrl, decoded = EncDec8B10B.dec_8b10b(byte_to_dec)
print(hex(decoded))
0xf
# ctrl variable confirm that it was a data byte
print(ctrl)
0
```
### Decode Control Byte
```
from encdec8b10b import EncDec8B10B
byte_to_dec = 0x17c # comma encoded
ctrl, decoded = EncDec8B10B.dec_8b10b(byte_to_dec)
print(hex(decoded))
0xbc
# ctrl variable confirm that it was a control byte
print(ctrl)
1
```
### 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)
Encoder - In: A0 - Encoded: 146 - Running Disparity: 0
ctrl, decoded = EncDec8B10B.dec_8b10b(encoded, verbose=True)
Decoded: A0 - Control: 0
```
## 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
- [Chuck Benz](http://asics.chuckbenz.com/) for creating awesome combinatorial 8B10B modules
- [Alex Forencich](http://www.alexforencich.com/wiki/en/scripts/matlab/enc8b10b) for his 8B10B Matlab script

1
encdec8b10b/__init__.py Executable file
View File

@ -0,0 +1 @@
from .core import EncDec_8B10B as EncDec8B10B

2168
encdec8b10b/core.py Executable file

File diff suppressed because it is too large Load Diff

17
setup.py Executable file
View File

@ -0,0 +1,17 @@
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name='encdec_8b10b',
version='1.0-alpha',
packages=setuptools.find_packages(),
url='https://github.com/olagrottvik/encdec_8b10b',
license='MIT',
author='Ola Grøttvik',
author_email='olagrottvik@gmail.com',
description='8B10B Encoding and Decoding',
long_description=long_description,
long_description_content_type="text/markdown",
)