Skip to content

Commit 67aa0da

Browse files
committed
Initial commit.
0 parents  commit 67aa0da

15 files changed

+711
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
out/
2+
*/__pycache__/*

Makefile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
SHELL=bash
2+
3+
.FOUT=out
4+
.PYTHON=python3
5+
.PYTEST=pytest
6+
7+
.RTL_FOLDER=$(shell cd rtl; pwd)
8+
.TEST_FOLDER=$(shell cd test; pwd)
9+
.SCRIPT_FOLDER=$(shell cd scripts; pwd)
10+
11+
#-------------------------------------------------------------------------------
12+
# XILINX ISE
13+
#-------------------------------------------------------------------------------
14+
.ISE_BIN=/opt/Xilinx/14.7/ISE_DS/ISE/bin/lin64
15+
#.ISE_BIN=/cygdrive/c/Xilinx/14.7/ISE_DS/ISE/bin/nt
16+
.PROJECT_NAME=Uname
17+
.TOPE_V=tope
18+
.FPGA=xc3s200-ft256-4
19+
.BIT_FOLDER=bitstream
20+
21+
export PATH:=$(.ISE_BIN):$(PATH)
22+
.PHONY: default clean distclean
23+
24+
# ********************************************************************
25+
# Verification
26+
# ********************************************************************
27+
check_driver:
28+
@verilator --lint-only $(.RTL_FOLDER)/driver7seg.v && echo "CHECK: OK"
29+
30+
check_alu:
31+
@verilator --lint-only $(.RTL_FOLDER)/alu.v && echo "CHECK: OK"
32+
33+
check_tope:
34+
@verilator --lint-only rtl/tope.v rtl/driver7seg.v rtl/alu.v && echo "CHECK: OK"
35+
36+
test_alu: check_alu
37+
@mkdir -p $(.FOUT)/
38+
@$(.PYTEST) --tb=short test/test_alu.py
39+
40+
# ********************************************************************
41+
# Implementation
42+
# ********************************************************************
43+
build-bitstream: $(.FOUT)/$(.BIT_FOLDER)/$(.PROJECT_NAME).bit
44+
45+
build-prom: build-bitstream $(.FOUT)/$(.BIT_FOLDER)/$(.PROJECT_NAME).mcs
46+
47+
program-fpga: build-prom
48+
@$(.SCRIPT_FOLDER)/program_fpga.sh $(.PROJECT_NAME) $(.BIT_FOLDER) $(.FOUT)
49+
50+
$(.FOUT)/$(.BIT_FOLDER)/$(.PROJECT_NAME).bit: ucf/pines.ucf
51+
@mkdir -p $(.FOUT)
52+
@$(.SCRIPT_FOLDER)/create_project.sh $(.RTL_FOLDER) $(.FOUT) $(.PROJECT_NAME)
53+
@$(.SCRIPT_FOLDER)/create_bitstream.sh $(.FPGA) $(.FOUT) $(.BIT_FOLDER) $(.PROJECT_NAME) $(.TOPE_V)
54+
55+
$(.FOUT)/$(.BIT_FOLDER)/$(.PROJECT_NAME).mcs:
56+
@$(.SCRIPT_FOLDER)/generate_prom_file.sh $(.PROJECT_NAME) $(.BIT_FOLDER) $(.FOUT)
57+
58+
# ********************************************************************
59+
# Clean
60+
# ********************************************************************
61+
clean:
62+
@rm -rf $(.FOUT)/
63+
@find . | grep -E "(\.vcd)" | xargs rm -rf
64+
65+
distclean: clean
66+
@find . | grep -E "(__pycache__|\.pyc|\.pyo|\.vcd|\.cache)" | xargs rm -rf

rtl/alu.v

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
`timescale 1ns / 1ps
2+
/*
3+
******************************************************************************
4+
* Autor: Ángel Terrones
5+
* Módulo: ALU de 4-bits
6+
******************************************************************************
7+
*/
8+
module alu(
9+
input [3:0] a_i,
10+
input [3:0] b_i,
11+
input [3:0] op_i,
12+
output reg [3:0] result_o,
13+
output invalid
14+
);
15+
16+
assign invalid = op_i > 4'ha;
17+
18+
always @(*) begin
19+
case (op_i)
20+
4'h0: result_o = a_i + b_i;
21+
4'h1: result_o = a_i - b_i;
22+
4'h2: result_o = a_i & b_i;
23+
4'h3: result_o = a_i | b_i;
24+
4'h4: result_o = a_i ^ b_i;
25+
4'h5: result_o = a_i;
26+
4'h6: result_o = b_i;
27+
4'h7: result_o = -a_i;
28+
4'h8: result_o = -b_i;
29+
4'h9: result_o = ~a_i;
30+
4'ha: result_o = ~b_i;
31+
default: result_o = 4'b0;
32+
endcase
33+
end
34+
35+
endmodule
36+
// ****************************************************************************
37+
// EOF
38+
// ****************************************************************************

rtl/driver7seg.v

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
`timescale 1ns / 1ps
2+
/*
3+
******************************************************************************
4+
* Autor: Ángel Terrones <[email protected]>
5+
* Módulo: Driver 7-segmentos
6+
******************************************************************************
7+
*/
8+
module driver(
9+
input [3:0] valor_i,
10+
output [3:0] anodos_o,
11+
output reg [7:0] segmentos_o
12+
);
13+
14+
assign anodos_o = 4'b1110;
15+
16+
always @(*) begin
17+
case (valor_i)
18+
// abcdefg.
19+
4'h0: segmentos_o = 8'b00000011;
20+
4'h1: segmentos_o = 8'b10011111;
21+
4'h2: segmentos_o = 8'b00100101;
22+
4'h3: segmentos_o = 8'b00001101;
23+
4'h4: segmentos_o = 8'b10011001;
24+
4'h5: segmentos_o = 8'b01001001;
25+
4'h6: segmentos_o = 8'b01000001;
26+
4'h7: segmentos_o = 8'b00011111;
27+
4'h8: segmentos_o = 8'b00000001;
28+
4'h9: segmentos_o = 8'b00001001;
29+
4'ha: segmentos_o = 8'b00010001;
30+
4'hb: segmentos_o = 8'b11000001;
31+
4'hc: segmentos_o = 8'b01100011;
32+
4'hd: segmentos_o = 8'b10000101;
33+
4'he: segmentos_o = 8'b01100001;
34+
4'hf: segmentos_o = 8'b01110001;
35+
endcase
36+
end
37+
38+
endmodule
39+
// ****************************************************************************
40+
// EOF
41+
// ****************************************************************************

rtl/tope.v

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
`timescale 1ns / 1ps
2+
/*
3+
******************************************************************************
4+
* Autor: Ángel Terrones <[email protected]>
5+
* Módulo: ALU + driver7seg
6+
******************************************************************************
7+
*/
8+
module tope(
9+
input [3:0] a_i,
10+
input [3:0] b_i,
11+
input [3:0] op_i,
12+
output [7:0] segmentos_o,
13+
output [3:0] anodos_o,
14+
output invalid_o,
15+
output [3:0] op_led_o
16+
);
17+
18+
wire [3:0] result;
19+
assign op_led_o = op_i;
20+
21+
alu alu(
22+
.a_i(a_i),
23+
.b_i(b_i),
24+
.op_i(op_i),
25+
.result_o(result),
26+
.invalid(invalid_o)
27+
);
28+
29+
driver driver7seg(
30+
.valor_i(result),
31+
.anodos_o(anodos_o),
32+
.segmentos_o(segmentos_o)
33+
);
34+
35+
endmodule
36+
// ****************************************************************************
37+
// EOF
38+
// ****************************************************************************

scripts/create_bitstream.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
#-------------------------------------------------------------------------------
3+
# Copyright (C) 2015 Angel Terrones <[email protected]>
4+
#-------------------------------------------------------------------------------
5+
#
6+
# File Name: create_bitstream.sh
7+
#
8+
# Author:
9+
# - Angel Terrones <[email protected]>
10+
# Description:
11+
# Generate FPGA bitstream
12+
#-------------------------------------------------------------------------------
13+
14+
#-------------------------------------------------------------------------------
15+
# Parameter check
16+
#-------------------------------------------------------------------------------
17+
EXPECTED_ARGS=5
18+
if [ $# -ne $EXPECTED_ARGS ]; then
19+
echo ""
20+
echo "ERROR : wrong number of arguments"
21+
echo "USAGE : create_bitstream.sh <fpga part> <build folder> <bitstream folder> <project name> <tope file>"
22+
echo ""
23+
24+
exit 1
25+
fi
26+
27+
#-------------------------------------------------------------------------------
28+
# folders
29+
#-------------------------------------------------------------------------------
30+
BUILD_FOLDER=$2
31+
32+
#-------------------------------------------------------------------------------
33+
# move to workspace
34+
#-------------------------------------------------------------------------------
35+
cd $BUILD_FOLDER
36+
37+
#-------------------------------------------------------------------------------
38+
# create link to UCF file
39+
#-------------------------------------------------------------------------------
40+
cp -f ../ucf/pines.ucf $4.ucf
41+
42+
#-------------------------------------------------------------------------------
43+
# copy xst_verilog and configure
44+
#-------------------------------------------------------------------------------
45+
cp ../scripts/xst_verilog.opt .
46+
sed -i "s/TOPE/$5/g" ./xst_verilog.opt
47+
48+
#-------------------------------------------------------------------------------
49+
# Execute XFLOW
50+
#-------------------------------------------------------------------------------
51+
xflow -p $1 \
52+
-implement high_effort.opt \
53+
-config bitgen.opt \
54+
-synth xst_verilog.opt \
55+
./$4.prj
56+
57+
#-------------------------------------------------------------------------------
58+
# copy bitstream to root folder
59+
#-------------------------------------------------------------------------------
60+
mkdir -p $3
61+
cp -f ./$4.bit $3/.

scripts/create_project.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
#-------------------------------------------------------------------------------
3+
# Copyright (C) 2014 Angel Terrones <[email protected]>
4+
#-------------------------------------------------------------------------------
5+
#
6+
# File Name: create_project.sh
7+
#
8+
# Author:
9+
# - Angel Terrones <[email protected]>
10+
#
11+
#-------------------------------------------------------------------------------
12+
13+
#-------------------------------------------------------------------------------
14+
# Parameter check
15+
#-------------------------------------------------------------------------------
16+
EXPECTED_ARGS=3
17+
if [ $# -ne $EXPECTED_ARGS ]; then
18+
echo ""
19+
echo "ERROR : wrong number of arguments"
20+
echo "USAGE : create_project.sh <rtl folder> <build folder> <project name>"
21+
echo ""
22+
exit 1
23+
fi
24+
25+
#-------------------------------------------------------------------------------
26+
# Hardware folder
27+
#-------------------------------------------------------------------------------
28+
RTL_FOLDER=$1
29+
30+
#-------------------------------------------------------------------------------
31+
# File project
32+
#-------------------------------------------------------------------------------
33+
FILE_PROJECT=$2/$3.prj
34+
35+
#-------------------------------------------------------------------------------
36+
# Create project file
37+
#-------------------------------------------------------------------------------
38+
rm -f $FILE_PROJECT
39+
touch $FILE_PROJECT
40+
41+
unamestr=`uname`
42+
43+
for module in $RTL_FOLDER; do
44+
for file in $(find $module -name "*.v")
45+
do
46+
if [[ "$unamestr" == 'Linux' ]]; then
47+
echo "\`include \"$file\"" >> $FILE_PROJECT
48+
else
49+
echo "\`include \"$(cygpath -w $file)\"" >> $FILE_PROJECT
50+
fi
51+
done
52+
done

scripts/generate_prom_file.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
#-------------------------------------------------------------------------------
3+
# Copyright (C) 2015 Angel Terrones <[email protected]>
4+
#-------------------------------------------------------------------------------
5+
#
6+
# File Name: generate_prom_file.sh
7+
#
8+
# Author:
9+
# - Angel Terrones <[email protected]>
10+
# Description:
11+
# Generate PROM file
12+
#-------------------------------------------------------------------------------
13+
14+
#-------------------------------------------------------------------------------
15+
# Parameter check
16+
#-------------------------------------------------------------------------------
17+
EXPECTED_ARGS=3
18+
if [ $# -ne $EXPECTED_ARGS ]; then
19+
echo ""
20+
echo "ERROR : wrong number of arguments"
21+
echo "USAGE : ./generate_prom_file.sh <bitstream name> <bitstream folder> <build folder>"
22+
echo ""
23+
exit 1
24+
fi
25+
26+
#-------------------------------------------------------------------------------
27+
# Check if requiered file exists
28+
#-------------------------------------------------------------------------------
29+
bitstreamfile=$3/$2/$1.bit;
30+
31+
if [ ! -e $bitstreamfile ]; then
32+
echo
33+
echo "Bitstream file does not exist: $bitstreamfile"
34+
echo
35+
exit 1
36+
fi
37+
38+
#-------------------------------------------------------------------------------
39+
# move to build folder
40+
#-------------------------------------------------------------------------------
41+
cd $3
42+
#-------------------------------------------------------------------------------
43+
# copy impact script & update
44+
#-------------------------------------------------------------------------------
45+
cp ../scripts/impact_generate_prom_file.batch .
46+
sed -i "s/BITSTREAM_NAME/$1/g" ./impact_generate_prom_file.batch
47+
48+
#-------------------------------------------------------------------------------
49+
# Create PROM
50+
#-------------------------------------------------------------------------------
51+
impact -batch ./impact_generate_prom_file.batch
52+
53+
#-------------------------------------------------------------------------------
54+
# Copy PROM to bitstream folder
55+
#-------------------------------------------------------------------------------
56+
cp -f ./$1.mcs $2
57+
58+
#-------------------------------------------------------------------------------
59+
# return
60+
#-------------------------------------------------------------------------------
61+
cd ..

0 commit comments

Comments
 (0)