vhdl_help 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/vhdl_help +6 -0
- data/lib/templates/clock.vhd +20 -0
- data/lib/templates/conversions.vhd +25 -0
- data/lib/templates/counter.vhd +31 -0
- data/lib/templates/entity.vhd +13 -0
- data/lib/templates/fsm.vhd +60 -0
- data/lib/templates/header.vhd +3 -0
- data/lib/templates/memory.vhd +21 -0
- data/lib/templates/procedure.vhd +18 -0
- data/lib/templates/skeleton.vhd +46 -0
- data/lib/templates/testbench.vhd +58 -0
- data/lib/vhdl_helper.rb +109 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a2aec5ff639c532645351dad1ff4f2bf3a57592
|
4
|
+
data.tar.gz: 60ebd00aae9fe2cddc24d5a5fc11616a8537ecc9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d2e48c0f2b426f501bef330853c9dbee9a9a54bb214ab08fbd702898c8e47a7e90932e09f048db56f2747420c5d808605ec93ea308de4fc17445e92889efa09
|
7
|
+
data.tar.gz: a7c3480e1043ade625e875f017f516bfa7e5cd13288862986755d278753df48b47057770e59c0139d639832755c8cece5b4ddb76eca40519a72678f6952ae153
|
data/bin/vhdl_help
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
library ieee;
|
2
|
+
use ieee.std_logic_1164.all;
|
3
|
+
use ieee.numeric_std.all;
|
4
|
+
|
5
|
+
entity tb is
|
6
|
+
end tb;
|
7
|
+
|
8
|
+
architecture bhv of tb is
|
9
|
+
|
10
|
+
constant HALF_PERIOD : time := 5 ns; --100Mhz
|
11
|
+
signal running : boolean := true;
|
12
|
+
signal clk : std_logic := '0';
|
13
|
+
|
14
|
+
begin
|
15
|
+
|
16
|
+
-- clock generator
|
17
|
+
clk <= not clk a after HALF_PERIOD when running else clk;
|
18
|
+
|
19
|
+
|
20
|
+
end bhv;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
library ieee;
|
2
|
+
use ieee.std_logic_1164.all;
|
3
|
+
use ieee.numeric_std.all;
|
4
|
+
|
5
|
+
entity tb is
|
6
|
+
end tb;
|
7
|
+
|
8
|
+
architecture bhv of tb is
|
9
|
+
|
10
|
+
signal stdlv : std_logic_vector(31 downto 0);
|
11
|
+
signal u32 : unsigned(11 downto 0);
|
12
|
+
signal u16 : unsigned(11 downto 0);
|
13
|
+
signal u12 : unsigned(11 downto 0);
|
14
|
+
signal s12 : signed(11 downto 0);
|
15
|
+
|
16
|
+
begin
|
17
|
+
stdlv <= x"deedbeef";
|
18
|
+
u32 <= unsigned(stdlv);
|
19
|
+
u12 <= resize(u32,12);
|
20
|
+
|
21
|
+
s12 <= resize(signed(stdlv),12);
|
22
|
+
|
23
|
+
u16 <= resize(to_unsigned(42,12),16);
|
24
|
+
|
25
|
+
end bhv;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
library ieee;
|
2
|
+
use ieee.std_logic_1164.all;
|
3
|
+
use ieee.numeric_std.all;
|
4
|
+
|
5
|
+
entity counter is
|
6
|
+
generic(N : natural := 8)
|
7
|
+
port(
|
8
|
+
reset_n : in std_logic;
|
9
|
+
clk : in std_logic;
|
10
|
+
enable : in std_logic;
|
11
|
+
value : out unsigned(N-1 downto 0)
|
12
|
+
);
|
13
|
+
end counter;
|
14
|
+
|
15
|
+
architecture rtl of counter is
|
16
|
+
signal count : unsigned(N-1 downto 0);
|
17
|
+
begin
|
18
|
+
|
19
|
+
counting: process(reset_n,clk)
|
20
|
+
begin
|
21
|
+
if reset_n='0' then
|
22
|
+
count <= to_unsigned(0,N);
|
23
|
+
elsif rising_edge(clk) then
|
24
|
+
if enable='1' then
|
25
|
+
count <= count + 1;
|
26
|
+
end if
|
27
|
+
end if;
|
28
|
+
end process;
|
29
|
+
|
30
|
+
value <= count;
|
31
|
+
end rtl;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
library ieee;
|
2
|
+
use ieee.std_logic_1164.all;
|
3
|
+
use ieee.numeric_std.all;
|
4
|
+
|
5
|
+
entity counter is
|
6
|
+
generic(N : natural := 8)
|
7
|
+
port(
|
8
|
+
reset_n : in std_logic;
|
9
|
+
clk : in std_logic;
|
10
|
+
enable : in std_logic;
|
11
|
+
value : out unsigned(N-1 downto 0)
|
12
|
+
);
|
13
|
+
end counter;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
library ieee;
|
2
|
+
use ieee.std_logic_1164.all;
|
3
|
+
use ieee.numeric_std.all;
|
4
|
+
|
5
|
+
entity fsm is
|
6
|
+
port(
|
7
|
+
reset_n : in std_logic;
|
8
|
+
clk : in std_logic;
|
9
|
+
go : in std_logic;
|
10
|
+
f : out unsigned(7 downto 0)
|
11
|
+
);
|
12
|
+
end fsm;
|
13
|
+
|
14
|
+
architecture rtl_1 of fsm is
|
15
|
+
|
16
|
+
type state_type is (IDLE,PING,PONG);
|
17
|
+
signal state_r,state_c : state_type;
|
18
|
+
signal output_f : unsigned(7 downto 0);
|
19
|
+
|
20
|
+
begin
|
21
|
+
|
22
|
+
tick : process(reset_n,clk)
|
23
|
+
begin
|
24
|
+
if reset_n='0' then
|
25
|
+
state_r <= IDLE;
|
26
|
+
elsif rising_edge(clk) then
|
27
|
+
state_r <= state_c;
|
28
|
+
end if;
|
29
|
+
end process;
|
30
|
+
|
31
|
+
comb:process(go)
|
32
|
+
begin
|
33
|
+
state_c <= state_r; --default assigment
|
34
|
+
case state_r is
|
35
|
+
when IDLE =>
|
36
|
+
if go='1' then
|
37
|
+
state_c <= PING;
|
38
|
+
end if;
|
39
|
+
when PING =>
|
40
|
+
state_c <= PONG;
|
41
|
+
when PONG =>
|
42
|
+
state_c <= PING;
|
43
|
+
when others =>
|
44
|
+
null;
|
45
|
+
end case;
|
46
|
+
end process;
|
47
|
+
|
48
|
+
output_gen :process(reset_n,clk)
|
49
|
+
begin
|
50
|
+
if reset_n='0' then
|
51
|
+
output_f <= (others=>'0');
|
52
|
+
elsif rising_edge(clk) then
|
53
|
+
if state_r=PONG then
|
54
|
+
output_f <= output_f + 1;
|
55
|
+
end if;
|
56
|
+
end if;
|
57
|
+
end process;
|
58
|
+
|
59
|
+
f <= output_f;
|
60
|
+
end rtl_1;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
architecture rtl of example_memory is
|
3
|
+
|
4
|
+
type memory_type is array(0 to 255) of std_logic_vector(7 downto 0);
|
5
|
+
signal mem : memory_type;
|
6
|
+
|
7
|
+
begin
|
8
|
+
|
9
|
+
write_p:process(reset_n,clk)
|
10
|
+
if reset_n='0' then
|
11
|
+
for i in 0 to 255 loop
|
12
|
+
mem(i) <= (others=>'0');
|
13
|
+
end loop;
|
14
|
+
elsif rising_edge(clk) then
|
15
|
+
if wr='1' then
|
16
|
+
mem(to_integer(unsigned(addr)) <= datain;
|
17
|
+
end if;
|
18
|
+
end if;
|
19
|
+
end process;
|
20
|
+
|
21
|
+
end rtl;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
-- procedure in a process
|
2
|
+
stim:process
|
3
|
+
procedure wait_cycles(n : natural)
|
4
|
+
begin
|
5
|
+
for i in 0 to n-1 loop
|
6
|
+
wait until rising_edge(clk);
|
7
|
+
end loop;
|
8
|
+
end procedure;
|
9
|
+
begin
|
10
|
+
report "starting simulation";
|
11
|
+
wait until reset_n='0';
|
12
|
+
|
13
|
+
wait_cycles(100);
|
14
|
+
report "100 clock cycles elapsed";
|
15
|
+
wait; --forever
|
16
|
+
end process;
|
17
|
+
|
18
|
+
end bhv;
|
@@ -0,0 +1,46 @@
|
|
1
|
+
library ieee;
|
2
|
+
use ieee.std_logic_1164.all;
|
3
|
+
use ieee.numeric_std.all;
|
4
|
+
|
5
|
+
entity example is
|
6
|
+
generic(N : natural := 8)
|
7
|
+
port(
|
8
|
+
reset_n : in std_logic;
|
9
|
+
clk : in std_logic;
|
10
|
+
enable : in std_logic;
|
11
|
+
|
12
|
+
);
|
13
|
+
end example ;
|
14
|
+
|
15
|
+
architecture rtl of example is
|
16
|
+
-- constant CST : natural := 42;
|
17
|
+
-- type regs is array(0 to 10) of ...
|
18
|
+
-- signal x : unsigned(N-1 downto 0);
|
19
|
+
begin
|
20
|
+
|
21
|
+
-- synchronous (a.k.a 'clocked') process
|
22
|
+
process(reset_n,clk)
|
23
|
+
begin
|
24
|
+
if reset_n='0' then
|
25
|
+
-- ...
|
26
|
+
elsif rising_edge(clk) then
|
27
|
+
if enable='1' then
|
28
|
+
-- ...
|
29
|
+
end if
|
30
|
+
end if;
|
31
|
+
end process;
|
32
|
+
|
33
|
+
-- conditional assignment
|
34
|
+
z <= a when c1 else
|
35
|
+
b when c2 else
|
36
|
+
d;
|
37
|
+
|
38
|
+
-- component instanciation
|
39
|
+
inst_0: use work.decoder(RTL)
|
40
|
+
generic map(param => 42)
|
41
|
+
port map(
|
42
|
+
reset_n => reset_n,
|
43
|
+
clk => clk
|
44
|
+
);
|
45
|
+
|
46
|
+
end rtl;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
library ieee;
|
2
|
+
use ieee.std_logic_1164.all;
|
3
|
+
use ieee.numeric_std.all;
|
4
|
+
|
5
|
+
entity tb is
|
6
|
+
end tb;
|
7
|
+
|
8
|
+
architecture bhv of tb is
|
9
|
+
|
10
|
+
constant HALF_PERIOD : time := 5 ns; --100Mhz
|
11
|
+
signal running : boolean := true;
|
12
|
+
signal clk : std_logic := '0';
|
13
|
+
|
14
|
+
begin
|
15
|
+
|
16
|
+
-- clock generator
|
17
|
+
clk <= not clk a after HALF_PERIOD when running else clk;
|
18
|
+
|
19
|
+
-- asynchronous reset
|
20
|
+
reset_n <= '0','1' after 123 ns;
|
21
|
+
|
22
|
+
-- circuit under test
|
23
|
+
DUT: entity work.my_circuit(RTL)
|
24
|
+
port map(
|
25
|
+
reset_n => reset_n,
|
26
|
+
clk => clk,
|
27
|
+
input_a => a,
|
28
|
+
output_f => f
|
29
|
+
)
|
30
|
+
|
31
|
+
-- stimuli
|
32
|
+
stim:process
|
33
|
+
begin
|
34
|
+
report "starting simulation";
|
35
|
+
wait until reset_n='0';
|
36
|
+
|
37
|
+
report "waiting 100 clock cycles";
|
38
|
+
for i in 0 to 100 loop
|
39
|
+
wait until rising_edge(clk);
|
40
|
+
end loop;
|
41
|
+
|
42
|
+
report "starting test vector";
|
43
|
+
wait until rising_edge(clk);
|
44
|
+
a <= to_unsigned(1,8);
|
45
|
+
|
46
|
+
wait until rising_edge(clk);
|
47
|
+
a <= to_unsigned(2,8);
|
48
|
+
|
49
|
+
report "waiting 100 clock cycles";
|
50
|
+
for i in 0 to 100 loop
|
51
|
+
wait until rising_edge(clk);
|
52
|
+
end loop;
|
53
|
+
|
54
|
+
running <= false;
|
55
|
+
wait; --forever
|
56
|
+
end process;
|
57
|
+
|
58
|
+
end bhv;
|
data/lib/vhdl_helper.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'pp'
|
3
|
+
# compiler options
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
class VhdlHelper
|
7
|
+
|
8
|
+
VERSION = "0.1"
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
puts "-- "+"="*60
|
12
|
+
puts "-- VHDL Helper. #{VERSION}. JC Le Lann 2017"
|
13
|
+
puts "-- "+"="*60
|
14
|
+
@date = Time.now.strftime('%c')
|
15
|
+
@options={}
|
16
|
+
end
|
17
|
+
|
18
|
+
def analyze_options args
|
19
|
+
args << "-h" if args.empty?
|
20
|
+
|
21
|
+
opt_parser = OptionParser.new do |opts|
|
22
|
+
opts.banner = "Usage: vhdl_help <keyword>"
|
23
|
+
|
24
|
+
opts.on("-k", "--keywords" ,"list concepts handled for far") do |n|
|
25
|
+
show_keywords
|
26
|
+
abort
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-gen", "generates a VHDL file") do |n|
|
30
|
+
@options[:gen]=true
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("--version", "Prints version") do |n|
|
34
|
+
puts VERSION
|
35
|
+
abort
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on("-h", "--help", "Prints this help") do
|
39
|
+
puts "Provides basic code examples in VHDL"
|
40
|
+
puts opts
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
opt_parser.parse!(args)
|
47
|
+
@args=args
|
48
|
+
rescue Exception => e
|
49
|
+
puts e
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# main method
|
55
|
+
def help
|
56
|
+
@args.each{|arg| generate(arg)}
|
57
|
+
end
|
58
|
+
|
59
|
+
def show_keywords
|
60
|
+
puts "Here are the keywords I know about :"
|
61
|
+
files=__dir__+"../templates/*.vhd"
|
62
|
+
concepts=files.collect{|filename| filename.split("/").last.match(/(.*).vhd/)[1]}
|
63
|
+
concepts.each do |concept|
|
64
|
+
puts "- #{concept}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def header filename
|
69
|
+
code=[]
|
70
|
+
code << "-- generated : #{@date}"
|
71
|
+
code << "-- design : #{filename}"
|
72
|
+
code << "-- author : "
|
73
|
+
code << "-- "+"="*60
|
74
|
+
code.join("\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
def write_file code,filename
|
78
|
+
vhdl=[]
|
79
|
+
vhdl << header(filename)
|
80
|
+
vhdl << code
|
81
|
+
vhdl=vhdl.join("\n")
|
82
|
+
puts vhdl
|
83
|
+
if @options[:gen]
|
84
|
+
File.open(filename,'w'){|f| f.puts vhdl}
|
85
|
+
puts "VHDL code written in : #{filename}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def generate what
|
90
|
+
filename=__dir__+"/templates/#{what}.vhd"
|
91
|
+
unless File.exist? filename
|
92
|
+
puts "Sorry...I cannot help you concerning '#{what}'"
|
93
|
+
else
|
94
|
+
template=IO.read(filename)
|
95
|
+
renderer = ERB.new(template,nil,'>')
|
96
|
+
code = renderer.result(binding)
|
97
|
+
write_file code,"#{what}.vhd"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
if $PROGRAM_NAME == __FILE__
|
104
|
+
filename=ARGV.first
|
105
|
+
raise "need an argument !" if filename.nil?
|
106
|
+
helper=VhdlHelper.new
|
107
|
+
helper.analyze_options(ARGV)
|
108
|
+
helper.help
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vhdl_help
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean-Christophe Le Lann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple snippets generator for VHDL
|
14
|
+
email: jean-christophe.le_lann@ensta-bretagne.fr
|
15
|
+
executables:
|
16
|
+
- vhdl_help
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/vhdl_help
|
21
|
+
- lib/templates/clock.vhd
|
22
|
+
- lib/templates/conversions.vhd
|
23
|
+
- lib/templates/counter.vhd
|
24
|
+
- lib/templates/entity.vhd
|
25
|
+
- lib/templates/fsm.vhd
|
26
|
+
- lib/templates/header.vhd
|
27
|
+
- lib/templates/memory.vhd
|
28
|
+
- lib/templates/procedure.vhd
|
29
|
+
- lib/templates/skeleton.vhd
|
30
|
+
- lib/templates/testbench.vhd
|
31
|
+
- lib/vhdl_helper.rb
|
32
|
+
homepage: http://rubygems.org/gems/vhdl_help
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata: {}
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 2.6.12
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: VHDL Snippets Generator
|
56
|
+
test_files: []
|