rggen-vhdl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/CODE_OF_CONDUCT.md +84 -0
  3. data/LICENSE +21 -0
  4. data/README.md +74 -0
  5. data/lib/rggen/vhdl.rb +50 -0
  6. data/lib/rggen/vhdl/bit_field/type.rb +85 -0
  7. data/lib/rggen/vhdl/bit_field/type/rc_w0c_w1c_wc_woc.erb +27 -0
  8. data/lib/rggen/vhdl/bit_field/type/rc_w0c_w1c_wc_woc.rb +51 -0
  9. data/lib/rggen/vhdl/bit_field/type/ro.erb +24 -0
  10. data/lib/rggen/vhdl/bit_field/type/ro.rb +21 -0
  11. data/lib/rggen/vhdl/bit_field/type/rof.erb +24 -0
  12. data/lib/rggen/vhdl/bit_field/type/rof.rb +7 -0
  13. data/lib/rggen/vhdl/bit_field/type/rs_w0s_w1s_ws_wos.erb +27 -0
  14. data/lib/rggen/vhdl/bit_field/type/rs_w0s_w1s_ws_wos.rb +42 -0
  15. data/lib/rggen/vhdl/bit_field/type/rw_w1_wo_wo1.erb +26 -0
  16. data/lib/rggen/vhdl/bit_field/type/rw_w1_wo_wo1.rb +23 -0
  17. data/lib/rggen/vhdl/bit_field/type/rwc.erb +25 -0
  18. data/lib/rggen/vhdl/bit_field/type/rwc.rb +24 -0
  19. data/lib/rggen/vhdl/bit_field/type/rwe_rwl.erb +25 -0
  20. data/lib/rggen/vhdl/bit_field/type/rwe_rwl.rb +33 -0
  21. data/lib/rggen/vhdl/bit_field/type/rws.erb +24 -0
  22. data/lib/rggen/vhdl/bit_field/type/rws.rb +27 -0
  23. data/lib/rggen/vhdl/bit_field/type/w0crs_w0src_w1crs_w1src_wcrs_wsrc.erb +26 -0
  24. data/lib/rggen/vhdl/bit_field/type/w0crs_w0src_w1crs_w1src_wcrs_wsrc.rb +36 -0
  25. data/lib/rggen/vhdl/bit_field/type/w0t_w1t.erb +25 -0
  26. data/lib/rggen/vhdl/bit_field/type/w0t_w1t.rb +22 -0
  27. data/lib/rggen/vhdl/bit_field/type/w0trg_w1trg.erb +17 -0
  28. data/lib/rggen/vhdl/bit_field/type/w0trg_w1trg.rb +19 -0
  29. data/lib/rggen/vhdl/bit_field/type/wrc_wrs.erb +25 -0
  30. data/lib/rggen/vhdl/bit_field/type/wrc_wrs.rb +22 -0
  31. data/lib/rggen/vhdl/bit_field/vhdl_top.rb +93 -0
  32. data/lib/rggen/vhdl/component.rb +7 -0
  33. data/lib/rggen/vhdl/factories.rb +11 -0
  34. data/lib/rggen/vhdl/feature.rb +31 -0
  35. data/lib/rggen/vhdl/register/default.erb +29 -0
  36. data/lib/rggen/vhdl/register/type.rb +109 -0
  37. data/lib/rggen/vhdl/register/type/default.erb +31 -0
  38. data/lib/rggen/vhdl/register/type/external.erb +29 -0
  39. data/lib/rggen/vhdl/register/type/external.rb +44 -0
  40. data/lib/rggen/vhdl/register/type/indirect.erb +35 -0
  41. data/lib/rggen/vhdl/register/type/indirect.rb +34 -0
  42. data/lib/rggen/vhdl/register/vhdl_top.rb +40 -0
  43. data/lib/rggen/vhdl/register_block/protocol.rb +48 -0
  44. data/lib/rggen/vhdl/register_block/protocol/apb.erb +34 -0
  45. data/lib/rggen/vhdl/register_block/protocol/apb.rb +20 -0
  46. data/lib/rggen/vhdl/register_block/protocol/axi4lite.erb +49 -0
  47. data/lib/rggen/vhdl/register_block/protocol/axi4lite.rb +42 -0
  48. data/lib/rggen/vhdl/register_block/vhdl_top.erb +26 -0
  49. data/lib/rggen/vhdl/register_block/vhdl_top.rb +103 -0
  50. data/lib/rggen/vhdl/register_file/vhdl_top.rb +25 -0
  51. data/lib/rggen/vhdl/setup.rb +11 -0
  52. data/lib/rggen/vhdl/utility.rb +28 -0
  53. data/lib/rggen/vhdl/utility/data_object.rb +91 -0
  54. data/lib/rggen/vhdl/utility/identifier.rb +38 -0
  55. data/lib/rggen/vhdl/utility/local_scope.rb +66 -0
  56. data/lib/rggen/vhdl/version.rb +7 -0
  57. metadata +130 -0
@@ -0,0 +1,17 @@
1
+ u_bit_field: entity work.rggen_bit_field_w01trg
2
+ generic map (
3
+ WRITE_ONE_TRIGGER => <%= write_one_trigger? %>,
4
+ WIDTH => <%= width %>
5
+ )
6
+ port map (
7
+ i_clk => i_clk,
8
+ i_rst_n => i_rst_n,
9
+ i_sw_valid => <%= bit_field_valid %>,
10
+ i_sw_read_mask => <%= bit_field_read_mask %>,
11
+ i_sw_write_enable => "1",
12
+ i_sw_write_mask => <%= bit_field_write_mask %>,
13
+ i_sw_write_data => <%= bit_field_write_data %>,
14
+ o_sw_read_data => <%= bit_field_read_data %>,
15
+ o_sw_value => <%= bit_field_value %>,
16
+ o_trigger => <%= trigger[loop_variables] %>
17
+ );
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_list_item_feature(:bit_field, :type, [:w0trg, :w1trg]) do
4
+ vhdl do
5
+ build do
6
+ output :trigger, {
7
+ name: "o_#{full_name}_trigger", width: width, array_size: array_size
8
+ }
9
+ end
10
+
11
+ main_code :bit_field, from_template: true
12
+
13
+ private
14
+
15
+ def write_one_trigger?
16
+ bit_field.type == :w1trg
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ u_bit_field: entity work.rggen_bit_field
2
+ generic map (
3
+ WIDTH => <%= width %>,
4
+ INITIAL_VALUE => <%= initial_value %>,
5
+ SW_READ_ACTION => <%= read_action %>
6
+ )
7
+ port map (
8
+ i_clk => <%= clock %>,
9
+ i_rst_n => <%= reset %>,
10
+ i_sw_valid => <%= bit_field_valid %>,
11
+ i_sw_read_mask => <%= bit_field_read_mask %>,
12
+ i_sw_write_enable => "1",
13
+ i_sw_write_mask => <%= bit_field_write_mask %>,
14
+ i_sw_write_data => <%= bit_field_write_data %>,
15
+ o_sw_read_data => <%= bit_field_read_data %>,
16
+ o_sw_value => <%= bit_field_value %>,
17
+ i_hw_write_enable => "0",
18
+ i_hw_write_data => (others => '0'),
19
+ i_hw_set => (others => '0'),
20
+ i_hw_clear => (others => '0'),
21
+ i_value => (others => '0'),
22
+ i_mask => (others => '1'),
23
+ o_value => <%= value_out[loop_variables] %>,
24
+ o_value_unmasked => open
25
+ );
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_list_item_feature(:bit_field, :type, [:wrc, :wrs]) do
4
+ vhdl do
5
+ build do
6
+ output :value_out, {
7
+ name: "o_#{full_name}", width: width, array_size: array_size
8
+ }
9
+ end
10
+
11
+ main_code :bit_field, from_template: true
12
+
13
+ private
14
+
15
+ def read_action
16
+ {
17
+ wrc: 'RGGEN_READ_CLEAR',
18
+ wrs: 'RGGEN_READ_SET'
19
+ }[bit_field.type]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_simple_feature(:bit_field, :vhdl_top) do
4
+ vhdl do
5
+ include RgGen::SystemVerilog::RTL::BitFieldIndex
6
+
7
+ export :initial_value
8
+ export :value
9
+
10
+ build do
11
+ if parameterized_initial_value?
12
+ generic :initial_value, {
13
+ name: initial_value_name, width: initial_value_width,
14
+ default: default_initial_value
15
+ }
16
+ else
17
+ define_accessor_for_initial_value
18
+ end
19
+ end
20
+
21
+ main_code :register do
22
+ local_scope("g_#{bit_field.name}") do |scope|
23
+ scope.loop_size loop_size
24
+ scope.body(&method(:body_code))
25
+ end
26
+ end
27
+
28
+ def value(offsets = nil, width = nil)
29
+ value_lsb = bit_field.lsb(offsets&.last || local_index)
30
+ value_width = width || bit_field.width
31
+ register_value(offsets&.slice(0..-2), value_lsb, value_width)
32
+ end
33
+
34
+ private
35
+
36
+ def parameterized_initial_value?
37
+ bit_field.initial_value? && !bit_field.fixed_initial_value?
38
+ end
39
+
40
+ def initial_value_name
41
+ "#{bit_field.full_name('_')}_initial_value".upcase
42
+ end
43
+
44
+ def initial_value_width
45
+ width = bit_field.width
46
+ repeat_size = bit_field.sequence_size || 1
47
+ width * repeat_size
48
+ end
49
+
50
+ def default_initial_value
51
+ width = bit_field.width
52
+ repeat_size = bit_field.sequence_size || 1
53
+ value = initial_value_rhs_default
54
+ "repeat(#{value}, #{width}, #{repeat_size})"
55
+ end
56
+
57
+ def define_accessor_for_initial_value
58
+ define_singleton_method(:initial_value) do
59
+ if bit_field.initial_value_array?
60
+ array_initial_value_rhs
61
+ elsif bit_field.initial_value?
62
+ initial_value_rhs_default
63
+ end
64
+ end
65
+ end
66
+
67
+ def initial_value_rhs_default
68
+ hex(bit_field.register_map.initial_value, bit_field.width)
69
+ end
70
+
71
+ def array_initial_value_rhs
72
+ value =
73
+ bit_field.initial_values
74
+ .map.with_index { |v, i| v << bit_field.width * i }
75
+ .inject(:|)
76
+ hex(value, bit_field.sequence_size * bit_field.width)
77
+ end
78
+
79
+ def register_value(offsets, lsb, width)
80
+ index = register.index(offsets || register.local_indices)
81
+ register_block.register_value[[index], lsb, width]
82
+ end
83
+
84
+ def loop_size
85
+ loop_variable = local_index
86
+ loop_variable && { loop_variable => bit_field.sequence_size }
87
+ end
88
+
89
+ def body_code(code)
90
+ bit_field.generate_code(code, :bit_field, :top_down)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module VHDL
5
+ Component = SystemVerilog::Common::Component
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module VHDL
5
+ class ComponentFactory < Core::OutputBase::SourceFileComponentFactory
6
+ end
7
+
8
+ class FeatureFactory < Core::OutputBase::FeatureFactory
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module VHDL
5
+ class Feature < SystemVerilog::Common::Feature
6
+ include Utility
7
+
8
+ private
9
+
10
+ def create_signal(_, attributes, &block)
11
+ DataObject.new(:signal, attributes, &block)
12
+ end
13
+
14
+ def create_port(direction, attributes, &block)
15
+ attributes =
16
+ attributes
17
+ .merge(direction: { input: :in, output: :out}[direction])
18
+ DataObject.new(:port, attributes, &block)
19
+ end
20
+
21
+ def create_generic(_, attributes, &block)
22
+ DataObject.new(:generic, attributes, &block)
23
+ end
24
+
25
+ define_entity :signal, :create_signal, :signal, -> { component }
26
+ define_entity :input, :create_port, :port, -> { register_block }
27
+ define_entity :output, :create_port, :port, -> { register_block }
28
+ define_entity :generic, :create_generic, :generic, -> { register_block }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ rggen_default_register #(
2
+ .READABLE (<%= readable %>),
3
+ .WRITABLE (<%= writable %>),
4
+ .ADDRESS_WIDTH (<%= address_width %>),
5
+ .OFFSET_ADDRESS (<%= offset_address %>),
6
+ .BUS_WIDTH (<%= bus_width %>),
7
+ .DATA_WIDTH (<%= width %>),
8
+ .VALID_BITS (<%= valid_bits %>),
9
+ .REGISTER_INDEX (<%= register_index %>)
10
+ ) u_register (
11
+ .i_clk (<%= clock %>),
12
+ .i_rst_n (<%= reset %>),
13
+ .i_register_valid (<%= register_valid %>),
14
+ .i_register_access (<%= register_access %>),
15
+ .i_register_address (<%= register_address %>),
16
+ .i_register_write_data (<%= register_write_data %>),
17
+ .i_register_strobe (<%= register_strobe %>),
18
+ .o_register_active (<%= register_active %>),
19
+ .o_register_ready (<%= register_ready %>),
20
+ .o_register_status (<%= register_status %>),
21
+ .o_register_read_data (<%= register_read_data %>),
22
+ .o_register_value (<%= register_value %>),
23
+ .o_bit_field_valid (<%= bit_field_valid %>),
24
+ .o_bit_field_read_mask (<%= bit_field_read_mask %>),
25
+ .o_bit_field_write_mask (<%= bit_field_write_mask %>),
26
+ .o_bit_field_write_data (<%= bit_field_write_data %>),
27
+ .i_bit_field_read_data (<%= bit_field_read_data %>),
28
+ .i_bit_field_value (<%= bit_field_value %>)
29
+ );
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_list_feature(:register, :type) do
4
+ vhdl do
5
+ base_feature do
6
+ include RgGen::SystemVerilog::RTL::RegisterType
7
+
8
+ private
9
+
10
+ def readable?
11
+ register.readable?
12
+ end
13
+
14
+ def writable?
15
+ register.writable?
16
+ end
17
+
18
+ def clock
19
+ register_block.clock
20
+ end
21
+
22
+ def reset
23
+ register_block.reset
24
+ end
25
+
26
+ def register_valid
27
+ register_block.register_valid
28
+ end
29
+
30
+ def register_access
31
+ register_block.register_access
32
+ end
33
+
34
+ def register_address
35
+ register_block.register_address
36
+ end
37
+
38
+ def register_write_data
39
+ register_block.register_write_data
40
+ end
41
+
42
+ def register_strobe
43
+ register_block.register_strobe
44
+ end
45
+
46
+ def register_active
47
+ register_block.register_active[[register.index]]
48
+ end
49
+
50
+ def register_ready
51
+ register_block.register_ready[[register.index]]
52
+ end
53
+
54
+ def register_status
55
+ register_block.register_status[[register.index]]
56
+ end
57
+
58
+ def register_read_data
59
+ register_block.register_read_data[[register.index]]
60
+ end
61
+
62
+ def register_value
63
+ register_block.register_value[[register.index], 0, width]
64
+ end
65
+
66
+ def bit_field_valid
67
+ register.bit_field_valid
68
+ end
69
+
70
+ def bit_field_read_mask
71
+ register.bit_field_read_mask
72
+ end
73
+
74
+ def bit_field_write_mask
75
+ register.bit_field_write_mask
76
+ end
77
+
78
+ def bit_field_write_data
79
+ register.bit_field_write_data
80
+ end
81
+
82
+ def bit_field_read_data
83
+ register.bit_field_read_data
84
+ end
85
+
86
+ def bit_field_value
87
+ register.bit_field_value
88
+ end
89
+ end
90
+
91
+ default_feature do
92
+ main_code :register, from_template: File.join(__dir__, 'type', 'default.erb')
93
+ end
94
+
95
+ factory do
96
+ def target_feature_key(_configuration, register)
97
+ type = register.type
98
+ valid_type?(type) && type ||
99
+ (error "code generator for #{type} register type is not implemented")
100
+ end
101
+
102
+ private
103
+
104
+ def valid_type?(type)
105
+ target_features.key?(type) || type == :default
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,31 @@
1
+ u_register: entity work.rggen_default_register
2
+ generic map (
3
+ READABLE => <%= readable? %>,
4
+ WRITABLE => <%= writable? %>,
5
+ ADDRESS_WIDTH => <%= address_width %>,
6
+ OFFSET_ADDRESS => <%= offset_address %>,
7
+ BUS_WIDTH => <%= bus_width %>,
8
+ DATA_WIDTH => <%= width %>,
9
+ VALID_BITS => <%= valid_bits %>,
10
+ REGISTER_INDEX => <%= register_index %>
11
+ )
12
+ port map (
13
+ i_clk => <%= clock %>,
14
+ i_rst_n => <%= reset %>,
15
+ i_register_valid => <%= register_valid %>,
16
+ i_register_access => <%= register_access %>,
17
+ i_register_address => <%= register_address %>,
18
+ i_register_write_data => <%= register_write_data %>,
19
+ i_register_strobe => <%= register_strobe %>,
20
+ o_register_active => <%= register_active %>,
21
+ o_register_ready => <%= register_ready %>,
22
+ o_register_status => <%= register_status %>,
23
+ o_register_read_data => <%= register_read_data %>,
24
+ o_register_value => <%= register_value %>,
25
+ o_bit_field_valid => <%= bit_field_valid %>,
26
+ o_bit_field_read_mask => <%= bit_field_read_mask %>,
27
+ o_bit_field_write_mask => <%= bit_field_write_mask %>,
28
+ o_bit_field_write_data => <%= bit_field_write_data %>,
29
+ i_bit_field_read_data => <%= bit_field_read_data %>,
30
+ i_bit_field_value => <%= bit_field_value %>
31
+ );
@@ -0,0 +1,29 @@
1
+ u_register: entity work.rggen_external_register
2
+ generic map (
3
+ ADDRESS_WIDTH => <%= address_width %>,
4
+ BUS_WIDTH => <%= bus_width %>,
5
+ START_ADDRESS => <%= start_address %>,
6
+ BYTE_SIZE => <%= byte_size %>
7
+ )
8
+ port map (
9
+ i_clk => <%= clock %>,
10
+ i_rst_n => <%= reset %>,
11
+ i_register_valid => <%= register_valid %>,
12
+ i_register_access => <%= register_access %>,
13
+ i_register_address => <%= register_address %>,
14
+ i_register_write_data => <%= register_write_data %>,
15
+ i_register_strobe => <%= register_strobe %>,
16
+ o_register_active => <%= register_active %>,
17
+ o_register_ready => <%= register_ready %>,
18
+ o_register_status => <%= register_status %>,
19
+ o_register_read_data => <%= register_read_data %>,
20
+ o_register_value => <%= register_value %>,
21
+ o_external_valid => <%= external_valid %>,
22
+ o_external_access => <%= external_access %>,
23
+ o_external_address => <%= external_address %>,
24
+ o_external_data => <%= external_write_data %>,
25
+ o_external_strobe => <%= external_strobe %>,
26
+ i_external_ready => <%= external_ready %>,
27
+ i_external_status => <%= external_status %>,
28
+ i_external_data => <%= external_read_data %>
29
+ );
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ RgGen.define_list_item_feature(:register, :type, :external) do
4
+ vhdl do
5
+ build do
6
+ output :external_valid, {
7
+ name: "o_#{register.name}_valid"
8
+ }
9
+ output :external_access, {
10
+ name: "o_#{register.name}_access", width: 2
11
+ }
12
+ output :external_address, {
13
+ name: "o_#{register.name}_address", width: address_width
14
+ }
15
+ output :external_write_data, {
16
+ name: "o_#{register.name}_data", width: bus_width
17
+ }
18
+ output :external_strobe, {
19
+ name: "o_#{register.name}_strobe", width: bus_width / 8
20
+ }
21
+ input :external_ready, {
22
+ name: "i_#{register.name}_ready"
23
+ }
24
+ input :external_status, {
25
+ name: "i_#{register.name}_status", width: 2
26
+ }
27
+ input :external_read_data, {
28
+ name: "i_#{register.name}_data", width: bus_width
29
+ }
30
+ end
31
+
32
+ main_code :register, from_template: true
33
+
34
+ private
35
+
36
+ def start_address
37
+ hex(register.offset_address, address_width)
38
+ end
39
+
40
+ def byte_size
41
+ register.byte_size
42
+ end
43
+ end
44
+ end