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 34

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 34 alirezamon
        my $start = localtime;
58 32 alirezamon
        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 34 alirezamon
        my $end = localtime;
96 32 alirezamon
 
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 34 alirezamon
        #create project directory if its not exist
105 32 alirezamon
        ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $path" );
106 34 alirezamon
        if($exit != 0 ){         print "$stdout\n";      message_dialog($stdout,'error'); return;}
107 32 alirezamon
 
108
        #move the log file 
109 34 alirezamon
        unlink "$path/$name.log";
110
        append_text_to_file("$path/$name.log","start:$start\n");
111
        merg_files("$script_dir/logfile1.txt" , "$path/$name.log");
112
        merg_files("$script_dir/logfile2.txt" , "$path/$name.log");
113
        append_text_to_file("$path/$name.log","end:$end\n");
114 32 alirezamon
        #check if the verilation was successful
115
        if ((-e $bin)==0) {#something goes wrong                 
116 34 alirezamon
        message_dialog("Verilator compilation was unsuccessful please check the $path/$name.log files for more information",'error');
117 32 alirezamon
        return;
118
        }
119
 
120
 
121
        #copy ($bin,"$path/$name") or  die "Can not copy: $!";
122
        ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("cp -f $bin $path/$name");
123 34 alirezamon
        if($exit != 0 ){         print "$stdout\n";      message_dialog($stdout,'error'); return;}
124 32 alirezamon
 
125
        #save noc info
126
        open(FILE,  ">$path/$name.inf") || die "Can not open: $!";
127
        print FILE perl_file_header("$name.inf");
128
        my %pp;
129
        $pp{'noc_param'}= $simulate->{'noc_param'};
130
        $pp{'sim_param'}= $simulate->{'sim_param'};
131
        print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
132
        close(FILE) || die "Error closing file: $!";
133
 
134
        message_dialog("The simulation binary file has been successfully generated in $path!");
135
 
136
 
137
        #make project dir
138
        #my $dir= $simulate->object_get_attribute ("sim_param","BIN_DIR");
139
        #my $name=$simulate->object_get_attribute ("sim_param","SAVE_NAME");    
140
        #my $path= "$dir/$name";
141
        #add_info($info_text, "$src_verilator_dir!\n");
142
        #mkpath("$path",1,01777);
143
 
144
 
145
 
146
 
147
 
148
}
149
 
150
 
151
##########
152 34 alirezamon
#       save_simulation
153 32 alirezamon
##########
154
sub save_simulation {
155
        my ($simulate)=@_;
156
        # read emulation name
157
        my $name=$simulate->object_get_attribute ("simulate_name",undef);
158
        my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
159
        if ($s == 0){
160
                message_dialog("Please set Simulation name!");
161
                return 0;
162
        }
163
        # Write object file
164
        open(FILE,  ">lib/simulate/$name.SIM") || die "Can not open: $!";
165
        print FILE perl_file_header("$name.SIM");
166
        print FILE Data::Dumper->Dump([\%$simulate],[$name]);
167
        close(FILE) || die "Error closing file: $!";
168
        message_dialog("Simulation has saved as lib/simulate/$name.SIM!");
169
        return 1;
170
}
171
 
172
#############
173
#       load_emulation
174
############
175
 
176
sub load_simulation {
177
        my ($simulate,$info)=@_;
178
        my $file;
179
        my $dialog = Gtk2::FileChooserDialog->new(
180
                'Select a File', undef,
181
                'open',
182
                'gtk-cancel' => 'cancel',
183
                'gtk-ok'     => 'ok',
184
                );
185
 
186
        my $filter = Gtk2::FileFilter->new();
187
        $filter->set_name("SIM");
188
        $filter->add_pattern("*.SIM");
189
        $dialog->add_filter ($filter);
190
        my $dir = Cwd::getcwd();
191
        $dialog->set_current_folder ("$dir/lib/simulate");
192
 
193
 
194
        if ( "ok" eq $dialog->run ) {
195
                $file = $dialog->get_filename;
196
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
197
                if($suffix eq '.SIM'){
198
                        my $pp= eval { do $file };
199
                        if ($@ || !defined $pp){
200
                                add_info($info,"**Error reading  $file file: $@\n");
201
                                 $dialog->destroy;
202
                                return;
203
                        }
204
                        #deactivate running simulations
205
                        $pp->object_add_attribute('status',undef,'ideal');
206
                        my $sample_num=$pp->object_get_attribute("emulate_num",undef);
207
                        for (my $i=1; $i<=$sample_num; $i++){
208
                                my $st=$pp->object_get_attribute ("sample$i","status");
209
                                $pp->object_add_attribute ("sample$i","status",'done');# if ($st eq "run");     
210
                        }
211
                        clone_obj($simulate,$pp);
212
                        #message_dialog("done!");                               
213
                }
214
     }
215
     $dialog->destroy;
216
}
217
 
218
 
219
############
220
#    main
221
############
222
sub simulator_main{
223
 
224
        add_color_to_gd();
225
        my $simulate= emulator->emulator_new();
226
        set_gui_status($simulate,"ideal",0);
227
        my $left_table = Gtk2::Table->new (25, 6, FALSE);
228
        my $right_table = Gtk2::Table->new (25, 6, FALSE);
229
 
230
        my $main_table = Gtk2::Table->new (25, 12, FALSE);
231
        my ($infobox,$info)= create_text();
232
        my $refresh = Gtk2::Button->new_from_stock('ref');
233
 
234
 
235
 
236
 
237
 
238
        my ($conf_box,$set_win)=process_notebook_gen($simulate,\$info,"simulate");
239
        my $chart   =gen_chart  ($simulate);
240
 
241
 
242
 
243
        $main_table->set_row_spacings (4);
244
        $main_table->set_col_spacings (1);
245
 
246
        #my  $device_win=show_active_dev($soc,$soc,$infc,$soc_state,\$refresh,$info);
247
 
248
 
249
        my $generate = def_image_button('icons/forward.png','Run all');
250
        my $open = def_image_button('icons/browse.png','Load');
251
 
252
 
253
 
254
 
255
        my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
256
        $entry->signal_connect( 'changed'=> sub{
257
                my $name=$entry->get_text();
258
                $simulate->object_add_attribute ("simulate_name",undef,$name);
259
        });
260
        my $save = def_image_button('icons/save.png','Save');
261
        $entrybox->pack_end($save,   FALSE, FALSE,0);
262
 
263
 
264
        #$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
265
        my $image = get_status_gif($simulate);
266
 
267
 
268
 
269
 
270
 
271
        $left_table->attach_defaults ($conf_box , 0, 6, 0, 20);
272
        $left_table->attach_defaults ($image , 0, 6, 20, 24);
273
        $left_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
274
        $left_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
275
        $right_table->attach_defaults ($infobox  , 0, 6, 0,12);
276
        $right_table->attach_defaults ($chart , 0, 6, 12, 24);
277
        $right_table->attach ($generate, 4, 6, 24,25,'expand','shrink',2,2);
278
        $main_table->attach_defaults ($left_table , 0, 6, 0, 25);
279
        $main_table->attach_defaults ($right_table , 6, 12, 0, 25);
280
 
281
 
282
 
283
        #referesh the mpsoc generator 
284
        $refresh-> signal_connect("clicked" => sub{
285
                my $name=$simulate->object_get_attribute ("simulate_name",undef);
286
                $entry->set_text($name) if(defined $name);
287
 
288
 
289
                $conf_box->destroy();
290
                $chart->destroy();
291
                $image->destroy();
292
                $image = get_status_gif($simulate);
293
                ($conf_box,$set_win)=process_notebook_gen($simulate,\$info,"simulate");
294
                $chart   =gen_chart  ($simulate);
295
                $left_table->attach_defaults ($image , 0, 6, 20, 24);
296
                $left_table->attach_defaults ($conf_box , 0, 6, 0, 12);
297
                $right_table->attach_defaults ($chart , 0, 6, 12, 24);
298
 
299
                $conf_box->show_all();
300
                $main_table->show_all();
301
 
302
 
303
        });
304
 
305
 
306
 
307
        #check soc status every 0.5 second. referesh device table if there is any changes 
308
        Glib::Timeout->add (100, sub{
309
 
310
                my ($state,$timeout)= get_gui_status($simulate);
311
 
312
                if ($timeout>0){
313
                        $timeout--;
314
                        set_gui_status($simulate,$state,$timeout);
315
 
316
                }
317
                elsif($state eq 'ref_set_win'){
318
 
319
                        my $s=$simulate->object_get_attribute("active_setting",undef);
320
                        $set_win->destroy();
321
                        $simulate->object_add_attribute("active_setting",undef,$s);
322
                        $refresh->clicked;
323
                        set_gui_status($simulate,"ideal",0);
324
 
325
                }
326
                elsif( $state ne "ideal" ){
327
                        $refresh->clicked;
328
                        #my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
329
                        #if(defined $saved_name) {$entry->set_text($saved_name);}
330
                        set_gui_status($simulate,"ideal",0);
331
 
332
                }
333
                return TRUE;
334
 
335
        } );
336
 
337
 
338
        $generate-> signal_connect("clicked" => sub{
339
                my $sample_num=$simulate->object_get_attribute("emulate_num",undef);
340
                for (my $i=1; $i<=$sample_num; $i++){
341
                        $simulate->object_add_attribute ("sample$i","status","run");
342
                }
343
                run_simulator($simulate,\$info);
344
                #set_gui_status($emulate,"ideal",2);
345
 
346
        });
347
 
348
#       $wb-> signal_connect("clicked" => sub{ 
349
#               wb_address_setting($mpsoc);
350
#       
351
#       });
352
 
353
        $open-> signal_connect("clicked" => sub{
354
 
355
                load_simulation($simulate,\$info);
356
                set_gui_status($simulate,"ref",5);
357
 
358
        });
359
 
360
        $save-> signal_connect("clicked" => sub{
361
                save_simulation($simulate);
362
                set_gui_status($simulate,"ref",5);
363
 
364
 
365
        });
366
 
367
        my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
368
                $sc_win->set_policy( "automatic", "automatic" );
369
                $sc_win->add_with_viewport($main_table);
370
 
371
        return $sc_win;
372
 
373
 
374
}
375
 
376
 
377
 

powered by: WebSVN 2.1.0

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