rggen 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rggen/builtins.rb +2 -1
  3. data/lib/rggen/builtins/bit_field/type.rb +3 -5
  4. data/lib/rggen/builtins/bit_field/types/ro.rb +5 -3
  5. data/lib/rggen/builtins/bit_field/types/rw.rb +5 -3
  6. data/lib/rggen/builtins/bit_field/types/rwl_rwe.rb +5 -3
  7. data/lib/rggen/builtins/bit_field/types/w0c_w1c.erb +1 -1
  8. data/lib/rggen/builtins/bit_field/types/w0c_w1c.rb +11 -5
  9. data/lib/rggen/builtins/bit_field/types/w0s_w1s.rb +10 -6
  10. data/lib/rggen/builtins/global/array_port_format.rb +15 -0
  11. data/lib/rggen/builtins/global/unfold_sv_interface_port.rb +22 -0
  12. data/lib/rggen/builtins/register/type.rb +10 -4
  13. data/lib/rggen/builtins/register/types/external.rb +56 -5
  14. data/lib/rggen/builtins/register_block/clock_reset.rb +2 -2
  15. data/lib/rggen/builtins/register_block/host_if.rb +1 -1
  16. data/lib/rggen/builtins/register_block/host_ifs/apb.rb +44 -4
  17. data/lib/rggen/builtins/register_block/host_ifs/axi4lite.rb +76 -7
  18. data/lib/rggen/builtins/register_block/rtl_top.rb +17 -7
  19. data/lib/rggen/core_components.rb +3 -3
  20. data/lib/rggen/core_components/ral/item.rb +16 -15
  21. data/lib/rggen/core_components/rtl/component.rb +0 -4
  22. data/lib/rggen/core_components/rtl/item.rb +27 -32
  23. data/lib/rggen/core_components/verilog_utility.rb +6 -6
  24. data/lib/rggen/core_components/verilog_utility/class_definition.rb +11 -11
  25. data/lib/rggen/core_components/verilog_utility/identifier.rb +49 -17
  26. data/lib/rggen/core_components/verilog_utility/{interface_instantiation.rb → interface_instance.rb} +7 -3
  27. data/lib/rggen/core_components/verilog_utility/{interface_port_declaration.rb → interface_port.rb} +7 -3
  28. data/lib/rggen/core_components/verilog_utility/local_scope.rb +8 -4
  29. data/lib/rggen/core_components/verilog_utility/module_definition.rb +20 -9
  30. data/lib/rggen/core_components/verilog_utility/package_definition.rb +15 -23
  31. data/lib/rggen/core_components/verilog_utility/structure_definition.rb +7 -6
  32. data/lib/rggen/core_components/verilog_utility/variable.rb +115 -0
  33. data/lib/rggen/version.rb +2 -2
  34. data/rtl/compile.f +0 -3
  35. data/rtl/rggen_address_decoder.sv +2 -2
  36. data/rtl/rggen_bus_splitter.sv +2 -2
  37. data/rtl/rggen_external_register.sv +2 -2
  38. data/rtl/rggen_host_if_apb.sv +2 -2
  39. data/rtl/rggen_indirect_register.sv +3 -3
  40. data/sample/sample.json +3 -1
  41. data/sample/sample.yaml +2 -0
  42. data/sample/sample_0.sv +30 -42
  43. data/sample/sample_1.sv +13 -13
  44. data/sample/sample_setup.rb +2 -2
  45. data/setup/default.rb +2 -2
  46. metadata +7 -9
  47. data/lib/rggen/builtins/register_block/irq_controller.erb +0 -9
  48. data/lib/rggen/builtins/register_block/irq_controller.rb +0 -43
  49. data/lib/rggen/builtins/register_block/rtl_top.erb +0 -7
  50. data/lib/rggen/core_components/verilog_utility/declaration.rb +0 -76
  51. data/rtl/rggen_irq_controller.sv +0 -21
@@ -9,7 +9,6 @@ module RgGen
9
9
  end
10
10
 
11
11
  def to_code
12
- bodies.unshift(signal_declarations) if signals?
13
12
  code_block do |c|
14
13
  header_code(c)
15
14
  body_code(c)
@@ -25,6 +24,13 @@ module RgGen
25
24
  loops? && generate_for_header(code)
26
25
  end
27
26
 
27
+ def body_code_blocks
28
+ blocks = []
29
+ signals? && (blocks << signal_declarations)
30
+ blocks.concat(super)
31
+ blocks
32
+ end
33
+
28
34
  def footer_code(code)
29
35
  loops? && generate_for_footer(code)
30
36
  code << :end
@@ -61,9 +67,7 @@ module RgGen
61
67
 
62
68
  def signal_declarations
63
69
  lambda do |code|
64
- signals.each do |signal|
65
- code << signal << semicolon << nl
66
- end
70
+ signals.each { |signal| code << signal << semicolon << nl }
67
71
  end
68
72
  end
69
73
  end
@@ -5,9 +5,9 @@ module RgGen
5
5
  attr_setter :ports
6
6
  attr_setter :signals
7
7
 
8
- def to_code
9
- bodies.unshift(signal_declarations) if signals?
10
- super
8
+ def include_file(file)
9
+ @include_files ||= []
10
+ @include_files << "`include #{file.to_s.quote}"
11
11
  end
12
12
 
13
13
  private
@@ -15,12 +15,20 @@ module RgGen
15
15
  def header_code
16
16
  code_block do |code|
17
17
  code << :module << space << @name << space
18
- parameter_declarations(code)
18
+ parameters? && parameter_declarations(code)
19
19
  port_declarations(code)
20
20
  code << semicolon
21
21
  end
22
22
  end
23
23
 
24
+ def body_code_blocks
25
+ blocks = []
26
+ @include_files && (blocks << include_files_code)
27
+ signals? && (blocks << signal_declarations)
28
+ blocks.concat(super)
29
+ blocks
30
+ end
31
+
24
32
  def footer_code
25
33
  :endmodule
26
34
  end
@@ -38,7 +46,6 @@ module RgGen
38
46
  end
39
47
 
40
48
  def parameter_declarations(code)
41
- return unless parameters?
42
49
  wrap(code, '#(', ')') do
43
50
  declarations(@parameters, code)
44
51
  end
@@ -46,15 +53,19 @@ module RgGen
46
53
 
47
54
  def port_declarations(code)
48
55
  wrap(code, '(', ')') do
49
- declarations(@ports, code) if ports?
56
+ ports? && declarations(@ports, code)
57
+ end
58
+ end
59
+
60
+ def include_files_code
61
+ lambda do |code|
62
+ @include_files.each { |file| code << file << nl }
50
63
  end
51
64
  end
52
65
 
53
66
  def signal_declarations
54
67
  lambda do |code|
55
- signals.each do |signal|
56
- code << signal << semicolon << nl
57
- end
68
+ signals.each { |signal| code << signal << semicolon << nl }
58
69
  end
59
70
  end
60
71
 
@@ -14,17 +14,13 @@ module RgGen
14
14
  end
15
15
 
16
16
  def import_package(name, items = nil)
17
- import_packages << ImportedPackage.new(name, items)
17
+ @import_packages ||= []
18
+ @import_packages << ImportedPackage.new(name, items)
18
19
  end
19
20
 
20
21
  def include_file(name)
21
- include_files << "`include #{name.to_s.quote}"
22
- end
23
-
24
- def to_code
25
- bodies.unshift(include_fiels_code ) unless @include_files.nil?
26
- bodies.unshift(import_packges_code) unless @import_packages.nil?
27
- super
22
+ @include_files ||= []
23
+ @include_files << "`include #{name.to_s.quote}"
28
24
  end
29
25
 
30
26
  private
@@ -33,31 +29,27 @@ module RgGen
33
29
  "package #{@name};"
34
30
  end
35
31
 
36
- def footer_code
37
- :endpackage
38
- end
39
-
40
- def import_packages
41
- @import_packages ||= []
32
+ def body_code_blocks
33
+ blocks = []
34
+ @import_packages && (blocks << import_packges_code)
35
+ @include_files && (blocks << include_files_code)
36
+ blocks.concat(super)
37
+ blocks
42
38
  end
43
39
 
44
- def include_files
45
- @include_files ||= []
40
+ def footer_code
41
+ :endpackage
46
42
  end
47
43
 
48
44
  def import_packges_code
49
45
  lambda do |code|
50
- import_packages.each do |package|
51
- code << package << nl
52
- end
46
+ @import_packages.each { |package| code << package << nl }
53
47
  end
54
48
  end
55
49
 
56
- def include_fiels_code
50
+ def include_files_code
57
51
  lambda do |code|
58
- include_files.each do |file|
59
- code << file << nl
60
- end
52
+ @include_files.each { |file| code << file << nl }
61
53
  end
62
54
  end
63
55
  end
@@ -9,7 +9,8 @@ module RgGen
9
9
  end
10
10
 
11
11
  def body(&block)
12
- bodies << block if block_given?
12
+ @bodies ||= []
13
+ @bodies << block if block_given?
13
14
  end
14
15
 
15
16
  def to_code
@@ -22,16 +23,16 @@ module RgGen
22
23
 
23
24
  private
24
25
 
25
- def bodies
26
- @bodies ||= []
27
- end
28
-
29
26
  def body_code(code)
30
- bodies.each do |body|
27
+ body_code_blocks.each do |body|
31
28
  generate_body_code(code, body)
32
29
  end
33
30
  end
34
31
 
32
+ def body_code_blocks
33
+ @bodies || []
34
+ end
35
+
35
36
  def generate_body_code(code, body)
36
37
  indent(code, 2) do
37
38
  if body.arity.zero?
@@ -0,0 +1,115 @@
1
+ module RgGen
2
+ module VerilogUtility
3
+ class Variable
4
+ def initialize(variable_type, attributes)
5
+ @variable_type = variable_type
6
+ @attributes = attributes
7
+ end
8
+
9
+ def to_s
10
+ code_snippets.join(' ')
11
+ end
12
+
13
+ def identifier
14
+ name = @attributes[:name]
15
+ width = @attributes[:width] || 1
16
+ dimensions = @attributes[:dimensions]
17
+ array_fomrat = @attributes[:array_format] || :unpacked
18
+ Identifier.new(name, width, dimensions, array_fomrat)
19
+ end
20
+
21
+ private
22
+
23
+ def code_snippets
24
+ [
25
+ rand_keyword,
26
+ port_direction,
27
+ parameter_keyword,
28
+ data_type,
29
+ width,
30
+ variable_identifier,
31
+ default_value_assignment
32
+ ].select(&:itself)
33
+ end
34
+
35
+ def rand_keyword
36
+ @variable_type == :variable && @attributes[:random] && :rand
37
+ end
38
+
39
+ def port_direction
40
+ @variable_type == :port && @attributes[:direction]
41
+ end
42
+
43
+ def parameter_keyword
44
+ @variable_type == :parameter && @attributes[:parameter_type]
45
+ end
46
+
47
+ def data_type
48
+ @attributes[:data_type]
49
+ end
50
+
51
+ def width
52
+ vector? || return
53
+ msb =
54
+ if numerical_width?
55
+ vectored_array_size * (@attributes[:width] || 1) - 1
56
+ elsif vectored_array?
57
+ "#{vectored_array_size}*#{@attributes[:width]}-1"
58
+ else
59
+ "#{@attributes[:width]}-1"
60
+ end
61
+ "[#{msb}:0]"
62
+ end
63
+
64
+ def vectored_array_size
65
+ vectored_array? || (return 1)
66
+ @attributes[:dimensions].inject(&:*)
67
+ end
68
+
69
+ def variable_identifier
70
+ "#{@attributes[:name]}#{dimensions}"
71
+ end
72
+
73
+ def dimensions
74
+ unpacked_array? || return
75
+ @attributes[:dimensions].map { |dimension| "[#{dimension}]" }.join
76
+ end
77
+
78
+ def default_value_assignment
79
+ @attributes[:default] || return
80
+ "= #{@attributes[:default]}"
81
+ end
82
+
83
+ def parameter?
84
+ @variable_type == :parameter
85
+ end
86
+
87
+ def vector?
88
+ @attributes[:vector] && (return true)
89
+ vectored_array? && (return true)
90
+ @attributes[:width] || (return false)
91
+ numerical_width? || (return true)
92
+ parameter? && (return true)
93
+ @attributes[:width] > 1
94
+ end
95
+
96
+ def numerical_width?
97
+ @attributes[:width] || (return true)
98
+ @attributes[:width].is_a?(Integer) && (return true)
99
+ false
100
+ end
101
+
102
+ def unpacked_array?
103
+ @attributes[:dimensions] || (return false)
104
+ @attributes[:array_format] == :vectored && (return false)
105
+ true
106
+ end
107
+
108
+ def vectored_array?
109
+ @attributes[:dimensions] || (return false)
110
+ @attributes[:array_format] == :vectored && (return true)
111
+ false
112
+ end
113
+ end
114
+ end
115
+ end
data/lib/rggen/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module RgGen
2
2
  MAJOR = 0
3
- MINOR = 7
4
- TEENY = 2
3
+ MINOR = 8
4
+ TEENY = 0
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{TEENY}".freeze
6
6
  end
data/rtl/compile.f CHANGED
@@ -3,7 +3,6 @@ ${RGGEN_HOME}/rtl/rggen_bus_if.sv
3
3
  ${RGGEN_HOME}/rtl/rggen_register_if.sv
4
4
  ${RGGEN_HOME}/rtl/rggen_bit_field_if.sv
5
5
  ${RGGEN_HOME}/rtl/rggen_bus_splitter.sv
6
- ${RGGEN_HOME}/rtl/rggen_irq_controller.sv
7
6
  ${RGGEN_HOME}/rtl/rggen_address_decoder.sv
8
7
  ${RGGEN_HOME}/rtl/rggen_register_base.sv
9
8
  ${RGGEN_HOME}/rtl/rggen_default_register.sv
@@ -13,9 +12,7 @@ ${RGGEN_HOME}/rtl/rggen_bit_field_ro.sv
13
12
  ${RGGEN_HOME}/rtl/rggen_bit_field_rw.sv
14
13
  ${RGGEN_HOME}/rtl/rggen_bit_field_rwl_rwe.sv
15
14
  ${RGGEN_HOME}/rtl/rggen_bit_field_w01s_w01c.sv
16
-
17
15
  ${RGGEN_HOME}/rtl/rggen_apb_if.sv
18
16
  ${RGGEN_HOME}/rtl/rggen_host_if_apb.sv
19
-
20
17
  ${RGGEN_HOME}/rtl/rggen_axi4lite_if.sv
21
18
  ${RGGEN_HOME}/rtl/rggen_host_if_axi4lite.sv
@@ -4,8 +4,8 @@ module rggen_address_decoder #(
4
4
  parameter bit [ADDRESS_WIDTH-1:0] END_ADDRESS = '0,
5
5
  parameter int DATA_WIDTH = 32
6
6
  )(
7
- input [ADDRESS_WIDTH-1:0] i_address,
8
- output o_match
7
+ input logic [ADDRESS_WIDTH-1:0] i_address,
8
+ output logic o_match
9
9
  );
10
10
  localparam int LSB = $clog2(DATA_WIDTH / 8);
11
11
  localparam bit [ADDRESS_WIDTH-LSB-1:0] SADDRESS = STAET_ADDRESS[ADDRESS_WIDTH-1:LSB];
@@ -2,8 +2,8 @@ module rggen_bus_splitter #(
2
2
  parameter int DATA_WIDTH = 32,
3
3
  parameter int TOTAL_REGISTERS = 1
4
4
  )(
5
- input clk,
6
- input rst_n,
5
+ input logic clk,
6
+ input logic rst_n,
7
7
  rggen_bus_if.slave bus_if,
8
8
  rggen_register_if.master register_if[TOTAL_REGISTERS]
9
9
  );
@@ -4,8 +4,8 @@ module rggen_external_register #(
4
4
  parameter bit [ADDRESS_WIDTH-1:0] END_ADDRESS = '0,
5
5
  parameter int DATA_WIDTH = 32
6
6
  )(
7
- input clk,
8
- input rst_n,
7
+ input logic clk,
8
+ input logic rst_n,
9
9
  rggen_register_if.slave register_if,
10
10
  rggen_bus_if.master bus_if
11
11
  );
@@ -3,8 +3,8 @@ module rggen_host_if_apb #(
3
3
  parameter int DATA_WIDTH = 32,
4
4
  parameter int TOTAL_REGISTERS = 1
5
5
  )(
6
- input clk,
7
- input rst_n,
6
+ input logic clk,
7
+ input logic rst_n,
8
8
  rggen_apb_if.slave apb_if,
9
9
  rggen_register_if.master register_if[TOTAL_REGISTERS]
10
10
  );
@@ -7,9 +7,9 @@ module rggen_indirect_register #(
7
7
  parameter int DATA_WIDTH = 32,
8
8
  parameter bit [DATA_WIDTH-1:0] VALID_BITS = '0
9
9
  )(
10
- rggen_register_if.slave register_if,
11
- rggen_bit_field_if.master bit_field_if,
12
- input [INDEX_WIDTH-1:0] i_index
10
+ rggen_register_if.slave register_if,
11
+ rggen_bit_field_if.master bit_field_if,
12
+ input logic [INDEX_WIDTH-1:0] i_index
13
13
  );
14
14
  logic index_match;
15
15
 
data/sample/sample.json CHANGED
@@ -1,4 +1,6 @@
1
1
  {
2
2
  "address_width": 16,
3
- "host_if" : "apb"
3
+ "host_if": "apb",
4
+ "array_port_format": "unpacked",
5
+ "unfold_sv_interface_port": "no"
4
6
  }
data/sample/sample.yaml CHANGED
@@ -1,2 +1,4 @@
1
1
  address_width: 16
2
2
  host_if: apb
3
+ array_port_format: unpacked
4
+ unfold_sv_interface_port: no
data/sample/sample_0.sv CHANGED
@@ -1,38 +1,37 @@
1
1
  module sample_0 (
2
- input clk,
3
- input rst_n,
2
+ input logic clk,
3
+ input logic rst_n,
4
4
  rggen_apb_if.slave apb_if,
5
- output o_irq,
6
- output [15:0] o_bit_field_0_0,
7
- output [15:0] o_bit_field_0_1,
8
- output [31:0] o_bit_field_1_0,
9
- input i_bit_field_2_0,
10
- output o_bit_field_2_1,
11
- input [31:0] i_bit_field_3_0,
12
- input [15:0] i_bit_field_4_0[4],
13
- output [15:0] o_bit_field_4_1[4],
14
- input [15:0] i_bit_field_5_0[2][4],
15
- output [15:0] o_bit_field_5_1[2][4],
16
- input i_bit_field_6_0_set,
17
- input i_bit_field_6_1_set,
18
- output o_bit_field_7_0,
19
- input i_bit_field_7_0_clear,
20
- output o_bit_field_7_1,
21
- input i_bit_field_7_1_clear,
22
- output [15:0] o_bit_field_8_0,
23
- output [15:0] o_bit_field_8_1,
5
+ output logic [15:0] o_bit_field_0_0,
6
+ output logic [15:0] o_bit_field_0_1,
7
+ output logic [31:0] o_bit_field_1_0,
8
+ input logic i_bit_field_2_0,
9
+ output logic o_bit_field_2_1,
10
+ input logic [31:0] i_bit_field_3_0,
11
+ input logic [15:0] i_bit_field_4_0[4],
12
+ output logic [15:0] o_bit_field_4_1[4],
13
+ input logic [15:0] i_bit_field_5_0[2][4],
14
+ output logic [15:0] o_bit_field_5_1[2][4],
15
+ input logic i_bit_field_6_0_set,
16
+ output logic o_bit_field_6_0,
17
+ input logic i_bit_field_6_1_set,
18
+ output logic o_bit_field_6_1,
19
+ output logic o_bit_field_7_0,
20
+ input logic i_bit_field_7_0_clear,
21
+ output logic o_bit_field_7_1,
22
+ input logic i_bit_field_7_1_clear,
23
+ output logic [15:0] o_bit_field_8_0,
24
+ output logic [15:0] o_bit_field_8_1,
24
25
  rggen_bus_if.master register_9_bus_if
25
26
  );
26
27
  rggen_register_if #(8, 32) register_if[20]();
27
- logic [1:0] ier;
28
- logic [1:0] isr;
29
28
  `define rggen_connect_bit_field_if(RIF, FIF, MSB, LSB) \
30
- assign FIF.read_access = RIF.read_access; \
31
- assign FIF.write_access = RIF.write_access; \
32
- assign FIF.write_data = RIF.write_data[MSB:LSB]; \
33
- assign FIF.write_mask = RIF.write_mask[MSB:LSB]; \
34
- assign RIF.value[MSB:LSB] = FIF.value; \
35
- assign RIF.read_data[MSB:LSB] = FIF.read_data;
29
+ assign FIF.read_access = RIF.read_access; \
30
+ assign FIF.write_access = RIF.write_access; \
31
+ assign FIF.write_data = RIF.write_data[MSB:LSB]; \
32
+ assign FIF.write_mask = RIF.write_mask[MSB:LSB]; \
33
+ assign RIF.value[MSB:LSB] = FIF.value; \
34
+ assign RIF.read_data[MSB:LSB] = FIF.read_data;
36
35
  rggen_host_if_apb #(
37
36
  .LOCAL_ADDRESS_WIDTH (8),
38
37
  .DATA_WIDTH (32),
@@ -43,17 +42,6 @@ module sample_0 (
43
42
  .apb_if (apb_if),
44
43
  .register_if (register_if)
45
44
  );
46
- assign ier = {register_if[2].value[0], register_if[2].value[0]};
47
- assign isr = {register_if[16].value[8], register_if[16].value[0]};
48
- rggen_irq_controller #(
49
- .TOTAL_INTERRUPTS (2)
50
- ) u_irq_controller (
51
- .clk (clk),
52
- .rst_n (rst_n),
53
- .i_ier (ier),
54
- .i_isr (isr),
55
- .o_irq (o_irq)
56
- );
57
45
  generate if (1) begin : g_register_0
58
46
  rggen_bit_field_if #(32) bit_field_if();
59
47
  rggen_default_register #(
@@ -289,7 +277,7 @@ module sample_0 (
289
277
  .rst_n (rst_n),
290
278
  .i_set_or_clear (i_bit_field_6_0_set),
291
279
  .bit_field_if (bit_field_sub_if),
292
- .o_value ()
280
+ .o_value (o_bit_field_6_0)
293
281
  );
294
282
  end
295
283
  if (1) begin : g_bit_field_6_1
@@ -305,7 +293,7 @@ module sample_0 (
305
293
  .rst_n (rst_n),
306
294
  .i_set_or_clear (i_bit_field_6_1_set),
307
295
  .bit_field_if (bit_field_sub_if),
308
- .o_value ()
296
+ .o_value (o_bit_field_6_1)
309
297
  );
310
298
  end
311
299
  end endgenerate