aboutsummaryrefslogtreecommitdiffstats
path: root/DigME.tex
blob: 30576a8c589f66fc94f8335d2530f979b2e1118c (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
% !TeX program = xelatex
% !TeX encoding = utf8
% !TeX root = DigME.tex

\documentclass[margin=small]{tex/hsrzf}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Packages

\usepackage{tex/hsrstud}
\usepackage{tex/docmacros}

%% Language configuration
\usepackage{polyglossia}
\setdefaultlanguage{english}

%% License configuration
\usepackage[
    type={CC},
    modifier={by-nc-sa},
    version={4.0},
]{doclicense}

%% Pretty pictures
\usepackage{tikz-timing}
\usetikztiminglibrary[rising arrows]{clockarrows}

\tikzset{
  timing/font = {\ttfamily},
  timing/xunit = 8mm,
  timing/yunit = 4mm,
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Metadata

\course{Electrial Engineering}
\module{DigMe}
\semester{Fall Semester 2021}

\authoremail{naoki.pross@ost.ch}
\author{\textsl{Naoki Pross} -- \texttt{\theauthoremail}}

\title{\texttt{\themodule}: Digital Microelectronics}
\date{\thesemester}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document

\begin{document}

\pagenumbering{roman}
\maketitle
\tableofcontents

\section{License}
\doclicenseThis

\twocolumn
\setcounter{page}{1}
\pagenumbering{arabic}


\section{Design Flow}

\section{Design constraints and static timing analysis (STA)}

\subsection{Physical constraints}

\subsection{Timing constraints}
\begin{figure}[h]
  \centering
  \begin{tikztimingtable}[]
    Clock & ccccccccccc\\
  \end{tikztimingtable}
\end{figure}
\[
  t_\text{input}
\]

\section{System level VHDL}

\subsection{Aliases}
The goal is now to build re-usable IP blocks with VHDL. For that we need to refresh some important features of the lanugage. The first of which are aliases.
\begin{lstlisting}[language=vhdl]
signal data_bus:
  std_logic_vector(31 downto 0);
alias first_nibble:
  std_logic_vector(0 downto 3)
    is data_bus(31 downto 28);
\end{lstlisting}

\subsection{Generics}
%% TODO: generics

\subsection{Generators}
Another useful feature are \vhdl{generate} statement, with the syntax that allows the instantiation of multiple components.
\begin{lstlisting}[language=vhdl]
`\optionalph{label}`: for `\reqph{identifier}` in `\reqph{range}` generate
  -- optional declaration part
  -- begin only required if there is a declaration
`\textrm{[}`begin`\textrm{]}`
  -- concurrent statements
end generate `\optionalph{label}`;
\end{lstlisting}
For example:
\begin{lstlisting}[language=vhdl]
for i in 0 to 7 generate
  x(i) <= a(i) xor b(7 - i);
end generate;
\end{lstlisting}
Or in a more realistic case, with components imported from elsewhere.
\begin{lstlisting}[
  language = vhdl,
  caption = {
    Example of generate with a component.
    \label{lst:generate-component}
  },
]
-- in architecture
bcd_to_sseg_inst_loop:
for i in 0 to nr_digits - 1 generate
  bcd_to_sseg_inst: component bcd_to_sseg
    port map(
      clk => clk,
      rst => rst,
      bcd => bcd_array(i),
      sseg => sseg_array(i)
    );
end generate;
\end{lstlisting}
where \vhdl{bcd_array} and \vhdl{sseg_array} are of course array types, and \vhdl{nr_digits} is a constant.

\subsection{Functions and procedures}
Furthermore VHDL has functions that can be useful to avoid rewriting the same code. Function have multiple inputs and a signel output, are allowed to be called recursively, but cannot declare or assign signals, nor use \vhdl{wait} statements.
\begin{lstlisting}[language=vhdl]
function `\reqph{name}` (`\optionalph{list of arguments with type}`)
  return `\reqph{return type}`
is
  `\optionalph{declaration of variables}`
begin
  -- sequential statement (but not wait)
end function `\reqph{name}`;
\end{lstlisting}
An example is a parity generator:
\begin{lstlisting}[
  language = vhdl,
  caption = {
    An odd parity generator function.
    \label{lst:pargen}
  }
]
function pargen(avect: std_ulogic_vector)
  return std_ulogic
is
  variable po_var : std_logic;
begin
  po_var := '1';
  for i in avect'range loop
    if avect(i) = '1' then
      po_var := not po_var;
    end if;
  end loop;
  return po_var;
end function pargen;
\end{lstlisting}

In testbenches it is common to see procedures. They differ for function as they can have multiple inputs and \emph{multiple output}. Because of this they in practice are usually not synthetizable. The syntax is similar to functions:
\begin{lstlisting}[language=vhdl]
procedure `\reqph{name}` (`\optionalph{list of arguments with direction}`) is
  `\optionalph{declaration of variables}`
begin
  -- sequential statement
end procedure `\reqph{name}`;
\end{lstlisting}
With \emph{list of arguments with direction} it is meant an expression like \vhdl{a, b : in real; w : out real}, similar to the arguments of \vhdl{port}.

\subsection{Arrays and records}

To efficiently use \vhdl{generate} statement, such as in listing \ref{lst:generate-component}, we ned array types. Arrays types (fields) of other types are defined with the following syntax.
\begin{lstlisting}[language=vhdl]
type `\reqph{name}` is array (`\reqph{upper limit}` downto `\reqph{lower limit}`) of `\reqph{base type}`;
\end{lstlisting}
For example to complete listing \ref{lst:generate-component}, we create 1 by 1 matrices.
\begin{lstlisting}[language = vhdl]
constant nr_digits : integer := 3;
type bcd_array_type is
  array (0 to nr_digits -1)
  of std_ulogic_vector(3 downto 0);
type bcd_array_type is
  array (0 to nr_digits -1)
  of std_ulogic_vector(6 downto 0);
\end{lstlisting}

While all arrays elements must have the same underlying type, \emph{records} allow for different types to be combined together.
%% TODO: syntax block
For example:
\begin{lstlisting}[language = vhdl]
type memory_access is record
  address : integer range 0 to address_max -1;
  mem_block : integer range 0 to 3;
  data : std_ulogic_vector(word_width -1 downto 0);
end record;
\end{lstlisting}

\subsection{Packages}

To declare your own packges, the syntax is rather easy:
\begin{lstlisting}[language = vhdl]
`\reqph{{\tt library} and / or {\tt use} statements}`
package `\reqph{name}` is
  `\optionalph{declarations}`
end package `\reqph{package name}`;
\end{lstlisting}
And possibly in another file the implementation is give with:
\begin{lstlisting}[language = vhdl]
package body `\reqph{name}` is
  `\reqph{list of definitions}`
end package body `\reqph{name}`;
\end{lstlisting}

In practice it is common to see for example a configuration package, that contains all constants for the project. For example if we were to put the function \vhdl{pargen} from listing \ref{lst:pargen} we could do:
\begin{lstlisting}[language = vhdl]
package parity_helpers is
  constant nibble : integer;
  constant word   : integer;
  function pargen(avect : std_ulogic_vector) return std_ulogic;
end package parity_helpers;

package body parity_helpers is
  -- functions
  function pargen(avect: std_ulogic_vector)
    return std_ulogic
  is `\textrm{From listing \ref{lst:pargen}}`
  end function pargen;
  -- instantiation of variables
  constant nibble : integer := 4;
  constant word   : integer := 8;
end package body parity_helpers;
\end{lstlisting}
And later use it with \vhdl{use work.parity_helpers.all}.

\end{document}