0% found this document useful (0 votes)
90 views

An Example VHDL Application For The TM-4

This document describes a simple VHDL application that implements a 32-bit counter circuit for the TM-4 educational FPGA board. The circuit uses handshaking signals to increment the counter value each time it is read by a C program running on a Linux workstation. Instructions are provided on compiling the VHDL code, downloading the circuit to the TM-4 board, running the program to read the counter values, and interacting with the circuit.

Uploaded by

anilshaw27
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

An Example VHDL Application For The TM-4

This document describes a simple VHDL application that implements a 32-bit counter circuit for the TM-4 educational FPGA board. The circuit uses handshaking signals to increment the counter value each time it is read by a C program running on a Linux workstation. Instructions are provided on compiling the VHDL code, downloading the circuit to the TM-4 board, running the program to read the counter values, and interacting with the circuit.

Uploaded by

anilshaw27
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

An Example VHDL Application for the TM-4

Dave Galloway Edward S. Rogers Sr. Department of Electrical and Computer Engineering University of Toronto March 2005 Introduction This document describes a simple application circuit written in VHDL for the TM-4, and explains how to create, compile and run it. The circuit implements a 32-bit counter. A program running on a workstation will read the output of the counter over the network. Getting the Source for the Circuit The source for this tm4/examples/countervhd. example circuit is on the EECG machines in the directory

Sign on to one of the EECG Debian Linux workstations (ex: crunch.eecg). Make a new directory, and copy some of the les from the example directory: mkdir counter cd counter set mydir=$cwd pushd tm4/examples/countervhd cp makefile counter.vhd counter.qsf counter.ports suncounter.c $mydir popd Add the following directory to your path, so that the Transmogrier commands are available to you: set path=(tm4/bin $path) You should probably add that line to your .cshrc le so that the change will be permanent. The four les that you copied are: counter.vhd counter.qsf the circuit that will run on the Transmogrier, described in VHDL a le containing commands for Alteras Quartus software

counter.ports a description of the inputs and outputs of the circuit makefile used to compile the circuit and the program

-2-

suncounter.c

a C program that runs on a UNIX workstation and talks to the circuit

Compiling the Example To compile the circuit into a form that can be used to program the TM-4, type: make bits The counter.vhd source will be compiled by the VHDL compiler, and the resulting circuit description will be passed through a series of scripts and programs that will produce the programming bits for the chips on the board. It will place the results, along with a number of intermediate les, into a new subdirectory called tm4 in your current directory. Any existing tm4 subdirectory will be removed. The whole process will take about 3 minutes (on a 1.4 GHz Linux workstation). To compile the program that runs on a Linux workstation and talks to the circuit, type: make my_linux_counter Downloading the Example to the Transmogrier First, you must decide which of the Transmogriers you want to use. By default, the commands will use the TM-4 attached to crunch.eecg. If you want any of the other Transmogriers, you must set the TM4_SERVER environment variable to the name of the workstation that is attached to the Transmogrier you want, something like this: setenv TM4_SERVER some_other_machine.eecg At this point, you may want to run the Transmogrier status monitor display on your workstation. Make sure your DISPLAY environment variable is set correctly and run: tm4status -t & This will produce a new window on your screen which displays the name of the design currently running in the machine, and a column of green and red lights. Now use the tm4get command to reserve the Transmogrier for 10 minutes: tm4get If someone else is using the machine, you will get a message telling you how long you will have to wait: sorry, drg has it (priority 100) for 597 more seconds To download your circuit into the TM-4, type: tm4run If you are running tm4status, you will see the lights go red as the previous design is stopped, and then

-3-

change to green as your design is loaded. The name of the directory containing your design will be displayed at the top of the status display. Interacting with the Circuit To communicate with the circuit, run the my_linux_counter program that you compiled earlier: % my_linux_counter 0 1 2 3 4 5 6 7 8 9 Every time you run it, you will get another 10 numbers from the counter. Stopping the Circuit and Releasing the Transmogrier You can stop the design, disabling the chips in the machine, by typing: tm4 stop You should now release the Transmogrier so that someone else can use it: tm4release How the Sample Design Works The circuit is written in VHDL. The complete counter.vhd le contains this: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity counter is port( tm4_devbus : inout std_logic_vector(40 downto 0); tm4_glbclk0 : in std_logic ); end; architecture arch_counter of counter is type count_states is (count_null, count_idle, count_count); signal counter : std_logic_vector(31 downto 0); signal count : std_logic; signal count_state, next_count_state : count_states; signal count_reset : std_logic; signal want_count : std_logic; signal count_ready : std_logic; signal result : std_logic_vector(31 downto 0); component tm4_portmux

- 4 -

port( tm4_devbus : inout std_logic_vector(40 downto 0); result : in std_logic_vector(31 downto 0); count_ready : in std_logic; want_count : out std_logic; tm4_glbclk0 : in std_logic); end component;

begin tm4_portmux_inst: tm4_portmux port map ( tm4_devbus, result, count_ready, want_count, tm4_glbclk0); process(count_state, want_count) begin case(count_state) is when count_null => count_reset <= 1; next_count_state <= count_idle; count_ready <= 0; count <= 0; when count_idle => count_reset <= 0; count_ready <= 1; count <= 0; if want_count = 1 then next_count_state <= count_count; else next_count_state <= count_idle; end if; when count_count => count_ready <= 0; count_reset <= 0; if want_count = 1 then next_count_state <= count_count; count <= 0; else next_count_state <= count_idle; count <= 1; end if; end case; end process; process(count_reset,tm4_glbclk0) begin

- 5 -

if count_reset = 1 then counter <= "00000000000000000000000000000000"; count_state <= count_idle; elsif tm4_glbclk0event and tm4_glbclk0 = 1 then if count = 1 then counter <= counter + 1; end if; count_state <= next_count_state; end if; result <= counter; end process; end arch_counter; The circuit has one 32-bit output port called result, and two 1-bit handshaking variables called want_count and count_ready. The circuit sits in an innite loop, waiting for someone to ask for a count. It performs a handshake with the outside world using the want_count and count_ready variables, increments the counter, and waits for the next request. The circuit uses the TM-4 ports package to communicate with the outside world. The connections to the outside world are handled by the component named tm4_portmux_inst . This component is automatically supplied by the TM-4 ports package. Read The TM-4 Ports Package for a description of how this works. The counter.ports le contains: # Name result direction o 32 bits Handshake_from_circuit count_ready want_count Handshake_from_workstation

It describes the single 32-bit output called result along with the two handshaking variables. The suncounter.c program that runs on the workstation looks like this: /* A program to test a simple counter on the TM-4, using the ports package */ #include <stdio.h> main(argc, argv) int argc; char *argv[]; { int portresult; int result[512 * 1024]; int i, count; tm_init(""); if((portresult = tm_open("result", "r")) < 0) { printf("Cant open port result\n"); exit(1);

- 6 -

} count = 10; if(argc>1) count = atoi(argv[1]); if(tm_read(portresult, result, count * sizeof(int)) != (count * sizeof(int))) { fprintf(stderr, "suncounter: error in reading\n"); exit(1); } for(i=0; i<count; i++) printf("%d ", result[i]); printf("\n\n"); exit(0); } It initializes the ports package by calling tm_init(), opens the result port with tm_open, reads 10 values of the counter with a single call to tm_read() and then prints them out.

You might also like