OpenCores
URL https://opencores.org/ocsvn/spacewire_light/spacewire_light/trunk

Subversion Repositories spacewire_light

[/] [spacewire_light/] [trunk/] [doc/] [timing_diagram.py] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jorisvr
#!/usr/bin/env python
2
# timing_diagram.py, Joris van Rantwijk, Jul 2010.
3
 
4
"""
5
Generate timing diagrams for SpaceWire Light manual.
6
"""
7
 
8
from pyx import *
9
 
10
riseWidth = 0.15
11
clockWidth = 1.0
12
lowLevel = 0
13
highLevel = 0.5
14
midLevel = 0.25
15
 
16
def drawGrid(x, y1, y2, tstart, nclk):
17
 
18
    for i in xrange(nclk):
19
        x0 = x + clockWidth * (tstart + i)
20
        c.stroke(path.line(x0, y1, x0, y2), [ style.linewidth.Thin, color.gray(0.5) ])
21
 
22
def drawSignal(x, y, events):
23
 
24
    for i in xrange(len(events)-1):
25
        (t, v) = events[i]
26
        (tnext, vnext) = events[i+1]
27
 
28
        firstevt = (i == 0)
29
        lastevt  = (i == len(events) - 2)
30
 
31
        x0 = x + clockWidth * t
32
        x1 = x + clockWidth * t + 0.5 * riseWidth
33
        x2 = x + clockWidth * tnext - 0.5 * riseWidth
34
        x3 = x + clockWidth * tnext
35
 
36
        # fill
37
        if v.lower() == 'x':
38
            p = path.path(path.moveto(x1, y + lowLevel))
39
            if not firstevt:
40
                p.append(path.lineto(x0, y + midLevel))
41
            p.append(path.lineto(x1, y + highLevel))
42
            p.append(path.lineto(x2, y + highLevel))
43
            if not lastevt:
44
                p.append(path.lineto(x3, y + midLevel))
45
            p.append(path.lineto(x2, y + lowLevel))
46
            p.append(path.lineto(x1, y + lowLevel))
47
            c.fill(p, [ color.gray(0.5) ])
48
 
49
        lineStyle = [ ]
50
        if v.lower() != 'x':
51
            lineStyle.append(style.linewidth.Thick)
52
 
53
        # draw low part of signal
54
        if v.lower() in '0vx':
55
            p = path.path()
56
            if firstevt:
57
                p.append(path.moveto(x1, y + lowLevel))
58
            else:
59
                p.append(path.moveto(x0, y + midLevel))
60
                p.append(path.lineto(x1, y + lowLevel))
61
            p.append(path.lineto(x2, y + lowLevel))
62
            if not lastevt:
63
                p.append(path.lineto(x3, y + midLevel))
64
            c.stroke(p, lineStyle)
65
 
66
        # draw high part of signal
67
        if v.lower() in '1vx':
68
            p = path.path()
69
            if firstevt:
70
                p.append(path.moveto(x1, y + highLevel))
71
            else:
72
                p.append(path.moveto(x0, y + midLevel))
73
                p.append(path.lineto(x1, y + highLevel))
74
            p.append(path.lineto(x2, y + highLevel))
75
            if not lastevt:
76
                p.append(path.lineto(x3, y + midLevel))
77
            c.stroke(p, lineStyle)
78
 
79
        # draw center part of signal
80
        if v.lower() == 'z':
81
            p = path.path()
82
            if firstevt:
83
                p.append(path.moveto(x1, y + midLevel))
84
            else:
85
                p.append(path.moveto(x0, y + midLevel))
86
            if lastevt:
87
                p.append(path.lineto(x2, y + midLevel))
88
            else:
89
                p.append(path.lineto(x3, y + midLevel))
90
            c.stroke(p, lineStyle)
91
 
92
 
93
th = 0.3 # an appearance of "hold time" in diagram
94
xstart = 1.2
95
 
96
text.set(mode='latex')
97
 
98
#### Read timing
99
 
100
c = canvas.canvas()
101
 
102
drawGrid(xstart, 0.9, 5.5, 1, 9)
103
 
104
c.text(0, 5, '\\textsf{\\textbf{CLK}}')
105
drawSignal(xstart, 5,
106
  [ (0.5+i/2.0, str(i%2)) for i in range(20) ])
107
 
108
c.text(0, 4, '\\textsf{\\textbf{RXVALID}}')
109
drawSignal(xstart, 4,
110
  [ (0.5, '0'), (2+th, '1'), (7+th, '0'), (10, '') ])
111
 
112
c.text(0, 3, '\\textsf{\\textbf{RXFLAG}}')
113
drawSignal(xstart, 3,
114
  [ (0.5, 'x'), (2+th, 'v'), (4+th, 'v'), (6+th, 'v'), (7+th, 'x'), (10, '') ])
115
 
116
c.text(0, 2, '\\textsf{\\textbf{RXDATA}}')
117
drawSignal(xstart, 2,
118
  [ (0.5, 'x'), (2+th, 'v'), (4+th, 'v'), (6+th, 'v'), (7+th, 'x'), (10, '') ])
119
 
120
c.text(0, 1, '\\textsf{\\textbf{RXREAD}}')
121
drawSignal(xstart, 1,
122
  [ (0.5, '0'), (3+th, '1'), (4+th, '0'), (5+th, '1'), (8+th, '0'), (10, '') ])
123
 
124
c.stroke(path.line(xstart+4*clockWidth, 0.4, xstart+4*clockWidth, 0.8), [ deco.arrow() ])
125
c.stroke(path.line(xstart+6*clockWidth, 0.4, xstart+6*clockWidth, 0.8), [ deco.arrow() ])
126
c.stroke(path.line(xstart+7*clockWidth, 0.4, xstart+7*clockWidth, 0.8), [ deco.arrow() ])
127
 
128
c.writeEPSfile('timing_read.eps')
129
 
130
#### Write timing
131
 
132
c = canvas.canvas()
133
 
134
drawGrid(xstart, 0.9, 5.5, 1, 9)
135
 
136
c.text(0, 5, '\\textsf{\\textbf{CLK}}')
137
drawSignal(xstart, 5,
138
  [ (0.5+i/2.0, str(i%2)) for i in range(20) ])
139
 
140
c.text(0, 4, '\\textsf{\\textbf{TXRDY}}')
141
drawSignal(xstart, 4,
142
  [ (0.5, '1'), (5+th, '0'), (6+th, '1'), (9+th, '0'), (10, '') ])
143
 
144
c.text(0, 3, '\\textsf{\\textbf{TXWRITE}}')
145
drawSignal(xstart, 3,
146
  [ (0.5, '0'), (2+th, '1'), (3+th, '0'), (4+th, '1'), (8+th, '0'), (10, '') ])
147
 
148
c.text(0, 2, '\\textsf{\\textbf{TXFLAG}}')
149
drawSignal(xstart, 2,
150
  [ (0.5, 'x'), (2+th, 'v'), (3+th, 'x'), (4+th, 'v'), (5+th, 'v'),
151
    (7+th, 'v'), (8+th, 'x'), (10, '') ])
152
 
153
c.text(0, 1, '\\textsf{\\textbf{TXDATA}}')
154
drawSignal(xstart, 1,
155
  [ (0.5, 'x'), (2+th, 'v'), (3+th, 'x'), (4+th, 'v'), (5+th, 'v'),
156
    (7+th, 'v'), (8+th, 'x'), (10, '') ])
157
 
158
c.stroke(path.line(xstart+3*clockWidth, 0.4, xstart+3*clockWidth, 0.8), [ deco.arrow() ])
159
c.stroke(path.line(xstart+5*clockWidth, 0.4, xstart+5*clockWidth, 0.8), [ deco.arrow() ])
160
c.stroke(path.line(xstart+7*clockWidth, 0.4, xstart+7*clockWidth, 0.8), [ deco.arrow() ])
161
c.stroke(path.line(xstart+8*clockWidth, 0.4, xstart+8*clockWidth, 0.8), [ deco.arrow() ])
162
 
163
c.writeEPSfile('timing_write.eps')
164
 
165
#### Time codes
166
 
167
c = canvas.canvas()
168
 
169
xstart = 1.4
170
 
171
drawGrid(xstart, 0, 6.5, 1, 9)
172
 
173
c.text(0, 6, '\\textsf{\\textbf{CLK}}')
174
drawSignal(xstart, 6,
175
  [ (0.5+i/2.0, str(i%2)) for i in range(20) ])
176
 
177
c.text(0, 5, '\\textsf{\\textbf{TICK\_OUT}}')
178
drawSignal(xstart, 5,
179
  [ (0.5, '0'), (2+th, '1'), (3+th, '0'), (5+th, '1'), (6+th, '0'), (10, '') ])
180
 
181
c.text(0, 4, '\\textsf{\\textbf{CTRL\_OUT}}')
182
drawSignal(xstart, 4, [ (0.5, 'x'), (2+th, 'v'), (5+th, 'v'), (10, '') ])
183
 
184
c.text(0, 3, '\\textsf{\\textbf{TIME\_OUT}}')
185
drawSignal(xstart, 3, [ (0.5, 'x'), (2+th, 'v'), (5+th, 'v'), (10, '') ])
186
 
187
c.text(0, 2, '\\textsf{\\textbf{TICK\_IN}}')
188
drawSignal(xstart, 2, [ (0.5, '0'), (7+th, '1'), (8+th, '0'), (10, '') ])
189
 
190
c.text(0, 1, '\\textsf{\\textbf{CTRL\_IN}}')
191
drawSignal(xstart, 1, [ (0.5, 'x'), (7+th, 'v'), (8+th, 'x'), (10, '') ])
192
 
193
c.text(0, 0, '\\textsf{\\textbf{TIME\_IN}}')
194
drawSignal(xstart, 0, [ (0.5, 'x'), (7+th, 'v'), (8+th, 'x'), (10, '') ])
195
 
196
c.writeEPSfile('timing_timecode.eps')
197
 
198
#### Link status
199
 
200
c = canvas.canvas()
201
 
202
clockWidth = 0.8
203
xstart = 1.6
204
 
205
c.text(0, 5, '\\textsf{\\textbf{LINKSTART}}')
206
drawSignal(xstart, 5, [ (1, '0'), (2, '1'), (10, '0'), (19, '') ])
207
 
208
c.text(0, 4, '\\textsf{\\textbf{STARTED}}')
209
drawSignal(xstart, 4, [ (1, '0'), (4, '1'), (6, '0'), (19, '') ])
210
 
211
c.text(0, 3, '\\textsf{\\textbf{CONNECTING}}')
212
drawSignal(xstart, 3, [ (1, '0'), (6, '1'), (8, '0'), (19, '') ])
213
 
214
c.text(0, 2, '\\textsf{\\textbf{RUNNING}}')
215
drawSignal(xstart, 2, [ (1, '0'), (8, '1'), (16, '0'), (19, '') ])
216
 
217
c.text(0, 1, '\\textsf{\\textbf{ERRPAR}}')
218
drawSignal(xstart, 1, [ (1, '0'), (15.5, '1'), (16.5, '0'), (19, '') ])
219
 
220
c.stroke(path.line(xstart+6*clockWidth, 4.8, xstart+6*clockWidth, 2.6), [ style.linewidth.Thin ])
221
c.stroke(path.line(xstart+8*clockWidth, 3.8, xstart+8*clockWidth, 1.6), [ style.linewidth.Thin ])
222
 
223
c.writeEPSfile('timing_link.eps')
224
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.