origen_sim 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3d9900584dd6370a9bcc96c61d79731dd3f54c0
4
- data.tar.gz: 79287986f985475310c43f51fc220d30430685c2
3
+ metadata.gz: 5d3ab8cb5d8aa155ae27711a8fba140910316c97
4
+ data.tar.gz: 6df912a7d278020ba64bda1d203fc3efd7f5d5a1
5
5
  SHA512:
6
- metadata.gz: e6db91532f5e684b77b82b2eebba479fe0ede7abc242ecd1f3566621e090f71103a378ab1f89987edd67bed8ec78ccf671b34c6281f410a0ac7a29658dc387de
7
- data.tar.gz: dbc381f99807bb2781ac7421b9b169e64f276eb03084256906c18ce3e11ad02aef44a4a568469a4c8b83cca935a48f1b153ebe7230ed1d312358690785b04927
6
+ metadata.gz: c5e6a4e7fcab4e0aff503dcbcacace8f929e50e4cb971029b4dc7ae850196a1014f512d5112af8685ff4a002b82d4493df1854fa07a99bc68ccb138d80857eed
7
+ data.tar.gz: c7dc8d1c270e0a1426177b0b3e96489aa8e714fe13299219f3a03fb7e675f3930c0dc9e106603f4042320118603aa42ecc6faaee0ffa1366152758d7af648a1c
@@ -1,5 +1,6 @@
1
1
  require 'origen'
2
2
  class OrigenSimApplication < Origen::Application
3
+ attr_accessor :update_sim_captures
3
4
 
4
5
  # See http://origen-sdk.org/origen/api/Origen/Application/Configuration.html
5
6
  # for a full list of the configuration options available
@@ -27,9 +28,19 @@ class OrigenSimApplication < Origen::Application
27
28
  #:patterns => "pattern",
28
29
  #:templates => "templates",
29
30
  #:programs => "program",
30
- :command_launcher => "config/shared_commands.rb"
31
+ :command_launcher => "config/shared_commands.rb",
32
+ :global_launcher => "config/global_commands.rb"
31
33
  }
32
34
 
35
+ config.remotes = [
36
+ {
37
+ dir: "example_rtl",
38
+ rc_url: 'https://github.com/Origen-SDK/example_rtl.git',
39
+ version: "master",
40
+ development: true
41
+ }
42
+ ]
43
+
33
44
  # See: http://origen-sdk.org/origen/latest/guides/utilities/lint/
34
45
  config.lint_test = {
35
46
  # Require the lint tests to pass before allowing a release to proceed
@@ -15,11 +15,34 @@ case @command
15
15
 
16
16
  # Here is an example of how to implement a command, the logic can go straight
17
17
  # in here or you can require an external file if preferred.
18
- when "my_command"
19
- puts "Doing something..."
20
- #require "commands/my_command" # Would load file lib/commands/my_command.rb
21
- # You must always exit upon successfully capturing a command to prevent
22
- # control flowing back to Origen
18
+ when "sim:build_example"
19
+ Dir.chdir(Origen.root) do
20
+ output = `origen sim:build #{Origen.app.remotes_dir}/example_rtl/dut1/dut1.v`
21
+ puts output
22
+ Origen.load_target
23
+ FileUtils.mkdir_p "simulation/default/#{tester.simulator.config[:vendor]}"
24
+ case tester.simulator.config[:vendor]
25
+ when :icarus
26
+ output =~ / (cd .*)\n/
27
+ system $1
28
+ FileUtils.mv "#{Origen.config.output_directory}/origen.vpi", "simulation/default/icarus"
29
+ output =~ / (iverilog .*)\n/
30
+ system $1
31
+ FileUtils.mv "origen.vvp", "simulation/default/icarus"
32
+
33
+ when :cadence
34
+ output =~ / (irun .*)\n/
35
+ system = $1
36
+ FileUtils.mv "INCA_libs", "simulation/default/cadence"
37
+
38
+ end
39
+
40
+ puts
41
+ puts "Done, run this command to run a test simulation:"
42
+ puts
43
+ puts " origen g test"
44
+ puts
45
+ end
23
46
  exit 0
24
47
 
25
48
  ## Example of how to make a command to run unit tests, this simply invokes RSpec on
@@ -65,10 +88,8 @@ else
65
88
  # You probably want to also add the your commands to the help shown via
66
89
  # origen -h, you can do this be assigning the required text to @application_commands
67
90
  # before handing control back to Origen. Un-comment the example below to get started.
68
- # @application_commands = <<-EOT
69
- # specs Run the specs (tests), -c will enable coverage
70
- # examples Run the examples (tests), -c will enable coverage
71
- # test Run both specs and examples, -c will enable coverage
72
- # EOT
91
+ @application_commands = <<-EOT
92
+ sim:build_example Build the example simulation object for the current environment setting
93
+ EOT
73
94
 
74
95
  end
@@ -0,0 +1,12 @@
1
+ case @command
2
+
3
+ when "sim:build", "origen_sim:build"
4
+ require "#{Origen.root!}/lib/origen_sim/commands/build"
5
+ exit 0
6
+
7
+ else
8
+ @global_commands << <<-EOT
9
+ sim:build Build an Origen testbench and simulator extension for a given RTL design
10
+ EOT
11
+
12
+ end
@@ -4,15 +4,22 @@ case @command
4
4
  when 'generate'
5
5
  $use_fast_probe_depth = false
6
6
  @application_options << ["--fast", "Fast simulation, minimum probe depth"]
7
- $use_fast_probe_depth = true if ARGV.include?('--fast')
7
+ $use_fast_probe_depth = ARGV.include?('--fast')
8
+ @application_options << ["--sim_capture", "Update sim captures (ignored when not running a simulation)"]
9
+ Origen.app!.update_sim_captures = ARGV.include?('--sim_capture')
8
10
 
9
- when "origen_sim:build", "sim:build"
10
- require "origen_sim/commands/build"
11
+ when "sim:ci", "origen_sim:ci"
12
+ require "#{Origen.root!}/lib/origen_sim/commands/ci"
13
+ exit 0
14
+
15
+ when "sim:co", "origen_sim:co"
16
+ require "#{Origen.root!}/lib/origen_sim/commands/co"
11
17
  exit 0
12
18
 
13
19
  else
14
20
  @plugin_commands << <<-EOT
15
- sim:build Build the simulation object for the current/given target
21
+ sim:ci Checkin a simulation snapshot
22
+ sim:co Checkout a simulation snapshot
16
23
  EOT
17
24
 
18
25
  end
@@ -1,7 +1,7 @@
1
1
  module OrigenSim
2
2
  MAJOR = 0
3
- MINOR = 5
4
- BUGFIX = 5
3
+ MINOR = 6
4
+ BUGFIX = 0
5
5
  DEV = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, BUGFIX].join(".") + (DEV ? ".pre#{DEV}" : '')
@@ -4,6 +4,7 @@
4
4
  ///
5
5
  #include "bridge.h"
6
6
  #include "client.h"
7
+ #include "defines.h"
7
8
  #include <stdint.h>
8
9
  #include <stdlib.h>
9
10
  #include <stdio.h>
@@ -39,7 +40,7 @@ typedef struct Wave {
39
40
  int active_pin_count;
40
41
  } Wave;
41
42
 
42
- static int period_in_ns;
43
+ static uint64_t period_in_ps;
43
44
  static long repeat = 0;
44
45
  static Pin pins[MAX_NUMBER_PINS];
45
46
  static int number_of_pins = 0;
@@ -261,7 +262,7 @@ static void bridge_clear_waves_and_pins() {
261
262
 
262
263
  static void bridge_set_period(char * p_in_ns) {
263
264
  int p = (int) strtol(p_in_ns, NULL, 10);
264
- period_in_ns = p;
265
+ period_in_ps = p * 1000;
265
266
  bridge_clear_waves_and_pins();
266
267
  }
267
268
 
@@ -472,6 +473,7 @@ PLI_INT32 bridge_apply_wave_event_cb(p_cb_data data) {
472
473
 
473
474
  /// Registers a callback to apply the given wave during this cycle
474
475
  static void bridge_register_wave_event(int wave_ix, int event_ix, int compare, int delay_in_ns) {
476
+ uint64_t delay_in_ps = delay_in_ns * 1000;
475
477
  s_cb_data call;
476
478
  s_vpi_time time;
477
479
 
@@ -487,8 +489,9 @@ static void bridge_register_wave_event(int wave_ix, int event_ix, int compare, i
487
489
  *d2 = compare;
488
490
 
489
491
  time.type = vpiSimTime;
490
- time.high = (uint32_t)(0);
491
- time.low = (uint32_t)(delay_in_ns);
492
+
493
+ time.high = (uint32_t)(delay_in_ps >> 32);
494
+ time.low = (uint32_t)(delay_in_ps);
492
495
 
493
496
  call.reason = cbAfterDelay;
494
497
  call.cb_rtn = bridge_apply_wave_event_cb;
@@ -512,7 +515,7 @@ PLI_INT32 bridge_init() {
512
515
  /// When Origen requests a cycle, time will be advanced and this func will be called again.
513
516
  PLI_INT32 bridge_wait_for_msg(p_cb_data data) {
514
517
  UNUSED(data);
515
- int max_msg_len = 100;
518
+ int max_msg_len = 1024;
516
519
  char msg[max_msg_len];
517
520
  int err;
518
521
  char *opcode, *arg1, *arg2, *arg3, *arg4;
@@ -646,8 +649,10 @@ PLI_INT32 bridge_wait_for_msg(p_cb_data data) {
646
649
  arg1 = strtok(NULL, "^");
647
650
  handle = vpi_handle_by_name(arg1, NULL);
648
651
  if (handle) {
649
- v.format = vpiDecStrVal; // Seems important to set this before get
652
+ //v.format = vpiDecStrVal; // Seems important to set this before get
653
+ v.format = vpiBinStrVal;
650
654
  vpi_get_value(handle, &v);
655
+ //DEBUG("%s\n", v.value.str);
651
656
  sprintf(msg, "%s\n", v.value.str);
652
657
  client_put(msg);
653
658
  } else {
@@ -726,6 +731,11 @@ PLI_INT32 bridge_wait_for_msg(p_cb_data data) {
726
731
  arg1 = strtok(NULL, "^");
727
732
  bridge_stop_capture_pin(arg1);
728
733
  break;
734
+ // Get version, returns the version of OrigenSim the DUT object was compiled with
735
+ // i^
736
+ case 'i' :
737
+ client_put(ORIGEN_SIM_VERSION"\n");
738
+ break;
729
739
  default :
730
740
  vpi_printf("ERROR: Illegal message received from Origen: %s\n", orig_msg);
731
741
  runtime_errors += 1;
@@ -768,8 +778,8 @@ static void bridge_cycle() {
768
778
  s_vpi_time time;
769
779
 
770
780
  time.type = vpiSimTime;
771
- time.high = (uint32_t)(0);
772
- time.low = (uint32_t)(period_in_ns);
781
+ time.high = (uint32_t)(period_in_ps >> 32);
782
+ time.low = (uint32_t)(period_in_ps);
773
783
 
774
784
  call.reason = cbAfterDelay;
775
785
  call.obj = 0;
@@ -9,6 +9,7 @@
9
9
  #include <sys/un.h>
10
10
  #include <unistd.h>
11
11
  #include <time.h>
12
+ #include <string.h>
12
13
 
13
14
  static int sock;
14
15
  static uint64_t msg_count = 0;
@@ -62,7 +63,6 @@ bool is_server_alive() {
62
63
  /// Send a message to the master Origen process.
63
64
  /// NOTE: THE CALLER IS RESPONSIBLE FOR ADDING A \n TERMINATOR TO
64
65
  /// THE MESSAGE
65
- /// to the data as this function will do it for you.
66
66
  int client_put(char* data) {
67
67
  if(send(sock, data , strlen(data), 0) < 0) {
68
68
  return 1;
@@ -0,0 +1,6 @@
1
+ #ifndef DEFINES_H
2
+ #define DEFINES_H
3
+
4
+ #define ORIGEN_SIM_VERSION "<%= OrigenSim::VERSION %>"
5
+
6
+ #endif
@@ -110,12 +110,12 @@ static void register_callback(PLI_INT32 aReason, PLI_INT32 (*aHandler)(p_cb_data
110
110
  void (*vlog_startup_routines[])(void) = { init, 0 };
111
111
 
112
112
  #if defined(CVER) || defined(VCS) || defined(NCSIM)
113
- void vlog_startup_routines_bootstrap()
113
+ void vlog_startup_routines_bootstrap()
114
+ {
115
+ unsigned int i;
116
+ for (i = 0; vlog_startup_routines[i]; i++)
114
117
  {
115
- unsigned int i;
116
- for (i = 0; vlog_startup_routines[i]; i++)
117
- {
118
- vlog_startup_routines[i]();
119
- }
118
+ vlog_startup_routines[i]();
120
119
  }
120
+ }
121
121
  #endif
@@ -1,25 +1,26 @@
1
1
  require 'optparse'
2
2
  require 'origen_sim'
3
+ require_relative '../../../config/version'
4
+ require 'origen_verilog'
3
5
 
4
- options = {}
6
+ options = { source_dirs: [] }
5
7
 
6
8
  # App options are options that the application can supply to extend this command
7
9
  app_options = @application_options || []
8
10
  opt_parser = OptionParser.new do |opts|
9
11
  opts.banner = <<-EOT
10
- Compile an RTL design into an object that Origen can simulate.
12
+ Build an Origen testbench and simulator VPI extension for the given top-level RTL design.
11
13
 
12
- All configuration apart from target selection should be done when instantiating the
13
- OrigenSim::Tester in an environment file. This encourages the configuration to be
14
- checked in, enabling repeatable builds in future.
14
+ The created artifacts should be included in a compilation of the given design to create
15
+ an Origen-enabled simulation object that can be used to simulate Origen-based test patterns.
15
16
 
16
- Usage: origen origen_sim:build [options]
17
+ Usage: origen sim:build TOP_LEVEL_RTL_FILE [options]
17
18
  EOT
18
- opts.on('-e', '--environment NAME', String, 'Override the default environment, NAME can be a full path or a fragment of an environment file name') { |e| options[:environment] = e }
19
- opts.on('-t', '--target NAME', String, 'Override the default target, NAME can be a full path or a fragment of a target file name') { |t| options[:target] = t }
20
- opts.on('-pl', '--plugin PLUGIN_NAME', String, 'Set current plugin') { |pl_n| options[:current_plugin] = pl_n }
21
- opts.on('--testrun', 'Displays the commands that will be generated but does not execute them') { options[:testrun] = true }
22
- opts.on('-i', '--incremental', 'Preserve existing compiled files to do an incremental build instead of starting from scratch') { options[:incremental] = true }
19
+ opts.on('-o', '--output DIR', String, 'Override the default output directory') { |t| options[:output] = t }
20
+ opts.on('-t', '--top NAME', String, 'Specify the top-level Verilog module name if OrigenSim can\'t work it out') { |t| options[:top_level_name] = t }
21
+ opts.on('-s', '--source_dir PATH', 'Directories to look for include files in (the directory containing the top-level is already considered)') do |path|
22
+ options[:source_dirs] << path
23
+ end
23
24
  opts.on('-d', '--debugger', 'Enable the debugger') { options[:debugger] = true }
24
25
  app_options.each do |app_option|
25
26
  opts.on(*app_option) {}
@@ -29,83 +30,120 @@ Usage: origen origen_sim:build [options]
29
30
  end
30
31
 
31
32
  opt_parser.parse! ARGV
32
- Origen.app.plugins.temporary = options[:current_plugin] if options[:current_plugin]
33
- Origen.environment.temporary = options[:environment] if options[:environment]
34
- Origen.target.temporary = options[:target] if options[:target]
35
- Origen.app.load_target!
36
-
37
- unless tester.is_a?(OrigenSim::Tester)
38
- puts 'The target/environment does not instantiate an OrigenSim::Tester instance!'
39
- exit
33
+
34
+ unless ARGV.size > 0
35
+ puts 'You must supply a path to the top-level RTL file'
36
+ exit 1
37
+ end
38
+ rtl_top = ARGV.first
39
+ unless File.exist?(rtl_top)
40
+ puts "File does not exist: #{rtl_top}"
41
+ exit 1
40
42
  end
41
43
 
42
- simulator = OrigenSim.simulator
43
- config = simulator.configuration
44
- tmp_dir = simulator.tmp_dir
45
-
46
- unless options[:testrun]
47
- FileUtils.rm_rf(tmp_dir) unless options[:incremental]
48
- FileUtils.mkdir_p(tmp_dir)
49
- FileUtils.rm_rf(simulator.compiled_dir) unless options[:incremental]
50
- FileUtils.mkdir_p(simulator.compiled_dir)
51
- FileUtils.rm_rf(simulator.artifacts_dir)
52
- FileUtils.mkdir_p(simulator.artifacts_dir)
53
- Array(config[:artifacts] || config[:artifact]).each do |f|
54
- FileUtils.cp(f, simulator.artifacts_dir)
55
- end
44
+ ast = OrigenVerilog.parse_file(rtl_top)
56
45
 
57
- # Create the testbench for the current Origen target and simulator vendor
58
- Origen.app.runner.launch action: :compile,
59
- files: "#{Origen.root!}/templates/rtl_v/origen.v.erb",
60
- output: tmp_dir,
61
- check_for_changes: false,
62
- options: { vendor: config[:vendor], top: config[:rtl_top], incl: config[:incl_files] }
46
+ unless ast
47
+ puts 'Sorry, but the given top-level RTL file failed to parse'
48
+ exit 1
63
49
  end
64
50
 
65
- case config[:vendor]
66
- when :icarus
67
- # Compile the VPI extension first
68
- Dir.chdir tmp_dir do
69
- system "iverilog-vpi #{Origen.root!}/ext/*.c -DICARUS --name=origen"
70
- system "mv origen.vpi #{simulator.compiled_dir}"
71
- end
72
- # Build the object containing the DUT and testbench
73
- cmd = "iverilog -o #{simulator.compiled_dir}/dut.vvp"
74
- Array(config[:rtl_dir] || config[:rtl_dirs]).each do |dir|
75
- cmd += " -I #{dir}"
76
- end
77
- Array(config[:rtl_file] || config[:rtl_files]).each do |f|
78
- cmd += " #{f}"
79
- end
80
- cmd += " #{tmp_dir}/origen.v"
51
+ candidates = ast.top_level_modules
52
+ candidates = ast.modules if candidates.empty?
81
53
 
82
- when :cadence
83
- cmd = config[:irun] || 'irun'
84
- Array(config[:rtl_file] || config[:rtl_files]).each do |f|
85
- cmd += " #{f}"
86
- end
87
- Array(config[:lib_file] || config[:lib_files]).each do |f|
88
- cmd += " -v #{f}"
89
- end
90
- Array(config[:rtl_dir] || config[:rtl_dirs]).each do |dir|
91
- cmd += " -incdir #{dir}"
54
+ if candidates.size == 0
55
+ puts "Sorry, couldn't find any Verilog module declarations in that file"
56
+ exit 1
57
+ elsif candidates.size > 1
58
+ if options[:top_level_name]
59
+ mod = candidates.find { |c| c.name == options[:top_level_name] }
92
60
  end
93
- cmd += " #{tmp_dir}/origen.v"
94
- if config[:alt_top]
95
- cmd += " -top #{config[:alt_top]}"
96
- else
97
- cmd += ' -top origen'
61
+ unless mod
62
+ puts "Sorry, couldn't work out what the top-level module is, please help by running again and specifying it via the --top switch with one of the following names:"
63
+ candidates.each do |c|
64
+ puts " #{c.name}"
65
+ end
66
+ exit 1
98
67
  end
99
- cmd += ' -timescale 1ns/1ns'
100
- cmd += " -nclibdirpath #{simulator.compiled_dir}"
101
- cmd += " #{Origen.root!}/ext/*.c -ccargs \"-std=c99\""
102
- cmd += ' -elaborate -snapshot origen -access +rw'
103
- cmd += " #{config[:explicit].strip.gsub(/\s+/, ' ')}" if config[:explicit]
68
+ else
69
+ mod = candidates.first
104
70
  end
105
71
 
106
- puts cmd
107
- unless options[:testrun]
108
- Dir.chdir tmp_dir do
109
- system cmd
110
- end
111
- end
72
+ rtl_top_module = mod.name
73
+
74
+ mod.to_top_level # Creates dut
75
+
76
+ output_directory = options[:output] || Origen.config.output_directory
77
+
78
+ Origen.app.runner.launch action: :compile,
79
+ files: "#{Origen.root!}/templates/rtl_v/origen.v.erb",
80
+ output: output_directory,
81
+ check_for_changes: false,
82
+ quiet: true,
83
+ options: { vendor: :cadence, top: dut.name, incl: options[:incl_files] }
84
+
85
+ Origen.app.runner.launch action: :compile,
86
+ files: "#{Origen.root!}/ext",
87
+ output: output_directory,
88
+ check_for_changes: false,
89
+ quiet: true
90
+
91
+ dut.export(rtl_top_module, file_path: "#{output_directory}")
92
+
93
+ puts
94
+ puts
95
+ puts 'Testbench and VPI extension created!'
96
+ puts
97
+ puts 'This file can be imported into an Origen top-level DUT model to define the pins:'
98
+ puts
99
+ puts " #{output_directory}/#{rtl_top_module}.rb"
100
+ puts
101
+ puts 'See below for what to do now to create an Origen-enabled simulation object for your particular simulator:'
102
+ puts
103
+ puts '-----------------------------------------------------------'
104
+ puts 'Cadence Incisive (irun)'
105
+ puts '-----------------------------------------------------------'
106
+ puts
107
+ puts 'Add the following to your build script (AND REMOVE ANY OTHER TESTBENCH!):'
108
+ puts
109
+ puts " #{output_directory}/origen.v \\"
110
+ puts " #{output_directory}/*.c \\"
111
+ puts ' -ccargs "-std=c99" \\'
112
+ puts ' -top origen \\'
113
+ puts ' -elaborate \\'
114
+ puts ' -snapshot origen \\'
115
+ puts ' -access +rw \\'
116
+ puts ' -timescale 1ns/1ns'
117
+ puts
118
+ puts 'Here is an example which may work for the file you just parsed (add additional -incdir options at the end if required):'
119
+ puts
120
+ puts " irun #{rtl_top} #{output_directory}/origen.v #{output_directory}/*.c -ccargs \"-std=c99\" -top origen -elaborate -snapshot origen -access +rw -timescale 1ns/1ns -incdir #{Pathname.new(rtl_top).dirname}"
121
+ puts
122
+ puts 'Copy the following directory (produced by irun) to simulation/<target>/cadence/. within your Origen application:'
123
+ puts
124
+ puts ' INCA_libs'
125
+ puts
126
+ puts '-----------------------------------------------------------'
127
+ puts 'Icarus Verilog'
128
+ puts '-----------------------------------------------------------'
129
+ puts
130
+ puts 'Compile the VPI extension using the following command:'
131
+ puts
132
+ puts " cd #{output_directory} && iverilog-vpi *.c -DICARUS --name=origen && cd #{Pathname.pwd}"
133
+ puts
134
+ puts 'Add the following to your build script (AND REMOVE ANY OTHER TESTBENCH!):'
135
+ puts
136
+ puts " #{output_directory}/origen.v \\"
137
+ puts ' -o origen.vvp \\'
138
+ puts ' -DICARUS'
139
+ puts
140
+ puts 'Here is an example which may work for the file you just parsed (add additional source dirs with more -I options at the end if required):'
141
+ puts
142
+ puts " iverilog #{rtl_top} #{output_directory}/origen.v -o origen.vvp -DICARUS -I #{Pathname.new(rtl_top).dirname}"
143
+ puts
144
+ puts 'Copy the following files to simulation/<target>/icarus/. within your Origen application:'
145
+ puts
146
+ puts " #{output_directory}/origen.vpi"
147
+ puts ' origen.vvp (produced by the iverilog command)'
148
+ puts
149
+ puts