Created
February 8, 2019 13:14
-
-
Save pcornier/ede3fe42803a4f4e89674a2b7a042c62 to your computer and use it in GitHub Desktop.
Signals in jupyter notebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import HTML | |
from Verilog_VCD import Verilog_VCD as vcd | |
dump = vcd.parse_vcd('./dump.vcd') | |
# make some signals more readable | |
resolvers = { | |
'ir': lambda v: opc._fields[int(v,2)] if len(opc)>=int(v,2) else str(hex(int(v,2))), | |
'cyc': lambda v: (['F1','F2','D','E','M1','M2'][int(v,2)],['#faa','#faa','#aaf','#faf','#0f0','#0f0'][int(v,2)]) | |
} | |
selection = ['ra', 'rx', 'pc', 'ir', 'di', 'adr', 'clk', 'cyc', 'rst'] | |
waves = '' | |
names = '' | |
ticks = '' | |
start = min([d[1]['tv'][-1][0] for d in dump.items()]) | |
stop = max([d[1]['tv'][-1][0] for d in dump.items()]) | |
for i in range(start,stop): ticks += f'<span class="tick">{i}</span>' | |
for n,d in dump.items(): | |
name = d['nets'][0]['name'] | |
size = d['nets'][0]['size'] | |
if name in selection: | |
wave = '' | |
pv = d['tv'][0][1] | |
pc = 'white' | |
for i in range(start, stop): | |
if len(d['tv']): | |
t,v = d['tv'][0] | |
else: t = -1 | |
if int(size) == 1: | |
cls = '' | |
if i == t: | |
del d['tv'][0] | |
cls = 'bc' if pv != v else '' | |
pv = v | |
else: | |
v = pv | |
if int(v) == 1: | |
wave += f'<span class="b1 {cls}"></span>' | |
else: | |
wave += f'<span class="b0 {cls}"></span>' | |
else: | |
c = pc | |
if i == t: | |
del d['tv'][0] | |
if name in resolvers: | |
v = resolvers[name](v) | |
if isinstance(v, tuple): v,c = v | |
pc = c | |
else: | |
v = str(hex(int(v, 2))) | |
wave += f'<span class="value" style="background-color:{c}">{v}</span>' | |
else: | |
wave += f'<span class="fill" style="background-color:{c}"></span>' | |
names += f'<span class="name">{name}</span>' | |
waves += wave + '<br>' | |
css = """<style> | |
.waves{width:max-content;width:-moz-max-content;margin-left:40px;overflow:hidden;background-image: | |
url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAUCAYAAAD/Rn+7AAAAQUlEQVRIS+3SwQkAMAzDQGWm7j9Cd+oQ+pSg/A3h7AEOcPn0pgdlMwlKQBJM0ArYfBtM0ArYfBtM0ArYfBtcL/gAGlIUFdA8RdcAAAAASUVORK5CYII=')} | |
.ticks{width:max-content;width:-moz-max-content;margin-left:40px;font-size:10px} | |
.tick{display:inline-block;width:40px;overflow:hidden} | |
.names{width:40px;position:absolute;z-index:10;margin-top:2px;margin-left:-6px;text-align:right} | |
span.name{display:block;background-color:white;font-size:10px;height:23px} | |
span.fill,span.value{display:inline-block;width:40px;height:20px;margin-top:2px;font-size:10px; | |
border-top:1px solid #000;border-bottom:1px solid #000;position:relative;box-sizing:border-box;padding-left:5px; | |
line-height:20px;vertical-align:middle} | |
span.value:before{content:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAUCAYAAAC07qxWAAAAXElEQVQ4T62TUQoAIAhD9f6HNhYpZWEK+utjm5lMRCIiFBWjFhDCwMoghJ+qy9SsS+AFqxoamlGHPuwj0FR36KVYAifsY/mMljUDzoHaMqafJwX27rr3P35PAVsYVTpKDYc2sIoAAAAASUVORK5CYII=');position:absolute; | |
font-size:16px;left:-5px;line-height:15px;top:-1px;} | |
.b0{border-bottom:1px solid #000;width:40px;height:16px;display:inline-block;margin-top:4px;box-sizing:border-box} | |
.b1{border-top:1px solid #000;width:40px;display:inline-block;height:16px;margin-top:4px;box-sizing:border-box} | |
.bc{border-left:1px solid #000} | |
</style> | |
""" | |
HTML( | |
css | |
+ '<div class="ticks">' + ticks + '</div>' | |
+ '<div class="names">' + names + '</div>' | |
+ '<div class="waves">' + waves + '</div>' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment