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 36

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

powered by: WebSVN 2.1.0

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