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

Subversion Repositories yahamm

[/] [yahamm/] [trunk/] [doc/] [src/] [specification.tex] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 ndesimone
\documentclass[twoside,a4paper]{refart}
2
\usepackage{ae} % CM-Zeichens"atze mit T1 encoding
3
\usepackage{makeidx}
4
\usepackage{ifthen}
5
 
6
%% \def\bs{\char'134 } % backslash in \tt font.
7
%% \newcommand{\ie}{i.\,e.,}
8
%% \newcommand{\eg}{e.\,g..}
9
%% \DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}}
10
 
11
\title{YAHAMM\\
12
  Yet Another Hamming Encoder and Decoder\\
13
  ---\\
14
  Specification
15
}
16 9 ndesimone
\author{Nicola De Simone (ndesimone@opencores.org)\\
17 8 ndesimone
Version 0.1}
18
\date{}
19
\emergencystretch1em  %
20
 
21
\pagestyle{myfootings}
22
\markboth{YAHAMM Specification}%
23
         {YAHAMM Specification}
24
 
25
\makeindex
26
 
27
\setcounter{tocdepth}{2}
28
\settextfraction{0.7}
29
 
30
 
31
\begin{document}
32
 
33
\maketitle
34
 
35
\tableofcontents
36
 
37
\newpage
38
 
39
 
40
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
 
42
\begin{abstract}
43 9 ndesimone
YAHAMM is a VHDL implementation of an Hamming encoder, as entity yahamm\_enc, and and Hamming decoder, as entity yahamm\_dec, of message length defined trough generic.  All the math needed to compute the code is internally implemented in VHDL and it is transparent to the user.  Single Error Correction and Double Error Detection is also provided (see next for details).  Encoder has latency 1 clock cycle, decoder latency 2, independently from their configuration.
44 8 ndesimone
\end{abstract}
45
 
46
 
47
\section{Project files}
48
The projects includes the file:
49
 
50
\begin{enumerate}
51
\item rtl/vhdl/yahamm\_enc.vhd: encoder entity
52
\item rtl/vhdl/yahamm\_dec.vhd: decoder entity
53
\item rtl/vhdl/matrix\_pkg.vhd: help functions for matrix manipulation
54
\item rtl/vhdl/yahamm\_pkg.vhd: core math functions
55
\item bench/vhdl/yahamm\_tb[0-3].vhd: test benches
56 9 ndesimone
\item sim/rtl\_sim/bin/Makefile: a set of rules for the analysis and simulation with GHDL.
57 8 ndesimone
\end{enumerate}
58
 
59
\section{Makefile}
60
 
61 9 ndesimone
The Makefile targets call ghdl for analyzing the VHDL and running simulations.
62 8 ndesimone
 
63
\subsection{Analyze the VHDL}
64
\begin{enumerate}
65
\item \verb|cd sim/rtl_sim/bin|
66
\item \verb|make <vhdl file>|
67
\end{enumerate}
68
 
69
\subsection{Run the simulation}
70
\begin{enumerate}
71
\item \verb|cd sim/rtl_sim/bin|
72
\end{enumerate}
73 9 ndesimone
To simulate a single test-bench:
74 8 ndesimone
\begin{enumerate}
75
\item[2] \verb|make simulate_tb[0..3]|
76
\end{enumerate}
77 9 ndesimone
or, to simulate all test-benches:
78 8 ndesimone
\begin{enumerate}
79
\item[2] \verb|make simulate|
80
\end{enumerate}
81
 
82 9 ndesimone
Each test-bench will output ``OK'' if successful.
83 8 ndesimone
 
84
The simulation will create waveform as VCD compressed file in \verb|cd sim/rtl_sim/out|.  They can be view, for example, with gtkwave by running:
85
 
86
\begin{enumerate}
87
\item[3] \verb|make view_[0..3]|
88
\end{enumerate}
89
 
90
\subsection{Cleanup}
91
\begin{enumerate}
92
\item \verb|cd sim/rtl_sim/bin|
93
\item \verb|make clean|
94
\end{enumerate}
95
 
96
 
97
\section{Encoder}
98
\label{sec:encoder}
99
 
100
\begin{verbatim}
101
entity yahamm_enc is
102
  generic (
103
    MESSAGE_LENGTH       : natural := 5;
104
    EXTRA_PARITY_BIT : natural range 0 to 1 := 1;
105
    ONE_PARITY_BIT : boolean := false
106
    );
107
  port(
108
    clk_i, rst_i : in  std_logic;
109
    en_i       : in  std_logic := '1';          -- Synchronous output enable .
110
    data_i        : in  std_logic_vector(MESSAGE_LENGTH - 1 downto 0);  -- Input data.
111
    data_o        : out std_logic_vector(MESSAGE_LENGTH - 1 downto 0);  -- Out data.
112
    data_valid_o : out std_logic;        -- High when data_o is valid.
113
    parity_o   : out std_logic_vector(calc_nparity_bits(MESSAGE_LENGTH, ONE_PARITY_BIT) + EXTRA_PARITY_BIT - 1 downto 0)    -- Parity bits.
114
    );
115
 
116
end yahamm_enc;
117
\end{verbatim}
118
 
119
Generics:
120
 
121
\begin{enumerate}
122 9 ndesimone
\item MESSAGE\_LENGTH: the data payload length, excluding parity bits.
123 8 ndesimone
\item EXTRA\_PARITY\_BIT: if 1 the Hamming codes are extended by an extra parity bit. This way the minimum Hamming distance is increased to 4, which allows the decoder to distinguish between single bit errors and two-bit errors. Thus the decoder can detect and correct a single error and at the same time detect (but not correct) a double error (SECDED). If the decoder does not attempt to correct errors, it can detect up to three errors.  \seealso{Sec \ref{sec:decoder}}.  Default is 1.
124 9 ndesimone
\item ONE\_PARITY\_BIT: if true the encoder does not perform Hamming encoding but just adds a single parity bit to the message.  Default is false.
125 8 ndesimone
\end{enumerate}
126
 
127 9 ndesimone
The generics MESSAGE\_LENGTH, EXTRA\_PARITY\_BIT and ONE\_PARITY\_BIT must have the same values on both the encoder and the decoder instances.
128 8 ndesimone
 
129
Ports:
130
 
131
\begin{enumerate}
132
\item clk\_i: input reset, active high.
133
\item rst\_i: input reset, active high.
134
\item en\_i: input enable.  When asserted input data are encoded.  If de-asserted, data and parity outputs are zero.  Default is high.
135 9 ndesimone
\item data\_i: input data.  Length equal to MESSAGE\_LENGTH.
136
\item data\_o: output data. Length equal to MESSAGE\_LENGTH.
137 8 ndesimone
\item data\_valid\_o: output valid signal for data\_o.  This is just en\_i delayed by the core latency.
138 9 ndesimone
\item parity\_o: output parity bits.  The length of this vectors corresponds to the number of parity bits needed by the hamming code and it's computed by the VHDL function calc\_nparity\_bits().  One extra parity bit is needed if the generic EXTRA\_PARITY\_BIT is true.  The user instantiating the entity and mapping that port can determine the length in three ways:
139 8 ndesimone
  \begin{enumerate}
140
  \item Calculate the number of parity bits $r$ needed for the specified message length $k$, looking for the smallest $r$ such that $k \geq 2^r - r - 1$ for $r \ge 2$.
141
  \item Use the script \verb|sw/calc_nparity_bits.sh|.
142
  \item Connect a bus or arbitrary random length.  Run any VHDL analysis tool and use the syntax error you get to see which is the right length.
143
  \end{enumerate}
144
\end{enumerate}
145
 
146
\section{Decoder}
147
\label{sec:decoder}
148
 
149
\begin{verbatim}
150
entity yahamm_dec is
151
  generic (
152
    MESSAGE_LENGTH       : natural := 5;
153
    CORRECT : boolean := true;
154
    EXTRA_PARITY_BIT : natural range 0 to 1 := 1;
155
    ONE_PARITY_BIT : boolean := false;
156
    ERROR_LEN : natural := 16
157
    );
158
  port(
159
    clk_i, rst_i : in  std_logic;
160
    cnt_clr_i : in std_logic := '0';             -- Clear monitor counters.
161
    en_i       : in  std_logic := '1';          -- Input enable.
162
    data_i        : in  std_logic_vector(MESSAGE_LENGTH - 1 downto 0);  -- Input data.
163
    parity_i   : in std_logic_vector(calc_nparity_bits(MESSAGE_LENGTH, ONE_PARITY_BIT) + EXTRA_PARITY_BIT - 1 downto 0);    -- Parity bits.
164
    data_o        : out std_logic_vector(MESSAGE_LENGTH - 1 downto 0);  -- Out data.
165
    dout_valid_o : out std_logic;                                          -- data_o valid.
166
    cnt_errors_corrected_o, cnt_errors_detected_o : out std_logic_vector(ERROR_LEN - 1 downto 0);
167
    log_wrong_bit_pos_data_o : out std_logic_vector(MESSAGE_LENGTH - 1 downto 0);
168
    log_wrong_bit_pos_parity_o : out std_logic_vector(calc_nparity_bits(MESSAGE_LENGTH, ONE_PARITY_BIT) + EXTRA_PARITY_BIT - 1 downto 0)
169
    );
170
 
171
end yahamm_dec;
172
\end{verbatim}
173
 
174
Generics:
175
 
176
\begin{enumerate}
177 9 ndesimone
\item \verb|CORRECT|: if true, the core corrects detected errors.  Default is true.
178 8 ndesimone
\item \verb|ERROR_LEN|: bit length of the error counters provided on ports \verb|cnt_errors_corrected_o| and \verb|cnt_errors_detected_o|.
179 9 ndesimone
\item \verb|MESSAGE_LENGTH|: see Sec. \ref{sec:encoder}.
180 8 ndesimone
\item \verb|EXTRA_PARITY_BIT|: see Sec. \ref{sec:encoder}.
181
\item \verb|ONE_PARITY_BIT|: see Sec. \ref{sec:encoder}.
182
\end{enumerate}
183
 
184 9 ndesimone
The generics MESSAGE\_LENGTH, EXTRA\_PARITY\_BIT and ONE\_PARITY\_BIT must have the same values on both the encoder and the decoder instances.
185 8 ndesimone
 
186
Ports:
187
 
188
\begin{enumerate}
189
\item \verb|cnt_clr_i|: input synchronous clear of the error counters.
190
\item \verb|en_i|: optional input enable.  Can be connected to \verb|dout_valid_o| of the encoder to propagate a valid signal to the output port \verb|data_valid_o|:  Default is high (\verb|data_valid_o| will be always asserted in this case).
191 9 ndesimone
\item \verb|data_i|: input data.  It must be connected to the \verb|data_o| of the decoder.  Length equal to MESSAGE\_LENGTH.
192 8 ndesimone
\item \verb|parity_i|: input parity bits.  It must be connected to the \verb|parity_o| of the decoder.
193 9 ndesimone
\item \verb|data_o|: output data.  Length equal to MESSAGE\_LENGTH.
194 8 ndesimone
\item data\_valid\_o: output valid signal for data\_o.  This is just en\_i delayed by the core latency.
195
\item \verb|cnt_errors_corrected_o|: counter of single errors corrected.  It is always zero if the generic \verb|CORRECT| is false.
196
\item \verb|cnt_errors_detected_o|: counter of errors detected.  It includes single, double and triple errors (not there's no way to distinguish between a single and a triple error), if the generic \verb|CORRECT| is false, otherwise it only counts double errors.
197 11 ndesimone
\item \verb|log_wrong_bit_pos_data_o|: position of the single errors in \verb|data_o|.  A bit is asserted high when there is an error in the same position in \verb|data_o|.  They are only de-asserted by a synchrnous clear \verb|cnt_clr_i| or by a reset.  It is not used if generic \verb|CORRECT| is false or if it's not a single error.
198
\item \verb|log_wrong_bit_pos_parity_o|: position of the single error in \verb|parity_o|.  A bit is asserted high when there is an error in the same position in \verb|parity_o|.  They are only de-asserted by a synchrnous clear \verb|cnt_clr_i| or by a reset.  It is not used if generic \verb|CORRECT| is false or if it's not a single error.
199 8 ndesimone
\end{enumerate}
200
 
201
 
202
\section{SEC-DED and other possibilities}
203
 
204 11 ndesimone
In order to have SEC-DED (Single Error Corrected - Double Error Detected) capability, user should use the default values for the generics \verb|EXTRA_PARITY_BITS| 1, and \verb|CORRECT| true.
205 8 ndesimone
 
206
Other choices can be made as described by the following table.
207
 
208
\begin{table}
209
  \begin{tabular}{||c|cc||}
210
    \hline
211
    \hline
212
    & \multicolumn{2}{|c||}{\texttt{CORRECT}} \\
213
    \hline
214
    \verb|EXTRA_PARITY_BIT| & false & true\\
215
    \hline
216
    false & SED-DED & SEC\\
217
    true & SED-DED-TED & SEC-DED\\
218
    \hline
219
    \hline
220
  \end{tabular}
221
  \caption{SEC = single bit error corrected,
222
    SED = single bit error detected,
223
    DED = double bit error detected,
224
    TED = triple bit error detected
225
  }
226
\end{table}
227
 
228 9 ndesimone
The generic \verb|EXTRA_PARITY_BITS| set to true (default) adds a parity bit so that the Hamming distance is $4$ between two code words (number of bits to flip in a code word to obtain another code word).  With \verb|EXTRA_PARITY_BITS| set to false the Hamming distance will be $3$.
229 8 ndesimone
 
230 11 ndesimone
The generic \verb|CORRECT| set to true (default) corrects for single bit errors.  It can be set to false if only error detection is needed.  This allows triple error detection with \verb|EXTRA_PARITY_BIT| set to true.  Indeed, a triple error is indistinguishable from a single error with an Hamming distance 4 and the correction would be wrong in this case.  Similarly, with \verb|EXTRA_PARITY_BIT| set to false, hence with Hamming distance 3, a double error is indistinguishable from a single error and the correction would be wrong.
231 8 ndesimone
 
232 11 ndesimone
If \verb|CORRECT| is false, the port \verb|cnt_errors_detected_o| provides the value of a counter that sums up any kind of error detected (single, double and triple).  If the configuration is SEC-DED, \verb|cnt_errors_detected_o| provides the counter for DED, \verb|cnt_errors_corrected_o| provides the counter for SEC.
233
 
234 9 ndesimone
For most applications, SEC-DED configuration (the default) is the preferred choice.  A communication channel can be considered reliable if the probability of double error is negligible.   A noisy channel showing double errors detected is not to be trusted because event a corrected single error may be a triple error and the correction would be wrong.
235 8 ndesimone
 
236
 
237
\printindex
238
 
239
\end{document}

powered by: WebSVN 2.1.0

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