Created
January 10, 2012 18:57
-
-
Save buhii/1590518 to your computer and use it in GitHub Desktop.
drw_analyzer.py - smaller layout
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
GRID = (24, 16) | |
BUS_STRIPE = 3 | |
class Wave(object): | |
@classmethod | |
def clk(cls, num): | |
ret = [] | |
for i in range(num): | |
ret.append((i + 1) % 2) | |
return ret | |
def __init__(self, name, data, bit_range=1, domain=False, stripe=BUS_STRIPE): | |
self.name = name | |
self.data = data | |
self.bit_range = bit_range | |
self.domain = domain | |
self.stripe = stripe | |
def draw_bit(self): | |
last_data = self.data[0] | |
l = self.domain if self.domain else GRID[0] | |
for i, x in enumerate(self.data): | |
if last_data != x: | |
if last_data in (0, "0", "_"): | |
line(i * l, GRID[1], i * l + self.stripe, 0) | |
else: | |
line(i * l, 0, i * l + self.stripe, GRID[1]) | |
if x in (0, "0", "_"): | |
line(i * l + self.stripe, GRID[1], (i + 1) * l, GRID[1]) | |
else: | |
line(i * l + self.stripe, 0, (i + 1) * l, 0) | |
else: | |
if x in (0, "0", "_"): | |
line(i * l, GRID[1], (i + 1) * l, GRID[1]) | |
else: | |
line(i * l, 0, (i + 1) * l, 0) | |
last_data = x | |
def draw_bus(self): | |
last_data = self.data[0] | |
l = self.domain if self.domain else GRID[0] | |
for i, x in enumerate(self.data): | |
if last_data != x: | |
line(i * l, 0, i * l + self.stripe, GRID[1]) | |
line(i * l, GRID[1], i * l+ self.stripe, 0) | |
line(i * l + self.stripe, 0, (i + 1) * l, 0) | |
line(i * l + self.stripe, GRID[1], (i + 1) * l, GRID[1]) | |
else: | |
line(i * l, 0, (i + 1) * l, 0) | |
line(i * l, GRID[1], (i + 1) * l, GRID[1]) | |
if last_data != x or i == 0: | |
text(x, i * l + self.stripe + 2, GRID[1] / 2 + 4) | |
last_data = x | |
def draw(self): | |
if not self.data: return | |
if self.bit_range == 1 and not (set(self.data) - set([0, 1, '0', '1', '_', '-', '^'])): | |
self.draw_bit() | |
else: | |
self.draw_bus() | |
def draw(*waves, **kwargs): | |
# get max label's width | |
label_width = 0 | |
for wave in waves: | |
label_width = max(label_width, textwidth(wave.name)) | |
label_width += GRID[1] | |
# draw grids | |
if 'width' in kwargs: | |
stroke(0.9) | |
translate(label_width) | |
for i in range(0, 30, kwargs['width']): | |
line(i * GRID[0], 0, i * GRID[0], len(waves) * 2 * GRID[1]) | |
translate(-label_width) | |
# draw waves | |
stroke(0.4) | |
for i, wave in enumerate(waves): | |
if wave.name.startswith("("): | |
fill(0.7, 0.1, 0.1) | |
else: | |
fill(0.3) | |
text(wave.name, 5, GRID[1] / 2 + 5) | |
fill(0.3) | |
translate(label_width, 0) | |
wave.draw() | |
translate(-label_width, GRID[1] * 2) | |
# main | |
size(1024, 420) # 480 | |
print "processing..." | |
fill(0.2) | |
stroke(0.2) | |
strokewidth(1) | |
font("Helvetica", 12) | |
translate(10, 20) | |
def _(prev, it): | |
return map(lambda c: prev + str(c), it) | |
def flatten(l): | |
return map(lambda t: ''.join(t), l) | |
def split(s): | |
return flatten(zip(s[0::2], s[1::2])) | |
def stretch(l, n): | |
ret = [] | |
for t in l: | |
for i in range(n): | |
ret.append(t) | |
return ret | |
DOMAIN_CLK = GRID[0] / 2 | |
draw( | |
Wave("CLK", Wave.clk(80), domain=DOMAIN_CLK, stripe=0), | |
Wave("RST_X", | |
"1111111111111111111111111111111"), | |
Wave("EXE", | |
"001111111111111111111111111111"), | |
Wave("AN_STATE", | |
["S_IDLE"] * 3 + ["S_RUN"] * 18 + ["S_BITBLT"] * 4 + ["S_IDLE"] * 5), | |
Wave("(CMDBUF_RD", | |
"000111111111111111110000100"), | |
Wave("DRAWCMD[31:24]", | |
["X"] * 4 + [20, "_", "_", 21, "_", "_", | |
30, 31, "_", "_", 32, 23, "_", | |
82] + ["_"] * 3 + ["_x"] * 4 + ["0F"] + ["X"]), | |
Wave("(C_CMDWAIT)", | |
"000021021002100103210000000"), | |
Wave("(is_cmd_start)", | |
"000010010011001101000000010"), | |
Wave("(is_processed)", | |
"000000000000000001111111100000"), | |
Wave("(CMDTYPE)", | |
["NOP"] * 4 + ["FR"] * 3 + ["DA"] * 3 + | |
["MO"] + ["SC"] * 3 + ["BO"] + ["FC"] * 2 + | |
["BITBLT"] * 8 + ["EODL"]), | |
width=1) | |
print "completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment