OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [simulator.pl] - Blame information for rev 32

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 32 alirezamon
#! /usr/bin/perl -w
2
use Glib qw/TRUE FALSE/;
3
use strict;
4
use warnings;
5
use Gtk2;
6
use Gtk2::Ex::Graph::GD;
7
use GD::Graph::Data;
8
use emulator;
9
use IO::CaptureOutput qw(capture qxx qxy);
10
use GD::Graph::colour qw/:colours/;
11
use Proc::Background;
12
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep  clock_gettime clock_getres clock_nanosleep clock stat );
13
 
14
use File::Basename;
15
use File::Path qw/make_path/;
16
use File::Copy;
17
use File::Find::Rule;
18
 
19
require "widget.pl";
20
require "mpsoc_gen.pl";
21
require "emulator.pl";
22
require "mpsoc_verilog_gen.pl";
23
require "readme_gen.pl";
24
 
25
use List::MoreUtils qw(uniq);
26
 
27
 
28
 
29
 
30
sub generate_sim_bin_file() {
31
        my ($simulate,$info_text) =@_;
32
        my $dir = Cwd::getcwd();
33
        my $project_dir   = abs_path("$dir/..");
34
        my $src_verilator_dir="$project_dir/src_verilator";
35
        my $script_dir="$project_dir/script";
36
        # save parameters inside parameter.v file in src_verilator folder
37
        my ($noc_param,$pass_param)=gen_noc_param_v($simulate);
38
        open(FILE,  ">$src_verilator_dir/parameter.v") || die "Can not open: $!";
39
        print FILE  " \`ifdef     INCLUDE_PARAM \n \n
40
        $noc_param
41
        localparam  P=(TOPOLOGY==\"RING\")? 3 : 5;
42
        localparam  ROUTE_TYPE = (ROUTE_NAME == \"XY\" || ROUTE_NAME == \"TRANC_XY\" )?    \"DETERMINISTIC\" :
43
                        (ROUTE_NAME == \"DUATO\" || ROUTE_NAME == \"TRANC_DUATO\" )?   \"FULL_ADAPTIVE\": \"PAR_ADAPTIVE\";
44
 
45
        //simulation parameter
46
        localparam MAX_PCK_NUM = ".MAX_SIM_CLKs.";
47
        localparam MAX_PCK_SIZ = ".MAX_PCK_SIZ.";
48
        localparam MAX_SIM_CLKs=  ".MAX_SIM_CLKs.";
49
        localparam TIMSTMP_FIFO_NUM = 16;
50
\n \n \`endif" ;
51
        close FILE;
52
 
53
 
54
 
55
 
56
        #verilate the noc
57
 
58
        add_info($info_text, "verilate the NoC and make the library files");
59
        my $command = "cd \"$script_dir/\" \n   xterm   -l -lf logfile1.txt -e  sh verilator_compile_hw.sh";
60
        my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $command);
61
        if($exit != 0){
62
                print "Verilator compilation failed !\n";
63
                add_info($info_text, "Verilator compilation failed !\n$command\n $stdout\n");
64
                return;
65
        }
66
 
67
 
68
 
69
        #compile the testbench
70
        my $param_h=gen_noc_param_h($simulate);
71
        $param_h =~ s/\d\'b/ /g;
72
        open(FILE,  ">$src_verilator_dir/parameter.h") || die "Can not open: $!";
73
        print FILE  "
74
#ifndef     INCLUDE_PARAM
75
        #define   INCLUDE_PARAM \n \n
76
 
77
        $param_h
78
 
79
        int   P=(strcmp (TOPOLOGY,\"RING\")==0)    ?   3 : 5;
80
 
81
 
82
        //simulation parameter
83
        #define AVG_LATENCY_METRIC \"HEAD_2_TAIL\"
84
        #define TIMSTMP_FIFO_NUM   16
85
\n \n \#endif" ;
86
        close FILE;
87
 
88
        $command = "cd \"$script_dir/\" \n      xterm   -l -lf logfile2.txt     -e  sh verilator_compile_simulator.sh";
89
        ($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $command);
90
        if($exit != 0){
91
                print "Verilator compilation failed !\n";
92
                add_info($info_text, "Verilator compilation failed !\n$command\n $stdout\n");
93
                return;
94
        }
95
 
96
 
97
 
98
 
99
        #save the binarry file
100
        my $bin= "$ENV{PRONOC_WORK}/verilator/work/processed_rtl/obj_dir/testbench";
101
        my $path=$simulate->object_get_attribute ('sim_param',"BIN_DIR");
102
        my $name=$simulate->object_get_attribute ('sim_param',"SAVE_NAME");
103
 
104
        #create project didrectory if its not exist
105
        ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $path" );
106
        if($exit != 0 ){         print "$stdout\n";      message_dialog($stdout); return;}
107
 
108
        #move the log file 
109
        move("$script_dir/logfile1.txt" , "$path/$name.log1");
110
        move("$script_dir/logfile2.txt" , "$path/$name.log2");
111
 
112
        #check if the verilation was successful
113
        if ((-e $bin)==0) {#something goes wrong                 
114
        message_dialog("Verilator compilation was unsuccessful please check the $path/$name.log files for more information");
115
        return;
116
        }
117
 
118
 
119
        #copy ($bin,"$path/$name") or  die "Can not copy: $!";
120
        ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("cp -f $bin $path/$name");
121
        if($exit != 0 ){         print "$stdout\n";      message_dialog($stdout); return;}
122
 
123
        #save noc info
124
        open(FILE,  ">$path/$name.inf") || die "Can not open: $!";
125
        print FILE perl_file_header("$name.inf");
126
        my %pp;
127
        $pp{'noc_param'}= $simulate->{'noc_param'};
128
        $pp{'sim_param'}= $simulate->{'sim_param'};
129
        print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
130
        close(FILE) || die "Error closing file: $!";
131
 
132
        message_dialog("The simulation binary file has been successfully generated in $path!");
133
 
134
 
135
        #make project dir
136
        #my $dir= $simulate->object_get_attribute ("sim_param","BIN_DIR");
137
        #my $name=$simulate->object_get_attribute ("sim_param","SAVE_NAME");    
138
        #my $path= "$dir/$name";
139
        #add_info($info_text, "$src_verilator_dir!\n");
140
        #mkpath("$path",1,01777);
141
 
142
 
143
 
144
 
145
 
146
}
147
 
148
 
149
##########
150
#       save_emulation
151
##########
152
sub save_simulation {
153
        my ($simulate)=@_;
154
        # read emulation name
155
        my $name=$simulate->object_get_attribute ("simulate_name",undef);
156
        my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
157
        if ($s == 0){
158
                message_dialog("Please set Simulation name!");
159
                return 0;
160
        }
161
        # Write object file
162
        open(FILE,  ">lib/simulate/$name.SIM") || die "Can not open: $!";
163
        print FILE perl_file_header("$name.SIM");
164
        print FILE Data::Dumper->Dump([\%$simulate],[$name]);
165
        close(FILE) || die "Error closing file: $!";
166
        message_dialog("Simulation has saved as lib/simulate/$name.SIM!");
167
        return 1;
168
}
169
 
170
#############
171
#       load_emulation
172
############
173
 
174
sub load_simulation {
175
        my ($simulate,$info)=@_;
176
        my $file;
177
        my $dialog = Gtk2::FileChooserDialog->new(
178
                'Select a File', undef,
179
                'open',
180
                'gtk-cancel' => 'cancel',
181
                'gtk-ok'     => 'ok',
182
                );
183
 
184
        my $filter = Gtk2::FileFilter->new();
185
        $filter->set_name("SIM");
186
        $filter->add_pattern("*.SIM");
187
        $dialog->add_filter ($filter);
188
        my $dir = Cwd::getcwd();
189
        $dialog->set_current_folder ("$dir/lib/simulate");
190
 
191
 
192
        if ( "ok" eq $dialog->run ) {
193
                $file = $dialog->get_filename;
194
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
195
                if($suffix eq '.SIM'){
196
                        my $pp= eval { do $file };
197
                        if ($@ || !defined $pp){
198
                                add_info($info,"**Error reading  $file file: $@\n");
199
                                 $dialog->destroy;
200
                                return;
201
                        }
202
                        #deactivate running simulations
203
                        $pp->object_add_attribute('status',undef,'ideal');
204
                        my $sample_num=$pp->object_get_attribute("emulate_num",undef);
205
                        for (my $i=1; $i<=$sample_num; $i++){
206
                                my $st=$pp->object_get_attribute ("sample$i","status");
207
                                $pp->object_add_attribute ("sample$i","status",'done');# if ($st eq "run");     
208
                        }
209
                        clone_obj($simulate,$pp);
210
                        #message_dialog("done!");                               
211
                }
212
     }
213
     $dialog->destroy;
214
}
215
 
216
 
217
############
218
#    main
219
############
220
sub simulator_main{
221
 
222
        add_color_to_gd();
223
        my $simulate= emulator->emulator_new();
224
        set_gui_status($simulate,"ideal",0);
225
        my $left_table = Gtk2::Table->new (25, 6, FALSE);
226
        my $right_table = Gtk2::Table->new (25, 6, FALSE);
227
 
228
        my $main_table = Gtk2::Table->new (25, 12, FALSE);
229
        my ($infobox,$info)= create_text();
230
        my $refresh = Gtk2::Button->new_from_stock('ref');
231
 
232
 
233
 
234
 
235
 
236
        my ($conf_box,$set_win)=process_notebook_gen($simulate,\$info,"simulate");
237
        my $chart   =gen_chart  ($simulate);
238
 
239
 
240
 
241
        $main_table->set_row_spacings (4);
242
        $main_table->set_col_spacings (1);
243
 
244
        #my  $device_win=show_active_dev($soc,$soc,$infc,$soc_state,\$refresh,$info);
245
 
246
 
247
        my $generate = def_image_button('icons/forward.png','Run all');
248
        my $open = def_image_button('icons/browse.png','Load');
249
 
250
 
251
 
252
 
253
        my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
254
        $entry->signal_connect( 'changed'=> sub{
255
                my $name=$entry->get_text();
256
                $simulate->object_add_attribute ("simulate_name",undef,$name);
257
        });
258
        my $save = def_image_button('icons/save.png','Save');
259
        $entrybox->pack_end($save,   FALSE, FALSE,0);
260
 
261
 
262
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
263
        my $image = get_status_gif($simulate);
264
 
265
 
266
 
267
 
268
 
269
        $left_table->attach_defaults ($conf_box , 0, 6, 0, 20);
270
        $left_table->attach_defaults ($image , 0, 6, 20, 24);
271
        $left_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
272
        $left_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
273
        $right_table->attach_defaults ($infobox  , 0, 6, 0,12);
274
        $right_table->attach_defaults ($chart , 0, 6, 12, 24);
275
        $right_table->attach ($generate, 4, 6, 24,25,'expand','shrink',2,2);
276
        $main_table->attach_defaults ($left_table , 0, 6, 0, 25);
277
        $main_table->attach_defaults ($right_table , 6, 12, 0, 25);
278
 
279
 
280
 
281
        #referesh the mpsoc generator 
282
        $refresh-> signal_connect("clicked" => sub{
283
                my $name=$simulate->object_get_attribute ("simulate_name",undef);
284
                $entry->set_text($name) if(defined $name);
285
 
286
 
287
                $conf_box->destroy();
288
                $chart->destroy();
289
                $image->destroy();
290
                $image = get_status_gif($simulate);
291
                ($conf_box,$set_win)=process_notebook_gen($simulate,\$info,"simulate");
292
                $chart   =gen_chart  ($simulate);
293
                $left_table->attach_defaults ($image , 0, 6, 20, 24);
294
                $left_table->attach_defaults ($conf_box , 0, 6, 0, 12);
295
                $right_table->attach_defaults ($chart , 0, 6, 12, 24);
296
 
297
                $conf_box->show_all();
298
                $main_table->show_all();
299
 
300
 
301
        });
302
 
303
 
304
 
305
        #check soc status every 0.5 second. referesh device table if there is any changes 
306
        Glib::Timeout->add (100, sub{
307
 
308
                my ($state,$timeout)= get_gui_status($simulate);
309
 
310
                if ($timeout>0){
311
                        $timeout--;
312
                        set_gui_status($simulate,$state,$timeout);
313
 
314
                }
315
                elsif($state eq 'ref_set_win'){
316
 
317
                        my $s=$simulate->object_get_attribute("active_setting",undef);
318
                        $set_win->destroy();
319
                        $simulate->object_add_attribute("active_setting",undef,$s);
320
                        $refresh->clicked;
321
                        set_gui_status($simulate,"ideal",0);
322
 
323
                }
324
                elsif( $state ne "ideal" ){
325
                        $refresh->clicked;
326
                        #my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
327
                        #if(defined $saved_name) {$entry->set_text($saved_name);}
328
                        set_gui_status($simulate,"ideal",0);
329
 
330
                }
331
                return TRUE;
332
 
333
        } );
334
 
335
 
336
        $generate-> signal_connect("clicked" => sub{
337
                my $sample_num=$simulate->object_get_attribute("emulate_num",undef);
338
                for (my $i=1; $i<=$sample_num; $i++){
339
                        $simulate->object_add_attribute ("sample$i","status","run");
340
                }
341
                run_simulator($simulate,\$info);
342
                #set_gui_status($emulate,"ideal",2);
343
 
344
        });
345
 
346
#       $wb-> signal_connect("clicked" => sub{ 
347
#               wb_address_setting($mpsoc);
348
#       
349
#       });
350
 
351
        $open-> signal_connect("clicked" => sub{
352
 
353
                load_simulation($simulate,\$info);
354
                set_gui_status($simulate,"ref",5);
355
 
356
        });
357
 
358
        $save-> signal_connect("clicked" => sub{
359
                save_simulation($simulate);
360
                set_gui_status($simulate,"ref",5);
361
 
362
 
363
        });
364
 
365
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
366
                $sc_win->set_policy( "automatic", "automatic" );
367
                $sc_win->add_with_viewport($main_table);
368
 
369
        return $sc_win;
370
 
371
 
372
}
373
 
374
 
375
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.