:photos
:papers
:tutorials
:drm
:nmicrocoder
:daes
:dhex
:deadline
:dettuxx
:circdraw
:systemc
:xf86config
:qdslconfig
:bootfloppy
:6502

:math

winscp.exe
putty.exe

:impressum

0. Introduction

FreeHDL 0.0.4 is a remarkable VHDL compiler. It takes VHDL files as input, parses them, and outputs an executable binar. This executable serves as a simulator. Instead of commercial software like ModelSim it does not utilize a gui itself. Instead, it relies on VCD as output format. Hence the users needs an external waveform viewer to analyse the output. GtkWave is a tool capable of doing just that.

Assuming that you have already compiled and installed freehdl and gtkwave, this mini-howto will present a simple example on how to write a VHDL-file, compile, simulate and analyse it.

1. A simple .vhdl-file

The following file should be saved as easy.vhdl:
entity easy is
        port (  a,b:    in      bit;
                q:      out     bit
        );
end easy;

architecture easy_arch of easy is
begin
        q<=a XOR b;
end;

use WORK.easy;
entity tb is
end tb;

architecture tb_arch of tb is
        signal tb_a,tb_b: bit;
        signal tb_q: bit;
        component easy
        port (  a,b:    in      bit;
                q:      out     bit
        );
        end component;
begin

        E0:     easy port map(a=>tb_a,b=>tb_b,q=>tb_q);

        tb_a<='0' after 10 ns,'1' after 20 ns,'0' after 30 ns,'1' after 40 ns,'0' after 50 ns;
        tb_b<='0' after 10 ns,'0' after 20 ns,'1' after 30 ns,'1' after 40 ns,'0' after 50 ns;

end;


2. Compiling the .vhdl-file

To compile the easy.vhdl file, the following commands have to be entered:
% freehdl-v2cc -m easy._main_.cc -o easy.cc easy.vhdl
% g++ -I/usr/local/include -c easy.cc
% g++ -I/usr/local/include -c easy._main_.cc
% freehdl-libtool --mode=link g++ easy._main_.o easy.o \
  -lm /usr/local/lib/libfreehdl-kernel.la /usr/local/lib/libfreehdl-std.la -o easy
Replace every /usr/local/ with the path you have installed freehdl in.
Hint: Instead of typing in everything at the shell it is smarter to save those commands in a skript-file.

3. Running the simulator

If everything works out as planned, you should have an executable easy.
Run it by typing
% ./easy
You'll get another prompt, this time from the simulator. Type in
> dc -f wave.vcd
> d
> run 60ns
> quit
You should have a file called wave.vcd by now.

4. Analysing the output

If you type in
% gtkwave wave.vcd
Press Alt+Shift+T or select Search/Signal Tree Search from the menu. Add all the signals in your design. Then you should see something like this:



5. Compiling freehdl on Mac OS X

I had a hard time compiling freehdl on my laptop, which is an Apple PowerBook G4. Somehow the socket.h implementation was fucked up. So what I did was, I opened the configure skript with vim, and I replaced the line
for ac_func in socket
with
for ac_func in _____socket
That is how i got rid of the nasty
main.cc: In function `int kernel_main(int, char**, handle_info*)':
main.cc:1204: error: invalid use of undefined type `struct socket'
/usr/include/sys/un.h:74: error: forward declaration of `struct socket'
main.cc:1207: error: `connect' undeclared (first use this function)
main.cc:1207: error: (Each undeclared identifier is reported only once for each 
   function it appears in.)
main.cc:1219: error: invalid use of undefined type `struct socket'
/usr/include/sys/un.h:74: error: forward declaration of `struct socket'
main.cc:1233: error: invalid use of undefined type `struct socket'
/usr/include/sys/un.h:74: error: forward declaration of `struct socket'
main.cc:1248: error: invalid use of undefined type `struct socket'
/usr/include/sys/un.h:74: error: forward declaration of `struct socket'
make[1]: *** [libfreehdl_kernel_la-main.lo] Error 1
make: *** [all-recursive] Error 1
when trying to compile the kernel/main.cc file. message.

6. VHDL examples

And finally, I'd like to give you some simple vhdl examples. You can run all of them through freehdl.

- easy.vhdl A simple vhdl-file.
- ramcell.vhdl An example that shows how to generate RAM or memory.
- romtab.vhdl An example of a romtable or multiplexer. It also shows how to use the textio-library, and do something similar to printf

Compiling them requires the freehdl-libtool line to look something like this:
freehdl-libtool --mode=link g++ /usr/local/share/freehdl/std/internal_textio.o \
/usr/local/share/freehdl/ieee/std_logic_1164.o  /usr/local/share/freehdl/ieee/numeric_std.o  \
romtab._main_.o romtab.o -lm /usr/local/lib/libfreehdl-kernel.la /usr/local/lib/libfreehdl-std.la -o romtab
Note the new .o-files: I don't know where they usully are, but I've just copied them to /usr/local/share/freehdl. Doesn't hurt. ;)