forked from yrasik/eskdi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiming.sty
72 lines (61 loc) · 1.79 KB
/
timing.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
% Some macros for logic timing diagrams.
%
% Author: ir. Pascal T. Wolkotte and Jochem Rutgers, University of Twente
% Version: 0.1
% Date: 2007/10/11
\usepackage{tikz,pgffor}
\newcounter{wavenum}
\setlength{\unitlength}{1cm}
% advance clock one cycle, not to be called directly
\newcommand*{\clki}{
\draw (t_cur) -- ++(0,.3) -- ++(.5,0) -- ++(0,-.6) -- ++(.5,0) -- ++(0,.3) node[time] (t_cur) {};
}
\newcommand*{\bitvector}[3]{
\draw[fill=#3] (t_cur) -- ++( .1, .3) -- ++(#2-.2,0) -- ++(.1, -.3)
-- ++(-.1,-.3) -- ++(.2-#2,0) -- cycle;
\path (t_cur) -- node[anchor=mid] {#1} ++(#2,0) node[time] (t_cur) {};
}
% \known{val}{length}
\newcommand*{\known}[2]{
\bitvector{#1}{#2}{white}
}
% \unknown{length}
\newcommand*{\unknown}[2][XXX]{
\bitvector{#1}{#2}{black!20}
}
% \bit{1 or 0}{length}
\newcommand*{\bit}[2]{
\draw (t_cur) -- ++(0,.6*#1-.3) -- ++(#2,0) -- ++(0,.3-.6*#1) node[time] (t_cur) {};
}
% \unknownbit{length}
\newcommand*{\unknownbit}[1]{
\draw[ultra thick,black!50] (t_cur) -- ++(#1,0) node[time] (t_cur) {};
}
% \nextwave{name}
\newcommand{\nextwave}[1]{
\path (0,\value{wavenum}) node[left] {#1} node[time] (t_cur) {};
\addtocounter{wavenum}{-1}
}
% \clk{name}{period}
\newcommand{\clk}[2]{
\nextwave{#1}
\FPeval{\res}{(\wavewidth+1)/#2}
\FPeval{\reshalf}{#2/2}
\foreach \t in {1,2,...,\res}{
\bit{\reshalf}{1}
\bit{\reshalf}{0}
}
}
% \begin{wave}[clkname]{num_waves}{clock_cycles}
\newenvironment{wave}[3][clk]{
\begin{tikzpicture}[draw=black, yscale=.7,xscale=1]
\tikzstyle{time}=[coordinate]
\setlength{\unitlength}{1cm}
\def\wavewidth{#3}
\setcounter{wavenum}{0}
\nextwave{#1}
\foreach \t in {0,1,...,\wavewidth}{
\draw[dotted] (t_cur) +(0,.5) node[above] {t=\t} -- ++(0,.4-#2);
\clki
}
}{\end{tikzpicture}}