mirror of
https://github.com/myhdl/myhdl.git
synced 2024-12-14 07:44:38 +08:00
31 lines
638 B
Python
31 lines
638 B
Python
|
from myhdl import intbv
|
||
|
concat = intbv.concat # shorthand
|
||
|
|
||
|
COSET = 0x55
|
||
|
|
||
|
def calculateHec(header):
|
||
|
""" Return ATM hec for a header.
|
||
|
|
||
|
header -- intbv ATM header
|
||
|
"""
|
||
|
hec = intbv(0)
|
||
|
for bit in header[32:]:
|
||
|
hec[8:] = concat(hec[7:2],
|
||
|
bit ^ hec[1] ^ hec[7],
|
||
|
bit ^ hec[0] ^ hec[7],
|
||
|
bit ^ hec[7]
|
||
|
)
|
||
|
return hec ^ COSET
|
||
|
|
||
|
|
||
|
|
||
|
headers = ( 0x00000000,
|
||
|
0x01234567,
|
||
|
0xbac6f4ca
|
||
|
)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
for header in headers:
|
||
|
print hex(calculateHec(intbv(header)))
|
||
|
|