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

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk/mpsoc/perl_gui/lib/perl
    from Rev 37 to Rev 38
    Reverse comparison

Rev 37 → Rev 38

/compile.pl
86,62 → 86,28
}
 
 
sub read_csv_file{
my $file=shift;
open(my $fh, "<$file") || die "Cannot open:$file; $!";
 
sub read_top_v_file{
my $top_v=shift;
my $board = soc->board_new();
#read header format
my $header;
while (my $line= <$fh>){
chomp $line;
$line=remove_all_white_spaces($line);
#print "l:$line\n";
if(length ( $line)!=0){
if ($line !~ /\#/) {
$header= $line;
last;
}
my $vdb=read_verilog_file($top_v);
my @modules=sort $vdb->get_modules($top_v);
my %Ptypes=get_ports_type($vdb,$modules[0]);
my %Pranges=get_ports_rang($vdb,$modules[0]);
foreach my $p (sort keys %Ptypes){
my $Ptype=$Ptypes{$p};
my $Prange=$Pranges{$p};
my $type=($Ptype eq "input")? "Input" : ($Ptype eq "output")? 'Output' : 'Bidir';
if ( $Prange ne ''){
my @r=split(":",$Prange);
my $a=($r[0]<$r[1])? $r[0] : $r[1];
my $b=($r[0]<$r[1])? $r[1] : $r[0];
for (my $i=$a; $i<=$b; $i++){
$board->board_add_pin ($type,"$p\[$i\]");
}
}
}
 
my @headers = split (',',$header);
my $pin_name_col = get_scolar_pos('To',@headers);
if(!defined $pin_name_col){
message_dialog("Error: $file file has an unsupported format!");
return $board;
}
my $direction_col = get_scolar_pos('Direction',@headers);
close $fh;
 
#save pins
open( $fh, "<$file") || die "Cannot open:$file; $!";
 
while (my $line= <$fh>){
chomp $line;
my @fileds = split (',',$line);
my $to = $fileds[$pin_name_col];
my $direction = (defined $direction_col )? $fileds[$direction_col] : 'Unknown';
if(defined $direction && length($to)!=0){
if ($direction eq 'Input' || $direction eq 'Output' || $direction eq 'Bidir'){
$board->board_add_pin ($fileds[1],$to);
}elsif($direction eq 'Unknown'){
$board->board_add_pin ('Input',$to);
$board->board_add_pin ('Output',$to);
$board->board_add_pin ('Bidir',$to);
 
}
}
 
}
close $fh;
else {$board->board_add_pin ($type,$p);}
}
return $board;
}
 
242,10 → 208,10
 
 
sub select_compiler {
my ($self,$name,$top,$target_dir)=@_;
my ($self,$name,$top,$target_dir,$end_func)=@_;
my $window = def_popwin_size(40,40,"Step 1: Select Compiler",'percent');
#get the list of boards located in "boards/*" folder
my @dirs = grep {-d} glob("./lib/boards/*");
my @dirs = grep {-d} glob("../boards/*");
my ($fpgas,$init);
foreach my $dir (@dirs) {
my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
256,7 → 222,9
my $col=0;
my $row=0;
 
my $compiler=gen_combobox_object ($self,'compile','type',"QuartusII,Verilator,Modelsim","QuartusII",undef,undef);
my $compilers=$self->object_get_attribute('compile','compilers');#"QuartusII,Verilator,Modelsim"
my $compiler=gen_combobox_object ($self,'compile','type',$compilers,"QuartusII",undef,undef);
$table->attach(gen_label_in_center("Compiler tool"),$col,$col+1,$row,$row+1,'fill','shrink',2,2);$col++;
$table->attach($compiler,$col,$col+1,$row,$row+1,'fill','shrink',2,2);$col++;
$row++;$col=0;
289,7 → 257,15
if($compiler_type eq "QuartusII"){
my $new_board_name=$self->object_get_attribute('compile','board');
if(defined $old_board_name) {
remove_pin_assignment($self) if ($old_board_name ne $new_board_name);
if ($old_board_name ne $new_board_name){
remove_pin_assignment($self);
my ($fname,$fpath,$fsuffix) = fileparse("$top",qr"\..[^.]*$");
#delete jtag_intfc.sh file
unlink "${fpath}../sw/jtag_intfc.sh";
#program_device.sh file
unlink "${fpath}../program_device.sh";
}
 
my ($fname,$fpath,$fsuffix) = fileparse("$top",qr"\..[^.]*$");
my $board_top_file= "$fpath/Top.v";
unlink $board_top_file if ($old_board_name ne $new_board_name);
296,13 → 272,13
 
 
}
get_pin_assignment($self,$name,$top,$target_dir);
if($new_board_name eq "Add New Board") {add_new_fpga_board($self,$name,$top,$target_dir,$end_func);}
else {get_pin_assignment($self,$name,$top,$target_dir,$end_func);}
}elsif($compiler_type eq "Modelsim"){
modelsim_compilation($self,$name,$top,$target_dir);
 
}else{#verilator
verilator_compilation($self,$name,$top,$target_dir);
verilator_compilation_win($self,$name,$top,$target_dir);
 
}
 
331,12 → 307,15
my ($self,$name,$top,$target_dir)=@_;
#get the list of boards located in "boards/*" folder
my @dirs = grep {-d} glob("./lib/boards/*");
my @dirs = grep {-d} glob("../boards/*");
my ($fpgas,$init);
$fpgas="Add New Board";
foreach my $dir (@dirs) {
my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
$init=$name;
$fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
$fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
$init="$name";
}
my $table = def_table(2, 2, FALSE);
my $col=0;
344,7 → 323,7
 
my $old_board_name=$self->object_get_attribute('compile','board');
$table->attach(gen_label_help("The list of supported boards are obtained from \"perl_gui/lib/boards/\" path. You can add your boards by adding its required files in aformentioned path. Note that currently only Altera FPGAs are supported. For boards from other vendors, you need to directly use their own compiler and call $name.v file in your top level module.",'Targeted Board:'),$col,$col+1,$row,$row+1,'fill','shrink',2,2);$col++;
$table->attach(gen_label_help("The list of supported boards are obtained from \"mpsoc/boards/\" path. You can add your boards by adding its required files in aformentioned path. Note that currently only Altera FPGAs are supported. For boards from other vendors, you need to directly use their own compiler and call $name.v file in your top level module.",'Targeted Board:'),$col,$col+1,$row,$row+1,'fill','shrink',2,2);$col++;
$table->attach(gen_combobox_object ($self,'compile','board',$fpgas,$init,undef,undef),$col,$col+1,$row,$row+1,'fill','shrink',2,2);$row++;
my $bin = $self->object_get_attribute('compile','quartus_bin');
393,8 → 372,375
}
 
 
 
 
 
sub add_new_fpga_board{
my ($self,$name,$top,$target_dir,$end_func)=@_;
my $window = def_popwin_size(50,80,"Add New FPGA Board",'percent');
my $table = def_table(2, 2, FALSE);
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->add_with_viewport($table);
 
 
my $mtable = def_table(10, 10, FALSE);
my $next=def_image_button('icons/plus.png','Add');
my $back=def_image_button('icons/left.png','Previous');
my $auto=def_image_button('icons/advance.png','Auto-fill');
 
$mtable->attach_defaults($scrolled_win,0,10,0,9);
$mtable->attach($back,2,3,9,10,'shrink','shrink',2,2);
$mtable->attach($auto,5,6,9,10,'shrink','shrink',2,2);
$mtable->attach($next,8,9,9,10,'shrink','shrink',2,2);
set_tip($auto, "Auto-fill JTAG configuration. The board must be powered on and be connecred to the PC.");
my $widgets= add_new_fpga_board_widgets($self,$name,$top,$target_dir,$end_func);
my ($Twin,$tview)=create_text();
add_colors_to_textview($tview);
 
my $v1=gen_vpaned($widgets,0.3,$Twin);
$table->attach_defaults($v1,0,3,0,2);
#$table->attach_defaults( $Twin,0,3,1,2);
$back-> signal_connect("clicked" => sub{
$window->destroy;
select_compiler($self,$name,$top,$target_dir,$end_func);
});
$next-> signal_connect("clicked" => sub{
my $result = add_new_fpga_board_files($self);
if(! defined $result ){
select_compiler($self,$name,$top,$target_dir,$end_func);
message_dialog("The new board has been added successfully!");
$window->destroy;
}else {
show_info(\$tview," ");
show_colored_info(\$tview,$result,'red');
}
});
$auto-> signal_connect("clicked" => sub{
my $pid;
my $hw;
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../"); #mpsoc directory address
my $command= "$project_dir/mpsoc/src_c/jtag/jtag_libusb/list_usb_dev";
add_info(\$tview,"$command\n");
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($command);
if(length $stderr>1){
add_colored_info(\$tview,"$stderr\n",'red');
add_colored_info(\$tview,"$command was not run successfully!\n",'red');
}else {
 
if($exit){
add_colored_info(\$tview,"$stdout\n",'red');
add_colored_info(\$tview,"$command was not run successfully!\n",'red');
}else{
add_info(\$tview,"$stdout\n");
my @a=split /vid=9fb/, $stdout;
if(defined $a[1]){
my @b=split /pid=/, $a[1];
my @c=split /\n/, $b[1];
$pid=$c[0];
$self->object_add_attribute('compile','quartus_pid',$pid);
add_colored_info(\$tview,"Detected PID: $pid\n",'blue');
}else{
add_colored_info(\$tview,"The Altera vendor ID of 9fb is not detected. Make sure You have connected your Altera board to your USB port\n",'red');
return;
}
}
}
$command= "$ENV{QUARTUS_BIN}/jtagconfig";
add_info(\$tview,"$command\n");
($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($command);
if(length $stderr>1){
add_colored_info(\$tview,"$stderr\n",'red');
add_colored_info(\$tview,"$command was not run successfully!\n",'red');
}else {
 
if($exit){
add_colored_info(\$tview,"$stdout\n",'red');
add_colored_info(\$tview,"$command was not run successfully!\n",'red');
}else{
add_info(\$tview,"$stdout\n");
my @a=split /1\)\s+/, $stdout;
if(defined $a[1]){
my @b=split /\s+/, $a[1];
$hw=$b[0];
$self->object_add_attribute('compile','quartus_hardware',$hw);
add_colored_info(\$tview,"Detected Hardware: $hw\n",'blue');
my $qsf=$self->object_get_attribute('compile','quartus_qsf');
if(!defined $qsf ){
add_colored_info (\$tview,"Cannot detect devce location in JTAG chin. Please enter the QSF file or fill in manually \n",'red');
}else{
#search for device nam ein qsf file
$qsf=add_project_dir_to_addr($qsf);
if (!(-f $qsf)){
add_colored_info (\$tview, "Error Could not find $qsf file!\n");
return;
}
my $str=load_file($qsf);
my $dw= capture_string_between(' DEVICE ',$str,"\n");
if(defined $dw){
add_colored_info(\$tview,"Device name in qsf file is: $dw\n",'blue');
@b=split /\n/, $a[1];
#capture device name in JTAG chain
my @f=(0);
foreach my $c (@b){
my @e=split /\s+/, $c;
push(@f,$e[2]) if(defined $e[2]);
}
my $pos=find_the_most_similar_position($dw ,@f);
$self->object_add_attribute('compile','quartus_device',$pos);
add_colored_info(\$tview,"$dw has the most similarity with $f[$pos] in JTAG chain\n",'blue');
}else{
add_colored_info (\$tview, "Could not find device name in the $qsf file!\n");
}
}
}else{
#add_colored_info(\$tview,"The Altera vendor ID of 9fb is not detected. Make sure You have connected your Altera board to your USB port\n",'red');
}
}
}
$widgets->destroy();
$widgets= add_new_fpga_board_widgets($self,$name,$top,$target_dir,$end_func);
$v1-> pack1($widgets, TRUE, TRUE);
#$table->attach_defaults($widgets,0,3,0,1);
$table->show_all();
# my $cmd=" $ENV{'QUARTUS_BIN'}"
});
$window->add ($mtable);
$window->show_all();
}
 
 
 
 
 
 
 
 
 
 
sub add_new_fpga_board_widgets{
my ($self,$name,$top,$target_dir,$end_func)=@_;
my $table = def_table(2, 2, FALSE);
my $help1="FPGA Board name. Do not use any space in given name";
my $help2="Path to FPGA board qsf file. In your Altra board installation CD or in the Internet search for a QSF file containing your FPGA device name with other necessary global project setting including the pin assignments (e.g DE10_Nano_golden_top.qsf).";
my $help3="Path to FPGA_board_top.v file. In your Altra board installation CD or in the Internet search for a verilog file containing all your FPGA device IO ports (e.g DE10_Nano_golden_top.v).";
my $help4="FPGA Borad USB-Blaster product ID (PID). Power on your FPGA board and connect it to your PC. Then press Auto-fill button to find PID. Optinally you can run mpsoc/
src_c/jtag/jtag_libusb/list_usb_dev to find your USB-Blaster PID. Search for PID of a device having 9fb (altera) Vendor ID (VID)";
my $help5="Power on your FPGA board and connect it to your PC. Then press Auto-fill button to find your hardware name. Optinally you can run \$QUARTUS_BIN/jtagconfig to find your programming hardware name.
an example of output from the 'jtagconfig' command:
\t 1) ByteBlasterMV on LPT1
\t 090010DD EPXA10
\t 049220DD EPXA_ARM922
or
\t 1) DE-SoC [1-3]
\t 48A00477 SOCVHP5
\t 02D020DC 5CS(EBA6ES|XFC6c6ES)
ByteBlasterMV \& DE-SoC are the programming hardware name.";
my $help6="Power on your FPGA board and connect it to your PC. Then press Auto-fill button to find your devive location in jtag chain. Optinally you can run \$QUARTUS_BIN/jtagconfig to find your target device location in jtag chain.";
 
 
 
my @info = (
{ label=>"FPGA Borad name:", param_name=>'quartus_board', type=>"Entry", default_val=>undef, content=>undef, info=>$help1, param_parent=>'compile', ref_delay=> undef},
{ label=>'FPGA board golden top QSF file:', param_name=>'quartus_qsf', type=>"FILE_path", default_val=>undef, content=>"qsf", info=>$help2, param_parent=>'compile', ref_delay=>undef},
{ label=>"FPGA board golden top verilog file", param_name=>'quartus_v', type=>"FILE_path", default_val=>undef, content=>"v", info=>$help3, param_parent=>'compile',ref_delay=>undef },
);
my @usb = (
{ label=>"FPGA Borad USB Blaster PID:", param_name=>'quartus_pid', type=>"Entry", default_val=>undef, content=>undef, info=>$help4, param_parent=>'compile', ref_delay=> undef},
{ label=>"FPGA Borad Programming Hardware Name:", param_name=>'quartus_hardware', type=>"Entry", default_val=>undef, content=>undef, info=>$help5, param_parent=>'compile', ref_delay=> undef},
{ label=>"FPGA Borad Device location in JTAG chain:", param_name=>'quartus_device', type=>"Spin-button", default_val=>0, content=>"0,100,1", info=>$help6, param_parent=>'compile', ref_delay=> undef},
);
my $col=0;
my $row=0;
foreach my $d (@info) {
($row,$col)=add_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,$col,1, $d->{param_parent}, $d->{ref_delay},undef,"vertical");
}
my $labl=def_pack_vbox(FALSE, 0,(Gtk2::HSeparator->new,gen_label_in_center("FPGA Board JTAG Configuration"),Gtk2::HSeparator->new));
$table->attach( $labl,0,3,$row,$row+1,'fill','shrink',2,2); $row++; $col=0;
foreach my $d (@usb) {
($row,$col)=add_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,$col,1, $d->{param_parent}, $d->{ref_delay},undef,"vertical");
}
return ($row, $col, $table);
}
 
 
 
 
 
sub add_new_fpga_board_files{
my $self=shift;
#check the board name
my $board_name=$self->object_get_attribute('compile','quartus_board');
return "Please define the Board Name\n" if(! defined $board_name );
return "Please define the Board Name\n" if(length($board_name) ==0 );
my $r=check_verilog_identifier_syntax($board_name);
return "Error in given Board Name: $r\n" if(defined $r );
#check qsf file
my $qsf=$self->object_get_attribute('compile','quartus_qsf');
return "Please define the QSF file\n" if(!defined $qsf );
#check v file
my $top=$self->object_get_attribute('compile','quartus_v');
return "Please define the verilog file file\n" if(!defined $top );
#check PID
my $pid=$self->object_get_attribute('compile','quartus_pid');
return "Please define the PID\n" if(! defined $pid );
return "Please define the PID\n" if(length($pid) ==0 );
#check Hardware name
my $hw=$self->object_get_attribute('compile','quartus_hardware');
return "Please define the Hardware Name\n" if(! defined $hw );
return "Please define the Hardware Name\n" if(length($hw) ==0 );
#check Device name name
my $dw=$self->object_get_attribute('compile','quartus_device');
return "Please define targeted Device location in JTAG chain. The device location must be larger than zero.\n" if( $dw == 0 );
#make board directory
my $dir = Cwd::getcwd();
my $path="$dir/../boards/$board_name";
mkpath($path,1,01777);
return "Error cannot make $path path" if ((-d $path)==0);
#generate new qsf file
$qsf=add_project_dir_to_addr($qsf);
$top=add_project_dir_to_addr($top);
open my $file, "<", $qsf or return "Error Could not open $qsf file in read mode!";
open my $newqsf, ">", "$path/$board_name.qsf" or return "Error Could not create $path/$board_name.qsf file in write mode!";
#remove the lines contain following strings
my @p=("TOP_LEVEL_ENTITY","VERILOG_FILE","SYSTEMVERILOG_FILE","VHDL_FILE","AHDL_FILE","PROJECT_OUTPUT_DIRECTORY" );
while (my $line = <$file>){
if ($line =~ /\Q$p[0]\E/ || $line =~ /\Q$p[1]\E/ || $line =~ /\Q$p[2]\E/ || $line =~ /\Q$p[3]\E/ || $line =~ /\Q$p[4]\E/){#dont copy the line contain TOP_LEVEL_ENTITY
}
else{
print $newqsf $line;
}
}
print $newqsf "\nset_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files\n";
 
close $newqsf;
close $file;
copy($top,"$path/$board_name.v");
#generate jtag_intfc.sh
open $file, ">", "$path/jtag_intfc.sh" or return "Error: Could not create $path/jtag_intfc.sh file in write mode!";
my $jtag;
if($pid eq 6001 || $pid eq 6002 || $pid eq 6003){
$jtag="JTAG_INTFC=\"\$PRONOC_WORK/toolchain/bin/jtag_libusb -a \$PRODUCT_ID\"";
}else{
$jtag="JTAG_INTFC=\"\$PRONOC_WORK/toolchain/bin/jtag_quartus_stp -a \$HARDWARE_NAME -b \$DEVICE_NAME\"";
}
print $file "#!/bin/sh
 
PRODUCT_ID=\"0x$pid\"
HARDWARE_NAME=\'$hw *\'
DEVICE_NAME=\"\@$dw*\"
$jtag
";
close $file;
#generate program_device.sh
open $file, ">", "$path/program_device.sh" or return "Error: Could not create $path/program_device.sh file in write mode!";
print $file "#!/bin/sh
 
#usage:
# sh program_device.sh programming_file.sof
 
#programming file
#given as an argument: \$1
 
#Programming mode
PROG_MODE=jtag
 
#cable name. Connect the board to ur PC and then run jtagconfig in terminal to find the cable name
NAME=\"$hw\"
 
#device name
DEVICE=\@$dw".'
 
 
#programming command
if [ -n "${QUARTUS_BIN+set}" ]; then
$QUARTUS_BIN/quartus_pgm -m $PROG_MODE -c "$NAME" -o "p;${1}${DEVICE}"
else
quartus_pgm -m $PROG_MODE -c "$NAME" -o "p;${1}${DEVICE}"
fi
';
close $file;
$self->object_add_attribute('compile','board',$board_name);
return undef;
}
 
sub get_pin_assignment{
my ($self,$name,$top,$target_dir)=@_;
my ($self,$name,$top,$target_dir,$end_func)=@_;
my $window = def_popwin_size(80,80,"Step 2: Pin Assignment",'percent');
 
my $table = def_table(2, 2, FALSE);
413,18 → 759,26
$mtable->attach($back,2,3,9,10,'shrink','shrink',2,2);
$mtable->attach($next,8,9,9,10,'shrink','shrink',2,2);
 
 
 
my $board_name=$self->object_get_attribute('compile','board');
#copy board jtag_intfc.sh file
my ($fname,$fpath,$fsuffix) = fileparse("$top",qr"\..[^.]*$");
copy("../boards/$board_name/jtag_intfc.sh","${fpath}../sw/jtag_intfc.sh");
 
#copy board program_device.sh file
copy("../boards/$board_name/program_device.sh","${fpath}../program_device.sh");
 
#get boards pin list
my $board_name=$self->object_get_attribute('compile','board');
my @csv_file = glob("./lib/boards/$board_name/*.csv");
if(!defined $csv_file[0]){
message_dialog("Error: ./lib/boards/$board_name folder does not contain the csv file.!");
my $top_v= "../boards/$board_name/$board_name.v";
if(!-f $top_v){
message_dialog("Error: Could not load the board pin list. The $top_v does not exist!");
$window->destroy;
}
my $board=read_csv_file($csv_file[0]);
my $board=read_top_v_file($top_v);
 
# Write object file
#open(FILE, ">lib/soc/tttttttt") || die "Can not open: $!";
542,13 → 896,13
$next-> signal_connect("clicked" => sub{
$window->destroy;
quartus_compilation($self,$board,$name,$top,$target_dir);
quartus_compilation($self,$board,$name,$top,$target_dir,$end_func);
});
$back-> signal_connect("clicked" => sub{
$window->destroy;
select_compiler($self,$name,$top,$target_dir);
select_compiler($self,$name,$top,$target_dir,$end_func);
});
 
562,10 → 916,12
 
 
sub quartus_compilation{
my ($self,$board,$name,$top,$target_dir)=@_;
my $run=def_image_button('icons/run.png','run');
my ($self,$board,$name,$top,$target_dir,$end_func)=@_;
my $run=def_image_button('icons/gate.png','Compile');
my $back=def_image_button('icons/left.png','Previous');
my $regen=def_image_button('icons/refresh.png','Regenerate Top.v');
my $regen=def_image_button('icons/refresh.png','Regenerate Top.v');
my $prog=def_image_button('icons/write.png','Program the board');
 
 
my ($fname,$fpath,$fsuffix) = fileparse("$top",qr"\..[^.]*$");
577,9 → 933,11
my ($app,$table,$tview,$window) = software_main($fpath,'Top.v');
$table->attach($back,1,2,1,2,'shrink','shrink',2,2);
$table->attach($regen,4,5,1,2,'shrink','shrink',2,2);
$table->attach ($run,9, 10, 1,2,'shrink','shrink',0,0);
$table->attach ($run,7, 8, 1,2,'shrink','shrink',2,2);
$table->attach($prog,9,10,1,2,'shrink','shrink',2,2);
 
$regen-> signal_connect("clicked" => sub{
my $dialog = Gtk2::MessageDialog->new (my $window,
'destroy-with-parent',
632,9 → 990,9
 
#append global assignets to qsf file
my $board_name=$self->object_get_attribute('compile','board');
my @qsfs = glob("./lib/boards/$board_name/*.qsf");
my @qsfs = glob("../boards/$board_name/*.qsf");
if(!defined $qsfs[0]){
message_dialog("Error: ./lib/boards/$board_name folder does not contain the qsf file.!");
message_dialog("Error: ../boards/$board_name folder does not contain the qsf file.!");
$window->destroy;
}
 
681,15 → 1039,55
}
}
add_colored_info(\$tview,"Quartus compilation is done successfully in $target_dir!\n", 'blue') if($error==0);
 
if (defined $end_func){
if ($error==0){
$end_func->($self);
$window->destroy;
}else {
message_dialog("Error in Quartus compilation!",'error');
}
}
});
 
 
#Programe the board
$prog-> signal_connect("clicked" => sub{
my $error = 0;
my $sof_file="$target_dir/output_files/${name}.sof";
my $bash_file="$target_dir/program_device.sh";
 
add_info(\$tview,"Programe the board using quartus_pgm and $sof_file file\n");
#check if the programming file exists
unless (-f $sof_file) {
add_colored_info(\$tview,"\tThe $sof_file does not exists! Make sure you have compiled the code successfully.\n", 'red');
$error=1;
}
#check if the program_device.sh file exists
unless (-f $bash_file) {
add_colored_info(\$tview,"\tThe $bash_file does not exists! This file veries depend on your target board and must be available inside mpsoc/boards/[board_name].\n", 'red');
$error=1;
}
return if($error);
my $command = "sh $bash_file $sof_file";
add_info(\$tview,"$command\n");
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($command);
if(length $stderr>1){
add_colored_info(\$tview,"$stderr\n",'red');
add_colored_info(\$tview,"Board was not programed successfully!\n",'red');
}else {
 
if($exit){
add_colored_info(\$tview,"$stdout\n",'red');
add_colored_info(\$tview,"Board was not programed successfully!\n",'red');
}else{
add_info(\$tview,"$stdout\n");
add_colored_info(\$tview,"Board is programed successfully!\n",'blue');
 
 
}
}
});
 
}
788,7 → 1186,7
view signals
run -all
";
 
add_info(\$tview,"Create run.tcl file\n");
save_file ("$model/run.tcl",$tcl);
$run -> signal_connect("clicked" => sub{
set_gui_status($self,'save_project',1);
795,9 → 1193,11
$app->do_save();
my $modelsim_bin= $self->object_get_attribute('compile','modelsim_bin');
my $cmd="cd $target_dir; $modelsim_bin/vsim -do $model/run.tcl";
add_info(\$tview,"$cmd\n");
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($cmd);
if(length $stderr>1){
add_info(\$tview,"$stderr\n");
if(length $stderr>1){
add_colored_info(\$tview,"$stderr\n","red");
}else {
add_info(\$tview,"$stdout\n");
}
808,38 → 1208,13
}
 
 
# source files : $target_dir/src_verilog
# work dir : $target_dir/src_verilog
 
 
sub verilator_compilation {
my ($self,$name,$top,$target_dir)=@_;
my $window = def_popwin_size(80,80,"Step 2: Compile",'percent');
my $mtable = def_table(10, 10, FALSE);
my ($outbox,$outtext)= create_text();
add_colored_tag($outtext,'red');
add_colored_tag($outtext,'blue');
my $next=def_image_button('icons/run.png','Next');
my $back=def_image_button('icons/left.png','Previous');
my ($top_ref,$target_dir,$outtext)=@_;
 
$mtable->attach_defaults ($outbox ,0, 10, 4,9);
$mtable->attach($back,2,3,9,10,'shrink','shrink',2,2);
$mtable->attach($next,8,9,9,10,'shrink','shrink',2,2);
 
 
$back-> signal_connect("clicked" => sub{
$window->destroy;
select_compiler($self,$name,$top,$target_dir);
});
$next-> signal_connect("clicked" => sub{
$window->destroy;
verilator_testbench($self,$name,$top,$target_dir);
});
 
my %tops = %{$top_ref};
#creat verilator dir
add_info(\$outtext,"creat verilator dir in $target_dir\n");
my $verilator="$target_dir/verilator";
852,11 → 1227,20
#copy all verilog files in rtl_work folder
add_info(\$outtext,"Copy all verilog files in rtl_work folder\n");
my @files = File::Find::Rule->file()
->name( '*.v','*.V','*.sv' )
->name( '*.v','*.V','*.sv','*.vh')
->in( "$target_dir/src_verilog" );
foreach my $file (@files) {
copy($file,"$verilator/rtl_work/");
}
@files = File::Find::Rule->file()
->name( '*.sv','*.vh' )
->in( "$target_dir/src_verilog" );
foreach my $file (@files) {
copy($file,"$verilator/processed_rtl");
}
 
#"split all verilog modules in separate files"
add_info(\$outtext,"split all verilog modules in separate files\n");
866,22 → 1250,132
celldefine => 0,
);
$split->read_and_split(glob("$verilator/rtl_work/*.v"));
$split->read_and_split(glob("$verilator/rtl_work/*.sv"));
$split->write_files();
$split->read_and_split(glob("$verilator/rtl_work/*.sv"));
$split->write_files();
#run verilator
#my $cmd= "cd \"$verilator/processed_rtl\" \n xterm -e sh -c ' verilator --cc $name.v --profile-cfuncs --prefix \"Vtop\" -O3 -CFLAGS -O3'";
my $cmd= "cd \"$verilator/processed_rtl\" \n verilator --cc $name.v --profile-cfuncs --prefix \"Vtop\" -O3 -CFLAGS -O3";
add_info(\$outtext,"$cmd\n");
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($cmd);
if(length $stderr>1){
add_info(\$outtext,"$stderr\n");
}else {
add_info(\$outtext,"$stdout\n");
}
foreach my $top (sort keys %tops) {
my $cmd= "cd \"$verilator/processed_rtl\" \n verilator --cc $tops{$top} --profile-cfuncs --prefix \"$top\" -O3 -CFLAGS -O3";
add_info(\$outtext,"$cmd\n");
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($cmd);
if(length $stderr>1){
add_info(\$outtext,"$stderr\n");
}else {
add_info(\$outtext,"$stdout\n");
}
}
 
#check if verilator model has been generated
if (-f "$verilator/processed_rtl/obj_dir/Vtop.cpp"){
foreach my $top (sort keys %tops) {
if (-f "$verilator/processed_rtl/obj_dir/$top.cpp"){#succsess
#generate makefile
gen_verilator_makefile($top_ref,"$verilator/processed_rtl/obj_dir/Makefile");
}else {
return 0;
}
}
return 1;
}
 
 
sub gen_verilator_makefile{
my ($top_ref,$target_dir) =@_;
my %tops = %{$top_ref};
my $p='';
my $q='';
my $h='';
my $l;
foreach my $top (sort keys %tops) {
$p = "$p ${top}__ALL.a ";
$q = "$q\t\$(MAKE) -f ${top}.mk\n";
$h = "$h ${top}.h ";
$l = $top;
}
my $make= "
default: sim
 
 
 
include $l.mk
 
lib:
$q
 
 
#######################################################################
# Compile flags
 
CPPFLAGS += -DVL_DEBUG=1
ifeq (\$(CFG_WITH_CCWARN),yes) # Local... Else don't burden users
CPPFLAGS += -DVL_THREADED=1
CPPFLAGS += -W -Werror -Wall
endif
 
#######################################################################
# Linking final exe -- presumes have a sim_main.cpp
 
 
sim: testbench.o \$(VK_GLOBAL_OBJS) $p
\$(LINK) \$(LDFLAGS) -g \$^ \$(LOADLIBES) \$(LDLIBS) -o testbench \$(LIBS) -Wall -O3 2>&1 | c++filt
 
testbench.o: testbench.cpp $h
 
clean:
rm *.o *.a main
";
 
 
 
save_file ($target_dir,$make);
 
 
 
 
}
 
 
 
sub verilator_compilation_win {
my ($self,$name,$top,$target_dir)=@_;
my $window = def_popwin_size(80,80,"Step 2: Compile",'percent');
my $mtable = def_table(10, 10, FALSE);
my ($outbox,$outtext)= create_text();
add_colors_to_textview($outtext);
my $next=def_image_button('icons/run.png','Next');
my $back=def_image_button('icons/left.png','Previous');
 
$mtable->attach_defaults ($outbox ,0, 10, 4,9);
$mtable->attach($back,2,3,9,10,'shrink','shrink',2,2);
$mtable->attach($next,8,9,9,10,'shrink','shrink',2,2);
 
 
$back-> signal_connect("clicked" => sub{
$window->destroy;
select_compiler($self,$name,$top,$target_dir);
});
$next-> signal_connect("clicked" => sub{
$window->destroy;
verilator_testbench($self,$name,$top,$target_dir);
});
my %tops;
$tops{"Vtop"}= "$name.v";
my $result = verilator_compilation (\%tops,$target_dir,$outtext);
#check if verilator model has been generated
if ($result){
add_colored_info(\$outtext,"Veriator model has been generated successfully!",'blue');
}else {
add_colored_info(\$outtext,"Verilator compilation failed!\n","red");
898,6 → 1392,8
 
}
 
 
 
sub gen_verilator_soc_testbench {
my ($self,$name,$top,$target_dir)=@_;
my $verilator="$target_dir/verilator";
1109,7 → 1605,7
my $dir="$verilator";
gen_verilator_soc_testbench (@_) if((-f "$dir/testbench.cpp")==0);
#copy makefile
copy("../script/verilator_soc_make", "$verilator/processed_rtl/obj_dir/Makefile");
#copy("../script/verilator_soc_make", "$verilator/processed_rtl/obj_dir/Makefile");
 
my ($app,$table,$tview,$window) = software_main($dir,'testbench.cpp');
1128,7 → 1624,7
$back-> signal_connect("clicked" => sub{
$window->destroy;
verilator_compilation($self,$name,$top,$target_dir);
verilator_compilation_win($self,$name,$top,$target_dir);
});
 
/diagram.pl
1,4 → 1,5
#!/usr/bin/perl -w
use Glib qw/TRUE FALSE/;
use strict;
use warnings;
use soc;
10,11 → 11,11
 
 
sub get_dot_file{
my $soc= shift;
my $soc_name=$soc->object_get_attribute('soc_name');
my $remove_clk = $soc->object_get_attribute("diagrame","show_clk");
my $remove_reset = $soc->object_get_attribute("diagrame","show_reset");
my $remove_unused = $soc->object_get_attribute("diagrame","show_unused");
my $self= shift;
my $self_name=$self->object_get_attribute('soc_name');
my $remove_clk = $self->object_get_attribute("tile_diagram","show_clk");
my $remove_reset = $self->object_get_attribute("tile_diagram","show_reset");
my $remove_unused = $self->object_get_attribute("tile_diagram","show_unused");
 
my $dotfile=
"digraph G {
22,7 → 23,7
node[shape=record];
";
 
my @all_instances=$soc->soc_get_all_instances();
my @all_instances=$self->soc_get_all_instances();
#print "@all_instances\n";
my $graph_connect= '';
my $n=0;
29,10 → 30,10
#my %socket_color;
foreach my $instance_id (@all_instances){
my $first=1;
my $instance_name=$soc->soc_get_instance_name($instance_id);
my $instance_name=$self->soc_get_instance_name($instance_id);
$dotfile="$dotfile \n\t$instance_id \[label=\"{ ";
my @sockets= $soc->soc_get_all_sockets_of_an_instance($instance_id);
my @sockets= $self->soc_get_all_sockets_of_an_instance($instance_id);
@sockets = remove_scolar_from_array(\@sockets,'clk') if ($remove_clk);
@sockets = remove_scolar_from_array(\@sockets,'reset') if ($remove_reset);
39,17 → 40,17
 
foreach my $socket (@sockets){
 
my @nums=$soc->soc_list_socket_nums($instance_id,$socket);
my @nums=$self->soc_list_socket_nums($instance_id,$socket);
foreach my $num (@nums){
my $name= $soc->soc_get_socket_name ($instance_id,$socket,$num);
my ($s_type,$s_value,$s_connection_num)=$soc->soc_get_socket_of_instance($instance_id,$socket);
my $v=$soc->soc_get_module_param_value($instance_id,$s_value);
my $name= $self->soc_get_socket_name ($instance_id,$socket,$num);
my ($s_type,$s_value,$s_connection_num)=$self->soc_get_socket_of_instance($instance_id,$socket);
my $v=$self->soc_get_module_param_value($instance_id,$s_value);
$v=1 if ( length( $v || '' ) ==0);
#for(my $i=$v-1; $i>=0; $i--) {
for(my $i=0; $i<$v; $i++) {
#$socket_color{socket_${socket}\_$i}=$n;
#$n = ($n<30)? $n+1 : 0;
my ($ref1,$ref2)= $soc->soc_get_modules_plug_connected_to_socket($instance_id,$socket,$i);
my ($ref1,$ref2)= $self->soc_get_modules_plug_connected_to_socket($instance_id,$socket,$i);
my %connected_plugs=%$ref1;
my %connected_plug_nums=%$ref2;
if(%connected_plugs || $remove_unused==0){
66,7 → 67,7
$dotfile=($first)? "$dotfile $instance_name" : "$dotfile}|$instance_name";
$first=1;
my @plugs= $soc->soc_get_all_plugs_of_an_instance($instance_id);
my @plugs= $self->soc_get_all_plugs_of_an_instance($instance_id);
@plugs = remove_scolar_from_array(\@plugs,'clk') if ($remove_clk);
@plugs = remove_scolar_from_array(\@plugs,'reset') if ($remove_reset);
 
74,14 → 75,14
my @noconnect;
foreach my $plug (@plugs){
my @nums=$soc->soc_list_plug_nums($instance_id,$plug);
my @nums=$self->soc_list_plug_nums($instance_id,$plug);
foreach my $num (@nums){
my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$soc->soc_get_plug($instance_id,$plug,$num);
my ($addr,$base,$end,$name,$connect_id,$connect_socket,$connect_socket_num)=$self->soc_get_plug($instance_id,$plug,$num);
if(defined $connect_socket || $remove_unused==0){
#$dotfile= ($first)? "$dotfile |{<plug_${plug}_${num}>$name" : "$dotfile|<plug_${plug}_${num}>$name";
if(defined $connect_id && defined $connect_socket){
my @sockets= $soc->soc_get_all_sockets_of_an_instance($connect_id);
my @sockets= $self->soc_get_all_sockets_of_an_instance($connect_id);
my $order_val=0;
my $s1=get_pos($connect_id, @all_instances);
my $s2=get_pos($connect_socket, @sockets);
91,7 → 92,7
}
 
#my $connect_name=$soc->soc_get_instance_name($connect_id);
#my $connect_name=$self->soc_get_instance_name($connect_id);
#my $color = get_color_hex_string($n);
#$n = ($n<30)? $n+1 : 0;
131,7 → 132,7
 
 
sub show_tile_diagram {
my $soc= shift;
my $self= shift;
 
my $table=def_table(20,20,FALSE);
143,13 → 144,13
my $plus = def_image_button('icons/plus.png',undef,TRUE);
my $minues = def_image_button('icons/minus.png',undef,TRUE);
my $unused = gen_check_box_object ($soc,"diagrame","show_unused",0,undef,undef);
my $unused = gen_check_box_object ($self,"tile_diagram","show_unused",0,undef,undef);
my $save = def_image_button('icons/save.png',undef,TRUE);
my $clk = gen_check_box_object ($soc,"diagrame","show_clk",0,undef,undef);
my $reset = gen_check_box_object ($soc,"diagrame","show_reset",0,undef,undef);
my $clk = gen_check_box_object ($self,"tile_diagram","show_clk",0,undef,undef);
my $reset = gen_check_box_object ($self,"tile_diagram","show_reset",0,undef,undef);
#my $save = def_image_button('icons/save.png',undef,TRUE);
 
my $scale=$soc->object_get_attribute("diagrame","scale");
my $scale=$self->object_get_attribute("tile_diagram","scale");
$scale= 1 if (!defined $scale);
173,58 → 174,53
$plus -> signal_connect("clicked" => sub{
$scale*=1.1 if ($scale <10);
$soc->object_add_attribute("diagrame","scale", $scale );
show_diagram ($soc,$scrolled_win,$table);
$self->object_add_attribute("tile_diagram","scale", $scale );
show_diagram ($self,$scrolled_win,$table,"tile_diagram");
});
$minues -> signal_connect("clicked" => sub{
$scale*=.9 if ($scale >0.1); ;
$soc->object_add_attribute("diagrame","scale", $scale );
show_diagram ($soc,$scrolled_win,$table);
$self->object_add_attribute("tile_diagram","scale", $scale );
show_diagram ($self,$scrolled_win,$table,"tile_diagram");
});
$save-> signal_connect("clicked" => sub{
save_diagram_as ($soc);
save_diagram_as ($self);
});
$unused-> signal_connect("toggled" => sub{
if(gen_diagram($soc)){
show_diagram ($soc,$scrolled_win,$table);
if(gen_diagram($self,'tile')){
show_diagram ($self,$scrolled_win,$table,"tile_diagram");
}
 
});
$clk-> signal_connect("toggled" => sub{
if(gen_diagram($soc)){
show_diagram ($soc,$scrolled_win,$table);
if(gen_diagram($self,'tile')){
show_diagram ($self,$scrolled_win,$table,"tile_diagram");
}
 
});
$reset-> signal_connect("toggled" => sub{
if(gen_diagram($soc)){
show_diagram ($soc,$scrolled_win,$table);
if(gen_diagram($self,'tile')){
show_diagram ($self,$scrolled_win,$table,"tile_diagram");
}
 
});
 
 
 
if(gen_diagram($soc)){
show_diagram ($soc,$scrolled_win,$table);
if(gen_diagram($self,'tile')){
show_diagram ($self,$scrolled_win,$table,"tile_diagram");
}
$window->show_all();
 
 
 
 
}
 
 
 
sub gen_diagram {
my ($soc)=@_;
my ($self,$type)=@_;
 
 
my $dotfile= get_dot_file($soc);
my $dotfile;
$dotfile= get_dot_file($self) if ($type eq 'tile');
$dotfile= generate_trace_dot_file($self) if ($type eq 'trace');
$dotfile= generate_map_dot_file($self) if ($type eq 'map');
my $tmp_dir = "$ENV{'PRONOC_WORK'}/tmp";
mkpath("$tmp_dir/",1,01777);
open(FILE, ">$tmp_dir/diagram.txt") || die "Can not open: $!";
231,7 → 227,9
print FILE $dotfile;
close(FILE) || die "Error closing file: $!";
 
my $cmd = "dot $tmp_dir/diagram.txt | neato -n -Tpng -o $tmp_dir/diagram.png";
my $cmd;
$cmd= "dot $tmp_dir/diagram.txt | neato -n -Tpng -o $tmp_dir/diagram.png" if ($type eq 'tile' || $type eq 'trace');
$cmd = "dot $tmp_dir/diagram.txt -Kfdp -n -Tpng -o $tmp_dir/diagram.png" if ( $type eq 'map');
 
my ($stdout,$exit,$stderr)= run_cmd_in_back_ground_get_stdout ($cmd);
254,13 → 252,13
 
 
sub show_diagram {
my ($soc,$scrolled_win,$table)=@_;
my ($self,$scrolled_win,$table, $name)=@_;
 
$scrolled_win->destroy;
$scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$table->attach_defaults ($scrolled_win, 0, 20, 1, 20); #,'fill','shrink',2,2);
my $scale=$soc->object_get_attribute("diagrame","scale");
my $scale=$self->object_get_attribute($name,"scale");
$scale= 1 if (!defined $scale);
my $tmp_dir = "$ENV{'PRONOC_WORK'}/tmp";
my $diagram=open_image("$tmp_dir/diagram.png",70*$scale,70*$scale,'percent');
274,7 → 272,7
 
 
sub save_diagram_as {
my $soc= shift;
my $self= shift;
my $file;
my $title ='Save as';
312,8 → 310,8
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
$file = ($suffix eq ".$ext" )? $file : "$file.$ext";
$soc->object_add_attribute("graph_save","name",$file);
$soc->object_add_attribute("graph_save","extension",$ext);
$self->object_add_attribute("graph_save","name",$file);
$self->object_add_attribute("graph_save","extension",$ext);
my $tmp = "$ENV{'PRONOC_WORK'}/tmp/diagram.png";
copy ($tmp,$file);
 
321,14 → 319,225
}
$dialog->destroy;
}
 
 
 
sub generate_trace_dot_file{
my $self=shift;
my $dotfile=
"digraph G {
graph [rankdir = LR , splines=polyline, overlap = false];
";
#add nodes
#my @tasks=get_all_tasks($self);
#foreach my $p (@tasks){
# $dotfile=$dotfile."\"$p\" [label=\"{ $p} }\"];\n";
#}
#add connections
 
my @traces= $self->get_trace_list();
foreach my $p (@traces) {
my ($src,$dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
$dotfile=$dotfile."\"$src\" -> \"$dst\" [label=\"$Mbytes\" ];\n";
}
$dotfile=$dotfile."\n}\n";
return $dotfile;
}
 
 
 
sub generate_map_dot_file_old{
my $self=shift;
my $dotfile=
"digraph G {
graph [rankdir = LR , splines=ortho, overlap = false];
node[shape=record];
NoC [label=\"";
 
#add nodes
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my $nc= $nx * $ny;
my @tasks=get_all_tasks($self);
 
 
for(my $y=0; $y<$ny; $y++){
for(my $x=0; $x<$nx; $x++){
my $task=get_task_assigned_to_tile($self,$x,$y);
my $id=$y*$nx+$x;
$dotfile= $dotfile."{" if ($x==0);
$dotfile= $dotfile." <$task> IP${id}(${y},$x)\n$task" if (defined $task);
$dotfile= $dotfile." IP${id}(${y},$x)" if (!defined $task);
$dotfile=$dotfile."|" if($nx != 1 && $x !=$nx-1 );
$dotfile= $dotfile."}" if ($x==$nx-1);
}
$dotfile=$dotfile."|" if($ny != 1 && $y !=$ny-1 );
}
$dotfile=$dotfile."\"];\n\n";
 
 
 
 
$dotfile=$dotfile."\n}\n";
return $dotfile;
}
 
sub generate_map_dot_file{
my $self=shift;
my $dotfile=
"digraph G {
graph [rankdir = LR ,splines=spline, overlap = false];
node[shape=record];
";
 
#add nodes
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my $nc= $nx * $ny;
my @tasks=get_all_tasks($self);
my @mappedtasks;
for(my $y=0; $y<$ny; $y++){
for(my $x=0; $x<$nx; $x++){
my $id=$y*$nx+$x;
my $task=get_task_assigned_to_tile($self,$x,$y);
push(@mappedtasks,$task) if (defined $task);
$task= "_" if (!defined $task);
my $n = ($ny==1)? "tile(${x})" : "tile${id}(${x}_$y)" ;
my $m = ($ny==1)? "tile(${x})" : "tile(${x}_$y)" ;
my $node = "\"$m\"";
my $label = "\"<S$task> $n|<R$task> $task\"" ;
my $xx=$x*1.5;
my $yy=($ny-$y-1)*1.5;
$dotfile=$dotfile."
$node\[
label = $label
pos = \"$xx,$yy!\"
];";
}
}
 
$dotfile=$dotfile."\n\n";
#add connections
my @traces= $self->get_trace_list();
foreach my $p (@traces){
my ($src,$dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
my $src_tile= $self->object_get_attribute("MAP_TILE","$src");
my $dst_tile= $self->object_get_attribute("MAP_TILE","$dst");
next if ( $src_tile eq "-" || $dst_tile eq "-" ) ;
$dotfile=$dotfile." \"$src_tile\" : \"S$src\" -> \"$dst_tile\" : \"R$dst\" ;\n";
}
 
 
 
$dotfile=$dotfile."\n}\n";
return $dotfile;
}
 
 
 
 
 
sub show_trace_diagram {
my ($self,$type)=@_;
 
my $table=def_table(20,20,FALSE);
my $window=def_popwin_size(80,80,"Processing Tile functional block diagram",'percent');
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$window->add ($table);
my $plus = def_image_button('icons/plus.png',undef,TRUE);
my $minues = def_image_button('icons/minus.png',undef,TRUE);
my $save = def_image_button('icons/save.png',undef,TRUE);
 
my $scale=$self->object_get_attribute("${type}_diagram","scale");
$scale= 1 if (!defined $scale);
my $col=0;
$table->attach ($plus , $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
$table->attach ($minues, $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
$table->attach ($save, $col, $col+1,0,1,'shrink','shrink',2,2); $col++;
while ($col<20){
 
my $tmp=gen_label_in_left('');
$table->attach_defaults ($tmp, $col, $col+1,0,1);$col++;
}
$plus -> signal_connect("clicked" => sub{
$scale*=1.1 if ($scale <10);
$self->object_add_attribute("${type}_diagram","scale", $scale );
show_diagram ($self,$scrolled_win,$table, "${type}_diagram");
});
$minues -> signal_connect("clicked" => sub{
$scale*=.9 if ($scale >0.1); ;
$self->object_add_attribute("${type}_diagram","scale", $scale );
show_diagram ($self,$scrolled_win,$table, "${type}_diagram");
});
$save-> signal_connect("clicked" => sub{
save_diagram_as ($self);
});
 
 
 
if(gen_diagram($self,$type)){
show_diagram ($self,$scrolled_win,$table, "${type}_diagram");
}
$window->show_all();
 
 
 
}
return 1;
/emulate_ram_gen.pl
7,13 → 7,22
 
use constant SIM_RAM_GEN => 0;
 
use constant JTAG_RAM_INDEX => 128;
use constant JTAG_STATIC_INDEX => 124;
use constant JTAG_RAM_INDEX => 125;
use constant JTAG_COUNTER_INDEX=>126;
use constant JTAG_DONE_RESET_INDEX => 127;
use constant RESET_NOC => " $ENV{'PRONOC_WORK'}/toolchain/bin/jtag_main -n ".JTAG_DONE_RESET_INDEX." -d \"I:1,D:2:1,I:0\" ";
use constant UNRESET_NOC => " $ENV{'PRONOC_WORK'}/toolchain/bin/jtag_main -n ".JTAG_DONE_RESET_INDEX." -d \"I:1,D:2:0,I:0\" ";
use constant STATISTIC_NUM =>8;
 
use constant READ_DONE_CMD => " $ENV{'PRONOC_WORK'}/toolchain/bin/jtag_main -n ".JTAG_DONE_RESET_INDEX." -d \"I:2,R:2:0,I:0\" ";
use constant CLK_CNTw=> 30; #log2(MAX_SIM_CLKs);
 
 
#use constant RESET_NOC => " $ENV{'JTAG_INTFC'} -n ".JTAG_DONE_RESET_INDEX." -d \"I:1,D:2:1,I:0\" ";
#use constant UNRESET_NOC => " $ENV{'JTAG_INTFC'} -n ".JTAG_DONE_RESET_INDEX." -d \"I:1,D:2:0,I:0\" ";
 
use constant READ_DONE_CMD => " \" -n ".JTAG_DONE_RESET_INDEX." -d I:2,R:2:0,I:0 \" ";
use constant READ_COUNTER_CMD => " \" -n ".JTAG_COUNTER_INDEX." -d I:2,R:".CLK_CNTw.":0,I:0 \" ";
 
 
use constant UPDATE_WB_ADDR => 0x7;
use constant UPDATE_WB_WR_DATA => 0x6;
use constant UPDATE_WB_RD_DATA => 0x5;
29,17 → 38,23
 
 
sub reset_cmd {
my ($ctrl_reset, $noc_reset)=@_;
my ($ctrl_reset, $noc_reset,$jtag_intfc)=@_;
my $reset_vector= (($ctrl_reset & 0x1) << 1) + ($noc_reset & 0x1);
my $cmd = " $ENV{'PRONOC_WORK'}/toolchain/bin/jtag_main -n ".JTAG_DONE_RESET_INDEX." -d \"I:1,D:2:$reset_vector,I:0\" ";
my $cmd = "sh $jtag_intfc \" -n ".JTAG_DONE_RESET_INDEX." -d I:1,D:2:$reset_vector,I:0 \" ";
#print "$cmd\n";
return $cmd;
 
}
 
sub set_time_limit_cmd {
my ($time_limit,$jtag_intfc)=@_;
my $hex = sprintf("0x%X", $time_limit);
my $cmd = "sh $jtag_intfc \" -n ".JTAG_COUNTER_INDEX." -d I:1,D:".CLK_CNTw.":$hex,I:0 \" ";
print "$cmd\n";
return $cmd;
}
 
 
 
sub help {
print
" usage: ./ram_gen X Y TRAFFIC
78,8 → 93,8
my ($cmd,$info)=@_;
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($cmd);
if($exit){
add_info($info, "$stdout\n") if(defined $stdout);
add_info($info, "$stderr\n") if(defined $stderr);
add_colored_info($info, "$stdout\n",'red') if(defined $stdout);
add_colored_info($info, "$stderr\n",'red') if(defined $stderr);
}
#print "\n$cmd \n $stdout";
152,19 → 167,19
 
 
sub gen_synthetic_traffic_ram_line{
my ($emulate, $x, $y, $sample_num,$ratio ,$line_num,$rnd)=@_;
my ($emulate, $x, $y, $sample,$ratio ,$line_num,$rnd)=@_;
 
my $ref=$emulate->object_get_attribute("sample$sample_num","noc_info");
my $ref=$emulate->object_get_attribute("$sample","noc_info");
my %noc_info= %$ref;
my $xn=$noc_info{NX};
my $yn=$noc_info{NY};
my $traffic=$emulate->object_get_attribute("sample$sample_num","traffic");
my $traffic=$emulate->object_get_attribute($sample,"traffic");
 
my $pck_num_to_send=$emulate->object_get_attribute("sample$sample_num","PCK_NUM_LIMIT");
my $pck_size=$emulate->object_get_attribute("sample$sample_num","PCK_SIZE");
my $pck_num_to_send=$emulate->object_get_attribute($sample,"PCK_NUM_LIMIT");
my $pck_size=$emulate->object_get_attribute($sample,"PCK_SIZE");
my $pck_class_in=0;
208,11 → 223,8
 
 
sub generate_synthetic_traffic_ram{
my ($emulate,$x,$y,$sample_num,$ratio , $file,$rnd,$num)=@_;
my $RAM_size=MAX_PATTERN+4;
 
 
my ($emulate,$x,$y,$sample,$ratio , $file,$rnd,$num)=@_;
my $line_num;
my $line_value;
my $ram;
220,8 → 232,8
my $ext= sprintf("%02u.txt",$num);
open( $ram, '>', RAM_SIM_FILE.$ext) || die "Can not create: \">lib/emulate/emulate_ram.bin\" $!";
}
for ($line_num= 0; $line_num<MAX_PATTERN+4; $line_num++ ) {
my ($value_s,$value_l)=gen_synthetic_traffic_ram_line ($emulate, $x, $y, $sample_num, $ratio ,$line_num,$rnd);
for ($line_num= 0; $line_num<RAM_SIZE; $line_num++ ) {
my ($value_s,$value_l)=gen_synthetic_traffic_ram_line ($emulate, $x, $y, $sample, $ratio ,$line_num,$rnd);
#printf ("\n%08x\t",$value_s);
258,8 → 270,8
 
 
sub generate_emulator_ram {
my ($emulate, $sample_num,$ratio_in,$info)=@_;
my $ref=$emulate->object_get_attribute("sample$sample_num","noc_info");
my ($emulate, $sample,$ratio_in,$info)=@_;
my $ref=$emulate->object_get_attribute($sample,"noc_info");
my %noc_info= %$ref;
my $C=$noc_info{C};
my $xn=$noc_info{NX};
266,7 → 278,7
my $yn=$noc_info{NY};
my $xc=$xn*$yn;
my $rnd=random_dest_gen($xc); # generate a matrix of sudo random number
my $traffic=$emulate->object_get_attribute("sample$sample_num","traffic");
my $traffic=$emulate->object_get_attribute($sample,"traffic");
my @traffics=("tornado", "transposed 1", "transposed 2", "bit reverse", "bit complement","random", "hot spot" );
if ( !defined $xn || $xn!~ /\s*\d+\b/ ){ add_info($info,"programe_pck_gens:invalid X value\n"); help(); return 0;}
282,7 → 294,7
for (my $y=0; $y<$yn; $y=$y+1){
for (my $x=0; $x<$xn; $x=$x+1){
my $num=($y * $xn) + $x;
generate_synthetic_traffic_ram($emulate,$x,$y,$sample_num,$ratio_in, $file,$rnd,$num);
generate_synthetic_traffic_ram($emulate,$x,$y,$sample,$ratio_in, $file,$rnd,$num);
 
}
}
292,23 → 304,33
}
 
sub programe_pck_gens{
my ($emulate, $sample_num,$ratio_in,$info)= @_;
my ($emulate, $sample,$ratio_in,$info,$jtag_intfc)= @_;
return 0 if(!generate_emulator_ram($emulate, $sample_num,$ratio_in,$info));
if(!generate_emulator_ram($emulate, $sample,$ratio_in,$info)){
add_colored_info($info, "Error in generate_emulator_ram function\n",'red');
return 0;
}
 
#reset the FPGA board
#run_cmd_in_back_ground("quartus_stp -t ./lib/tcl/mem.tcl reset");
return 0 if(run_cmd_update_info(reset_cmd(1,1),$info)); #reset both noc and jtag
return 0 if(run_cmd_update_info(reset_cmd(0,1),$info)); #enable jtag keep noc in reset
return 0 if(run_cmd_update_info(reset_cmd(1,1,$jtag_intfc),$info)); #reset both noc and jtag
return 0 if(run_cmd_update_info(reset_cmd(0,1,$jtag_intfc),$info)); #enable jtag keep noc in reset
#set time limit
my $time_limit = $emulate->object_get_attribute($sample,"SIM_CLOCK_LIMIT");
return 0 if(run_cmd_update_info(set_time_limit_cmd($time_limit,$jtag_intfc),$info));
 
 
#programe packet generators rams
my $cmd= "$ENV{'PRONOC_WORK'}/toolchain/bin/jtag_main -n ".JTAG_RAM_INDEX." -w 8 -i ".RAM_BIN_FILE." -c";
my $cmd= "sh $jtag_intfc \"-n ".JTAG_RAM_INDEX." -w 8 -i ".RAM_BIN_FILE." -c\" ";
#my ($result,$exit) = run_cmd_in_back_ground_get_stdout($cmd);
return 0 if(run_cmd_update_info ($cmd,$info));
#print $result;
return 0 if(run_cmd_update_info(reset_cmd(1,1),$info)); #reset both
return 0 if(run_cmd_update_info(reset_cmd(0,0),$info)); #enable both
return 0 if(run_cmd_update_info(reset_cmd(1,1,$jtag_intfc),$info)); #reset both
return 0 if(run_cmd_update_info(reset_cmd(0,0,$jtag_intfc),$info)); #enable both
#run_cmd_in_back_ground("quartus_stp -t ./lib/tcl/mem.tcl unreset");
#add_info($info,"$r\n");
 
318,10 → 340,18
 
 
sub read_jtag_memory{
my $addr=shift;
my $cmd= "$ENV{'PRONOC_WORK'}/toolchain/bin/jtag_main -n ".JTAG_RAM_INDEX." -w 8 -d \"I:".UPDATE_WB_ADDR.",D:64:$addr,I:5,R:64:$addr,I:0\"";
my ($addr,$jtag_intfc,$info)=@_;
my $cmd= "sh $jtag_intfc \" -n ".JTAG_STATIC_INDEX." -w 8 -d I:".UPDATE_WB_ADDR.",D:64:$addr,I:5,R:64:$addr,I:0\"";
#print "$cmd\n";
my ($result,$exit) = run_cmd_in_back_ground_get_stdout($cmd);
my ($result,$exit,$stderr) = run_cmd_in_back_ground_get_stdout($cmd);
if($exit){
add_colored_info($info, "$result\n",'red') if(defined $result);
add_colored_info($info, "$stderr\n",'red') if(defined $stderr);
return undef;
}
#print "$result\n";
my @q =split (/###read data#/,$result);
my $d=$q[1];
my $s= substr $d,2;
330,13 → 360,103
}
 
 
sub read_statistic_mem {
my($yn,$xn,$jtag_intfc,$info)=@_;
my %results;
my $sum_of_latency=0;
my $sum_of_pck=0;
my $total_router=0;
for (my $y=0; $y<$yn; $y=$y+1){
for (my $x=0; $x<$xn; $x=$x+1){
my $num=($y * $xn) + $x;
my $read_addr=($num * STATISTIC_NUM);
 
my $sent_pck_addr= sprintf ("%X",$read_addr);
my $got_pck_addr = sprintf ("%X",$read_addr+1);
my $latency_addr = sprintf ("%X",$read_addr+2);
my $worst_latency_addr = sprintf ("%X",$read_addr+3);
 
$results{$num}{sent_pck}=read_jtag_memory($sent_pck_addr,$jtag_intfc,$info);
$results{$num}{got_pck}=read_jtag_memory($got_pck_addr,$jtag_intfc,$info);
$results{$num}{latency}=read_jtag_memory($latency_addr,$jtag_intfc,$info);
$results{$num}{worst_latency}=read_jtag_memory($worst_latency_addr,$jtag_intfc,$info);
add_info($info, "$num, ");
$sum_of_latency+=$results{$num}{latency};
$sum_of_pck+=$results{$num}{got_pck};
$total_router++ if($results{$num}{sent_pck}>0);
#$i=$i+2;
}}
add_info($info, "\n");
return (\%results,$sum_of_latency,$sum_of_pck,$total_router);
}
 
 
sub read_statistic_mem_fast {
my($yn,$xn,$jtag_intfc,$info)=@_;
my %results;
my $sum_of_latency=0;
my $sum_of_pck=0;
my $total_router=0;
#read static memory
my $end= STATISTIC_NUM * 8 *$yn * $xn;
$end=sprintf ("%X",$end);
my $cmd= "sh $jtag_intfc \"-n ".JTAG_STATIC_INDEX." -w 8 -r -s 0 -e $end\"";
#print "$cmd\n";
my ($result,$exit,$stderr) = run_cmd_in_back_ground_get_stdout($cmd);
if($exit){
add_colored_info($info, "$result\n",'red') if(defined $result);
add_colored_info($info, "$stderr\n",'red') if(defined $stderr);
return undef;
}
#print "$result\n";
my @q =split (/###read data#\n/,$result);
my @data= split (/\n/,$q[1]);
#print "$data[0]\n";
for (my $y=0; $y<$yn; $y=$y+1){
for (my $x=0; $x<$xn; $x=$x+1){
my $num=($y * $xn) + $x;
my $read_addr=($num * STATISTIC_NUM);
 
my $sent_pck_addr= $read_addr;
my $got_pck_addr = $read_addr+1;
my $latency_addr = $read_addr+2;
my $worst_latency_addr = $read_addr+3;
 
$results{$num}{sent_pck}=hex($data[$sent_pck_addr]);
$results{$num}{got_pck}=hex($data[$got_pck_addr]);
$results{$num}{latency}=hex($data[$latency_addr]);
$results{$num}{worst_latency}=hex($data[$worst_latency_addr]);
#add_info($info, "$num, ");
$sum_of_latency+=$results{$num}{latency};
$sum_of_pck+=$results{$num}{got_pck};
$total_router++ if($results{$num}{sent_pck}>0);
#$i=$i+2;
}}
#add_info($info, "\n");
return (\%results,$sum_of_latency,$sum_of_pck,$total_router);
}
 
 
sub read_pack_gen{
my ($emulate,$sample_num,$info)= @_;
my $ref=$emulate->object_get_attribute("sample$sample_num","noc_info");
my ($emulate,$sample,$info,$jtag_intfc,$ratio_in)= @_;
my $ref=$emulate->object_get_attribute($sample,"noc_info");
my %noc_info= %$ref;
my $xn=$noc_info{NX};
my $yn=$noc_info{NY};
347,9 → 467,9
while ($done ==0){
usleep(300000);
#my ($result,$exit) = run_cmd_in_back_ground_get_stdout("quartus_stp -t ./lib/tcl/read.tcl done");
my ($result,$exit) = run_cmd_in_back_ground_get_stdout(READ_DONE_CMD);
my ($result,$exit) = run_cmd_in_back_ground_get_stdout("sh $jtag_intfc".READ_DONE_CMD);
if($exit != 0 ){
add_info($info,$result);
add_colored_info($info,$result,'red');
return undef;
}
my @q =split (/###read data#/,$result);
362,54 → 482,66
$counter++;
if($counter == 15){ #
add_info($info,"Done is not asserted. I reset the board and try again\n");
return if(run_cmd_update_info (reset_cmd(1,1),$info));
return if(run_cmd_update_info (reset_cmd(1,1,$jtag_intfc),$info));
#run_cmd_in_back_ground("quartus_stp -t ./lib/tcl/mem.tcl reset");
usleep(300000);
return if(run_cmd_update_info (reset_cmd(0,0),$info));
return if(run_cmd_update_info (reset_cmd(0,0,$jtag_intfc),$info));
#run_cmd_in_back_ground("quartus_stp -t ./lib/tcl/mem.tcl unreset");
}
if($counter>30){
#something is wrong
add_info($info,"Done is not asserted again. I am going to ignore this test case");
add_colored_info($info,"Done is not asserted again. I am going to ignore this test case\n",'green');
return undef;
}
}
add_info($info,"Done is asserted\n");
add_info($info,"Done is asserted\nStart reading statistic data from cores:\n\t");
#print" Done is asserted\n";
#my $i=0;
my %results;
my $sum_of_latency=0;
my $sum_of_pck=0;
for (my $y=0; $y<$yn; $y=$y+1){
for (my $x=0; $x<$xn; $x=$x+1){
my $num=($y * $xn) + $x;
my $read_addr=($num * RAM_SIZE) + MAX_PATTERN +1;
 
my $sent_pck_addr= sprintf ("%X",$read_addr);
my $got_pck_addr = sprintf ("%X",$read_addr+1);
my $latency_addr = sprintf ("%X",$read_addr+2);
 
$results{$num}{sent_pck}=read_jtag_memory($sent_pck_addr);
$results{$num}{got_pck}=read_jtag_memory($got_pck_addr);
$results{$num}{latency}=read_jtag_memory($latency_addr);
print "read pckgen $num\n";
$sum_of_latency+=$results{$num}{latency};
$sum_of_pck+=$results{$num}{got_pck};
#$i=$i+2;
}}
#my ($results_ref,$sum_of_latency,$sum_of_pck,$total_router)= read_statistic_mem($yn,$xn,$jtag_intfc,$info);
my ($results_ref,$sum_of_latency,$sum_of_pck,$total_router)= read_statistic_mem_fast($yn,$xn,$jtag_intfc,$info);
my %results=%$results_ref;
foreach my $p (sort keys %results){
update_result($emulate,$sample,"packet_rsvd_result",$ratio_in,$p,$results{$p}{got_pck} );
update_result($emulate,$sample,"packet_sent_result",$ratio_in,$p,$results{$p}{sent_pck});
update_result($emulate,$sample,"worst_delay_rsvd_result",$ratio_in,$p,$results{$p}{worst_latency});
#print "$p : \n latency: $results{$p}{latency}\n";
#print " got_pck : $results{$p}{got_pck}\n";
#print "got_pck : $results{$p}{got_pck}\n";
#print "sent_pck:$results{$p}{sent_pck}\n\n";
#print "worst_delay:$results{$p}{worst_latency}\n\n";
 
}
my $avg= ($sum_of_pck>0)? $sum_of_latency/$sum_of_pck : 0;
#print "total active router=$total_router\n";
#read clock counter
my $clk_counter;
my ($result,$exit) = run_cmd_in_back_ground_get_stdout("sh $jtag_intfc".READ_COUNTER_CMD);
if($exit != 0 ){
add_colored_info($info,$result,'red');
}else {
my @q =split (/###read data#/,$result);
my $d=$q[1];
my $s= substr $d,2;
$clk_counter= hex($s);
}
return sprintf("%.1f", $avg);
my $avg_latency= ($sum_of_pck>0)? $sum_of_latency/$sum_of_pck : 0;
my $packet_size=$emulate->object_get_attribute($sample,"PCK_SIZE");
my $avg_throughput= ($sum_of_pck>0 && $total_router>0 && $clk_counter>0 )? (($sum_of_pck * $packet_size *100)/ $total_router )/$clk_counter:0;
#print "($sum_of_pck * $packet_size *100)/ $total_router )/$clk_counter = $avg_throughput)";
#print "$avg = $sum_of_latency/$sum_of_pck ";
$avg_latency= sprintf("%.1f", $avg_latency);
update_result ($emulate,$sample,"latency_result",$ratio_in,$avg_latency);
update_result ($emulate,$sample,"throughput_result",$ratio_in,$avg_throughput);
update_result ($emulate,$sample,"exe_time_result",$ratio_in,$clk_counter);
return 1;
}
 
/emulator.pl
21,6 → 21,7
require "mpsoc_gen.pl";
require "mpsoc_verilog_gen.pl";
require "readme_gen.pl";
require "graph.pl";
 
use List::MoreUtils qw(uniq);
 
32,525 → 33,24
use constant MAXYw =>4; # 16 nodes in y dimention : hence max emulator size is 16X16
use constant MAXCw =>4; # 16 message classes
use constant RATIOw =>7; # log2(100)
use constant MAX_PATTERN => 124;
use constant RAM_SIZE => (MAX_PATTERN+4);
use constant RAM_Aw =>7;
use constant RAM_RESERVED_ADDR_NUM=>8;
use constant MAX_PATTERN => ((2**RAM_Aw)-(RAM_RESERVED_ADDR_NUM));
use constant RAM_SIZE => (2**RAM_Aw);
 
#use constant MAX_PCK_NUM => (2**PCK_CNTw)-1;
use constant MAX_PCK_NUM => (2**PCK_CNTw)-1;
use constant MAX_PCK_SIZ => (2**PCK_SIZw)-1;
use constant MAX_SIM_CLKs=> 100000000; # simulation end at if clock counter reach this number
use constant MAX_SIM_CLKs=> 1000000000; # simulation end at if clock counter reach this number
 
use constant EMULATION_RTLS => "/mpsoc/src_emulate/rtl/noc_emulator.v , /mpsoc/src_peripheral/jtag/jtag_wb/ , /mpsoc/src_peripheral/ram/generic_ram.v, /mpsoc/src_noc/";
use constant MAX_RATIO => 1000;# 0->0 1->0.1 ... 1000->100
use constant EMULATION_RTLS => "/mpsoc/src_emulate/rtl/ , /mpsoc/src_peripheral/jtag/jtag_wb/ , /mpsoc/src_peripheral/ram/ , /mpsoc/src_noc/ ,";
use constant EMULATION_TOP => "/mpsoc/src_emulate/emulator_top.v";
 
 
 
 
 
sub gen_chart {
my $emulate=shift;
my($width,$hight)=max_win_size();
my $graph_w=$width/2.5;
my $graph_h=$hight/2.5;
my $graph = Gtk2::Ex::Graph::GD->new($graph_w, $graph_h, 'linespoints');
my @x;
my @legend_keys;
my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
my $scale= $emulate->object_get_attribute("graph_scale",undef);
my @results;
$results[0]=[0];
$results[1]= [0];
my $legend_info="This attribute controls placement of the legend within the graph image. The value is supplied as a two-letter string, where the first letter is placement (a B or an R for bottom or right, respectively) and the second is alignment (L, R, C, T, or B for left, right, center, top, or bottom, respectively). ";
my $fontsize="Tiny,Small,MediumBold,Large,Giant";
 
 
 
my @ginfo = (
#{ label=>"Graph Title", param_name=>"G_Title", type=>"Entry", default_val=>undef, content=>undef, info=>undef, param_parent=>'graph_param', ref_delay=>undef },
{ label=>"Y Axix Title", param_name=>"Y_Title", type=>"Entry", default_val=>'Latency (clock)', content=>undef, info=>undef, param_parent=>'graph_param', ref_delay=>undef },
{ label=>"X Axix Title", param_name=>"X_Title", type=>"Entry", default_val=>'Load per router (flits/clock (%))', content=>undef, info=>undef, param_parent=>'graph_param',ref_delay=>undef },
{ label=>"legend placement", param_name=>"legend_placement", type=>'Combo-box', default_val=>'BL', content=>"BL,BC,BR,RT,RC,RB", info=>$legend_info, param_parent=>'graph_param', ref_delay=>1},
{ label=>"Y min", param_name=>"Y_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"Y axix minimum value", param_parent=>'graph_param', ref_delay=> 5},
{ label=>"X min", param_name=>"X_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"X axix minimum value", param_parent=>'graph_param', ref_delay=> 5},
{ label=>"X max", param_name=>"X_MAX", type=>'Spin-button', default_val=>100, content=>"0,1024,1", info=>"X axix maximum value", param_parent=>'graph_param', ref_delay=> 5},
{ label=>"Line Width", param_name=>"LINEw", type=>'Spin-button', default_val=>3, content=>"1,20,1", info=>undef, param_parent=>'graph_param', ref_delay=> 5},
{ label=>"legend font size", param_name=>"legend_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>'graph_param', ref_delay=>1},
{ label=>"label font size", param_name=>"label_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>'graph_param', ref_delay=>1},
{ label=>"label font size", param_name=>"x_axis_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>'graph_param', ref_delay=>1},
);
 
 
 
 
 
if(defined $sample_num){
my @color;
my $min_y=200;
for (my $i=1;$i<=$sample_num; $i++) {
my $color_num=$emulate->object_get_attribute("sample$i","color");
my $l_name= $emulate->object_get_attribute("sample$i","line_name");
$legend_keys[$i-1]= (defined $l_name)? $l_name : "NoC$i";
$color_num=$i+1 if(!defined $color_num);
push(@color, "my_color$color_num");
my $ref=$emulate->object_get_attribute ("sample$i","result");
if(defined $ref) {
push(@x, sort {$a<=>$b} keys %{$ref});
}
}#for
my @x2;
@x2 = uniq(sort {$a<=>$b} @x) if (scalar @x);
my @x1; #remove x values larger than x_max
my $x_max= $emulate->object_get_attribute( 'graph_param','X_MAX');
foreach my $p (@x2){
if(defined $x_max) {push (@x1,$p) if($p<$x_max);}
else {push (@x1,$p);}
}
 
#print "\@x1=@x1\n";
if (scalar @x1){
$results[0]=\@x1;
my $i;
for ($i=1;$i<=$sample_num; $i++) {
my $j=0;
my $ref=$emulate->object_get_attribute ("sample$i","result");
if(defined $ref){
#print "$i\n";
my %line=%$ref;
foreach my $k (@x1){
$results[$i][$j]=$line{$k};
$min_y= $line{$k} if (defined $line{$k} && $line{$k}!=0 && $min_y > $line{$k});
$j++;
}#$k
}#if
else {
$results[$i][$j]=undef;
 
}
}#$i
}#if
my $max_y=$min_y*$scale;
my $s=scalar @x1;
# all results which is larger than ymax will be changed to ymax,
for (my $i=1;$i<=$sample_num; $i++) {
for (my $j=1;$j<=$s; $j++) {
$results[$i][$j]=($results[$i][$j]>$max_y)? $max_y: $results[$i][$j] if (defined $results[$i][$j]);
}
}
 
my $graphs_info;
foreach my $d ( @ginfo){
$graphs_info->{$d->{param_name}}=$emulate->object_get_attribute( 'graph_param',$d->{param_name});
if(!defined $graphs_info->{$d->{param_name}}){
$graphs_info->{$d->{param_name}}= $d->{default_val};
$emulate->object_add_attribute( 'graph_param',$d->{param_name},$d->{default_val} );
}
}
 
$graph->set (
x_label => $graphs_info->{X_Title},
y_label => $graphs_info->{Y_Title},
y_max_value => $max_y,
y_min_value => $graphs_info->{Y_MIN},
y_tick_number => 8,
# x_min_value => $graphs_info->{X_MIN}, # dosent work?
title => $graphs_info->{G_Title},
bar_spacing => 1,
shadowclr => 'dred',
box_axis => 0,
skip_undef=> 1,
# transparent => 1,
 
transparent => '0',
bgclr => 'white',
boxclr => 'white',
fgclr => 'black',
textclr => 'black',
labelclr => 'black',
axislabelclr => 'black',
legendclr => 'black',
cycle_clrs => '1',
 
line_width => $graphs_info->{LINEw},
# cycle_clrs => 'black',
legend_placement => $graphs_info->{legend_placement},
dclrs=>\@color,
y_number_format=>"%.1f",
BACKGROUND=>'black',
);
}#if
$graph->set_legend(@legend_keys);
 
 
 
 
my $data = GD::Graph::Data->new(\@results) or die GD::Graph::Data->error;
$data->make_strict();
my $image = my_get_image($emulate,$graph,$data);
# print Data::Dumper->Dump ([\@results],['ttt']);
my $table = Gtk2::Table->new (25, 10, FALSE);
my $box = Gtk2::HBox->new (TRUE, 2);
my $filename;
$box->set_border_width (4);
my $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
my $frame = Gtk2::Frame->new;
$frame->set_shadow_type ('in');
$frame->add ($image);
$align->add ($frame);
my $plus = def_image_button('icons/plus.png',undef,TRUE);
my $minues = def_image_button('icons/minus.png',undef,TRUE);
my $setting = def_image_button('icons/setting.png',undef,TRUE);
my $save = def_image_button('icons/save.png',undef,TRUE);
 
$minues -> signal_connect("clicked" => sub{
$emulate->object_add_attribute("graph_scale",undef,$scale+0.5);
set_gui_status($emulate,"ref",1);
});
 
$plus -> signal_connect("clicked" => sub{
$emulate->object_add_attribute("graph_scale",undef,$scale-0.5) if( $scale>0.5);
set_gui_status($emulate,"ref",5);
});
 
$setting -> signal_connect("clicked" => sub{
get_graph_setting ($emulate,\@ginfo);
});
$save-> signal_connect("clicked" => sub{
my $G = $graph->{graph};
my @imags=$G->export_format();
save_graph_as ($emulate,\@imags);
});
$table->attach_defaults ($align , 0, 9, 0, 25);
my $row=0;
$table->attach ($plus , 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($minues, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($setting, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($save, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
while ($row<10){
my $tmp=gen_label_in_left('');
$table->attach_defaults ($tmp, 9, 10, $row, $row+1);$row++;
}
return $table;
}
 
 
##############
# save_graph_as
##############
 
sub save_graph_as {
my ($emulate,$ref)=@_;
my $file;
my $title ='Save as';
 
 
 
my @extensions=@$ref;
my $open_in=undef;
my $dialog = Gtk2::FileChooserDialog->new(
'Save file', undef,
'save',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok',
);
# if(defined $extension){
foreach my $ext (@extensions){
my $filter = Gtk2::FileFilter->new();
$filter->set_name($ext);
$filter->add_pattern("*.$ext");
$dialog->add_filter ($filter);
}
# }
if(defined $open_in){
$dialog->set_current_folder ($open_in);
# print "$open_in\n";
}
if ( "ok" eq $dialog->run ) {
$file = $dialog->get_filename;
my $ext = $dialog->get_filter;
$ext=$ext->get_name;
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
$file = ($suffix eq ".$ext" )? $file : "$file.$ext";
$emulate->object_add_attribute("graph_save","name",$file);
$emulate->object_add_attribute("graph_save","extension",$ext);
$emulate->object_add_attribute("graph_save","save",1);
set_gui_status($emulate,"ref",1);
 
 
}
$dialog->destroy;
 
 
 
 
}
 
 
 
 
sub my_get_image {
my ($emulate,$self, $data) = @_;
$self->{graphdata} = $data;
my $graph = $self->{graph};
my $font;
$font= $emulate->object_get_attribute( 'graph_param','label_font');
$graph->set_x_label_font(GD::Font->$font);
$graph->set_y_label_font(GD::Font->$font);
$font= $emulate->object_get_attribute( 'graph_param','legend_font');
$graph->set_legend_font(GD::Font->$font);
 
$font= $emulate->object_get_attribute( 'graph_param','x_axis_font');
#$graph->set_values_font(GD::gdGiantFont);
$graph->set_x_axis_font(GD::Font->$font);
$graph->set_y_axis_font(GD::Font->$font);
 
my $gd2=$graph->plot($data) or warn $graph->error;
my $loader = Gtk2::Gdk::PixbufLoader->new;
#cut the upper side of the image to remove the stright line created by chaanging large results to ymax
my $gd1= GD::Image->new($gd2->getBounds);
my $white= $gd1->colorAllocate(255,255,254);
my ($x,$h)=$gd2->getBounds;
$gd1->transparent($white);
$gd1->copy( $gd2, 0, 0, 0, ,$h*0.05, $x ,$h*.95 );
$loader->write ($gd1->png);
$loader->close;
 
my $save=$emulate->object_get_attribute("graph_save","save");
$save=0 if (!defined $save);
if ($save ==1){
my $file=$emulate->object_get_attribute("graph_save","name");
my $ext=$emulate->object_get_attribute("graph_save","extension");
$emulate->object_add_attribute("graph_save","save",0);
 
#image
open(my $out, '>', $file);
if (tell $out )
{
warn "Cannot open '$file' to write: $!";
}else
{
#my @extens=$graph->export_format();
binmode $out;
print $out $gd1->$ext;# if($ext eq 'png');
#print $out $gd1->gif if($ext eq 'gif');
close $out;
}
#text_file
open( $out, '>', "$file.txt");
if (tell $out )
{
warn "Cannot open $file.txt to write: $!";
}
else
{
my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
if (defined $sample_num){
for (my $i=1;$i<=$sample_num; $i++) {
my $l_name= $emulate->object_get_attribute("sample$i","line_name");
my $ref=$emulate->object_get_attribute ("sample$i","result");
my @x;
if(defined $ref) {
print $out "$l_name\n";
foreach my $x (sort {$a<=>$b} keys %{$ref}) {
my $y=$ref->{$x};
print $out "\t$x , $y\n";
}
print $out "\n\n";
}
}#for
 
}
close $out;
}
 
}
 
my $image = Gtk2::Image->new_from_pixbuf($loader->get_pixbuf);
 
 
$self->{graphimage} = $image;
my $hotspotlist;
if ($self->{graphtype} eq 'bars' or
$self->{graphtype} eq 'lines' or
$self->{graphtype} eq 'linespoints') {
foreach my $hotspot ($graph->get_hotspot) {
push @$hotspotlist, $hotspot if $hotspot;
}
}
$self->{hotspotlist} = $hotspotlist;
my $eventbox = $self->{eventbox};
my @children = $eventbox->get_children;
foreach my $child (@children) {
$eventbox->remove($child);
}
$eventbox->add ($image);
 
$eventbox->signal_connect ('button-press-event' =>
sub {
my ($widget, $event) = @_;
return TRUE;
return FALSE unless $event->button == 3;
$self->{optionsmenu}->popup(
undef, # parent menu shell
undef, # parent menu item
undef, # menu pos func
undef, # data
$event->button,
$event->time
);
}
);
$eventbox->show_all;
return $eventbox;
}
 
 
############
# get_graph_setting
###########
 
sub get_graph_setting {
my ($emulate,$ref)=@_;
my $window=def_popwin_size(33,33,'Graph Setting','percent');
my $table = def_table(10, 2, FALSE);
my $row=0;
 
 
my @data=@$ref;
foreach my $d (@data) {
$row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
}
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->add_with_viewport($table);
my $ok = def_image_button('icons/select.png',' OK ');
my $mtable = def_table(10, 1, FALSE);
$mtable->attach_defaults($scrolled_win,0,1,0,9);
$mtable->attach($ok,0,1,9,10,'shrink','shrink',2,2);
$window->add ($mtable);
$window->show_all();
$ok-> signal_connect("clicked" => sub{
$window->destroy;
set_gui_status($emulate,"ref",1);
});
 
 
 
}
 
 
 
 
 
 
 
 
 
 
 
 
################
# get_color_window
###############
sub get_color_window{
my ($emulate,$atrebute1,$atrebute2)=@_;
my $window=def_popwin_size(40,40,"Select line color",'percent');
my ($r,$c)=(4,8);
my $table= def_table(5,6,TRUE);
for (my $col=0;$col<$c;$col++){
for (my $row=0;$row<$r;$row++){
my $color_num=$row*$c+$col;
my $color=def_colored_button(" ",$color_num);
$table->attach_defaults ($color, $col, $col+1, $row, $row+1);
$color->signal_connect("clicked"=> sub{
$emulate->object_add_attribute($atrebute1,$atrebute2,$color_num);
#print "$emulate->object_add_attribute($atrebute1,$atrebute2,$color_num);\n";
set_gui_status($emulate,"ref",1);
$window->destroy;
});
}
}
$window->add($table);
$window->show_all();
 
}
 
 
 
 
sub check_inserted_ratios {
my $str=shift;
my @ratios;
574,10 → 74,8
}else{
message_dialog ("$p has invalid format. The correct format for range is \$min:\$max:\$step" );
}
}
}#foreach
my @r=uniq(sort {$a<=>$b} @ratios);
return \@r;
585,11 → 83,6
}
 
 
 
 
 
 
 
sub get_injection_ratios{
my ($emulate,$atrebute1,$atrebute2)=@_;
my $box = Gtk2::HBox->new( FALSE, 0 );
619,35 → 112,80
 
 
sub get_noc_configuration{
my ($emulate,$mode,$n,$set_win) =@_;
my ($emulate,$mode,$sample,$set_win) =@_;
if($mode eq "simulate") {get_simulator_noc_configuration(@_); return;}
get_emulator_noc_configuration(@_);
}
 
sub get_sof_file_full_addr{
my ($emulate,$sample)=@_;
my $open_in = $emulate->object_get_attribute($sample,"sof_path");
my $board = $emulate->object_get_attribute($sample,"FPGA_board");
my $file = $emulate->object_get_attribute($sample,"sof_file");
return undef if(!defined ${open_in} || !defined ${board} || !defined $file );
my $sof = "${open_in}/${board}/$file";
#print "\n$sof\n";
return $sof;
}
 
 
sub get_emulator_noc_configuration{
my ($emulate,$mode,$sample,$set_win) =@_;
my $table=def_table(10,2,FALSE);
my $row=0;
my $traffics="tornado,transposed 1,transposed 2,bit reverse,bit complement,random"; #TODO hot spot for emulator
#search path
my $dir = Cwd::getcwd();
if($mode eq "simulate"){
$traffics=$traffics.",hot spot";
my $open_in = abs_path("$ENV{PRONOC_WORK}/simulate");
attach_widget_to_table ($table,$row,gen_label_in_left("Verilated file:"),gen_button_message ("Select the the verilator simulation file. Different NoC simulators can be generated using Generate NoC configuration tab.","icons/help.png"), get_file_name_object ($emulate,"sample$n","sof_file",undef,$open_in)); $row++;
my $open_in = abs_path("$ENV{PRONOC_WORK}/emulate/sof");
attach_widget_to_table ($table,$row,gen_label_in_left("Search Path:"),gen_button_message ("Select the the Path where the verilator simulation files are located. Different NoC verilated models can be generated using Generate NoC configuration tab.","icons/help.png"),
get_dir_in_object ($emulate,$sample,"sof_path",undef,'ref_set_win',1,$open_in)); $row++;
$open_in = $emulate->object_get_attribute($sample,"sof_path");
#select the board
my($label,$param,$default,$content,$type,$info);
my @dirs = grep {-d} glob("$open_in/*");
my $fpgas;
foreach my $dir (@dirs) {
my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
$default=$name;
$fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
}
attach_widget_to_table ($table,$row,gen_label_in_left("Select FPGA board:"),gen_button_message ("Select the FPGA board. You can add your own FPGA board by adding its configuration file to mpsoc/boards directory","icons/help.png"),
gen_combobox_object ($emulate,$sample, "FPGA_board", $fpgas, undef,'ref_set_win',1)); $row++;
#select the sram object file
my $board = $emulate->object_get_attribute($sample,"FPGA_board");
my @files;
@files = glob "${open_in}/${board}/*" if(defined $board);
my $sof_files="";
foreach my $file (@files){
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
$sof_files="$sof_files,$name" if($suffix eq '.sof');
}
attach_widget_to_table ($table,$row,gen_label_in_left("Sram Object File:"),gen_button_message ("Select the verilator simulation file. Different NoC simulators can be generated using Generate NoC configuration tab.","icons/help.png"),
gen_combobox_object ($emulate,$sample, "sof_file", $sof_files, undef,undef,undef)); $row++;
}else{
my $open_in = abs_path("$ENV{PRONOC_WORK}/emulate/sof");
attach_widget_to_table ($table,$row,gen_label_in_left("SoF file:"),gen_button_message ("Select the SRAM Object File (sof) for this NoC configration.","icons/help.png"), get_file_name_object ($emulate,"sample$n","sof_file",'sof',$open_in)); $row++;
}
#attach_widget_to_table ($table,$row,gen_label_in_left("SoF file:"),gen_button_message ("Select the SRAM Object File (sof) for this NoC configration.","icons/help.png"), get_file_name_object ($emulate,$sample,"sof_file",'sof',$open_in)); $row++;
 
my @emulateinfo = (
{ label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>"NoC$n", content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>"sample$n", ref_delay=> undef},
{ label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>$sample, content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>$sample, ref_delay=> undef},
 
{ label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>"sample$n", ref_delay=>undef},
{ label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>$sample, ref_delay=>undef},
 
{ label=>"Packet size in flit:", param_name=>'PCK_SIZE', type=>'Spin-button', default_val=>4, content=>"2,".MAX_PCK_SIZ.",1", info=>undef, param_parent=>"sample$n", ref_delay=>undef},
{ label=>"Packet size in flit:", param_name=>'PCK_SIZE', type=>'Spin-button', default_val=>4, content=>"2,".MAX_PCK_SIZ.",1", info=>undef, param_parent=>$sample, ref_delay=>undef},
 
{ label=>"Packet number limit per node:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>1000000, content=>"2,".MAX_PCK_NUM.",1", info=>"Each node stops sending packets when it reaches packet number limit or simulation clock number limit", param_parent=>"sample$n", ref_delay=>undef},
{ label=>"Packet number limit per node:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>1000000, content=>"2,".MAX_PCK_NUM.",1", info=>"Each node stops sending packets when it reaches packet number limit or simulation clock number limit", param_parent=>$sample, ref_delay=>undef},
 
{ label=>"Emulation clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>MAX_SIM_CLKs, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit or simulation clock number limit", param_parent=>"sample$n", ref_delay=>undef},
{ label=>"Emulation clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>MAX_SIM_CLKs, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit or simulation clock number limit", param_parent=>$sample, ref_delay=>undef},
 
);
655,32 → 193,38
 
 
my @siminfo = (
{ label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>"NoC$n", content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>"sample$n", ref_delay=> undef, new_status=>undef},
{ label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>$sample, content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>$sample, ref_delay=> undef, new_status=>undef},
 
{ label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>"sample$n", ref_delay=>1, new_status=>'ref_set_win'},
{ label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>$sample, ref_delay=>1, new_status=>'ref_set_win'},
 
{ label=>"Packet size in flit:", param_name=>'PCK_SIZE', type=>'Spin-button', default_val=>4, content=>"2,".MAX_PCK_SIZ.",1", info=>undef, param_parent=>"sample$n", ref_delay=>undef},
{ label=>"Packet size in flit:", param_name=>'PCK_SIZE', type=>'Spin-button', default_val=>4, content=>"2,".MAX_PCK_SIZ.",1", info=>undef, param_parent=>$sample, ref_delay=>undef},
 
{ label=>"Total packet number limit:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>200000, content=>"2,".MAX_PCK_NUM.",1", info=>"Simulation will stop when total numbr of sent packets by all nodes reaches packet number limit or total simulation clock reach its limit", param_parent=>"sample$n", ref_delay=>undef, new_status=>undef},
{ label=>"Total packet number limit:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>200000, content=>"2,".MAX_PCK_NUM.",1", info=>"Simulation will stop when total numbr of sent packets by all nodes reaches packet number limit or total simulation clock reach its limit", param_parent=>$sample, ref_delay=>undef, new_status=>undef},
 
{ label=>"Simulator clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>100000, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit or simulation clock number limit", param_parent=>"sample$n", ref_delay=>undef, new_status=>undef},
{ label=>"Simulator clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>100000, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit or simulation clock number limit", param_parent=>$sample, ref_delay=>undef, new_status=>undef},
);
 
 
my $hot_num=$emulate->object_get_attribute($sample,"HOTSPOT_NUM");
$hot_num=1 if(!defined $hot_num);
my $max= ($hot_num>0)? 100/$hot_num: 20;
 
my @hotspot_info=(
{ label=>'Hot Spot num:', param_name=>'HOTSPOT_NUM', type=>'Spin-button', default_val=>1,
content=>"1,5,1", info=>"Number of hot spot nodes in the network",
param_parent=>"sample$n", ref_delay=> 1, new_status=>'ref_set_win'},
param_parent=>$sample, ref_delay=> 1, new_status=>'ref_set_win'},
{ label=>'Hot Spot traffic percentage:', param_name=>'HOTSPOT_PERCENTAGE', type=>'Spin-button', default_val=>1,
content=>"1,20,1", info=>"If it is set as n then each node sends n % of its traffic to each hotspot node",
param_parent=>"sample$n", ref_delay=> undef, new_status=>undef},
content=>"1, $max,1", info=>"If it is set as n then each node sends n % of its traffic to each hotspot node",
param_parent=>$sample, ref_delay=> undef, new_status=>undef},
{ label=>'Hot Spot nodes send enable:', param_name=>'HOTSPOT_SEND', type=>'Combo-box', default_val=>1,
content=>"0,1", info=>"If it is set as 0 then hot spot nodes only recieves packet from other nodes and do not send packets to others",
param_parent=>$sample, ref_delay=> undef, new_status=>undef},
);
my @info= ($mode eq "simulate")? @siminfo : @emulateinfo;
687,30 → 231,26
foreach my $d ( @info) {
$row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
}
my $traffic=$emulate->object_get_attribute("sample$n","traffic");
my $traffic=$emulate->object_get_attribute($sample,"traffic");
 
if ($traffic eq 'hot spot'){
foreach my $d ( @hotspot_info) {
$row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
}
my $num=$emulate->object_get_attribute("sample$n","HOTSPOT_NUM");
my $num=$emulate->object_get_attribute($sample,"HOTSPOT_NUM");
for (my $i=0;$i<$num;$i++){
my $m=$i+1;
$row=noc_param_widget ($emulate, "Hotspot $m tile num:", "HOTSPOT_CORE_$m", 0, 'Spin-button', "0,256,1",
"Defne the tile number which is hotspt. All other nodes will send [Hot Spot traffic percentage] of their traffic to this node ", $table,$row,1,"sample$n" );
"Defne the tile number which is hotspt. All other nodes will send [Hot Spot traffic percentage] of their traffic to this node ", $table,$row,1,$sample );
}
}
 
 
 
my $l= "Define injection ratios. You can define individual ratios seprating by comma (\',\') or define a range of injection ratios with \$min:\$max:\$step format.
As an example defining 2,3,4:10:2 will result in (2,3,4,6,8,10) injection ratios." ;
my $u=get_injection_ratios ($emulate,"sample$n","ratios");
my $l= "Define injection ratios. You can define individual ratios seprating by comma (\',\') or define a range of injection ratios with \$min:\$max:\$step format.
As an example defining 2,3,4:10:2 will result in (2,3,4,6,8,10) injection ratios." ;
my $u=get_injection_ratios ($emulate,$sample,"ratios");
attach_widget_to_table ($table,$row,gen_label_in_left("Injection ratios:"),gen_button_message ($l,"icons/help.png") , $u); $row++;
attach_widget_to_table ($table,$row,gen_label_in_left("Injection ratios:"),gen_button_message ($l,"icons/help.png") , $u); $row++;
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
730,21 → 270,13
$emulate->object_add_attribute("active_setting",undef,undef);
});
 
 
 
$ok->signal_connect("clicked"=> sub{
#check if sof file has been selected
my $s=$emulate->object_get_attribute("sample$n","sof_file");
my $s=get_sof_file_full_addr($emulate,$sample);
#check if injection ratios are valid
my $r=$emulate->object_get_attribute("sample$n","ratios");
my $r=$emulate->object_get_attribute($sample,"ratios");
if(defined $s && defined $r) {
$set_win->destroy;
#$emulate->object_add_attribute("active_setting",undef,undef);
760,15 → 292,7
}
});
 
 
}
 
778,12 → 302,11
###################
sub gen_emulation_column {
my ($emulate,$mode, $row_num,$info)=@_;
my ($emulate,$mode, $row_num,$info,@charts)=@_;
my $table=def_table($row_num,10,FALSE);
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
my $set_win=def_popwin_size(40,80,"NoC configuration setting",'percent');
$scrolled_win->set_policy( "automatic", "automatic" );
my $scrolled_win = gen_scr_win_with_adjst ($emulate,"emulation_column");
$scrolled_win->add_with_viewport($table);
my $row=0;
790,43 → 313,18
#title
my $title_l =($mode eq "simulate" ) ? "NoC Simulator" : "NoC Emulator";
my $title=gen_label_in_center($title_l);
my $box=def_vbox(FALSE, 1);
$box->pack_start( $title, FALSE, FALSE, 3);
my $separator = Gtk2::HSeparator->new;
$box->pack_start( $separator, FALSE, FALSE, 3);
$table->attach_defaults ($box , 0, 10, $row, $row+1); $row++;
$table->attach ($title , 0, 10, $row, $row+1,'expand','shrink',2,2); $row++;
my $separator = Gtk2::HSeparator->new;
$table->attach ($separator , 0, 10 , $row, $row+1,'fill','fill',2,2); $row++;
my $lb=($mode ne "simulate" ) ? gen_label_in_left("Number of emulations"): gen_label_in_left("Number of simulations");
my $spin= gen_spin_object ($emulate,"emulate_num",undef,"1,100,1",1,'ref','1');
$table->attach ($lb, 0, 2, $row, $row+1,'expand','shrink',2,2);
$table->attach ($spin, 2, 4, $row, $row+1,'expand','shrink',2,2);
#my $mod=gen_combobox_object ($emulate,'mode',undef, 'Emulation,Simulation','Emulation','ref','1');
 
 
#$table->attach ($lb, 4, 6, $row, $row+1,'expand','shrink',2,2);
#$table->attach ($mod, 6, 8, $row, $row+1,'expand','shrink',2,2);
$row++;
 
 
 
 
$separator = Gtk2::HSeparator->new;
$table->attach_defaults ($separator , 0, 10, $row, $row+1); $row++;
 
my @positions=(0,1,2,3,6,7);
my @positions=(0,1,2,3,4,5,6);
my $col=0;
my @title=(" Name", " Configuration Setting ", "Line's color", "Clear Graph"," ");
my @title=("Name", " Add/Remove "," Setting ", "Line\'s color", "Clear","Run");
foreach my $t (@title){
$table->attach (gen_label_in_left($title[$col]), $positions[$col], $positions[$col+1], $row, $row+1,'fill','shrink',2,2);$col++;
$table->attach (gen_label_in_center($title[$col]), $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
}
my $traffics="Random,Transposed 1,Transposed 2,Tornado";
834,44 → 332,56
$col=0;
$row++;
@positions=(0,1,2,3,4,5,6,7);
 
my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
if(!defined $sample_num){
$sample_num=1;
$emulate->object_add_attribute("emulate_num",undef,1);
}
my $i=0;
#my $i=0;
my $active=$emulate->object_get_attribute("active_setting",undef);
for ($i=1;$i<=$sample_num; $i++){
my @samples;
@samples =$emulate->object_get_attribute_order("samples");
foreach my $ss (@samples){
$col=0;
my $sample="sample$i";
my $n=$i;
my $set=def_image_button("icons/setting.png");
my $sample=$ss;
#my $sample="sample$i";
#my $n=$i;
my $name=$emulate->object_get_attribute($sample,"line_name");
my $l;
my $s=$emulate->object_get_attribute("sample$n","sof_file");
my $s=($mode eq "simulate" ) ? 1 : get_sof_file_full_addr($emulate,$sample);
#check if injection ratios are valid
my $r=$emulate->object_get_attribute("sample$n","ratios");
if(defined $s && defined $r && defined $name){
$l=gen_label_in_left(" $i- ".$name);
my $r=$emulate->object_get_attribute($sample,"ratios");
if(defined $s && defined $name){
$l=gen_label_in_center($name);
} else {
$l=gen_label_in_left("Define NoC configuration");
$l->set_markup("<span foreground= 'red' ><b>Define NoC configuration</b></span>");
}
#my $box=def_pack_hbox(FALSE,0,(gen_label_in_left("$i- "),$l,$set));
$table->attach ($l, $positions[$col], $positions[$col+1], $row, $row+1,'fill','shrink',2,2);$col++;
$table->attach ($set, $positions[$col], $positions[$col+1], $row, $row+1,'shrink','shrink',2,2);$col++;
$table->attach ($l, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
 
#remove
my $remove=def_image_button("icons/cancel.png");
$table->attach ($remove, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
$remove->signal_connect("clicked"=> sub{
$emulate->object_delete_attribute_order("samples",$sample);
set_gui_status($emulate,"ref",2);
});
 
#setting
my $set=def_image_button("icons/setting.png");
$table->attach ($set, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
 
if(defined $active){#The setting windows ask for refershing so open it again
get_noc_configuration($emulate,$mode,$n,$set_win) if ($active ==$n);
get_noc_configuration($emulate,$mode,$sample,$set_win) if ($active eq $sample);
}
$set->signal_connect("clicked"=> sub{
$emulate->object_add_attribute("active_setting",undef,$n);
get_noc_configuration($emulate,$mode,$n,$set_win);
$emulate->object_add_attribute("active_setting",undef,$sample);
get_noc_configuration($emulate,$mode,$sample,$set_win);
});
878,7 → 388,7
my $color_num=$emulate->object_get_attribute($sample,"color");
if(!defined $color_num){
$color_num = $i+1;
$color_num = (scalar @samples) +1;
$emulate->object_add_attribute($sample,"color",$color_num);
}
my $color=def_colored_button(" ",$color_num);
886,9 → 396,6
$color->signal_connect("clicked"=> sub{
get_color_window($emulate,$sample,"color");
});
896,12 → 403,17
#clear line
my $clear = def_image_button('icons/clear.png');
$clear->signal_connect("clicked"=> sub{
$emulate->object_add_attribute ($sample,'result',undef);
foreach my $chart (@charts){
$emulate->object_add_attribute ($sample,"$chart->{result_name}",undef);
#print "\$emulate->object_add_attribute ($sample,$chart->{result_name}_result,undef);";
}
set_gui_status($emulate,"ref",2);
});
$table->attach ($clear, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
#run/pause
my $run = def_image_button('icons/run.png','Run');
my $run = def_image_button('icons/run.png',undef);
$table->attach ($run, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
$run->signal_connect("clicked"=> sub{
$emulate->object_add_attribute ($sample,"status","run");
916,53 → 428,64
});
my $image = gen_noc_status_image($emulate,$i);
my $image = gen_noc_status_image($emulate,$sample);
$table->attach_defaults ($image, $positions[$col], $positions[$col+1], $row, $row+1);
$table->attach ($image, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);
$row++;
}
while ( $row<15){
$table->attach_defaults (gen_label_in_left(' '), 0, 1, $row, $row+1); $row++;
}
# add new simulation
my $add=def_image_button("icons/plus.png", );
$table->attach ($add, $positions[1], $positions[2], $row, $row+1,'expand','shrink',2,2);
 
 
 
 
$add->signal_connect("clicked"=> sub{
my $n=$emulate->object_get_attribute("id",undef);
$n=0 if (!defined $n);
my $sample="sample$n";
$n++;
$emulate->object_add_attribute("id",undef,$n);
$emulate->object_add_attribute("active_setting",undef,$sample);
#get_noc_configuration($emulate,$mode,$sample,$set_win);
$emulate->object_add_attribute_order("samples",$sample);
set_gui_status($emulate,"ref",1);
});
return ($scrolled_win,$set_win);
}
 
 
 
 
##########
#
# check_sample
##########
 
sub check_sample{
my ($emulate,$i,$info)=@_;
my ($emulate,$sample,$info)=@_;
my $status=1;
my $sof=$emulate->object_get_attribute ("sample$i","sof_file");
my $sof=get_sof_file_full_addr($emulate,$sample);
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../"); #mpsoc directory address
$sof= "$project_dir/$sof" if(!(-f $sof));
# ckeck if sample have sof file
if(!defined $sof){
add_info($info, "Error: SoF file has not set for NoC$i!\n");
$emulate->object_add_attribute ("sample$i","status","failed");
#add_info($info, "Error: SoF file has not set for $sample!\n");
add_colored_info($info, "Error: SoF file has not set for $sample!\n",'red');
$emulate->object_add_attribute ($sample,"status","failed");
$status=0;
} else {
# ckeck if sof file has info file
my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
my $sof_info= "$path$name.inf";
# print "\n $sof \t $sof_info\n";
if(!(-f $sof_info)){
add_info($info, "Could not find $name.inf file in $path. An information file is required for each sof file containig the device name and NoC configuration. Press F4 for more help.\n");
$emulate->object_add_attribute ("sample$i","status","failed");
add_colored_info($info, "Error: Could not find $name.inf file in $path. An information file is required for each sof file containig the device name and NoC configuration. Press F4 for more help.\n",'red');
$emulate->object_add_attribute ($sample,"status","failed");
$status=0;
}else { #add info
my $pp= do $sof_info ;
969,49 → 492,30
 
my $p=$pp->{'noc_param'};
 
 
 
 
$status=0 if $@;
message_dialog("Error reading: $@") if $@;
if ($status==1){
$emulate->object_add_attribute ("sample$i","noc_info",$p) ;
#print"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n";
$emulate->object_add_attribute ($sample,"noc_info",$p) ;
}
}
}
}
return $status;
}
 
 
 
 
##########
# run external commands
##########
 
 
 
 
 
sub run_cmd_in_back_ground
{
my $command = shift;
#print "\t$command\n";
 
 
 
 
### Start running the Background Job:
my $proc = Proc::Background->new($command);
my $PID = $proc->pid;
1096,14 → 600,14
 
 
sub gen_noc_status_image {
my ($emulate,$i)=@_;
my $status= $emulate->object_get_attribute ("sample$i","status");
my ($emulate,$sample)=@_;
my $status= $emulate->object_get_attribute ($sample,"status");
$status='' if(!defined $status);
my $image;
my $vbox = Gtk2::HBox->new (TRUE,1);
$image = Gtk2::Image->new_from_file ("icons/load.gif") if($status eq "run");
$image = def_icon("icons/button_ok.png") if($status eq "done");
$image = def_icon("icons/cancel.png") if($status eq "failed");
$image = def_icon("icons/warnning.png") if($status eq "failed");
#$image_file = "icons/load.gif" if($status eq "run");
if (defined $image) {
1126,86 → 630,97
 
sub run_emulator {
my ($emulate,$info)=@_;
#my $graph_name="latency_ratio";
#return if(!check_samples($emulate,$info));
$emulate->object_add_attribute('status',undef,'run');
set_gui_status($emulate,"ref",1);
show_info($info, "start emulation\n");
show_colored_info($info, "start emulation\n",'blue');
 
#search for available usb blaster
my $cmd = "jtagconfig";
my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
my @matches= ($stdout =~ /USB-Blaster.*/g);
my $usb_blaster=$matches[0];
if (!defined $usb_blaster){
add_info($info, "jtagconfig could not find any USB blaster cable: $stdout \n");
$emulate->object_add_attribute('status',undef,'programer_failed');
set_gui_status($emulate,"ref",2);
#/***/
return;
}else{
add_info($info, "find $usb_blaster\n");
}
my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
for (my $i=1; $i<=$sample_num; $i++){
my $status=$emulate->object_get_attribute ("sample$i","status");
# #search for available usb blaster
# my $cmd = "jtagconfig";
# my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
# my @matches= ($stdout =~ /USB-Blaster.*/g);
# my $usb_blaster=$matches[0];
# if (!defined $usb_blaster){
# add_info($info, "jtagconfig could not find any USB blaster cable: $stdout \n");
# $emulate->object_add_attribute('status',undef,'programer_failed');
# set_gui_status($emulate,"ref",2);
# #/***/
# return;
# }else{
# add_info($info, "find $usb_blaster\n");
# }
my @samples =$emulate->object_get_attribute_order("samples");
foreach my $sample (@samples){
my $status=$emulate->object_get_attribute ($sample,"status");
next if($status ne "run");
next if(!check_sample($emulate,$i,$info));
my $r= $emulate->object_get_attribute("sample$i","ratios");
next if(!check_sample($emulate,$sample,$info));
my $r= $emulate->object_get_attribute($sample,"ratios");
my @ratios=@{check_inserted_ratios($r)};
#$emulate->object_add_attribute ("sample$i","status","run");
my $sof=$emulate->object_get_attribute ("sample$i","sof_file");
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../"); #mpsoc directory address
$sof= "$project_dir/$sof" if(!(-f $sof));
my $sof=get_sof_file_full_addr($emulate,$sample);
add_info($info, "Programe FPGA device using $sof.sof\n");
my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
my $programer="$path/program_device.sh";
my $jtag_intfc="$path/jtag_intfc.sh";
if((-f $programer)==0){
add_colored_info ($info, " Error: file \"$programer\" dose not exist. \n",'red');
$emulate->object_add_attribute('status',undef,'programer_failed');
$emulate->object_add_attribute ($sample,"status","failed");
set_gui_status($emulate,"ref",2);
last;
}
if((-f $jtag_intfc)==0){
add_colored_info ($info, " Error: file \"$jtag_intfc\" dose not exist. \n",'red');
$emulate->object_add_attribute('status',undef,'programer_failed');
$emulate->object_add_attribute ($sample,"status","failed");
set_gui_status($emulate,"ref",2);
last;
}
my $cmd = "sh $programer $sof.sof";
add_info($info, "Programe FPGA device using $sof\n");
my $Quartus_bin= $ENV{QUARTUS_BIN};
#my $Quartus_bin= $ENV{QUARTUS_BIN};
 
my $cmd = "$Quartus_bin/quartus_pgm -c \"$usb_blaster\" -m jtag -o \"p;$sof\"";
#my $cmd = "$Quartus_bin/quartus_pgm -c \"$usb_blaster\" -m jtag -o \"p;$sof\"";
#my $output = `$cmd 2>&1 1>/dev/null`; # either with backticks
 
 
 
#/***/
my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("$cmd");
if($exit){#programming FPGA board has failed
$emulate->object_add_attribute('status',undef,'programer_failed');
add_info($info, "$stdout\n");
$emulate->object_add_attribute ("sample$i","status","failed");
add_colored_info($info, "$stdout\n",'red');
$emulate->object_add_attribute ($sample,"status","failed");
set_gui_status($emulate,"ref",2);
next;
}
#print "$stdout\n";
# read noc configuration
# load noc configuration
foreach my $ratio_in (@ratios){
add_info($info, "Configure packet generators for injection ratio of $ratio_in \% \n");
next if(!programe_pck_gens($emulate,$i,$ratio_in,$info));
if(!programe_pck_gens($emulate,$sample,$ratio_in,$info,$jtag_intfc)){
add_colored_info($info, "Error in programe_pck_gens function\n",'red');
next;
}
my $avg=read_pack_gen($emulate,$i,$info);
next if (!defined $avg);
my $ref=$emulate->object_get_attribute ("sample$i","result");
my %results;
%results= %{$ref} if(defined $ref);
#push(@results,$avg);
$results{$ratio_in}=$avg;
$emulate->object_add_attribute ("sample$i","result",\%results);
my $r=read_pack_gen($emulate,$sample,$info,$jtag_intfc,$ratio_in);
next if (!defined $r);
set_gui_status($emulate,"ref",2);
}
$emulate->object_add_attribute ("sample$i","status","done");
$emulate->object_add_attribute ($sample,"status","done");
}
add_info($info, "End emulation!\n");
add_colored_info($info, "End emulation!\n",'blue');
$emulate->object_add_attribute('status',undef,'ideal');
set_gui_status($emulate,"ref",1);
}
1215,12 → 730,13
 
 
 
##############
# process_notebook_gen
##############
 
 
 
 
sub process_notebook_gen{
my ($emulate,$info,$mode)=@_;
my ($emulate,$info,$mode,@charts)=@_;
my $notebook = Gtk2::Notebook->new;
$notebook->set_tab_pos ('left');
$notebook->set_scrollable(TRUE);
1227,17 → 743,20
$notebook->can_focus(FALSE);
 
my ($page1,$set_win)=gen_emulation_column($emulate, $mode,10,$info);
my ($page1,$set_win)=gen_emulation_column($emulate, $mode,10,$info,@charts);
$notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic (" _Run emulator ")) if($mode eq "emulate");
$notebook->append_page ($page1,Gtk2::Label->new_with_mnemonic (" _Run simulator ")) if($mode eq "simulate");
my $page2=get_noc_setting_gui ($emulate,$info,$mode);
my $pp=$notebook->append_page ($page2,Gtk2::Label->new_with_mnemonic (" _Generate NoC \n Configuration"));
my $tt=($mode eq "emulate")? " _Generate NoC \nEmulation Model" : " _Generate NoC \nSimulation Model" ;
$notebook->append_page ($page2,Gtk2::Label->new_with_mnemonic ($tt));
#if($mode eq "simulate"){
#my $page3=gen_custom_traffic ($emulate,$info,$mode);
#$notebook->append_page ($page3,Gtk2::Label->new_with_mnemonic ("_Generate Custom\n Traffic Pattern"));
#}
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->add_with_viewport($notebook);
1257,186 → 776,279
sub get_noc_setting_gui {
my ($emulate,$info_text,$mode)=@_;
my $table=def_table(20,10,FALSE);# my ($row,$col,$homogeneous)=@_;
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
my $scrolled_win = gen_scr_win_with_adjst ($emulate,"noc_setting_gui");
$scrolled_win->add_with_viewport($table);
my $row=noc_config ($emulate,$table);
my($label,$param,$default,$content,$type,$info);
my @dirs = grep {-d} glob("../src_emulate/fpga/*");
my @dirs = grep {-d} glob("../boards/*");
my $fpgas;
foreach my $dir (@dirs) {
my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
$default=$name;
$fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
$fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
}
my @fpgainfo;
my @fpgainfo;
if($mode eq "emulate"){
@fpgainfo = (
{ label=>'Pck. injector FIFO Width:', param_name=>'TIMSTMP_FIFO_NUM', type=>'Spin-button', default_val=>16, content=>"2,128,2", info=>"Packet injectors' timestamp FIFO width. In case a packet cannot be injected according to the desired injection ratio, the current system time is saved in a FIFO and then at injection time it will be read and attached to the packet. The larger FIFO width results in more accurate latency calculation at the cost of higher area overhead." , param_parent=>'fpga_param', ref_delay=> undef},
{ label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'emulate1', content=>undef, info=>undef, param_parent=>'fpga_param', ref_delay=>undef},
{ label=>"Project directory", param_name=>"SOF_DIR", type=>"DIR_path", default_val=>"$ENV{'PRONOC_WORK'}/emulate", content=>undef, info=>"Define the working directory for generating .sof file", param_parent=>'fpga_param',ref_delay=>undef },
);
 
}
else {
@fpgainfo = (
{ label=>'Pck. injector FIFO Width:', param_name=>'TIMSTMP_FIFO_NUM', type=>'Spin-button', default_val=>16, content=>"2,128,2", info=>"Packet injectors' timestamp FIFO width. In case a packet cannot be injected according to the desired injection ratio, the current system time is saved in a FIFO and then at injection time it will be read and attached to the packet. The larger FIFO width results in more accurate latency calculation." , param_parent=>'fpga_param', ref_delay=> undef},
{ label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'simulate1', content=>undef, info=>undef, param_parent=>'sim_param', ref_delay=>undef},
{ label=>"Project directory", param_name=>"BIN_DIR", type=>"DIR_path", default_val=>"$ENV{'PRONOC_WORK'}/simulate", content=>undef, info=>"Define the working directory for generating simulation executable binarry file", param_parent=>'sim_param',ref_delay=>undef },
);
}
if($mode eq "emulate"){
@fpgainfo = (
{ label=>'FPGA board', param_name=>'FPGA_BOARD', type=>'Combo-box', default_val=>undef, content=>$fpgas, info=>undef, param_parent=>'fpga_param', ref_delay=> undef},
{ label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'emulate1', content=>undef, info=>undef, param_parent=>'fpga_param', ref_delay=>undef},
{ label=>"Project directory", param_name=>"SOF_DIR", type=>"DIR_path", default_val=>"$ENV{'PRONOC_WORK'}/emulate", content=>undef, info=>"Define the working directory for generating .sof file", param_parent=>'fpga_param',ref_delay=>undef },
foreach my $d (@fpgainfo) {
$row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
}
my $generate = def_image_button('icons/gen.png','Generate');
$table->attach ($generate, 0,3, $row, $row+1,'expand','shrink',2,2);
$generate->signal_connect ('clicked'=> sub{
generate_sof_file($emulate,$info_text) if($mode eq "emulate");
generate_sim_bin_file($emulate,$info_text) if($mode eq "simulate");
});
return $scrolled_win;
}
 
);
##########
# generate_sof_file
##########
 
}
else {
 
@fpgainfo = (
#{ label=>'FPGA board', param_name=>'FPGA_BOARD', type=>'Combo-box', default_val=>undef, content=>$fpgas, info=>undef, param_parent=>'fpga_param', ref_delay=> undef},
{ label=>'Save as:', param_name=>'SAVE_NAME', type=>"Entry", default_val=>'simulate1', content=>undef, info=>undef, param_parent=>'sim_param', ref_delay=>undef},
{ label=>"Project directory", param_name=>"BIN_DIR", type=>"DIR_path", default_val=>"$ENV{'PRONOC_WORK'}/simulate", content=>undef, info=>"Define the working directory for generating simulation executable binarry file", param_parent=>'sim_param',ref_delay=>undef },
sub generate_sof_file {
my ($self,$info)=@_;
 
);
}
my $name=$self->object_get_attribute ('fpga_param',"SAVE_NAME");
my $target_dir = "$ENV{'PRONOC_WORK'}/emulate/$name";
my $top = "$target_dir/src_verilog/${name}_top.v";
 
if (!defined $name){
message_dialog("Please define the Save as filed!");
return;
}
 
#copy all noc source codes
my @files = split(/\s*,\s*/,EMULATION_RTLS);
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../");
my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $target_dir/src_verilog" );
copy_file_and_folders(\@files,$project_dir,"$target_dir/src_verilog/lib/");
 
foreach my $d (@fpgainfo) {
$row=noc_param_widget ($emulate, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
#generate parameters for emulator_top.v file
my ($localparam, $pass_param)=gen_noc_param_v( $self);
open(FILE, ">$target_dir/src_verilog/noc_parameters.v") || die "Can not open: $!";
print FILE $localparam;
close(FILE) || die "Error closing file: $!";
open(FILE, ">$target_dir/src_verilog/pass_parameters.v") || die "Can not open: $!";
print FILE $pass_param;
my $fifow=$self->object_get_attribute('fpga_param','TIMSTMP_FIFO_NUM');
print FILE ",.TIMSTMP_FIFO_NUM($fifow)\n";
close(FILE) || die "Error closing file: $!";
open(FILE, ">$top") || die "Can not open: $!";
print FILE create_emulate_top($self,$name,$top);
close(FILE) || die "Error closing file: $!";
select_compiler($self,$name,$top,$target_dir,\&save_the_sof_file);
return;
}
 
sub create_emulate_top{
my ($self,$name,$top)=@_;
my $top_v= get_license_header("$top");
 
$top_v ="$top_v
 
`timescale 1ns/1ps
 
module ${name}_top(
output done_led,
output noc_reset_led,
output jtag_reset_led,
input reset,
input clk
);
 
my $generate = def_image_button('icons/gen.png','Generate');
$table->attach ($generate, 0,3, $row, $row+1,'expand','shrink',2,2);
$generate->signal_connect ('clicked'=> sub{
generate_sof_file($emulate,$info_text) if($mode eq "emulate");
generate_sim_bin_file($emulate,$info_text) if($mode eq "simulate");
});
return $scrolled_win;
}
 
localparam
STATISTIC_VJTAG_INDEX=124,
PATTERN_VJTAG_INDEX=125,
COUNTER_VJTAG_INDEX=126,
DONE_RESET_VJTAG_INDEX=127;
 
//NoC parameters will be defined by user
`define NOC_PARAM
`include \"noc_parameters.v\"
wire reset_noc, reset_injector, reset_noc_sync, reset_injector_sync, done;
wire jtag_reset_injector, jtag_reset_noc;
wire start_o;
wire done_time_limit;
assign done_led = done | done_time_limit;
assign noc_reset_led= reset_noc;
assign jtag_reset_led = reset_injector;
 
 
// two reset sources which can be controled using jtag. One for reseting NoC another packet injectors
jtag_source_probe #(
.VJTAG_INDEX(DONE_RESET_VJTAG_INDEX),
.Dw(2) //source/probe width in bits
)the_reset(
.probe({done_time_limit,done}),
.source({jtag_reset_injector,jtag_reset_noc})
);
 
 
assign reset_noc = (jtag_reset_noc | reset);
assign reset_injector = (jtag_reset_injector | reset);
 
sub generate_sof_file {
my ($emulate,$info)=@_;
print "start compilation\n";
my $fpga_board= $emulate->object_get_attribute ('fpga_param',"FPGA_BOARD");
#create work directory
my $dir_name=$emulate->object_get_attribute ('fpga_param',"SOF_DIR");
$dir_name="$dir_name/$fpga_board";
my $save_name=$emulate->object_get_attribute ('fpga_param',"SAVE_NAME");
$save_name=$fpga_board if (!defined $save_name);
$dir_name= "$dir_name/$save_name";
altera_reset_synchronizer noc_rst_sync
(
.reset_in(reset_noc),
.clk(clk),
.reset_out(reset_noc_sync)
);
 
show_info($info, "generate working directory: $dir_name\n");
#copy all noc source codes
my @files = split(/\s*,\s*/,EMULATION_RTLS);
 
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../");
my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $dir_name/src/" );
copy_file_and_folders(\@files,$project_dir,"$dir_name/src/");
foreach my $f(@files){
my $n="$project_dir/$f";
if (!(-f "$n") && !(-f "$f" ) && !(-d "$n") && !(-d "$f" ) ){
add_info ($info, " WARNING: file/folder \"$f\" ($n) dose not exists \n");
}
}
altera_reset_synchronizer inject_rst_sync
(
.reset_in(reset_injector),
.clk(clk),
.reset_out(reset_injector_sync)
);
//noc emulator
noc_emulator #(
.STATISTIC_VJTAG_INDEX(STATISTIC_VJTAG_INDEX),
.PATTERN_VJTAG_INDEX(PATTERN_VJTAG_INDEX),
`include \"pass_parameters.v\"
)
noc_emulate_top
(
.reset(reset_noc_sync),
.jtag_ctrl_reset(reset_injector_sync),
.clk(clk),
.start_o(start_o),
.done(done)
);
//clock counter
function integer log2;
input integer number; begin
log2=(number <=1) ? 1: 0;
while(2**log2<number) begin
log2=log2+1;
end
end
endfunction // log2
localparam MAX_SIM_CLKs = 1_000_000_000;
localparam CLK_CNTw = log2(MAX_SIM_CLKs+1);
reg [CLK_CNTw-1 : 0] clk_counter;
wire [CLK_CNTw-1 : 0] clk_limit;
reg start;
always @(posedge clk or posedge reset_injector_sync) begin
if(reset_injector_sync)begin
clk_counter <= {CLK_CNTw{1'b0}};
start<=1'b0;
end else begin
if(start_o) start<=1'b1;
if(done==1'b0 && start ) clk_counter<=clk_counter +1'b1;
end
end
jtag_source_probe #(
.VJTAG_INDEX(COUNTER_VJTAG_INDEX),
.Dw(CLK_CNTw) //source/probe width in bits
)the_clk_counter(
.probe(clk_counter),
.source(clk_limit)
);
assign done_time_limit = (clk_counter >= clk_limit);
endmodule
";
return $top_v;
}
 
sub save_the_sof_file{
 
#copy fpga board files
($stdout,$exit)=run_cmd_in_back_ground_get_stdout("cp -Rf \"$project_dir/mpsoc/src_emulate/fpga/$fpga_board\"/* \"$dir_name/\"");
if($exit != 0 ){ print "$stdout\n"; message_dialog($stdout); return;}
#generate parameters for emulator_top.v file
my ($localparam, $pass_param)=gen_noc_param_v( $emulate);
open(FILE, ">$dir_name/src/noc_parameters.v") || die "Can not open: $!";
print FILE $localparam;
close(FILE) || die "Error closing file: $!";
open(FILE, ">$dir_name/src/pass_parameters.v") || die "Can not open: $!";
print FILE $pass_param;
close(FILE) || die "Error closing file: $!";
#compile the code
my $Quartus_bin= $ENV{QUARTUS_BIN};
add_info($info, "Start Quartus compilation\n $stdout\n");
my @compilation_command =("cd \"$dir_name/\" \n xterm -e $Quartus_bin/quartus_map --64bit $fpga_board --read_settings_files=on ",
"cd \"$dir_name/\" \n xterm -e $Quartus_bin/quartus_fit --64bit $fpga_board --read_settings_files=on ",
"cd \"$dir_name/\" \n xterm -e $Quartus_bin/quartus_asm --64bit $fpga_board --read_settings_files=on ",
"cd \"$dir_name/\" \n xterm -e $Quartus_bin/quartus_sta --64bit $fpga_board ");
my $self=shift;
my $name=$self->object_get_attribute ('fpga_param',"SAVE_NAME");
my $sofdir="$ENV{PRONOC_WORK}/emulate/sof";
my $fpga_board=$self->object_get_attribute('compile','board');
my $target_dir = "$ENV{'PRONOC_WORK'}/emulate/$name";
 
mkpath("$sofdir/$fpga_board/",1,01777);
open(FILE, ">$sofdir/$fpga_board/$name.inf") || die "Can not open: $!";
print FILE perl_file_header("$name.inf");
my %pp;
$pp{'noc_param'}= $self->{'noc_param'};
$pp{'fpga_param'}= $self->{'fpga_param'};
print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
close(FILE) || die "Error closing file: $!";
 
 
#find $dir_name -name \*.sof -exec cp '{}' $sofdir/$fpga_board/$save_name.sof"
my @files = File::Find::Rule->file()
->name( '*.sof' )
->in( "$target_dir" );
copy($files[0],"$sofdir/$fpga_board/$name.sof") or do {
my $err= "Error copy($files[0] , $sofdir/$fpga_board/$name.sof";
print "$err\n";
message_dialog($err);
return;
};
#copy the board's programming and jtag interface files
my $board_name=$self->object_get_attribute('compile','board');
#copy board jtag_intfc.sh file
copy("../boards/$board_name/jtag_intfc.sh","$sofdir/$fpga_board/jtag_intfc.sh");
#print "../boards/$board_name/jtag_intfc.sh","$sofdir/$fpga_board/jtag_intfc.sh\n";
#add argument run to jtag_interface file
my $runarg='
 
if [ $# -ne 0 ]
then
$JTAG_INTFC $1
fi
';
append_text_to_file ("$sofdir/$fpga_board/jtag_intfc.sh",$runarg );
 
foreach my $cmd (@compilation_command){
($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $cmd);
if($exit != 0){
print "Quartus compilation failed !\n";
add_info($info, "Quartus compilation failed !\n$cmd\n $stdout\n");
return;
}
}
#copy board program_device.sh file
copy("../boards/$board_name/program_device.sh","$sofdir/$fpga_board/program_device.sh");
 
#save sof file
my $sofdir="$ENV{PRONOC_WORK}/emulate/sof";
mkpath("$sofdir/$fpga_board/",1,01777);
open(FILE, ">$sofdir/$fpga_board/$save_name.inf") || die "Can not open: $!";
print FILE perl_file_header("$save_name.inf");
my %pp;
$pp{'noc_param'}= $emulate->{'noc_param'};
$pp{'fpga_param'}= $emulate->{'fpga_param'};
print FILE Data::Dumper->Dump([\%pp],["emulate_info"]);
close(FILE) || die "Error closing file: $!";
message_dialog("sof file has been generated successfully");
}
 
 
#find $dir_name -name \*.sof -exec cp '{}' $sofdir/$fpga_board/$save_name.sof"
@files = File::Find::Rule->file()
->name( '*.sof' )
->in( "$dir_name" );
copy($files[0],"$sofdir/$fpga_board/$save_name.sof") or do {
my $err= "Error copy($files[0] , $sofdir/$fpga_board/$save_name.sof";
print "$err\n";
message_dialog($err);
return;
};
message_dialog("sof file has been generated successfully");
}
 
##########
# save_emulation
1453,7 → 1065,7
# Write object file
open(FILE, ">lib/emulate/$name.EML") || die "Can not open: $!";
print FILE perl_file_header("$name.EML");
print FILE Data::Dumper->Dump([\%$emulate],[$name]);
print FILE Data::Dumper->Dump([\%$emulate],["emulate"]);
close(FILE) || die "Error closing file: $!";
message_dialog("Emulation saved as lib/emulate/$name.EML!");
return 1;
1487,7 → 1099,7
if($suffix eq '.EML'){
my $pp= eval { do $file };
if ($@ || !defined $pp){
add_info($info,"**Error reading $file file: $@\n");
add_colored_info($info,"**Error reading $file file: $@\n",'red');
$dialog->destroy;
return;
}
1499,43 → 1111,82
$dialog->destroy;
}
 
 
 
sub update_result {
my ($self,$sample,$name,$x,$y,$z)=@_;
my $ref=$self->object_get_attribute ($sample,$name);
my %results;
%results= %{$ref} if(defined $ref);
if(!defined $z) {$results{$x}=$y;}
else {$results{$x}{$y}=$z;}
$self->object_add_attribute ($sample,$name,\%results);
}
 
 
sub capture_cores_data {
my ($data,$text)=@_;
my %result;
my @q =split (/Core/,$text);
my $i=0;
foreach my $p (@q){
if ($i!=0){
my @d = split (/[^0-9. ]/,$p);
my $n= $d[0];
my $val = capture_number_after("$data",$p);
$result{remove_all_white_spaces($n)}=remove_all_white_spaces($val);
}
$i++;
}
return %result;
}
 
 
 
 
 
############
# main
############
sub emulator_main{
add_color_to_gd();
my $emulate= emulator->emulator_new();
set_gui_status($emulate,"ideal",0);
$emulate->object_add_attribute('compile','compilers',"QuartusII");
my $left_table = Gtk2::Table->new (25, 6, FALSE);
my $right_table = Gtk2::Table->new (25, 6, FALSE);
 
my $main_table = Gtk2::Table->new (25, 12, FALSE);
my ($infobox,$info)= create_text();
my $refresh = Gtk2::Button->new_from_stock('ref');
my ($infobox,$info)= create_text();
add_colors_to_textview($info);
my @pages =(
{page_name=>" Avg. throughput/latency", page_num=>0},
{page_name=>" Injected Packet ", page_num=>1},
{page_name=>" Worst-Case Delay ",page_num=>2},
{page_name=>" Executaion Time ",page_num=>3},
);
 
my ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate");
my $chart =gen_chart ($emulate);
my @charts = (
{ type=>"2D_line", page_num=>0, graph_name=> "Latency", result_name => "latency_result", X_Title=> 'Desired Avg. Injected Load Per Router (flits/clock (%))', Y_Title=>'Latency (clock)', Z_Title=>undef, Y_Max=>100},
{ type=>"2D_line", page_num=>0, graph_name=> "Throughput", result_name => "throughput_result", X_Title=> 'Desired Avg. Injected Load Per Router (flits/clock (%))', Y_Title=>'Avg. Throughput (flits/clock (%))', Z_Title=>undef},
{ type=>"3D_bar", page_num=>1, graph_name=> "Received", result_name => "packet_rsvd_result", X_Title=>'Core ID' , Y_Title=>'Received Packets Per Router', Z_Title=>undef},
{ type=>"3D_bar", page_num=>1, graph_name=> "Sent", result_name => "packet_sent_result", X_Title=>'Core ID' , Y_Title=>'Sent Packets Per Router', Z_Title=>undef},
{ type=>"3D_bar", page_num=>2, graph_name=> "Received", result_name => "worst_delay_rsvd_result",X_Title=>'Core ID' , Y_Title=>'Worst-Case Delay (clk)', Z_Title=>undef},
{ type=>"2D_line", page_num=>3, graph_name=> "-", result_name => "exe_time_result",X_Title=>'Desired Avg. Injected Load Per Router (flits/clock (%))' , Y_Title=>'Total Emulation Time (clk)', Z_Title=>undef},
);
my ($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate", @charts);
my $chart =gen_multiple_charts ($emulate,\@pages,\@charts);
 
 
$main_table->set_row_spacings (4);
$main_table->set_col_spacings (1);
#my $device_win=show_active_dev($soc,$soc,$infc,$soc_state,\$refresh,$info);
my $generate = def_image_button('icons/forward.png','Run all');
my $open = def_image_button('icons/browse.png','Load');
my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
$entry->signal_connect( 'changed'=> sub{
my $name=$entry->get_text();
$emulate->object_add_attribute ("emulate_name",undef,$name);
1542,80 → 1193,54
});
my $save = def_image_button('icons/save.png','Save');
$entrybox->pack_end($save, FALSE, FALSE,0);
my $image = get_status_gif($emulate);
my $v1=gen_vpaned($conf_box,.45,$image);
my $v2=gen_vpaned($infobox,.2,$chart);
my $h1=gen_hpaned($v1,.4,$v2);
 
#$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
my $image = get_status_gif($emulate);
$left_table->attach_defaults ($conf_box , 0, 6, 0, 20);
$left_table->attach_defaults ($image , 0, 6, 20, 24);
$left_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
$left_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
$right_table->attach_defaults ($infobox , 0, 6, 0,12);
$right_table->attach_defaults ($chart , 0, 6, 12, 24);
$right_table->attach ($generate, 4, 6, 24,25,'expand','shrink',2,2);
$main_table->attach_defaults ($left_table , 0, 6, 0, 25);
$main_table->attach_defaults ($right_table , 6, 12, 0, 25);
 
#referesh the mpsoc generator
$refresh-> signal_connect("clicked" => sub{
my $name=$emulate->object_get_attribute ("emulate_name",undef);
$entry->set_text($name) if(defined $name);
 
 
$conf_box->destroy();
$set_win->destroy();
$chart->destroy();
$image->destroy();
$image = get_status_gif($emulate);
$main_table->attach_defaults ($h1 , 0, 12, 0,24);
$main_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
$main_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
$main_table->attach ($generate, 6, 9, 24,25,'expand','shrink',2,2);
($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate");
$chart =gen_chart ($emulate);
$left_table->attach_defaults ($image , 0, 6, 20, 24);
$left_table->attach_defaults ($conf_box , 0, 6, 0, 12);
$right_table->attach_defaults ($chart , 0, 6, 12, 24);
 
$conf_box->show_all();
$main_table->show_all();
 
 
});
 
 
 
#check soc status every 0.5 second. referesh device table if there is any changes
Glib::Timeout->add (100, sub{
Glib::Timeout->add (100, sub{
my ($state,$timeout)= get_gui_status($emulate);
if ($timeout>0){
$timeout--;
set_gui_status($emulate,$state,$timeout);
return TRUE;
}
if($state eq "ideal"){
return TRUE;
}
elsif($state eq 'ref_set_win'){
my $s=$emulate->object_get_attribute("active_setting",undef);
$set_win->destroy();
$emulate->object_add_attribute("active_setting",undef,$s);
$refresh->clicked;
#my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
#if(defined $saved_name) {$entry->set_text($saved_name);}
set_gui_status($emulate,"ideal",0);
$emulate->object_add_attribute("active_setting",undef,$s);
}
elsif( $state ne "ideal" ){
$refresh->clicked;
#my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
#if(defined $saved_name) {$entry->set_text($saved_name);}
set_gui_status($emulate,"ideal",0);
}
#refresh GUI
my $name=$emulate->object_get_attribute ("emulate_name",undef);
$entry->set_text($name) if(defined $name);
$conf_box->destroy();
$set_win->destroy();
$chart->destroy();
$image->destroy();
$image = get_status_gif($emulate);
($conf_box,$set_win)=process_notebook_gen($emulate,\$info,"emulate", @charts);
$chart =gen_multiple_charts ($emulate,\@pages,\@charts);
$v1 -> pack1($conf_box, TRUE, TRUE);
$v1 -> pack2($image, TRUE, TRUE);
$v2 -> pack2($chart, TRUE, TRUE);
$conf_box->show_all();
$main_table->show_all();
set_gui_status($emulate,"ideal",0);
return TRUE;
} );
1622,157 → 1247,30
$generate-> signal_connect("clicked" => sub{
my $sample_num=$emulate->object_get_attribute("emulate_num",undef);
for (my $i=1; $i<=$sample_num; $i++){
$emulate->object_add_attribute ("sample$i","status","run");
my @samples =$emulate->object_get_attribute_order("samples");
foreach my $sample (@samples){
$emulate->object_add_attribute ($sample,"status","run");
}
run_emulator($emulate,\$info);
#set_gui_status($emulate,"ideal",2);
 
});
 
# $wb-> signal_connect("clicked" => sub{
# wb_address_setting($mpsoc);
#
# });
 
$open-> signal_connect("clicked" => sub{
load_emulation($emulate,\$info);
set_gui_status($emulate,"ref",5);
});
 
$save-> signal_connect("clicked" => sub{
save_emulation($emulate);
set_gui_status($emulate,"ref",5);
});
 
my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
$sc_win->set_policy( "automatic", "automatic" );
$sc_win->add_with_viewport($main_table);
$sc_win->set_policy( "automatic", "automatic" );
$sc_win->add_with_viewport($main_table);
 
return $sc_win;
 
}
 
 
 
 
 
 
 
############
# run_simulator
###########
 
sub run_simulator {
my ($simulate,$info)=@_;
#return if(!check_samples($emulate,$info));
$simulate->object_add_attribute('status',undef,'run');
set_gui_status($simulate,"ref",1);
show_info($info, "Start Simulation\n");
my $name=$simulate->object_get_attribute ("simulate_name",undef);
my $log= (defined $name)? "$ENV{PRONOC_WORK}/simulate/$name.log": "$ENV{PRONOC_WORK}/simulate/sim.log";
#unlink $log; # remove old log file
my $sample_num=$simulate->object_get_attribute("emulate_num",undef);
for (my $i=1; $i<=$sample_num; $i++){
my $status=$simulate->object_get_attribute ("sample$i","status");
next if($status ne "run");
next if(!check_sample($simulate,$i,$info));
my $r= $simulate->object_get_attribute("sample$i","ratios");
my @ratios=@{check_inserted_ratios($r)};
#$emulate->object_add_attribute ("sample$i","status","run");
my $bin=$simulate->object_get_attribute ("sample$i","sof_file");
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../"); #mpsoc directory address
$bin= "$project_dir/$bin" if(!(-f $bin));
#load traffic configuration
my $patern=$simulate->object_get_attribute ("sample$i",'traffic');
my $PCK_SIZE=$simulate->object_get_attribute ("sample$i","PCK_SIZE");
my $PCK_NUM_LIMIT=$simulate->object_get_attribute ("sample$i","PCK_NUM_LIMIT");
my $SIM_CLOCK_LIMIT=$simulate->object_get_attribute ("sample$i","SIM_CLOCK_LIMIT");
my $HOTSPOT_PERCENTAGE=$simulate->object_get_attribute ("sample$i",'HOTSPOT_PERCENTAGE');
my $HOTSPOT_NUM=$simulate->object_get_attribute ("sample$i","HOTSPOT_NUM");
my $HOTSPOT_CORE_1=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_1");
my $HOTSPOT_CORE_2=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_2");
my $HOTSPOT_CORE_3=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_3");
my $HOTSPOT_CORE_4=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_4");
my $HOTSPOT_CORE_5=$simulate->object_get_attribute ("sample$i","HOTSPOT_CORE_5");
$HOTSPOT_PERCENTAGE = 0 if (!defined $HOTSPOT_PERCENTAGE);
$HOTSPOT_NUM=0 if (!defined $HOTSPOT_NUM);
$HOTSPOT_CORE_1=0 if (!defined $HOTSPOT_CORE_1);
$HOTSPOT_CORE_2=0 if (!defined $HOTSPOT_CORE_2);
$HOTSPOT_CORE_3=0 if (!defined $HOTSPOT_CORE_3);
$HOTSPOT_CORE_4=0 if (!defined $HOTSPOT_CORE_4);
$HOTSPOT_CORE_5=0 if (!defined $HOTSPOT_CORE_5);
foreach my $ratio_in (@ratios){
add_info($info, "Run $bin with injection ratio of $ratio_in \% \n");
my $cmd="$bin -t \"$patern\" -s $PCK_SIZE -n $PCK_NUM_LIMIT -c $SIM_CLOCK_LIMIT -i $ratio_in -p \"100,0,0,0,0\" -h \"$HOTSPOT_PERCENTAGE,$HOTSPOT_NUM,$HOTSPOT_CORE_1,$HOTSPOT_CORE_2,$HOTSPOT_CORE_3,$HOTSPOT_CORE_4,$HOTSPOT_CORE_5\"";
add_info($info, "$cmd \n");
my $time_strg = localtime;
append_text_to_file($log,"started at:$time_strg\n"); #save simulation output
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout("$cmd");
if($exit){
add_info($info, "Error in running simulation: $stderr \n");
$simulate->object_add_attribute ("sample$i","status","failed");
$simulate->object_add_attribute('status',undef,'ideal');
return;
}
append_text_to_file($log,$stdout); #save simulation output
$time_strg = localtime;
append_text_to_file($log,"Ended at:$time_strg\n"); #save simulation output
my @q =split (/average latency =/,$stdout);
my $d=$q[1];
@q =split (/\n/,$d);
my $avg=$q[0];
#my $avg = sprintf("%.1f", $avg);
next if (!defined $avg);
my $ref=$simulate->object_get_attribute ("sample$i","result");
my %results;
%results= %{$ref} if(defined $ref);
#push(@results,$avg);
$results{$ratio_in}=$avg;
$simulate->object_add_attribute ("sample$i","result",\%results);
set_gui_status($simulate,"ref",2);
}
$simulate->object_add_attribute ("sample$i","status","done");
}
add_info($info, "Simulation is done!\n");
$simulate->object_add_attribute('status',undef,'ideal');
set_gui_status($simulate,"ref",1);
}
 
 
 
/emulator.pm
22,6 → 22,7
$self = {};
$self->{file_name} = (); # information on each file
$self->{samples} = ();
emulator_initial_setting($self);
 
34,7 → 35,6
sub emulator_initial_setting{
my $self=shift;
$self->{status}="ideal";
$self->{graph_scale}=5;
$self->{setting}{show_noc_setting}=1;
$self->{setting}{show_adv_setting}=0;
$self->{setting}{show_tile_setting}=0;
75,10 → 75,47
 
sub object_get_attribute_order{
my ($self,$attribute)=@_;
return @{$self->{parameters_order}{$attribute}};
my @array;
@array = @{$self->{parameters_order}{$attribute}} if (defined $self->{parameters_order}{$attribute});
return @array;
}
 
 
sub object_delete_attribute_order{
my ($self,$attribute,@param)=@_;
my @array=object_get_attribute_order($self,$attribute);
foreach my $p (@param){
@array=remove_scolar_from_array(\@array,$p);
 
}
$self->{'parameters_order'}{$attribute}=[];
object_add_attribute_order($self,$attribute,@array);
}
 
sub object_remove_attribute{
my ($self,$attribute1,$attribute2)=@_;
if(!defined $attribute2){
delete $self->{$attribute1} if ( exists( $self->{$attribute1}));
}
else {
delete $self->{$attribute1}{$attribute2} if ( exists( $self->{$attribute1}{$attribute2})); ;
 
}
 
}
sub remove_scolar_from_array{
my ($array_ref,$item)=@_;
my @array=@{$array_ref};
my @new;
foreach my $p (@array){
if($p ne $item ){
push(@new,$p);
}
}
return @new;
}
 
 
 
1
/graph.pl
0,0 → 1,1005
#!/usr/bin/perl
use strict;
use warnings;
use GD::Graph::bars3d;
use Glib qw/TRUE FALSE/;
 
 
 
 
 
sub gen_multiple_charts{
my ($self,$pageref,$charts_ref)=@_;
my @pages=@{$pageref};
my @charts=@{$charts_ref};
my $notebook = Gtk2::Notebook->new;
$notebook->set_scrollable(TRUE);
$notebook->can_focus(FALSE);
 
 
 
foreach my $page (@pages){
my @selects;
my $page_id= "P$page->{page_num}";
my $active = $self->object_get_attribute ($page_id,'active');
foreach my $chart (@charts){
push (@selects,$chart->{graph_name})if($page->{page_num} == $chart->{page_num} );
}
$active =$selects[0] if (!defined $active);
foreach my $chart (@charts){
my $graph_id= $page_id."$chart->{graph_name}";
if($active eq $chart->{graph_name} && $page->{page_num} == $chart->{page_num}){
my $p= gen_graph ($self,$chart,@selects);
$notebook->append_page ($p,Gtk2::Label->new_with_mnemonic ($page->{page_name}));
$self->object_add_attribute ($graph_id,'type',$chart->{type});
}
}
#print "$page->{page_name} : @selects \n";
}
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->add_with_viewport($notebook);
$scrolled_win->show_all;
my $page_num=$self->object_get_attribute ("chart_notebook","currentpage");
$notebook->set_current_page ($page_num) if(defined $page_num);
$notebook->signal_connect( 'switch-page'=> sub{
$self->object_add_attribute ("chart_notebook","currentpage",$_[2]); #save the new pagenumber
#print "$self->object_add_attribute (\"chart_notebook\",\"currentpage\",$_[2]);\n";
});
#return ($scrolled_win,$set_win);
return $scrolled_win;
 
 
 
}
 
 
 
sub get_uniq_keys {
my ($ref,@x)=@_;
if(defined $ref) {
my %r=%$ref;
push(@x, sort {$a<=>$b} keys %r);
my @x2;
@x2 = uniq(sort {$a<=>$b} @x) if (scalar @x);
return @x2;
}
return @x;
}
 
 
sub gen_graph {
my ($self,$chart,@selects)=@_;
if($chart->{type} eq '2D_line') {return gen_2D_line($self,$chart,@selects);}
return gen_3D_bar($self,$chart,@selects);
}
 
 
 
 
 
sub gen_3D_bar{
my ($self,$chart,@selects)=@_;
 
my($width,$hight)=max_win_size();
my $page_id= "P$chart->{page_num}";
my $graph_id= $page_id."$chart->{graph_name}";
#my $graph_name=$chart->{graph_name};
my $result_name= $chart->{result_name};
my @legend_keys;
my @results;
$results[0]= [0];
$results[1]= [0];
#$results[2]= [0];
 
 
my $legend_info="This attribute controls placement of the legend within the graph image. The value is supplied as a two-letter string, where the first letter is placement (a B or an R for bottom or right, respectively) and the second is alignment (L, R, C, T, or B for left, right, center, top, or bottom, respectively). ";
my $fontsize="Tiny,Small,MediumBold,Large,Giant";
 
 
 
my @ginfo = (
#{ label=>"Graph Title", param_name=>"G_Title", type=>"Entry", default_val=>undef, content=>undef, info=>undef, param_parent=>"${graph_name}_param" , ref_delay=>undef },
{ label=>"Y Axix Title", param_name=>"Y_Title", type=>"Entry", default_val=>$chart->{"Y_Title"}, content=>undef, info=>undef, param_parent=>"${graph_id}_param" , ref_delay=>undef },
{ label=>"X Axix Title", param_name=>"X_Title", type=>"Entry", default_val=>$chart->{"X_Title"}, content=>undef, info=>undef, param_parent=>"${graph_id}_param" ,ref_delay=>undef },
{ label=>"legend placement", param_name=>"legend_placement", type=>'Combo-box', default_val=>'BL', content=>"BL,BC,BR,RT,RC,RB", info=>$legend_info, param_parent=>"${graph_id}_param" , ref_delay=>1},
{ label=>"Y min", param_name=>"Y_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"Y axix minimum value", param_parent=>"${graph_id}_param" , ref_delay=> 5},
{ label=>"X min", param_name=>"X_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"X axix minimum value", param_parent=>"${graph_id}_param" , ref_delay=> 5},
{ label=>"X max", param_name=>"X_MAX", type=>'Spin-button', default_val=>100, content=>"0,1024,1", info=>"X axix maximum value", param_parent=>"${graph_id}_param" , ref_delay=> 5},
{ label=>"Line Width", param_name=>"LINEw", type=>'Spin-button', default_val=>3, content=>"1,20,1", info=>undef, param_parent=>"${graph_id}_param" , ref_delay=> 5},
#{ label=>"Y Axis Values", param_name=>"y_value", type=>'Combo-box', default_val=>'Original', content=>"Original,Normalized to 1,Normalized to 100", info=>undef, param_parent=>"${graph_name}_param" , ref_delay=>1},
{ label=>"legend font size", param_name=>"legend_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param" , ref_delay=>1},
{ label=>"label font size", param_name=>"label_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param" , ref_delay=>1},
{ label=>"label font size", param_name=>"x_axis_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param" , ref_delay=>1},
);
 
my $content=join( ',', @selects);
 
my $dimention=gen_combobox_object ($self,$graph_id,"dimention","2D,3D","3D",'ref',2);
my $active_page=gen_combobox_object ($self,$page_id,"active",$content,$selects[0],'ref',2);
 
 
#print "${graph_name}_${dir}_result\n";
my @ratios;
my @color;
my $min_y=200;
my $i=0;
my @samples =$self->object_get_attribute_order("samples");
@samples = ('no_name') if (scalar @samples == 0);
foreach my $sample (@samples){
my $color_num=$self->object_get_attribute($sample,"color");
my $l_name= $self->object_get_attribute($sample,"line_name");
#push(@color, "my_color$color_num");
my $ref=$self->object_get_attribute ($sample,$result_name);
if(defined $ref){
$i++;
@ratios=get_uniq_keys($ref,@ratios);
$color_num=$i+1 if(!defined $color_num);
push(@color, "my_color$color_num");
$legend_keys[$i-1]= (defined $l_name)? $l_name : $sample;
}
}#for
$content = join(",", @ratios);
my $ratio_combx=gen_combobox_object ($self,${graph_id},"ratio",$content,$ratios[0],'ref',2);
@color= ("my_color0") if ((scalar @color) ==0);
@legend_keys=("-") if ((scalar @legend_keys) ==0);
 
 
my $ymax=10;
my $ratio = $self->object_get_attribute ($graph_id,"ratio");
my @x;
if (defined $ratio){
foreach my $sample (@samples){
my $ref=$self->object_get_attribute ($sample,"$result_name");
if(defined $ref){
@x=get_uniq_keys($ref->{$ratio},@x);
}
}
my $i=1;
foreach my $sample (@samples){
my @y;
my $ref=$self->object_get_attribute ($sample,"$result_name");
if(defined $ref){
foreach my $v (@x){
my $w=$ref->{$ratio}->{$v};
push(@y,$w);
$ymax=$w+1 if($w>$ymax);
}
$results[$i]=\@y if(scalar @x);
$i++;
}
}
}
$results[0]=\@x if(scalar @x);
$i=1;
# all results which is larger than ymax will be changed to ymax,
$i=0;
#foreach my $sample (@samples){
#$i++;
#for (my $j=1;$j<=$s; $j++) {
# $results[$i][$j]=($results[$i][$j]>$max_y)? $max_y: $results[$i][$j] if (defined $results[$i][$j]);
#}
#}
my $graphs_info;
foreach my $d ( @ginfo){
$graphs_info->{$d->{param_name}}=$self->object_get_attribute( "${graph_id}_param" ,$d->{param_name});
if(!defined $graphs_info->{$d->{param_name}}){
$graphs_info->{$d->{param_name}}= $d->{default_val};
$self->object_add_attribute( "${graph_id}_param" ,$d->{param_name},$d->{default_val} );
}
}
my $graph_w=$width/2.5;
my $graph_h=$hight/2.5;
my $graph = new GD::Graph::bars3d($graph_w, $graph_h);
my $dim = $self->object_get_attribute (${graph_id},"dimention");
#my $dir = $self->object_get_attribute ($graph_name,"direction");
my $over= ($dim eq "2D")? 0 : 1;
$graph->set(
overwrite => $over,
x_label => $graphs_info->{X_Title},
y_label => $graphs_info->{Y_Title},
title => $graphs_info->{G_Title},
y_max_value => $ymax,
y_tick_number => 18,
y_label_skip => 2,
x_label_skip => 1,
x_all_ticks => 1,
x_labels_vertical => 1,
box_axis => 0,
y_long_ticks => 1,
legend_placement => $graphs_info->{legend_placement},
dclrs=>\@color,
y_number_format=>"%.1f",
transparent => '0',
bgclr => 'white',
boxclr => 'white',
fgclr => 'black',
textclr => 'black',
labelclr => 'black',
axislabelclr => 'black',
legendclr => 'black',
#cycle_clrs => '1',
# Draw bars with width 3 pixels
bar_width => 3,
# Sepearte the bars with 4 pixels
bar_spacing => 10,
# Show the grid
#long_ticks => 1,
# Show values on top of each bar
#show_values => 1,
);
$graph->set_legend(@legend_keys);
my $font;
$font= $self->object_get_attribute( "${graph_id}_param" ,'label_font');
$graph->set_x_label_font(GD::Font->$font);
$graph->set_y_label_font(GD::Font->$font);
$font= $self->object_get_attribute( "${graph_id}_param" ,'legend_font');
$graph->set_legend_font(GD::Font->$font);
 
$font= $self->object_get_attribute( "${graph_id}_param" ,'x_axis_font');
#$graph->set_values_font(GD::gdGiantFont);
$graph->set_x_axis_font(GD::Font->$font);
$graph->set_y_axis_font(GD::Font->$font);
#@results=reorder_result(@results);
my $gd = $graph->plot( \@results );
my $loader = Gtk2::Gdk::PixbufLoader->new;
$loader->write ($gd->png);
$loader->close;
my $image = Gtk2::Image->new_from_pixbuf($loader->get_pixbuf);
write_image ($self,$graph_id,$gd);
write_image_result ($self,$graph_id,$graph,$result_name,$chart->{type},\@results);
# my $image = my_get_image($self,$graph,$data,$graph_name);
# print Data::Dumper->Dump ([\@results],['ttt']);
my $table = Gtk2::Table->new (25, 10, FALSE);
my $box = Gtk2::HBox->new (TRUE, 2);
my $filename;
$box->set_border_width (4);
my $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
my $frame = Gtk2::Frame->new;
$frame->set_shadow_type ('in');
$frame->add ($image);
$align->add ($frame);
my $plus = def_image_button('icons/plus.png',undef,TRUE);
my $minues = def_image_button('icons/minus.png',undef,TRUE);
my $setting = def_image_button('icons/setting.png',undef,TRUE);
my $save = def_image_button('icons/save.png',undef,TRUE);
my $scale= $self->object_get_attribute("${graph_id}_graph_scale",undef);
$scale = 5 if(!defined $scale);
$minues -> signal_connect("clicked" => sub{
$self->object_add_attribute("${graph_id}_graph_scale",undef,$scale+0.5);
set_gui_status($self,"ref",1);
});
 
$plus -> signal_connect("clicked" => sub{
$self->object_add_attribute("${graph_id}_graph_scale",undef,$scale-0.5) if( $scale>0.5);
set_gui_status($self,"ref",5);
});
 
$setting -> signal_connect("clicked" => sub{
get_graph_setting ($self,\@ginfo);
});
set_tip($setting, "Setting");
$save-> signal_connect("clicked" => sub{
# my $G = $graph->{graph};
my @imags=$graph->export_format();
save_graph_as ($self,\@imags,$graph_id);
});
set_tip($save, "Save graph");
$table->attach_defaults ($align , 0, 9, 0, 25);
my $row=0;
$table->attach (gen_label_in_center('Injection-Ratio'), 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($ratio_combx, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($active_page, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($dimention, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
#$table->attach ($plus , 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
#$table->attach ($minues, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($setting, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($save, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
while ($row<10){
my $tmp=gen_label_in_left('');
$table->attach_defaults ($tmp, 9, 10, $row, $row+1);$row++;
}
return $table;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sub gen_2D_line {
 
my ($self,$chart,@selects)=@_;
my($width,$hight)=max_win_size();
my $page_id= "P$chart->{page_num}";
my $graph_id= $page_id."$chart->{graph_name}";
#my $graph_name=$chart->{graph_name};
my $result_name= $chart->{result_name};
my @x;
my @legend_keys;
my @results;
$results[0]=[0];
$results[1]= [0];
my $legend_info="This attribute controls placement of the legend within the graph image. The value is supplied as a two-letter string, where the first letter is placement (a B or an R for bottom or right, respectively) and the second is alignment (L, R, C, T, or B for left, right, center, top, or bottom, respectively). ";
my $fontsize="Tiny,Small,MediumBold,Large,Giant";
 
my $content=join( ',', @selects);
my $active_page=gen_combobox_object ($self,$page_id,"active",$content,$selects[0],'ref',2);
 
 
 
my @ginfo = (
#{ label=>"Graph Title", param_name=>"G_Title", type=>"Entry", default_val=>undef, content=>undef, info=>undef, param_parent=>"${graph_name}_param" , ref_delay=>undef },
{ label=>"Y Axis Title", param_name=>"Y_Title", type=>"Entry", default_val=>$chart->{"Y_Title"}, content=>undef, info=>undef, param_parent=>"${graph_id}_param" , ref_delay=>undef },
{ label=>"X Axis Title", param_name=>"X_Title", type=>"Entry", default_val=>$chart->{"X_Title"}, content=>undef, info=>undef, param_parent=>"${graph_id}_param" ,ref_delay=>undef },
{ label=>"legend placement", param_name=>"legend_placement", type=>'Combo-box', default_val=>'BL', content=>"BL,BC,BR,RT,RC,RB", info=>$legend_info, param_parent=>"${graph_id}_param" , ref_delay=>1},
{ label=>"Y min", param_name=>"Y_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"Y axis minimum value", param_parent=>"${graph_id}_param" , ref_delay=> 5},
{ label=>"X min", param_name=>"X_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"X axis minimum value", param_parent=>"${graph_id}_param" , ref_delay=> 5},
{ label=>"X max", param_name=>"X_MAX", type=>'Spin-button', default_val=>100, content=>"0,1024,1", info=>"X axis maximum value", param_parent=>"${graph_id}_param" , ref_delay=> 5},
{ label=>"Line Width", param_name=>"LINEw", type=>'Spin-button', default_val=>3, content=>"1,20,1", info=>undef, param_parent=>"${graph_id}_param" , ref_delay=> 5},
#{ label=>"Y Axis Values", param_name=>"y_value", type=>'Combo-box', default_val=>'Original', content=>"Original,Normalized to 1,Normalized to 100", info=>undef, param_parent=>"${graph_name}_param" , ref_delay=>1},
 
{ label=>"legend font size", param_name=>"legend_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"{$graph_id}_param" , ref_delay=>1},
{ label=>"label font size", param_name=>"label_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param" , ref_delay=>1},
{ label=>"label font size", param_name=>"x_axis_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param" , ref_delay=>1},
);
 
 
 
 
 
my @color;
my $min_y;#=200;
my $i=0;
my @samples =$self->object_get_attribute_order("samples");
@samples = ('no_name') if (scalar @samples == 0);
foreach my $sample (@samples){
my $ref=$self->object_get_attribute ($sample,$result_name);
$i++;
my $color_num=$self->object_get_attribute($sample,"color");
my $l_name= $self->object_get_attribute($sample,"line_name");
$legend_keys[$i-1]= (defined $l_name)? $l_name : $sample;
$color_num=$i+1 if(!defined $color_num);
push(@color, "my_color$color_num");
if(defined $ref) {
push(@x, sort {$a<=>$b} keys %{$ref});
}
}#for
my @x2;
@x2 = uniq(sort {$a<=>$b} @x) if (scalar @x);
my @x1; #remove x values larger than x_max
my $x_max= $self->object_get_attribute( "${graph_id}_param" ,'X_MAX');
foreach my $p (@x2){
if(defined $x_max) {push (@x1,$p) if($p<$x_max);}
else {push (@x1,$p);}
}
 
#print "\@x1=@x1\n";
if (scalar @x1){
$results[0]=\@x1;
$i=0;
foreach my $sample (@samples){
$i++;
my $j=0;
my $ref=$self->object_get_attribute ($sample,$result_name);
if(defined $ref){
#print "$i\n";
my %line=%$ref;
foreach my $k (@x1){
$results[$i][$j]=$line{$k};
if(defined $line{$k}){
$min_y = $line{$k} if (!defined $min_y);
$min_y= $line{$k} if ($line{$k}!=0 && $min_y > $line{$k});
$j++;
}
}#$k
}#if
else {
$results[$i][$j]=undef;
}
}#$i
}#if
$min_y = 200 if (!defined $min_y);
my $scale= $self->object_get_attribute("${graph_id}_graph_scale",undef);
$scale = 5 if(!defined $scale);
 
my $max_y=$min_y* $scale;
my $s=scalar @x1;
# all results which is larger than ymax will be changed to ymax,
$i=0;
foreach my $sample (@samples){
$i++;
for (my $j=1;$j<=$s; $j++) {
$results[$i][$j]=($results[$i][$j]>$max_y)? $max_y: $results[$i][$j] if (defined $results[$i][$j]);
}
}
my $graphs_info;
foreach my $d ( @ginfo){
$graphs_info->{$d->{param_name}}=$self->object_get_attribute( "${graph_id}_param" ,$d->{param_name});
if(!defined $graphs_info->{$d->{param_name}}){
$graphs_info->{$d->{param_name}}= $d->{default_val};
$self->object_add_attribute( "${graph_id}_param" ,$d->{param_name},$d->{default_val} );
}
}
my $graph_w=$width/2.5;
my $graph_h=$hight/2.5;
my $graph = Gtk2::Ex::Graph::GD->new($graph_w, $graph_h, 'linespoints');
 
$graph->set (
x_label => $graphs_info->{X_Title},
y_label => $graphs_info->{Y_Title},
y_max_value => $max_y,
y_min_value => $graphs_info->{Y_MIN},
y_tick_number => 8,
# x_min_value => $graphs_info->{X_MIN}, # dosent work?
title => $graphs_info->{G_Title},
bar_spacing => 1,
shadowclr => 'dred',
 
 
box_axis => 0,
skip_undef=> 1,
# transparent => 1,
transparent => '0',
bgclr => 'white',
boxclr => 'white',
fgclr => 'black',
textclr => 'black',
labelclr => 'black',
axislabelclr => 'black',
legendclr => 'black',
cycle_clrs => '1',
line_width => $graphs_info->{LINEw},
# cycle_clrs => 'black',
legend_placement => $graphs_info->{legend_placement},
dclrs=>\@color,
y_number_format=>"%.1f",
BACKGROUND=>'black',
);
$graph->set_legend(@legend_keys);
 
 
 
 
my $data = GD::Graph::Data->new(\@results) or die GD::Graph::Data->error;
$data->make_strict();
my $image = my_get_image($self,$graph,$data,$graph_id,$result_name,$chart->{type});
# print Data::Dumper->Dump ([\@results],['ttt']);
my $table = Gtk2::Table->new (25, 10, FALSE);
my $box = Gtk2::HBox->new (TRUE, 2);
my $filename;
$box->set_border_width (4);
my $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
my $frame = Gtk2::Frame->new;
$frame->set_shadow_type ('in');
$frame->add ($image);
$align->add ($frame);
my $plus = def_image_button('icons/plus.png',undef,TRUE);
my $minues = def_image_button('icons/minus.png',undef,TRUE);
my $setting = def_image_button('icons/setting.png',undef,TRUE);
my $save = def_image_button('icons/save.png',undef,TRUE);
 
$minues -> signal_connect("clicked" => sub{
$self->object_add_attribute("${graph_id}_graph_scale",undef,$scale+0.5);
set_gui_status($self,"ref",1);
});
set_tip($minues, "Zoom out");
 
$plus -> signal_connect("clicked" => sub{
$self->object_add_attribute("${graph_id}_graph_scale",undef,$scale-0.5) if( $scale>0.5);
set_gui_status($self,"ref",5);
});
set_tip($plus, "Zoom in");
 
$setting -> signal_connect("clicked" => sub{
get_graph_setting ($self,\@ginfo);
});
set_tip($setting, "Setting");
 
$save-> signal_connect("clicked" => sub{
my $G = $graph->{graph};
my @imags=$G->export_format();
save_graph_as ($self,\@imags,$graph_id);
});
set_tip($save, "Save graph");
$table->attach_defaults ($align , 0, 9, 0, 25);
my $row=0;
$table->attach ($active_page, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($plus , 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($minues, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($setting, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
$table->attach ($save, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
while ($row<10){
my $tmp=gen_label_in_left('');
$table->attach_defaults ($tmp, 9, 10, $row, $row+1);$row++;
}
return $table;
 
}
 
 
##############
# save_graph_as
##############
 
sub save_graph_as {
my ($self,$ref,$graph_name)=@_;
my $file;
my $title ='Save as';
 
 
 
my @extensions=@$ref;
my $open_in=undef;
my $dialog = Gtk2::FileChooserDialog->new(
'Save file', undef,
'save',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok',
);
# if(defined $extension){
foreach my $ext (@extensions){
my $filter = Gtk2::FileFilter->new();
$filter->set_name($ext);
$filter->add_pattern("*.$ext");
$dialog->add_filter ($filter);
}
# }
if(defined $open_in){
$dialog->set_current_folder ($open_in);
# print "$open_in\n";
}
if ( "ok" eq $dialog->run ) {
$file = $dialog->get_filename;
my $ext = $dialog->get_filter;
$ext=$ext->get_name;
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
$file = ($suffix eq ".$ext" )? $file : "$file.$ext";
$self->object_add_attribute("graph_save","name",$file);
$self->object_add_attribute("graph_save","extension",$ext);
$self->object_add_attribute("graph_save","save",1);
$self->object_add_attribute("graph_save","save_result",1);
$self->object_add_attribute("graph_save","graph_name",$graph_name);
set_gui_status($self,"ref",1);
}
$dialog->destroy;
}
 
 
 
sub my_get_image {
my ($self,$exgraph, $data, $graph_name, $result_name,$charttype) = @_;
$exgraph->{graphdata} = $data;
my $graph = $exgraph->{graph};
my $font;
$font= $self->object_get_attribute( "${graph_name}_param" ,'label_font');
$graph->set_x_label_font(GD::Font->$font);
$graph->set_y_label_font(GD::Font->$font);
$font= $self->object_get_attribute( "${graph_name}_param" ,'legend_font');
$graph->set_legend_font(GD::Font->$font);
 
$font= $self->object_get_attribute( "${graph_name}_param" ,'x_axis_font');
#$graph->set_values_font(GD::gdGiantFont);
$graph->set_x_axis_font(GD::Font->$font);
$graph->set_y_axis_font(GD::Font->$font);
 
my $gd2=$graph->plot($data) or warn $graph->error;
my $loader = Gtk2::Gdk::PixbufLoader->new;
#cut the upper side of the image to remove the stright line created by chaanging large results to ymax
my $gd1= GD::Image->new($gd2->getBounds);
my $white= $gd1->colorAllocate(255,255,254);
my ($x,$h)=$gd2->getBounds;
$gd1->transparent($white);
$gd1->copy( $gd2, 0, 0, 0, ,$h*0.05, $x ,$h*.95 );
$loader->write ($gd1->png);
$loader->close;
 
write_image ($self,$graph_name,$gd1);
write_image_result ($self,$graph_name,$graph,$result_name,$charttype);
 
my $image = Gtk2::Image->new_from_pixbuf($loader->get_pixbuf);
 
 
$exgraph->{graphimage} = $image;
my $hotspotlist;
if ($exgraph->{graphtype} eq 'bars' or
$exgraph->{graphtype} eq 'lines' or
$exgraph->{graphtype} eq 'linespoints') {
foreach my $hotspot ($graph->get_hotspot) {
push @$hotspotlist, $hotspot if $hotspot;
}
}
$exgraph->{hotspotlist} = $hotspotlist;
my $eventbox = $exgraph->{eventbox};
my @children = $eventbox->get_children;
foreach my $child (@children) {
$eventbox->remove($child);
}
# $eventbox->add ($image);
 
# $eventbox->show_all;
return $image;
}
 
 
 
############
# get_graph_setting
###########
 
sub get_graph_setting {
my ($self,$ref)=@_;
my $window=def_popwin_size(33,33,'Graph Setting','percent');
my $table = def_table(10, 2, FALSE);
my $row=0;
 
 
my @data=@$ref;
foreach my $d (@data) {
$row=noc_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
}
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->add_with_viewport($table);
my $ok = def_image_button('icons/select.png',' OK ');
my $mtable = def_table(10, 1, FALSE);
$mtable->attach_defaults($scrolled_win,0,1,0,9);
$mtable->attach($ok,0,1,9,10,'shrink','shrink',2,2);
$window->add ($mtable);
$window->show_all();
$ok-> signal_connect("clicked" => sub{
$window->destroy;
set_gui_status($self,"ref",1);
});
 
 
 
}
 
 
 
sub write_image {
my ($self,$graph_name,$image)=@_;
my $save=$self->object_get_attribute("graph_save","save");
my $active_graph=$self->object_get_attribute("graph_save","graph_name");
$save=0 if (!defined $save);
$active_graph = 0 if(!defined $active_graph);
if ($save ==1 && $active_graph eq $graph_name){
my $file=$self->object_get_attribute("graph_save","name");
my $ext=$self->object_get_attribute("graph_save","extension");
$self->object_add_attribute("graph_save","save",0);
 
#image
open(my $out, '>', $file);
if (tell $out )
{
warn "Cannot open '$file' to write: $!";
}else
{
#my @extens=$graph->export_format();
binmode $out;
print $out $image->$ext;# if($ext eq 'png');
#print $out $gd1->gif if($ext eq 'gif');
close $out;
}
}
}
 
 
sub write_image_result {
my ($self,$graph_name,$graph,$result_name,$charttype,$result_ref)=@_;
my $save=$self->object_get_attribute("graph_save","save_result");
my $active_graph=$self->object_get_attribute("graph_save","graph_name");
$save=0 if (!defined $save);
$active_graph = 0 if(!defined $active_graph);
if ($save ==1 && $active_graph eq $graph_name){
my $file=$self->object_get_attribute("graph_save","name");
my $ext=$self->object_get_attribute("graph_save","extension");
$self->object_add_attribute("graph_save","save_result",0);
open( my $out, '>', "$file.txt");
if (tell $out )
{
warn "Cannot open $file.txt to write: $!";
}
else
{
if($charttype eq '2D_line'){
my @samples =$self->object_get_attribute_order("samples");
foreach my $sample (@samples){
my $l_name= $self->object_get_attribute($sample,"line_name");
my $ref=$self->object_get_attribute ($sample,$result_name);
my @x;
if(defined $ref) {
print $out "$l_name\n";
foreach my $x (sort {$a<=>$b} keys %{$ref}) {
my $y=$ref->{$x};
print $out "\t$x , $y\n";
}
print $out "\n\n";
}
}#for
} else{
write_3d_graph_results($self,$out,$result_ref);
}
close $out;
}
}
}
 
 
sub write_3d_graph_results{
my ($self,$out,$result_ref)=@_;
my @r=@{$result_ref};
my @samples =$self->object_get_attribute_order("samples");
my $i=0;
if(defined $r[$i]){
my @k=@{$r[$i]};
print $out "@k\n\n";
}
foreach my $sample (@samples){
$i++;
my $l_name= $self->object_get_attribute($sample,"line_name");
print $out "$l_name:\n";
if(defined $r[$i]){
my @k=@{$r[$i]};
print $out "@k\n\n";
}
}
}
 
 
 
################
# get_color_window
###############
sub get_color_window{
my ($self,$atrebute1,$atrebute2)=@_;
my $window=def_popwin_size(40,40,"Select line color",'percent');
my ($r,$c)=(4,8);
my $table= def_table(5,6,TRUE);
for (my $col=0;$col<$c;$col++){
for (my $row=0;$row<$r;$row++){
my $color_num=$row*$c+$col;
my $color=def_colored_button(" ",$color_num);
$table->attach_defaults ($color, $col, $col+1, $row, $row+1);
$color->signal_connect("clicked"=> sub{
$self->object_add_attribute($atrebute1,$atrebute2,$color_num);
#print "$self->object_add_attribute($atrebute1,$atrebute2,$color_num);\n";
set_gui_status($self,"ref",1);
$window->destroy;
});
}
}
$window->add($table);
$window->show_all();
 
}
 
 
sub reorder_result{
my @results=@_;
my @app=(
"a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11"," "," "," "," ",
"b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","b10","b11","b12","b13","b14","b15"," "," "," "," ",
"c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11"," "," "," "," ",
"d0","d1","d2","d3","d4","d5","d6","d7","d8");
my %nmap=(
"b7" => 0 ,"b9" => 1 ,"b8" => 2 ,"a11"=> 3 ,"b11"=> 4 ,"b12"=> 5 ,"b13"=> 6 ,
"b6" => 7 ,"b5" => 8 ,"a10"=> 9 ,"a8" => 10,"a9" => 11,"b14"=> 12,"b10"=> 13,
"b3" => 14,"b4" => 15,"a5" => 16,"a7" => 17,"a2" => 18,"d8" => 19,"d0" => 20,
"b2" => 21,"a3" => 22,"a6" => 23,"a0" => 24,"a1" => 25,"d1" => 26,"d2" => 27,
"b1" => 28,"b15"=> 29,"c2" => 30,"a4" => 31,"d4" => 32,"d3" => 33,"d5" => 34,
"b0" => 35,"c9" => 36,"c8" => 37,"c3" => 38,"d7" => 39,"d6" => 40,"c7" => 41,
"c11"=> 42,"c10"=> 43,"c5" => 44,"c4" => 45,"c1" => 46,"c0" => 47,"c6" => 48);
my %worst=(
"a0" => 0 ,"a8" => 1 ,"b7" => 2 ,"d8"=> 3 ,"b1"=> 4 ,"b5"=> 5 ,"b8"=> 6 ,
"a5" => 7 ,"c2" => 8 ,"c10"=> 9 ,"c3" => 10,"c5" => 11,"b12"=> 12,"b3"=> 13,
"d1" => 14,"d7" => 15,"c1" => 16,"c7" => 17,"c0" => 18,"c8" => 19,"b10" => 20,
"b15" => 21,"d2" => 22,"c4" => 23,"c6" => 24,"c9" => 25,"d3" => 26,"a4" => 27,
"b2" => 28,"b13"=> 29,"d4" => 30,"c11" => 31,"d5" => 32,"a2" => 33,"a10" => 34,
"b6" => 35,"b0" => 36,"d0" => 37,"d6" => 38,"a3" => 39,"a9" => 40,"a6" => 41,
"b9"=> 42,"b4"=> 43,"b11" => 44,"b14" => 45,"a1" => 46,"a11" => 47,"a7" => 48);
my %rnd=(
"d3" => 0 ,"d6" => 1 ,"b8" => 2 ,"c10"=> 3 ,"d5" => 4 ,"d8" => 5 ,"a3" => 6 ,
"b15"=> 7 ,"a9" => 8 ,"c3" => 9 ,"b12"=> 10,"a4" => 11,"b9" => 12,"b6" => 13,
"d2" => 14,"c2" => 15,"b0" => 16,"b13"=> 17,"a5" => 18,"c9" => 19,"a2" => 20,
"c0" => 21,"c7" => 22,"c5" => 23,"b14"=> 24,"b7" => 25,"c4" => 26,"b10"=> 27,
"d1" => 28,"c6" => 29,"b11"=> 30,"a10"=> 31,"b1" => 32,"c1" => 33,"b5" => 34,
"d7" => 35,"d4" => 36,"a6" => 37,"a11"=> 38,"a7" => 39,"b2" => 40,"c11" => 41,
"c8" => 42,"a1" => 43,"a0" => 44,"d0" => 45,"a8" => 46,"b3" => 47,"b4" => 48);
my @r;
my $tile=0;
foreach my $p (@app){
#my $l=$nmap{$p};
#my $l=$rnd{$p};
my $l=$worst{$p};
$r[0][$tile]=$p;
$r[1][$tile]=(defined $l)? $results[1][$l]: undef;
$r[2][$tile]=(defined $l)? $results[2][$l]: undef;
$tile++;
}
return @r;
}
 
1;
graph.pl Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: hdr_file_gen.pl =================================================================== --- hdr_file_gen.pl (revision 37) +++ hdr_file_gen.pl (revision 38) @@ -64,7 +64,7 @@ sub generate_header_file{ - my ($soc,$project_dir,$sw_path,$dir)= @_; + my ($soc,$project_dir,$sw_path,$hw_path,$dir)= @_; my $soc_name=$soc->object_get_attribute('soc_name'); $soc_name = uc($soc_name); if(!defined $soc_name){$soc_name='soc'}; @@ -140,6 +140,30 @@ } } + # Write Hardware gen files + my @hw_file_gen = $ip->ip_get_list($category,$module,"gen_hw_files"); + foreach my $file (@hw_file_gen){ + if(defined $file ){ + my ($path,$rename)=split('frename_sep_t',$file); + $rename=replace_golb_var($rename,\%params); + #read the file content + my $content=read_file_cntent($path,$project_dir); + $content=replace_golb_var($content,\%params); + + + if(defined $rename){ + + open(FILE, ">lib/verilog/tmp") || die "Can not open: $!"; + print FILE $content; + close(FILE) || die "Error closing file: $!"; + move ("$dir/lib/verilog/tmp","$hw_path/$rename"); + + + } + } + } + + }
/interface_gen.pl
329,7 → 329,7
my $entrybox=labele_widget_info(" Interface name:",$entry);
 
my $combo=gen_combobox_object($intfc_gen,'connection_num',undef,"single connection,multi connection","single connection",'refresh',1);
my $combo_box=labele_widget_info(" Select soket type:",$combo,'Define the soket as multi connection if only all interfaces ports all output and they can feed more than one plug connection');
my $combo_box=labele_widget_info(" Select soket type:",$combo,'Define the soket as multi connection if only if all interfaces ports are output oprts and they can feed more than one plug interface. E.g. clk is defined as multi connection');
$table->attach ($entrybox, 0, 2 , $row, $row+1,'expand','shrink',2,2);
$table->attach ($combo_box, 3, 6 , $row, $row+1,'expand','shrink',2,2);
/ip.pm
44,11 → 44,11
 
 
sub ip_add_parameter {
my ($self,$category,$module,$parameter,$deafult,$type,$content,$info,$glob_param,$redefine_param)=@_;
my ($self,$category,$module,$parameter,$default,$type,$content,$info,$glob_param,$redefine_param)=@_;
if (!defined($category) ) {return 0;}
if ( exists ($self->{categories}{$category}{names}{$module}) ){
$self->{categories}{$category}{names}{$module}{parameters}{$parameter}={};
$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{deafult}=$deafult;
$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{"default"}=$default;
$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{type}=$type;
$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{content}=$content;
$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{info}=$info;
72,9 → 72,9
 
sub ip_get_parameter {
my ($self,$category,$module,$parameter)=@_;
my ($deafult,$type,$content,$info,$glob_param,$redefine_param);
my ($default,$type,$content,$info,$glob_param,$redefine_param);
if ( exists ($self->{categories}{$category}{names}{$module}) ){
$deafult =$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{deafult};
$default =$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{"default"};
$type =$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{type};
$content =$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{content};
$info =$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{info};
81,7 → 81,7
$glob_param =$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{glob_param};
$redefine_param =$self->{categories}{$category}{names}{$module}{parameters}{$parameter}{redefine_param};
}
return ($deafult,$type,$content,$info,$glob_param,$redefine_param);
return ($default,$type,$content,$info,$glob_param,$redefine_param);
}
 
 
226,7 → 226,7
my %r;
if (!defined($module) ) {return %r;}
foreach my $p (sort keys %{$self->{categories}{$category}{names}{$module}{parameters}}){
$r{$p}=$self->{categories}{$category}{names}{$module}{parameters}{$p}{deafult};
$r{$p}=$self->{categories}{$category}{names}{$module}{parameters}{$p}{"default"};
#print "$p=$r{$p}\n";
}
return %r;
425,8 → 425,8
}
my @parameters= $ipgen->ipgen_get_all_parameters_list();
foreach my $param (@parameters){
my ($deafult,$type,$content,$info,$glob_param,$redefine_param)=$ipgen->ipgen_get_parameter_detail($param);
ip_add_parameter($self,$category,$module,$param,$deafult,$type,$content,$info,$glob_param,$redefine_param);
my ($default,$type,$content,$info,$glob_param,$redefine_param)=$ipgen->ipgen_get_parameter_detail($param);
ip_add_parameter($self,$category,$module,$param,$default,$type,$content,$info,$glob_param,$redefine_param);
}
436,7 → 436,7
ip_add_port($self,$category,$module,$port,$type,$range,$intfc_name,$intfc_port);
}
my @fileds =("system_h","hdl_files","sw_files","gen_sw_files","sw_params_list","unused","parameters_order","description","version",'description_pdf');
my @fileds =("system_h","hdl_files","sw_files","gen_sw_files","gen_hw_files","sw_params_list","unused","parameters_order","description","version",'description_pdf');
foreach my $p (@fileds){
my $val=$ipgen->ipgen_get($p);
$self->{categories}{$category}{names}{$module}{$p}=$ipgen->ipgen_get($p) if(defined $val );
/ip_gen.pl
18,26 → 18,7
require "widget.pl";
require "readme_gen.pl";
 
use String::Similarity;
 
sub find_the_most_similar_position{
my ($item ,@list)=@_;
my $most_similar_pos=0;
my $lastsim=0;
my $i=0;
# convert item to lowercase
$item = lc $item;
foreach my $p(@list){
my $similarity= similarity $item, $p;
if ($similarity > $lastsim){
$lastsim=$similarity;
$most_similar_pos=$i;
}
$i++;
}
return $most_similar_pos;
}
 
 
use constant DISPLY_COLUMN => 0;
81,7 → 62,7
 
$ipgen->ipgen_add("module_name",$modules[0]);
$ipgen->ipgen_set_module_list(@modules);
load_deafult_setting($ipgen,$modules[0]);
load_default_setting($ipgen,$modules[0]);
set_gui_status($ipgen,"file_selected",1);
352,7 → 333,7
$combo->signal_connect("changed"=> sub{
my $module= $combo->get_active_text();
load_deafult_setting($ipgen,$module);
load_default_setting($ipgen,$module);
set_gui_status($ipgen,'intfc_changed',0);
377,7 → 358,7
$header_h->signal_connect("clicked"=> sub{
my %page_info;
my $help1="The files and folder that selected here will be copied in genertated processing tile SW folder.";
my $help2="The file listed here can contain some variable with \${var_name} format. The file genertor will replace them with their values during file generation. The variable can be selected from above listed global vairable";
my $help2="The file listed here can contain some variable with \${var_name} format. The file genertor will replace them with their values during file generation. The variable can be selected from above listed global vairables";
my $help3='Define the header file for this peripheral device. You can use global vriables listed at the top.
header file example
397,14 → 378,14
$page_info{0}{folder_en}=1;
$page_info{0}{help}=$help1;
 
$page_info{1}{page_name} = "_Add file generator(s)";
$page_info{1}{page_name} = "_Add files contain variables";
$page_info{1}{filed_name}= "gen_sw_files";
$page_info{1}{filed_type}= "file_generators";
$page_info{1}{filed_type}= "file_with_variables";
$page_info{1}{rename_file}=1;
$page_info{1}{folder_en}=0;
$page_info{1}{help}=$help2;
 
$page_info{2}{page_name} = "_Add to system.h";
$page_info{2}{page_name} = "_Add to tile.h";
$page_info{2}{filed_name}= "system_h";
$page_info{2}{filed_type}= "file_content";
$page_info{2}{rename_file}=undef;
418,6 → 399,7
});
$lib_hdl->signal_connect("clicked"=> sub{
my $help1="The files and folder that selected here will be copied in genertated processing tile RTL folder.";
my $help2="The file listed here can contain some variable with \${var_name} format. The file genertor will replace them with their values during file generation. The variable can be selected from above listed global vairables";
my %page_info;
$page_info{0}{page_name} = "_Add exsiting HDL file/folder";
$page_info{0}{filed_name}= "hdl_files";
426,6 → 408,13
$page_info{0}{folder_en}=1;
$page_info{0}{help}=$help1;
 
$page_info{1}{page_name} = "_Add files contain variables";
$page_info{1}{filed_name}= "gen_hw_files";
$page_info{1}{filed_type}= "file_with_variables";
$page_info{1}{rename_file}=1;
$page_info{1}{folder_en}=0;
$page_info{1}{help}=$help2;
 
get_source_file($ipgen,$info,0,"Add HDL file(s)", "hw",\%page_info);
 
#get_hdl_file($ipgen,$info);
434,7 → 423,7
});
}
 
sub load_deafult_setting{
sub load_default_setting{
my ($ipgen,$module)=@_;
my $file= $ipgen->ipgen_get("file_name");
$ipgen->ipgen_add("module_name",$module);
444,7 → 433,7
my @ports_order=$vdb->get_module_ports_order($module);
#print "@port_order\n";
#add deafult parameter setting
#add default parameter setting
$ipgen->ipgen_remove_all_parameters();
foreach my $p (keys %parameters){
#print "$p\n";
619,11 → 608,11
#title
my @title;
$title[0]=gen_label_in_center("Parameter name");
$title[1]=gen_label_in_center("Deafult value");
$title[1]=gen_label_in_center("Default value");
$title[2]=gen_label_help($type_info,"Widget type");
$title[3]=gen_label_help($content_info,"Widget content");
$title[4]=gen_label_help($param_info);
$title[5]=gen_label_help($redefine_info);
$title[4]=gen_label_help($param_info,"Type");
$title[5]=gen_label_help($redefine_info,"");
$title[6]=gen_label_help("You can add aditional information about this parameter.","info");
$title[7]=gen_label_in_center("add/remove");
659,8 → 648,8
my $error;
push(@parameters,"#new#");
foreach my $p (@parameters) {
my ($saved_deafult,$saved_widget_type,$saved_content,$saved_info,$vfile_param_type,$redefine_param)= $ipgen->ipgen_get_parameter_detail($p);
#print "($saved_deafult,$saved_type,$saved_content)\n";
my ($saved_default,$saved_widget_type,$saved_content,$saved_info,$vfile_param_type,$redefine_param)= $ipgen->ipgen_get_parameter_detail($p);
#print "($saved_default,$saved_type,$saved_content)\n";
my $parameter_box = def_hbox(TRUE,5);
my $param_name;
my $add_remove;
672,7 → 661,7
$add_remove=def_image_button("icons/plus.png","add");
}
 
my $deafult_entry= gen_entry($saved_deafult);
my $default_entry= gen_entry($saved_default);
my $pos=(defined $saved_widget_type ) ? get_scolar_pos( $saved_widget_type,@widget_type_list) : 0;
my $widget_type_combo=gen_combo(\@widget_type_list, $pos);
my $content_entry= gen_entry($saved_content);
703,7 → 692,7
#print "\$vfile_param_type =$vfile_param_type\n";
$col=0;
my @all_widget=($param_name,$deafult_entry,$widget_type_combo,$content_entry,$check_param,$check_redefine,$info,$add_remove);
my @all_widget=($param_name,$default_entry,$widget_type_combo,$content_entry,$check_param,$check_redefine,$info,$add_remove);
foreach my $t (@all_widget){
$table->attach ($t, $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
 
718,13 → 707,13
$ok->signal_connect (clicked => sub{
if($p ne "#new#"){
my $deafult=$deafult_entry->get_text();
my $default=$default_entry->get_text();
my $type= $widget_type_combo->get_active_text();
my $content=$content_entry->get_text();
my $vfile_param_type=$check_param->get_active_text();
my $check_result=$check_redefine->get_active();
my $redefine_param=($check_result eq 1)? 1:0;
$ipgen->ipgen_add_parameter($p,$deafult,$type,$content,$saved_info,$vfile_param_type,$redefine_param);
$ipgen->ipgen_add_parameter($p,$default,$type,$content,$saved_info,$vfile_param_type,$redefine_param);
if ($type eq "Spin-button"){
my @d=split(",",$content);
743,13 → 732,13
$param=remove_all_white_spaces($param);
if( length($param) ){
my $deafult=$deafult_entry->get_text();
my $default=$default_entry->get_text();
my $type=$widget_type_combo->get_active_text();
my $content=$content_entry->get_text();
my $vfile_param_type=$check_param->get_active_text();
my $check_result=$check_redefine->get_active();
my $redefine_param=($check_result eq 1)? 1:0;
$ipgen->ipgen_add_parameter($param,$deafult,$type,$content,$saved_info,$vfile_param_type,$redefine_param);
$ipgen->ipgen_add_parameter($param,$default,$type,$content,$saved_info,$vfile_param_type,$redefine_param);
$ipgen->ipgen_push_parameters_order($param);
set_gui_status($ipgen,"change_parameter",0);
$ok->clicked;
1600,7 → 1589,7
mkpath("$dir/lib/ip/$category/",1,01777);
open(FILE, ">lib/ip/$category/$ip_name.IP") || die "Can not open: $!";
print FILE perl_file_header("$ip_name.IP");
print FILE Data::Dumper->Dump([\%$ipgen],[$name]);
print FILE Data::Dumper->Dump([\%$ipgen],["ipgen"]);
close(FILE) || die "Error closing file: $!";
my $message="IP $ip_name has been generated successfully. In order to see the generated IP in processing tile generator you need to reset the ProNoC. Do you want to reset the ProNoC now?" ;
1771,7 → 1760,7
foreach my $p (sort keys %page_info){
my $page_ref;
$page_ref=get_file_folder($ipgen,$info,$window,$p,$page_info_ref) if($page_info{$p}{filed_type} eq "exsiting_file/folder");
$page_ref=get_file_folder($ipgen,$info,$window,$p,$page_info_ref) if($page_info{$p}{filed_type} eq "file_generators");
$page_ref=get_file_folder($ipgen,$info,$window,$p,$page_info_ref) if($page_info{$p}{filed_type} eq "file_with_variables");
$page_ref=get_file_content($ipgen,$info,$window,$page_info{$p},$page_info_ref) if($page_info{$p}{filed_type} eq "file_content");
$notebook->append_page ($page_ref,Gtk2::Label->new_with_mnemonic ($page_info{$p}{page_name}));
 
/ip_gen.pm
59,8 → 59,8
 
 
sub ipgen_add_parameter{
my ($self,$parameter,$deafult,$type,$content,$info,$global_param,$redefine)=@_;
$self->{parameters}{$parameter}{deafult}=$deafult;
my ($self,$parameter,$default,$type,$content,$info,$global_param,$redefine)=@_;
$self->{parameters}{$parameter}{"default"}=$default;
$self->{parameters}{$parameter}{type}=$type;
$self->{parameters}{$parameter}{content}=$content;
$self->{parameters}{$parameter}{info}=$info;
119,9 → 119,9
sub ipgen_get_parameter_detail{
my ($self,$parameter)=@_;
my ($deafult,$type,$content,$info,$global_param,$redefine);
my ($default,$type,$content,$info,$global_param,$redefine);
if(exists ($self->{parameters}{$parameter})){
$deafult =$self->{parameters}{$parameter}{deafult};
$default =$self->{parameters}{$parameter}{"default"};
$type =$self->{parameters}{$parameter}{type};
$content =$self->{parameters}{$parameter}{content};
$info =$self->{parameters}{$parameter}{info};
129,7 → 129,7
$redefine =$self->{parameters}{$parameter}{redefine_param};
}
return ($deafult,$type,$content,$info,$global_param,$redefine);
return ($default,$type,$content,$info,$global_param,$redefine);
}
 
sub ipgen_get_all_parameters_list{
520,8 → 520,8
 
 
sub top_add_parameter{
my ($self,$inst,$parameter,$deafult,$type,$content,$info,$global_param,$redefine)=@_;
$self->{instance_ids}{$inst}{parameters}{$parameter}{deafult}=$deafult;
my ($self,$inst,$parameter,$default,$type,$content,$info,$global_param,$redefine)=@_;
$self->{instance_ids}{$inst}{parameters}{$parameter}{"default"}=$default;
$self->{instance_ids}{$inst}{parameters}{$parameter}{type}=$type;
$self->{instance_ids}{$inst}{parameters}{$parameter}{content}=$content;
$self->{instance_ids}{$inst}{parameters}{$parameter}{info}=$info;
531,14 → 531,14
 
sub top_get_parameter{
my ($self,$inst,$parameter)=@_;
my ($deafult,$type,$content,$info,$global_param,$redefine);
$deafult=$self->{instance_ids}{$inst}{parameters}{$parameter}{deafult};
my ($default,$type,$content,$info,$global_param,$redefine);
$default=$self->{instance_ids}{$inst}{parameters}{$parameter}{"default"};
$type=$self->{instance_ids}{$inst}{parameters}{$parameter}{type};
$content=$self->{instance_ids}{$inst}{parameters}{$parameter}{content};
$info=$self->{instance_ids}{$inst}{parameters}{$parameter}{info};
$global_param=$self->{instance_ids}{$inst}{parameters}{$parameter}{global_param};
$redefine=$self->{instance_ids}{$inst}{parameters}{$parameter}{redefine_param};
return ($deafult,$type,$content,$info,$global_param,$redefine);
return ($default,$type,$content,$info,$global_param,$redefine);
}
 
sub top_get_parameter_list{
/mpsoc_gen.pl
166,16 → 166,9
return $row;
}
 
sub attach_widget_to_table {
my ($table,$row,$label,$inf_bt,$widget)=@_;
my $tmp=gen_label_in_left(" ");
$table->attach ($label , 0, 4, $row,$row+1,'fill','shrink',2,2);
$table->attach ($inf_bt , 4, 5, $row,$row+1,'fill','shrink',2,2);
$table->attach ($widget , 5, 9, $row,$row+1,'fill','shrink',2,2);
$table->attach ($tmp , 9, 10, $row,$row+1,'fill','shrink',2,2);
}
 
 
 
sub initial_default_param{
my $mpsoc=shift;
my @socs=$mpsoc->mpsoc_get_soc_list();
584,10 → 577,10
 
if($show){
$table->attach_defaults ( $button, 0, 4, $row,$row+1);
$table->attach_defaults ( $remove, 4, 5, $row,$row+1);
$table->attach_defaults ( $entry , 5, 9, $row,$row+1);
$table->attach_defaults ( $set, 9, 10, $row,$row+1);
$table->attach ( $button, 0, 1, $row,$row+1,'fill','fill',2,2);
$table->attach ( $remove, 1, 2, $row,$row+1,'fill','shrink',2,2);
$table->attach ( $entry , 2, 3, $row,$row+1,'fill','shrink',2,2);
$table->attach ( $set, 3, 4, $row,$row+1,'fill','shrink',2,2);
 
618,7 → 611,7
$box1->pack_start( $separator1, FALSE, FALSE, 3);
$box1->pack_start( $title2, FALSE, FALSE, 3);
$box1->pack_start( $separator2, FALSE, FALSE, 3);
if($show){$table->attach_defaults ($box1 ,0,10, $row,$row+1);$row++;}
if($show){$table->attach_defaults ($box1 ,0,4, $row,$row+1);$row++;}
677,10 → 670,10
if($show){
my $tmp=gen_label_in_left(" ");
$table->attach_defaults ($label, 0, 4 , $row,$row+1);
$table->attach_defaults ($tmp, 4, 5 , $row,$row+1);
$table->attach_defaults ($entry, 5, 9 , $row,$row+1);
$table->attach_defaults ($browse, 9, 10, $row,$row+1);
$table->attach ($label, 0, 1 , $row,$row+1,'fill','shrink',2,2);
$table->attach ($tmp, 1, 2 , $row,$row+1,'fill','shrink',2,2);
$table->attach ($entry, 2, 3 , $row,$row+1,'fill','shrink',2,2);
$table->attach ($browse, 3, 4, $row,$row+1,'fill','shrink',2,2);
$row++;
}
702,8 → 695,8
eg: 0,2,5:10
', ' Tile numbers ');
if($show){
$table->attach_defaults ($lab1 ,0,3, $row,$row+1);
$table->attach_defaults ($lab2 ,5,10, $row,$row+1);$row++;
$table->attach_defaults ($lab1 ,0,1, $row,$row+1);
$table->attach_defaults ($lab2 ,2,3, $row,$row+1);$row++;
}
my $soc_num=0;
729,12 → 722,11
 
#title
my $row=0;
my $title=gen_label_in_center("NoC Configuration");
my $box=def_vbox(FALSE, 1);
$box->pack_start( $title, FALSE, FALSE, 3);
my $separator = Gtk2::HSeparator->new;
$box->pack_start( $separator, FALSE, FALSE, 3);
$table->attach_defaults ($box , 0, 10, 0,1);
$table->attach ($title , 0, 4, $row, $row+1,'expand','shrink',2,2); $row++;
my $separator = Gtk2::HSeparator->new;
$table->attach ($separator , 0, 4 , $row, $row+1,'fill','fill',2,2); $row++;
 
my $label;
my $param;
742,8 → 734,8
my $type;
my $content;
my $info;
my $row=1;
#parameter start
my $b1;
my $show_noc=$mpsoc->object_get_attribute('setting','show_noc_setting');
755,8 → 747,9
if($show_noc == 0){
$b1= def_image_button("icons/down.png","NoC Parameters");
$label=gen_label_in_center(' ');
$table->attach_defaults ( $label , 2, 10, $row,$row+1);
$table->attach_defaults ( $b1 , 0, 4, $row,$row+1);$row++;
$table->attach ( $label , 2, 3, $row,$row+1 ,'fill','shrink',2,2);
$table->attach ( $b1 , 0, 2, $row,$row+1,'fill','shrink',2,2);
$row++;
}
771,30 → 764,43
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_type',1);
my $router_type=$mpsoc->object_get_attribute('noc_type',"ROUTER_TYPE");
#topology
$label='Topology';
$param='TOPOLOGY';
$default='"MESH"';
$content='"MESH","TORUS","RING","LINE"';
$type='Combo-box';
$info="NoC topology";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_param',1);
 
my $topology=$mpsoc->object_get_attribute('noc_param','TOPOLOGY');
#Routers per row
$label= 'Routers per row';
$param= 'NX';
$default=' 2';
$content='2,16,1';
$content=($topology eq '"MESH"' || $topology eq '"TORUS"') ? '2,16,1':'2,64,1';
$info= 'Number of NoC routers in row (X dimention)';
$type= 'Spin-button';
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_param',1);
 
 
#Routers per column
$label= 'Routers per column';
$param= 'NY';
$default=' 2';
$content='2,16,1';
$info= 'Number of NoC routers in column (Y dimention)';
$type= 'Spin-button';
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_param',1);
 
if($router_type eq '"VC_BASED"'){
#VC number per port
if($topology eq '"MESH"' || $topology eq '"TORUS"') {
$label= 'Routers per column';
$param= 'NY';
$default=' 2';
$content='2,16,1';
$info= 'Number of NoC routers in column (Y dimention)';
$type= 'Spin-button';
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_param',1);
} else {
$mpsoc->object_add_attribute('noc_param','NY',1);
}
#VC number per port
if($router_type eq '"VC_BASED"'){
my $v=$mpsoc->object_get_attribute('noc_param','V');
if(defined $v){ $mpsoc->object_add_attribute('noc_param','V',2) if($v eq 1);}
$label='VC number per port';
806,9 → 812,7
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_param',1);
} else {
$mpsoc->object_add_attribute('noc_param','V',1);
$mpsoc->object_add_attribute('noc_param','C',0);
$mpsoc->object_add_attribute('noc_param','C',0);
}
#buffer width per VC
829,31 → 833,25
$info="The packet payload width in bits";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info,$table,$row,$show_noc,'noc_param',undef);
 
#topology
$label='Topology';
$param='TOPOLOGY';
$default='"MESH"';
$content='"MESH","TORUS"';
$type='Combo-box';
$info="NoC topology";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_param',1);
 
#routing algorithm
my $topology=$mpsoc->object_get_attribute('noc_param','TOPOLOGY');
$label='Routing Algorithm';
$param="ROUTE_NAME";
$type="Combo-box";
if($router_type eq '"VC_BASED"'){
$content=($topology eq '"MESH"')? '"XY","WEST_FIRST","NORTH_LAST","NEGETIVE_FIRST","DUATO"' :
'"TRANC_XY","TRANC_WEST_FIRST","TRANC_NORTH_LAST","TRANC_NEGETIVE_FIRST","TRANC_DUATO"';
$content=($topology eq '"MESH"')? '"XY","WEST_FIRST","NORTH_LAST","NEGETIVE_FIRST","ODD_EVEN","DUATO"' :
($topology eq '"TORUS"')? '"TRANC_XY","TRANC_WEST_FIRST","TRANC_NORTH_LAST","TRANC_NEGETIVE_FIRST","TRANC_DUATO"':
($topology eq '"RING"')? '"TRANC_XY"' : '"XY"';
}else{
$content=($topology eq '"MESH"')? '"XY","WEST_FIRST","NORTH_LAST","NEGETIVE_FIRST"' :
'"TRANC_XY","TRANC_WEST_FIRST","TRANC_NORTH_LAST","TRANC_NEGETIVE_FIRST"';
$content=($topology eq '"MESH"')? '"XY","WEST_FIRST","NORTH_LAST","NEGETIVE_FIRST","ODD_EVEN"' :
($topology eq '"TORUS"')? '"TRANC_XY","TRANC_WEST_FIRST","TRANC_NORTH_LAST","TRANC_NEGETIVE_FIRST"':
($topology eq '"RING"')? '"TRANC_XY"' : '"XY"';
}
$default=($topology eq '"MESH"')? '"XY"':'"TRANC_XY"';
$default=($topology eq '"MESH"' || $topology eq '"LINE"' )? '"XY"':'"TRANC_XY"';
$info="Select the routing algorithm: XY(DoR) , partially adaptive (Turn models). Fully adaptive (Duato) ";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_param',1);
 
864,110 → 862,99
$default='"NO"';
$content='"YES","NO"';
$type='Combo-box';
$info="Enable single cycle latency on packets traversing in the same direction using static straight allocator (SSA)";
$info="Enable single cycle latency on packets traversing in the same direction using static straight allocator (SSA)";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$show_noc,'noc_param',undef);
 
 
 
 
 
if($show_noc == 1){
$b1= def_image_button("icons/up.png","NoC Parameters");
$table->attach_defaults ( $b1 , 0, 2, $row,$row+1);$row++;
$table->attach ( $b1 , 0, 2, $row,$row+1,'fill','shrink',2,2);
$row++;
}
$b1->signal_connect("clicked" => sub{
$show_noc=($show_noc==1)?0:1;
$mpsoc->object_add_attribute('setting','show_noc_setting',$show_noc);
set_gui_status($mpsoc,"ref",1);
 
});
 
 
#advance parameter start
my $advc;
my $adv_set=$mpsoc->object_get_attribute('setting','show_adv_setting');
if($adv_set == 0){
$advc= def_image_button("icons/down.png","Advance Parameters");
$table->attach_defaults ( $advc , 0, 4, $row,$row+1);$row++;
$table->attach ( $advc , 0, 2, $row,$row+1,'fill','shrink',2,2);
$row++;
}
#Fully and partially adaptive routing setting
my $route=$mpsoc->object_get_attribute('noc_param',"ROUTE_NAME");
$label="Congestion index";
$param="CONGESTION_INDEX";
$type="Spin-button";
$content="0,12,1";
$info="Congestion index determines how congestion information is collected from neighboring routers. Please refer to the usere manual for more information";
$default=3;
if($route ne '"XY"' and $route ne '"TRANC_XY"' ){
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',undef);
} else {
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,0,'noc_param',undef);
}
#Fully and partially adaptive routing setting
my $route=$mpsoc->object_get_attribute('noc_param',"ROUTE_NAME");
#Fully adaptive routing setting
my $v=$mpsoc->object_get_attribute('noc_param',"V");
$label="Select Escap VC";
$param="ESCAP_VC_MASK";
$type="Check-box";
$content=$v;
$default="$v\'b";
for (my $i=1; $i<=$v-1; $i++){$default= "${default}0";}
$default= "${default}1";
$info="Select the escap VC for fully adaptive routing.";
if( $route eq '"TRANC_DUATO"' or $route eq '"DUATO"' ){
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set, 'noc_param',undef);
}
else{
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,0, 'noc_param',undef);
}
$label="Congestion index";
$param="CONGESTION_INDEX";
$type="Spin-button";
$content="0,12,1";
$info="Congestion index determines how congestion information is collected from neighboring routers. Please refer to the usere manual for more information";
$default=3;
if($route ne '"XY"' and $route ne '"TRANC_XY"' ){
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',undef);
} else {
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,0,'noc_param',undef);
}
#Fully adaptive routing setting
my $v=$mpsoc->object_get_attribute('noc_param',"V");
$label="Select Escap VC";
$param="ESCAP_VC_MASK";
$type="Check-box";
$content=$v;
$default="$v\'b";
for (my $i=1; $i<=$v-1; $i++){$default= "${default}0";}
$default= "${default}1";
$info="Select the escap VC for fully adaptive routing.";
if( $route eq '"TRANC_DUATO"' or $route eq '"DUATO"' ){
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set, 'noc_param',undef);
}
else{
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,0, 'noc_param',undef);
}
# VC reallocation type
$label=($router_type eq '"VC_BASED"')? 'VC reallocation type': 'Queue reallocation type';
$param='VC_REALLOCATION_TYPE';
$info="VC reallocation type: If set as atomic only empty VCs can be allocated for new packets. Whereas, in non-atomic a non-empty VC which has received the last packet tail flit can accept a new packet";
$default='"NONATOMIC"';
$content='"ATOMIC","NONATOMIC"';
$type='Combo-box';
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',undef);
$label=($router_type eq '"VC_BASED"')? 'VC reallocation type': 'Queue reallocation type';
$param='VC_REALLOCATION_TYPE';
$info="VC reallocation type: If set as atomic only empty VCs can be allocated for new packets. Whereas, in non-atomic a non-empty VC which has received the last packet tail flit can accept a new packet";
$default='"NONATOMIC"';
$content='"ATOMIC","NONATOMIC"';
$type='Combo-box';
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',undef);
 
 
 
 
#vc/sw allocator type
$label = 'VC/SW combination type';
$param='COMBINATION_TYPE';
$default='"COMB_NONSPEC"';
$content='"BASELINE","COMB_SPEC1","COMB_SPEC2","COMB_NONSPEC"';
$type='Combo-box';
$info="The joint VC/ switch allocator type. using canonical combination is not recommanded";
$label = 'VC/SW combination type';
$param='COMBINATION_TYPE';
$default='"COMB_NONSPEC"';
$content='"BASELINE","COMB_SPEC1","COMB_SPEC2","COMB_NONSPEC"';
$type='Combo-box';
$info="The joint VC/ switch allocator type. using canonical combination is not recommanded";
if ($router_type eq '"VC_BASED"'){
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',undef);
 
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',undef);
} else{
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,0,'noc_param',undef);
 
}
# Crossbar mux type
$label='Crossbar mux type';
$param='MUX_TYPE';
$default='"BINARY"';
$content='"ONE_HOT","BINARY"';
$type='Combo-box';
$info="Crossbar multiplexer type";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',undef);
$label='Crossbar mux type';
$param='MUX_TYPE';
$default='"BINARY"';
$content='"ONE_HOT","BINARY"';
$type='Combo-box';
$info="Crossbar multiplexer type";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',undef);
#class
if($router_type eq '"VC_BASED"'){
#class
$label='class number';
$param='C';
$default= 0;
992,29 → 979,23
$content=$v;
$info="Select the permitted VCs which the message class $i can be sent via them.";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'class_param',undef);
 
 
}
 
 
}#($router_type eq '"VC_BASED"')
 
#simulation debuge enable
$label='Debug enable';
$param='DEBUG_EN';
$info= "Add extra verilog code for debuging NoC for simulation";
$default='0';
$content='0,1';
$type='Combo-box';
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param');
#simulation debuge enable
$label='Debug enable';
$param='DEBUG_EN';
$info= "Add extra verilog code for debuging NoC for simulation";
$default='0';
$content='0,1';
$type='Combo-box';
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param');
 
 
 
#pipeline reg
$label="Add pipeline reg after crossbar";
$param="ADD_PIPREG_AFTER_CROSSBAR";
$type="Check-box";
1022,15 → 1003,60
$default="1\'b0";
$info="If enabeled it adds a pipline register at the output port of the router.";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param');
#FIRST_ARBITER_EXT_P_EN
$label='Swich allocator first level
arbiters extenal priority enable';
$param='FIRST_ARBITER_EXT_P_EN';
$default= 1;
$info='If set as 1 then the switch allocator\'s input (first) arbiters\' priority registers are enabled only when a request get both input and output arbiters\' grants';
$content='0,1';
$type="Combo-box";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info,$table,$row,$adv_set,'noc_param');
#Arbiter type
$label='SW allocator arbiteration type';
$param='SWA_ARBITER_TYPE';
$default='"RRA"';
$content='"RRA","WRRA"'; #,"WRRA_CLASSIC"';
$type='Combo-box';
$info="Switch allocator arbitertion type:
RRA: Round robin arbiter. Only local fairness in a router.
WRRA: Weighted round robin arbiter. Results in global fairness in the NoC.
Switch allocation requests are grated acording to their weight which increases due to contention";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$adv_set,'noc_param',1);
my $arbiter=$mpsoc->object_get_attribute('noc_param',"SWA_ARBITER_TYPE");
my $wrra_show = ($arbiter ne '"RRA"' && $adv_set == 1 )? 1 : 0;
# weight width
$label='Weight width';
$param='WEIGHTw';
$default='4';
$content='2,7,1';
$info= 'Maximum weight width';
$type= 'Spin-button';
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$wrra_show,'noc_param',undef);
#WRRA_CONFIG_INDEX
$label='Weight configuration index';
$param='WRRA_CONFIG_INDEX';
$default='0';
$content='0,7,1';
$info= 'WRRA_CONFIG_INDEX:
 
';
$type= 'Spin-button';
#$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info, $table,$row,$wrra_show,'noc_param',undef);
if($adv_set == 1){
$advc= def_image_button("icons/up.png","Advance Parameters");
$table->attach_defaults ( $advc , 0, 4, $row,$row+1);$row++;
$table->attach ( $advc , 0, 2, $row,$row+1,'fill','shrink',2,2);
$row++;
}
$advc->signal_connect("clicked" => sub{
$adv_set=($adv_set==1)?0:1;
1041,15 → 1067,9
#other fixed parameters
 
#FIRST_ARBITER_EXT_P_EN
$label='FIRST_ARBITER_EXT_P_EN';
$param='FIRST_ARBITER_EXT_P_EN';
$default= 0;
$info='FIRST_ARBITER_EXT_P_EN';
$content='0,1';
$type="Combo-box";
$row=noc_param_widget ($mpsoc,$label,$param, $default,$type,$content,$info,$table,$row,0,'noc_param');
1115,7 → 1135,8
if($show == 0){
$tile_set= def_image_button("icons/down.png","Tiles setting");
$table->attach_defaults ( $tile_set , 0, 4, $row,$row+1);$row++;
$table->attach ( $tile_set , 0, 2, $row,$row+1,'fill','shrink',2,2);
$row++;
}
1135,7 → 1156,8
#end tile setting
if($show == 1){
$tile_set= def_image_button("icons/up.png","Tiles setting");
$table->attach_defaults ( $tile_set , 0, 1, $row,$row+1);$row++;
$table->attach ( $tile_set , 0, 2, $row,$row+1,'fill','shrink',2,2);
$row++;
}
$tile_set->signal_connect("clicked" => sub{
$show=($show==1)?0:1;
1148,11 → 1170,11
 
 
for(my $i=$row; $i<25; $i++){
my $empty_col=gen_label_in_left(' ');
$table->attach_defaults ($empty_col , 0, 1, $i,$i+1);
#for(my $i=$row; $i<25; $i++){
#my $empty_col=gen_label_in_left(' ');
#$table->attach_defaults ($empty_col , 0, 1, $i,$i+1);
 
}
#}
 
1252,7 → 1274,7
# Write object file
open(FILE, ">lib/soc/$soc_name.SOC") || die "Can not open: $!";
print FILE perl_file_header("$soc_name.SOC");
print FILE Data::Dumper->Dump([\%$soc],['mpsoc']);
print FILE Data::Dumper->Dump([\%$soc],['soc']);
close(FILE) || die "Error closing file: $!";
# Write verilog file
1300,7 → 1322,7
# Write header file
generate_header_file($soc,$project_dir,$target_dir,$dir);
generate_header_file($soc,$project_dir,$target_dir,$target_dir,$dir);
1325,7 → 1347,7
$mpsoc->mpsoc_remove_all_soc_tops();
open(FILE, ">lib/mpsoc/$name.MPSOC") || die "Can not open: $!";
print FILE perl_file_header("$name.MPSOC");
print FILE Data::Dumper->Dump([\%$mpsoc],[$name]);
print FILE Data::Dumper->Dump([\%$mpsoc],['mpsoc']);
close(FILE) || die "Error closing file: $!";
get_soc_list($mpsoc,$info);
1437,11 → 1459,13
#!/bin/sh
 
 
JTAG_MAIN="$PRONOC_WORK/toolchain/bin/jtag_main"
#JTAG_INTFC="$PRONOC_WORK/toolchain/bin/JTAG_INTFC"
source ./jtag_intfc.sh
 
 
#reset and disable cpus, then release the reset but keep the cpus disabled
 
$JTAG_MAIN -n 127 -d "I:1,D:2:3,D:2:2,I:0"
$JTAG_INTFC -n 127 -d "I:1,D:2:3,D:2:2,I:0"
 
# jtag instruction
# 0: bypass
1464,7 → 1488,7
done
#Enable the cpu
$JTAG_MAIN -n 127 -d "I:1,D:2:0,I:0"
$JTAG_INTFC -n 127 -d "I:1,D:2:0,I:0"
# I:1 set jtag_enable in active mode
# D:2:0 load jtag_enable data register with 0x0 reset=0 disable=0
# I:0 set jtag_enable in bypass mode
1587,11 → 1611,13
my ($soc_name,$num)= $mpsoc->mpsoc_get_tile_soc_name($tile);
my $button;
my $topology=$mpsoc->object_get_attribute('noc_param','TOPOLOGY');
my $cordibate = ($topology eq '"RING"' || $topology eq '"LINE"' ) ? "" : "($x,$y)";
if( defined $soc_name){
my $setting=$mpsoc->mpsoc_get_tile_param_setting($tile);
$button=($setting eq 'Custom')? def_colored_button("Tile $tile ($x,$y)*\n$soc_name",$num) : def_colored_button("Tile $tile ($x,$y)\n$soc_name",$num) ;
$button=($setting eq 'Custom')? def_colored_button("Tile $tile ${cordibate}*\n$soc_name",$num) : def_colored_button("Tile $tile ${cordibate}\n$soc_name",$num) ;
}else {
$button =def_colored_button("Tile $tile ($x,$y)\n",50) if(! defined $soc_name);
$button =def_colored_button("Tile $tile ${cordibate}\n",50) if(! defined $soc_name);
}
$button->signal_connect("clicked" => sub{
1710,9 → 1736,7
 
#print "($nx,$ny);\n";
my $table=def_table($nx,$ny,FALSE);# my ($row,$col,$homogeneous)=@_;
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->add_with_viewport($table);
 
 
 
1728,9 → 1752,14
 
 
}}
return $table;
}
 
 
 
 
 
 
sub software_edit_mpsoc {
my $self=shift;
my $name=$self->object_get_attribute('mpsoc_name');
1753,6 → 1782,7
 
$make -> signal_connect("clicked" => sub{
$app->do_save();
apend_to_textview($tview,' ');
run_make_file($sw,$tview);
 
});
1761,10 → 1791,68
 
 
 
#############
# load_mpsoc
#############
 
sub load_mpsoc{
my ($mpsoc,$info)=@_;
my $file;
my $dialog = Gtk2::FileChooserDialog->new(
'Select a File', undef,
'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok',
);
 
my $filter = Gtk2::FileFilter->new();
$filter->set_name("MPSoC");
$filter->add_pattern("*.MPSOC");
$dialog->add_filter ($filter);
my $dir = Cwd::getcwd();
$dialog->set_current_folder ("$dir/lib/mpsoc") ;
my @newsocs=$mpsoc->mpsoc_get_soc_list();
add_info(\$info,'');
if ( "ok" eq $dialog->run ) {
$file = $dialog->get_filename;
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
if($suffix eq '.MPSOC'){
my $pp= eval { do $file };
if ($@ || !defined $pp){
add_info(\$info,"**Error: cannot open $file file: $@\n");
$dialog->destroy;
return;
}
 
clone_obj($mpsoc,$pp);
#read save mpsoc socs
my @oldsocs=$mpsoc->mpsoc_get_soc_list();
#add exsiting SoCs and add them to mpsoc
my $error;
#print "old: @oldsocs\n new @newsocs \n";
foreach my $p (@oldsocs) {
#print "$p\n";
my @num= $mpsoc->mpsoc_get_soc_tiles_num($p);
if (scalar @num && ( grep (/^$p$/,@newsocs)==0)){
my $m="Processing tile $p that has been used for ties @num but is not located in librray anymore\n";
$error = (defined $error ) ? "$error $m" : $m;
}
$mpsoc->mpsoc_remove_soc ($p) if (grep (/^$p$/,@newsocs)==0);
 
}
@newsocs=get_soc_list($mpsoc,$info); # add all existing socs
add_info(\$info,"**Error: \n $error\n") if(defined $error);
 
set_gui_status($mpsoc,"load_file",0);
}
}
$dialog->destroy;
}
 
############
# main
############
1772,24 → 1860,16
my $infc = interface->interface_new();
my $soc = ip->lib_new ();
#my $soc = soc->soc_new();
 
my $mpsoc= mpsoc->mpsoc_new();
set_gui_status($mpsoc,"ideal",0);
# main window
#my $window = def_win_size(1000,800,"Top");
# The main table containg the lib tree, selected modules and info section
my $main_table = Gtk2::Table->new (25, 12, FALSE);
# The box which holds the info, warning, error ... mesages
my ($infobox,$info)= create_text();
my $refresh = Gtk2::Button->new_from_stock('ref');
my $noc_conf_box=get_config ($mpsoc,$info);
my $noc_tiles=gen_tiles($mpsoc);
 
1796,74 → 1876,35
my $scr_conf = new Gtk2::ScrolledWindow (undef, undef);
$scr_conf->set_policy( "automatic", "automatic" );
$scr_conf->add_with_viewport($noc_conf_box);
my $scr_tile = new Gtk2::ScrolledWindow (undef, undef);
$scr_tile->set_policy( "automatic", "automatic" );
$scr_tile->add_with_viewport($noc_tiles);
 
$main_table->set_row_spacings (4);
$main_table->set_col_spacings (1);
#my $device_win=show_active_dev($soc,$soc,$infc,\$refresh,$info);
my $generate = def_image_button('icons/gen.png','Generate');
my $generate = def_image_button('icons/gen.png','Generate RTL');
my $open = def_image_button('icons/browse.png','Load MPSoC');
my $compile = def_image_button('icons/run.png','Compile');
my $compile = def_image_button('icons/gate.png','Compile RTL');
my $software = def_image_button('icons/binary.png','Software');
my $entry=gen_entry_object($mpsoc,'mpsoc_name',undef,undef,undef,undef);
my $entrybox=labele_widget_info(" MPSoC name:",$entry);
#$table->attach_defaults ($event_box, $col, $col+1, $row, $row+1);
#$main_table->attach_defaults ($noc_conf_box , 0, 4, 0, 22);
#$main_table->attach_defaults ($noc_tiles , 4, 12, 0, 22);
#$main_table->attach_defaults ($infobox , 0, 12, 22,24);
my $h1=gen_hpaned($scr_conf,.3,$scr_tile);
my $v2=gen_vpaned($h1,.55,$infobox);
 
my $h1=gen_hpaned($scr_conf,.3,$noc_tiles);
my $v2=gen_vpaned($h1,.55,$infobox);
$main_table->attach_defaults ($v2 , 0, 12, 0,24);
 
 
 
 
 
$main_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
$main_table->attach_defaults ($entrybox,3, 7, 24,25);
$main_table->attach ($generate, 8, 9, 24,25,'expand','shrink',2,2);
$main_table->attach ($software, 9, 10, 24,25,'expand','shrink',2,2);
$main_table->attach ($compile, 10, 12, 24,25,'expand','shrink',2,2);
 
#referesh the mpsoc generator
$refresh-> signal_connect("clicked" => sub{
$noc_conf_box->destroy();
$noc_conf_box=get_config ($mpsoc,$info);
$scr_conf->add_with_viewport($noc_conf_box);
#$main_table->attach_defaults ($noc_conf_box , 0, 4, 0, 22);
#$noc_conf_box->show_all();
 
 
$noc_tiles->destroy();
$noc_tiles=gen_tiles($mpsoc);
#$h1->destroy();
#$h1=gen_hpaned($noc_conf_box,.3,$noc_tiles);
$h1 -> pack1($scr_conf, TRUE, TRUE);
$h1 -> pack2($noc_tiles, TRUE, TRUE);
$v2-> pack1($h1, TRUE, TRUE);
$h1->show_all;
#$main_table->attach_defaults ($noc_tiles , 4, 12, 0, 22);
 
$main_table->show_all();
 
 
});
 
 
 
#check soc status every 0.5 second. referesh device table if there is any changes
Glib::Timeout->add (100, sub{
my ($state,$timeout)= get_gui_status($mpsoc);
1882,7 → 1923,17
set_gui_status($mpsoc,"ideal",0);
}
elsif( $state ne "ideal" ){
$refresh->clicked;
$noc_conf_box->destroy();
$noc_conf_box=get_config ($mpsoc,$info);
$scr_conf->add_with_viewport($noc_conf_box);
$noc_tiles->destroy();
$noc_tiles=gen_tiles($mpsoc);
$scr_tile->add_with_viewport($noc_tiles);
$h1 -> pack1($scr_conf, TRUE, TRUE);
$h1 -> pack2($scr_tile, TRUE, TRUE);
$v2-> pack1($h1, TRUE, TRUE);
$h1->show_all;
$main_table->show_all();
my $saved_name=$mpsoc->object_get_attribute('mpsoc_name');
if(defined $saved_name) {$entry->set_text($saved_name);}
set_gui_status($mpsoc,"ideal",0);
1896,14 → 1947,10
$generate-> signal_connect("clicked" => sub{
generate_mpsoc($mpsoc,$info);
$refresh->clicked;
set_gui_status($mpsoc,"refresh_soc",1);
 
});
 
# $wb-> signal_connect("clicked" => sub{
# wb_address_setting($mpsoc);
#
# });
 
$open-> signal_connect("clicked" => sub{
set_gui_status($mpsoc,"ref",5);
1913,6 → 1960,7
 
 
$compile -> signal_connect("clicked" => sub{
$mpsoc->object_add_attribute('compile','compilers',"QuartusII,Verilator,Modelsim");
my $name=$mpsoc->object_get_attribute('mpsoc_name');
if (length($name)==0){
message_dialog("Please define the MPSoC name!");
1946,77 → 1994,7
 
 
 
return $scrolled_win;
}
 
 
 
 
#############
# load_mpsoc
#############
 
sub load_mpsoc{
my ($mpsoc,$info)=@_;
my $file;
my $dialog = Gtk2::FileChooserDialog->new(
'Select a File', undef,
'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok',
);
 
my $filter = Gtk2::FileFilter->new();
$filter->set_name("MPSoC");
$filter->add_pattern("*.MPSOC");
$dialog->add_filter ($filter);
my $dir = Cwd::getcwd();
$dialog->set_current_folder ("$dir/lib/mpsoc") ;
my @newsocs=$mpsoc->mpsoc_get_soc_list();
add_info(\$info,'');
if ( "ok" eq $dialog->run ) {
$file = $dialog->get_filename;
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
if($suffix eq '.MPSOC'){
my $pp= eval { do $file };
if ($@ || !defined $pp){
add_info(\$info,"**Error: cannot open $file file: $@\n");
$dialog->destroy;
return;
}
 
clone_obj($mpsoc,$pp);
#read save mpsoc socs
my @oldsocs=$mpsoc->mpsoc_get_soc_list();
#add exsiting SoCs and add them to mpsoc
my $error;
#print "old: @oldsocs\n new @newsocs \n";
foreach my $p (@oldsocs) {
#print "$p\n";
my @num= $mpsoc->mpsoc_get_soc_tiles_num($p);
if (scalar @num && ( grep (/^$p$/,@newsocs)==0)){
my $m="Processing tile $p that has been used for ties @num but is not located in librray anymore\n";
$error = (defined $error ) ? "$error $m" : $m;
}
$mpsoc->mpsoc_remove_soc ($p) if (grep (/^$p$/,@newsocs)==0);
 
}
@newsocs=get_soc_list($mpsoc,$info); # add all existing socs
add_info(\$info,"**Error: \n $error\n") if(defined $error);
 
set_gui_status($mpsoc,"load_file",0);
}
}
$dialog->destroy;
 
 
 
 
}
 
 
/mpsoc_verilog_gen.pl
115,7 → 115,7
 
localparam Fw = 2+V+Fpay,
NC = (TOPOLOGY=="RING")? NX : NX*NY, //number of cores
NC = (TOPOLOGY=="RING" || TOPOLOGY=="LINE" )? NX : NX*NY, //number of cores
Xw = log2(NX),
Yw = log2(NY) ,
Cw = (C>1)? log2(C): 1,
/simulator.pl
21,6 → 21,7
require "emulator.pl";
require "mpsoc_verilog_gen.pl";
require "readme_gen.pl";
require "graph.pl";
 
use List::MoreUtils qw(uniq);
 
29,50 → 30,95
 
sub generate_sim_bin_file() {
my ($simulate,$info_text) =@_;
$simulate->object_add_attribute('status',undef,'run');
set_gui_status($simulate,"ref",1);
my $target_dir= "$ENV{PRONOC_WORK}/simulate";
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/..");
my $src_verilator_dir="$project_dir/src_verilator";
my $src_noc_dir="$project_dir/src_noc";
my $script_dir="$project_dir/script";
# save parameters inside parameter.v file in src_verilator folder
my $testbench_file= "$src_verilator_dir/simulator.cpp";
my $src_verilog_dr ="$target_dir/src_verilog";
my $obj_dir ="$target_dir/verilator/processed_rtl/obj_dir/";
rmtree("$src_verilog_dr");
mkpath("$src_verilog_dr/",1,01777);
#copy src_verilator files
my @files=(
$src_noc_dir,
"$src_verilator_dir/noc_connection.sv",
"$src_verilator_dir/router_verilator.v",
"$src_verilator_dir/traffic_gen_verilator.v"
);
copy_file_and_folders (\@files,$project_dir,$src_verilog_dr);
# generate NoC parameter file
my ($noc_param,$pass_param)=gen_noc_param_v($simulate);
open(FILE, ">$src_verilator_dir/parameter.v") || die "Can not open: $!";
open(FILE, ">$src_verilog_dr/parameter.v") || die "Can not open: $!";
my $fifow=$simulate->object_get_attribute('fpga_param','TIMSTMP_FIFO_NUM');
 
 
 
print FILE " \`ifdef INCLUDE_PARAM \n \n
$noc_param
localparam P=(TOPOLOGY==\"RING\")? 3 : 5;
$noc_param
/* verilator lint_off WIDTH */
localparam P=(TOPOLOGY==\"RING\" || TOPOLOGY==\"LINE\")? 3 : 5;
localparam ROUTE_TYPE = (ROUTE_NAME == \"XY\" || ROUTE_NAME == \"TRANC_XY\" )? \"DETERMINISTIC\" :
(ROUTE_NAME == \"DUATO\" || ROUTE_NAME == \"TRANC_DUATO\" )? \"FULL_ADAPTIVE\": \"PAR_ADAPTIVE\";
/* verilator lint_on WIDTH */
//simulation parameter
localparam MAX_RATIO = ".MAX_RATIO.";
localparam MAX_PCK_NUM = ".MAX_SIM_CLKs.";
localparam MAX_PCK_SIZ = ".MAX_PCK_SIZ.";
localparam MAX_SIM_CLKs= ".MAX_SIM_CLKs.";
localparam TIMSTMP_FIFO_NUM = 16;
localparam TIMSTMP_FIFO_NUM = $fifow;
\n \n \`endif" ;
close FILE;
my %tops = (
"Vrouter" => "router_verilator.v",
"Vnoc" => "noc_connection.sv",
"Vtraffic"=> "traffic_gen_verilator.v"
);
my $result = verilator_compilation (\%tops,$target_dir,$$info_text);
if ($result){
add_colored_info($info_text,"Veriator model has been generated successfully!\n",'blue');
}else {
add_colored_info($info_text,"Verilator compilation failed!\n","red");
$simulate->object_add_attribute('status',undef,'programer_failed');
set_gui_status($simulate,"ref",1);
return;
}
#verilate the noc
my $command = "rm -f $script_dir/logfile1.txt $script_dir/logfile2.txt";
my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $command);
my $start = localtime;
add_info($info_text, "verilate the NoC and make the library files");
$command = "cd \"$script_dir/\" \n xterm -l -lf logfile1.txt -e sh verilator_compile_hw.sh";
($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $command);
if($exit != 0){
print "Verilator compilation failed !\n";
add_info($info_text, "Verilator compilation failed !\n$command\n $stdout\n");
return;
}
 
 
@files=(
"$src_verilator_dir/traffic_task_graph.h",
);
 
copy_file_and_folders (\@files,$project_dir,$obj_dir);
copy($testbench_file,"$obj_dir/testbench.cpp");
#compile the testbench
my $param_h=gen_noc_param_h($simulate);
$param_h =~ s/\d\'b/ /g;
open(FILE, ">$src_verilator_dir/parameter.h") || die "Can not open: $!";
open(FILE, ">$obj_dir/parameter.h") || die "Can not open: $!";
print FILE "
#ifndef INCLUDE_PARAM
#define INCLUDE_PARAM \n \n
79,45 → 125,58
 
$param_h
int P=(strcmp (TOPOLOGY,\"RING\")==0) ? 3 : 5;
int P=(strcmp (TOPOLOGY,\"RING\")==0 || strcmp (TOPOLOGY,\"LINE\")==0 ) ? 3 : 5;
//simulation parameter
#define MAX_RATIO ".MAX_RATIO."
#define AVG_LATENCY_METRIC \"HEAD_2_TAIL\"
#define TIMSTMP_FIFO_NUM 16
#define TIMSTMP_FIFO_NUM $fifow
\n \n \#endif" ;
close FILE;
$command = "cd \"$script_dir/\" \n xterm -l -lf logfile2.txt -e sh verilator_compile_simulator.sh";
($stdout,$exit)=run_cmd_in_back_ground_get_stdout( $command);
if($exit != 0){
print "Verilator compilation failed !\n";
add_info($info_text, "Verilator compilation failed !\n$command\n $stdout\n");
$result = run_make_file("$obj_dir/",$$info_text,'lib');
if ($result ==0){
$simulate->object_add_attribute('status',undef,'programer_failed');
set_gui_status($simulate,"ref",1);
return;
}
my $end = localtime;
}
run_make_file("$obj_dir/",$$info_text);
if ($result ==0){
$simulate->object_add_attribute('status',undef,'programer_failed');
set_gui_status($simulate,"ref",1);
return;
}
#my $end = localtime;
 
#save the binarry file
my $bin= "$ENV{PRONOC_WORK}/verilator/work/processed_rtl/obj_dir/testbench";
my $bin= "$obj_dir/testbench";
my $path=$simulate->object_get_attribute ('sim_param',"BIN_DIR");
my $name=$simulate->object_get_attribute ('sim_param',"SAVE_NAME");
#create project directory if its not exist
($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $path" );
#create project directory if it does not exist
my ($stdout,$exit)=run_cmd_in_back_ground_get_stdout("mkdir -p $path" );
if($exit != 0 ){ print "$stdout\n"; message_dialog($stdout,'error'); return;}
#move the log file
unlink "$path/$name.log";
append_text_to_file("$path/$name.log","start:$start\n");
merg_files("$script_dir/logfile1.txt" , "$path/$name.log");
merg_files("$script_dir/logfile2.txt" , "$path/$name.log");
append_text_to_file("$path/$name.log","end:$end\n");
 
#check if the verilation was successful
if ((-e $bin)==0) {#something goes wrong
message_dialog("Verilator compilation was unsuccessful please check the $path/$name.log files for more information",'error');
return;
#message_dialog("Verilator compilation was unsuccessful please check the $path/$name.log files for more information",'error');
add_colored_info($info_text,"Verilator compilation failed!\n","red");
$simulate->object_add_attribute('status',undef,'programer_failed');
set_gui_status($simulate,"ref",1);
return;
}
136,7 → 195,8
 
message_dialog("The simulation binary file has been successfully generated in $path!");
 
 
$simulate->object_add_attribute('status',undef,'ideal');
set_gui_status($simulate,"ref",1);
#make project dir
#my $dir= $simulate->object_get_attribute ("sim_param","BIN_DIR");
#my $name=$simulate->object_get_attribute ("sim_param","SAVE_NAME");
166,7 → 226,7
# Write object file
open(FILE, ">lib/simulate/$name.SIM") || die "Can not open: $!";
print FILE perl_file_header("$name.SIM");
print FILE Data::Dumper->Dump([\%$simulate],[$name]);
print FILE Data::Dumper->Dump([\%$simulate],["simulate"]);
close(FILE) || die "Error closing file: $!";
message_dialog("Simulation has saved as lib/simulate/$name.SIM!");
return 1;
206,10 → 266,10
}
#deactivate running simulations
$pp->object_add_attribute('status',undef,'ideal');
my $sample_num=$pp->object_get_attribute("emulate_num",undef);
for (my $i=1; $i<=$sample_num; $i++){
my $st=$pp->object_get_attribute ("sample$i","status");
$pp->object_add_attribute ("sample$i","status",'done');# if ($st eq "run");
my @samples =$pp->object_get_attribute_order("samples");
foreach my $sample (@samples){
my $st=$pp->object_get_attribute ($sample,"status");
$pp->object_add_attribute ($sample,"status",'done');# if ($st eq "run");
}
clone_obj($simulate,$pp);
#message_dialog("done!");
219,7 → 279,629
}
 
 
 
sub gen_custom_traffic {
my ($self,$info,$mode)=@_;
my $table=def_table(20,10,FALSE);
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->add_with_viewport($table);
my $row=0;
#page title
my $title_l = "Custom Traffic Generator";
my $title=gen_label_in_center($title_l);
$table->attach ($title , 0, 10, $row, $row+1,'expand','shrink',2,2); $row++;
my $separator = Gtk2::HSeparator->new;
$table->attach ($separator , 0, 10 , $row, $row+1,'fill','fill',2,2); $row++;
#fileds title
my @positions=(0,1,2,3,4,5,6);
my $col=0;
my @title=("Traffic name", " Add/Remove "," Edit ");
foreach my $t (@title){
$table->attach (gen_label_in_center($title[$col]), $positions[$col], $positions[$col+1], $row, $row+1,'expand','shrink',2,2);$col++;
}
$row++;
#create new traffic
my $add=def_image_button("icons/plus.png", );
$table->attach ($add, $positions[1], $positions[2], $row, $row+1,'expand','shrink',2,2);
 
$add->signal_connect("clicked"=> sub{
generate_new_traffic ($self);
});
return $scrolled_win;
}
 
 
 
 
 
 
sub generate_new_traffic {
my $self=shift;
my $window = def_popwin_size(40,40,"Step 2: Compile",'percent');
my $table = def_table(10, 10, FALSE);
my @info = (
{ label=>'Traffic_name', param_name=>'CUSTOM_NAME', type=>"Entry", default_val=>undef, content=>undef, info=>undef, param_parent=>'traffic_param', ref_delay=> undef},
{ label=>'Routers per Row', param_name=>'CUSTOM_X', type=>"Spin-button", default_val=>2, content=>"2,64,1", info=>undef, param_parent=>'traffic_param', ref_delay=>undef},
{ label=>"Routers per Column", param_name=>"CUSTOM_Y", type=>"Spin-button", default_val=>2, content=>"1,64,1", info=>undef, param_parent=>'traffic_param',ref_delay=>undef },
);
my $row=0;
my $col=0;
foreach my $d (@info) {
($row,$col)=add_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,$col,1, $d->{param_parent}, $d->{ref_delay},undef,"vertical");
}
$row++;
my $next=def_image_button('icons/run.png','Next');
my $back=def_image_button('icons/left.png','Previous');
$col=1;
my $i;
for ($i=$row; $i<5; $i++){
my $temp=gen_label_in_center(" ");
$table->attach_defaults ($temp, 3, 4 , $i, $i+1);
}
$row=$i;
#$table->attach($back,2,3,9,10,'shrink','shrink',2,2);
$table->attach($next,3,4,$row,$row+1,'shrink','shrink',2,2);
 
 
$back-> signal_connect("clicked" => sub{
$window->destroy;
});
$next-> signal_connect("clicked" => sub{
$window->destroy;
});
 
 
 
$window->add ($table);
$window->show_all();
 
 
 
}
 
 
sub check_hotspot_parameters{
my ($self,$sample)=@_;
my $num=$self->object_get_attribute($sample,"HOTSPOT_NUM");
my $result;
if (defined $num){
my @hotspots;
my $acuum=0;
for (my $i=0;$i<$num;$i++){
my $w1 = $self->object_get_attribute($sample,"HOTSPOT_CORE_$i");
if( grep (/^\Q$w1\E$/,@hotspots)){
$result="Error: Tile $w1 has been selected for Two or more than two hotspot nodes.\n";
}
push( @hotspots,$w1);
my $w2 = $self->object_get_attribute($sample,"HOTSPOT_PERCENT_$i");
$acuum+=$w2;
}
if ($acuum > 100){
$result="Error: The traffic sumation of all hotspot nodes is $acuum. The hotspot sumation must be <=100";
}
}
return $result;
}
 
 
sub get_simulator_noc_configuration{
my ($self,$mode,$sample,$set_win) =@_;
my $table=def_table(10,2,FALSE);
my $row=0;
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->add_with_viewport($table);
my $ok = def_image_button('icons/select.png','OK');
my $mtable = def_table(10, 1, TRUE);
 
$mtable->attach_defaults($scrolled_win,0,1,0,9);
$mtable-> attach ($ok , 0, 1, 9, 10,'expand','shrink',2,2);
 
$set_win ->signal_connect (destroy => sub{
$self->object_add_attribute("active_setting",undef,undef);
});
my $dir = Cwd::getcwd();
my $open_in = abs_path("$ENV{PRONOC_WORK}/simulate");
attach_widget_to_table ($table,$row,gen_label_in_left(" Search Path:"),gen_button_message ("Select the the Path where the verilator simulation files are located. Different NoC verilated models can be generated using Generate NoC configuration tab.","icons/help.png"),
get_dir_in_object ($self,$sample,"sof_path",undef,'ref_set_win',1,$open_in)); $row++;
$open_in = $self->object_get_attribute($sample,"sof_path");
my @files = glob "$open_in/*";
my $exe_files="";
foreach my $file (@files){
#print "$file is executable\n" if( -x $file && -f $file) ;
if( -x $file && -f $file){
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
$exe_files="$exe_files,$name"
}
}
attach_widget_to_table ($table,$row,gen_label_in_left(" Verilated Model:"),gen_button_message ("Select the verilator simulation file. Different NoC simulators can be generated using Generate NoC configuration tab.","icons/help.png"),
gen_combobox_object ($self,$sample, "sof_file", $exe_files, undef, undef, undef)); $row++;
 
$row=noc_param_widget ($self, "Traffic Type", "TRAFFIC_TYPE", "Synthetic", 'Combo-box', "Synthetic,Task-graph", undef, $table,$row,1, $sample, 1,'ref_set_win');
 
my $traffictype=$self->object_get_attribute($sample,"TRAFFIC_TYPE");
 
 
 
if($traffictype eq "Synthetic"){
my $min=$self->object_get_attribute($sample,'MIN_PCK_SIZE');
my $max=$self->object_get_attribute($sample,'MAX_PCK_SIZE');
$min=$max=5 if(!defined $min);
my $avg=floor(($min+$max)/2);
my $traffics="tornado,transposed 1,transposed 2,bit reverse,bit complement,random,hot spot";
my @synthinfo = (
{ label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>$sample, content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>$sample, ref_delay=> undef, new_status=>undef},
{ label=>"Traffic name", param_name=>'traffic', type=>'Combo-box', default_val=>'random', content=>$traffics, info=>"Select traffic pattern", param_parent=>$sample, ref_delay=>1, new_status=>'ref_set_win'},
{ label=>"Min pck size :", param_name=>'MIN_PCK_SIZE', type=>'Spin-button', default_val=>5, content=>"2,$max,1", info=>"Minimum packet size in flit. The injected packet size is randomly selected between minimum and maximum packet size", param_parent=>$sample, ref_delay=>10, new_status=>'ref_set_win'},
{ label=>"Max pck size :", param_name=>'MAX_PCK_SIZE', type=>'Spin-button', default_val=>5, content=>"$min,".MAX_PCK_SIZ.",1", info=>"Maximum packet size in flit. The injected packet size is randomly selected between minimum and maximum packet size", param_parent=>$sample, ref_delay=>10, new_status=>'ref_set_win'},
{ label=>"Avg. Packet size:", param_name=>'PCK_SIZE', type=>'Combo-box', default_val=>$avg, content=>"$avg", info=>undef, param_parent=>$sample, ref_delay=>undef},
{ label=>"Total packet number limit:", param_name=>'PCK_NUM_LIMIT', type=>'Spin-button', default_val=>200000, content=>"2,".MAX_PCK_NUM.",1", info=>"Simulation will stop when total numbr of sent packets by all nodes reaches packet number limit or total simulation clock reach its limit", param_parent=>$sample, ref_delay=>undef, new_status=>undef},
{ label=>"Simulator clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>100000, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit or simulation clock number limit", param_parent=>$sample, ref_delay=>undef, new_status=>undef},
);
foreach my $d (@synthinfo) {
$row=noc_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
}
 
my $traffic=$self->object_get_attribute($sample,"traffic");
 
if ($traffic eq 'hot spot'){
my $htable=def_table(10,2,FALSE);
my $d= { label=>'number of Hot Spot nodes:', param_name=>'HOTSPOT_NUM', type=>'Spin-button', default_val=>1, content=>"1,256,1", info=>"Number of hot spot nodes in the network", param_parent=>$sample, ref_delay=> 1, new_status=>'ref_set_win'};
$row=noc_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
my $l1=gen_label_help("Defne the tile number which is hotspt. All other nodes will send [Hot Spot traffic percentage] of their traffic to this node"," Hot Spot tile number \%");
my $l2=gen_label_help("If it is set as \"n\" then each node sends n % of its traffic to each hotspot node"," Hot Spot traffic \%");
my $l3=gen_label_help("If it is checked then hot spot node also sends packets to other nodes otherwise it only recieves packets from other nodes"," send enable");
$htable->attach ($l1 , 0, 1, $row,$row+1,'fill','shrink',2,2);
$htable->attach ($l2 , 1, 2, $row,$row+1,'fill','shrink',2,2);
$htable->attach ($l3 , 2,3, $row,$row+1,'fill','shrink',2,2);
$row++;
my $num=$self->object_get_attribute($sample,"HOTSPOT_NUM");
for (my $i=0;$i<$num;$i++){
my $w1 = gen_spin_object ($self,$sample,"HOTSPOT_CORE_$i","0,256,1", $i,undef,undef);
my $w2 = gen_spin_object ($self,$sample,"HOTSPOT_PERCENT_$i","0.1,100,0.1", 0.1,undef,undef);
my $w3 = gen_check_box_object ($self,$sample,"HOTSPOT_SEND_EN_$i", 0,undef,undef);
$htable->attach ($w1 , 0, 1, $row,$row+1,'fill','shrink',2,2);
$htable->attach ($w2 ,1, 2, $row,$row+1,'fill','shrink',2,2);
$htable->attach ($w3 , 2,3, $row,$row+1,'fill','shrink',2,2);
$row++;
}
$table->attach ($htable , 0, 3, $row,$row+1,'shrink','shrink',2,2); $row++;
}
my $l= "Define injection ratios. You can define individual ratios seprating by comma (\',\') or define a range of injection ratios with \$min:\$max:\$step format.
As an example defining 2,3,4:10:2 will result in (2,3,4,6,8,10) injection ratios." ;
my $u=get_injection_ratios ($self,$sample,"ratios");
attach_widget_to_table ($table,$row,gen_label_in_left(" Injection ratios:"),gen_button_message ($l,"icons/help.png") , $u); $row++;
$ok->signal_connect("clicked"=> sub{
#check if sof file has been selected
my $s=$self->object_get_attribute($sample,"sof_file");
#check if injection ratios are valid
my $r=$self->object_get_attribute($sample,"ratios");
my $h;
if ($traffic eq 'hot spot'){
$h= check_hotspot_parameters($self,$sample);
}
if(defined $s && defined $r && !defined $h) {
$set_win->destroy;
#$emulate->object_add_attribute("active_setting",undef,undef);
set_gui_status($self,"ref",1);
} else {
if(!defined $s){
my $m= "Please select NoC verilated file";
message_dialog($m);
} elsif (! defined $r) {
message_dialog("Please define valid injection ratio(s)!");
} else {
message_dialog("$h");
}
}
});
}
if($traffictype eq "Task-graph"){
my @custominfo = (
#{ label=>"Verilated Model", param_name=>'sof_file', type=>'Combo-box', default_val=>undef, content=>$exe_files, info=>"Select the the verilator simulation file. Different NoC simulators can be generated using Generate NoC configuration tab.", param_parent=>$sample, ref_delay=>undef, new_status=>undef},
{ label=>'Configuration name:', param_name=>'line_name', type=>'Entry', default_val=>$sample, content=>undef, info=>"NoC configration name. This name will be shown in load-latency graph for this configuration", param_parent=>$sample, ref_delay=> undef, new_status=>undef},
{ label=>"Number of Files", param_name=>"TRAFFIC_FILE_NUM", type=>'Spin-button', default_val=>1, content=>"1,100,1", info=>"Select number of input files", param_parent=>$sample, ref_delay=>1, new_status=>'ref_set_win'},
{ label=>"Simulator clocks limit:", param_name=>'SIM_CLOCK_LIMIT', type=>'Spin-button', default_val=>100000, content=>"2,".MAX_SIM_CLKs.",1", info=>"Each node stops sending packets when it reaches packet number limit or simulation clock number limit", param_parent=>$sample, ref_delay=>undef, new_status=>undef},
);
foreach my $d (@custominfo) {
$row=noc_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
}
my $open_in = "$ENV{'PRONOC_WORK'}/traffic_pattern";
my $num=$self->object_get_attribute($sample,"TRAFFIC_FILE_NUM");
for (my $i=0; $i<$num; $i++){
attach_widget_to_table ($table,$row,gen_label_in_left("traffic pattern file $i:"),gen_button_message ("Select the the traffic pattern input file.","icons/help.png"), get_file_name_object ($self,$sample,"traffic_file$i",undef,$open_in)); $row++;
}
$ok->signal_connect("clicked"=> sub{
#check if sof file has been selected
my $s=$self->object_get_attribute($sample,"sof_file");
if(!defined $s){
message_dialog("Please select NoC verilated file");
return;
}
#check if traffic files have been selected
for (my $i=0; $i<$num; $i++){
my $f=$self->object_get_attribute($sample,"traffic_file$i");
if(!defined $f){
my $m= "Please select traffic_file$i";
message_dialog($m);
return;
}
}
$set_win->destroy;
set_gui_status($self,"ref",1);
});
}
$set_win->add ($mtable);
$set_win->show_all();
}
 
 
 
############
# run_simulator
###########
 
sub run_simulator {
my ($simulate,$info)=@_;
#return if(!check_samples($emulate,$info));
$simulate->object_add_attribute('status',undef,'run');
set_gui_status($simulate,"ref",1);
show_info($info, "Start Simulation\n");
my $name=$simulate->object_get_attribute ("simulate_name",undef);
#unlink $log; # remove old log file
my @samples =$simulate->object_get_attribute_order("samples");
foreach my $sample (@samples){
my $status=$simulate->object_get_attribute ($sample,"status");
next if($status ne "run");
next if(!check_sim_sample($simulate,$sample,$info));
my $traffictype=$simulate->object_get_attribute($sample,"TRAFFIC_TYPE");
run_synthetic_simulation($simulate,$info,$sample,$name) if($traffictype eq "Synthetic");
run_custom_simulation($simulate,$info,$sample,$name) if($traffictype eq "Task-graph");
}
add_info($info, "Simulation is done!\n");
$simulate->object_add_attribute('status',undef,'ideal');
set_gui_status($simulate,"ref",1);
}
 
 
sub run_synthetic_simulation {
my ($simulate,$info,$sample,$name)=@_;
my $log= (defined $name)? "$ENV{PRONOC_WORK}/simulate/$name.log": "$ENV{PRONOC_WORK}/simulate/sim.log";
my $r= $simulate->object_get_attribute($sample,"ratios");
my @ratios=@{check_inserted_ratios($r)};
#$emulate->object_add_attribute ("sample$i","status","run");
my $bin_path=$simulate->object_get_attribute ($sample,"sof_path");
my $bin_file=$simulate->object_get_attribute ($sample,"sof_file");
my $bin="$bin_path/$bin_file";
#load traffic configuration
my $patern=$simulate->object_get_attribute ($sample,'traffic');
my $MIN_PCK_SIZE=$simulate->object_get_attribute ($sample,"MIN_PCK_SIZE");
my $MAX_PCK_SIZE=$simulate->object_get_attribute ($sample,"MAX_PCK_SIZE");
my $PCK_NUM_LIMIT=$simulate->object_get_attribute ($sample,"PCK_NUM_LIMIT");
my $SIM_CLOCK_LIMIT=$simulate->object_get_attribute ($sample,"SIM_CLOCK_LIMIT");
#hotspot
my $hotspot="";
if($patern eq "hot spot"){
$hotspot="-h \" ";
my $num=$simulate->object_get_attribute($sample,"HOTSPOT_NUM");
if (defined $num){
$hotspot="$hotspot $num";
for (my $i=0;$i<$num;$i++){
my $w1 = $simulate->object_get_attribute($sample,"HOTSPOT_CORE_$i");
my $w2 = $simulate->object_get_attribute($sample,"HOTSPOT_PERCENT_$i");
$w2=$w2*10;
my $w3 = $simulate->object_get_attribute($sample,"HOTSPOT_SEND_EN_$i");
$hotspot="$hotspot,$w1,$w3,$w2";
}
}
$hotspot="$hotspot \"";
}
foreach my $ratio_in (@ratios){
#my $r= $ratio_in * MAX_RATIO/100;
add_info($info, "Run $bin with injection ratio of $ratio_in \% \n");
my $cmd="$bin -t \"$patern\" -s $MIN_PCK_SIZE -m $MAX_PCK_SIZE -n $PCK_NUM_LIMIT -c $SIM_CLOCK_LIMIT -i $ratio_in -p \"100,0,0,0,0\" $hotspot";
add_info($info, "$cmd \n");
my $time_strg = localtime;
append_text_to_file($log,"started at:$time_strg\n"); #save simulation output
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout("$cmd");
if($exit){
add_info($info, "Error in running simulation: $stderr \n");
$simulate->object_add_attribute ($sample,"status","failed");
$simulate->object_add_attribute('status',undef,'ideal');
return;
}
append_text_to_file($log,$stdout); #save simulation output
$time_strg = localtime;
append_text_to_file($log,"Ended at:$time_strg\n"); #save simulation output
#my @q =split (/average latency =/,$stdout);
#my $d=$q[1];
#@q =split (/\n/,$d);
#my $avg=$q[0];
my $avg_latency =capture_number_after("average latency =",$stdout);
my $avg_thput =capture_number_after("Avg throughput is:",$stdout);
my $total_time =capture_number_after("simulation clock cycles:",$stdout);
my %packet_rsvd_per_core = capture_cores_data("total number of received packets:",$stdout);
my %worst_rsvd_delay_per_core = capture_cores_data('worst-case-delay of received pckets \(clks\):',$stdout);
my %packet_sent_per_core = capture_cores_data("total number of sent packets:",$stdout);
my %worst_sent_delay_per_core = capture_cores_data('worst-case-delay of sent pckets \(clks\):',$stdout);
#my $avg = sprintf("%.1f", $avg);
next if (!defined $avg_latency);
update_result($simulate,$sample,"latency_result",$ratio_in,$avg_latency);
update_result($simulate,$sample,"throughput_result",$ratio_in,$avg_thput);
update_result($simulate,$sample,"exe_time_result",$ratio_in,$total_time);
foreach my $p (sort keys %packet_rsvd_per_core){
update_result($simulate,$sample,"packet_rsvd_result",$ratio_in,$p,$packet_rsvd_per_core{$p} );
update_result($simulate,$sample,"worst_delay_rsvd_result",$ratio_in,$p,$worst_rsvd_delay_per_core{$p});
update_result($simulate,$sample,"packet_sent_result",$ratio_in,$p,$packet_sent_per_core{$p} );
update_result($simulate,$sample,"worst_delay_sent_result",$ratio_in,$p,$worst_sent_delay_per_core{$p});
}
set_gui_status($simulate,"ref",2);
}
$simulate->object_add_attribute ($sample,"status","done");
}
 
 
 
sub run_custom_simulation{
my ($simulate,$info,$sample,$name)=@_;
my $log= (defined $name)? "$ENV{PRONOC_WORK}/simulate/$name.log": "$ENV{PRONOC_WORK}/simulate/sim.log";
my $SIM_CLOCK_LIMIT=$simulate->object_get_attribute ($sample,"SIM_CLOCK_LIMIT");
my $bin_path=$simulate->object_get_attribute ($sample,"sof_path");
my $bin_file=$simulate->object_get_attribute ($sample,"sof_file");
my $bin="$bin_path/$bin_file";
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../.."); #mpsoc directory address
$bin= "$project_dir/$bin" if(!(-f $bin));
my $num=$simulate->object_get_attribute($sample,"TRAFFIC_FILE_NUM");
for (my $i=0; $i<$num; $i++){
my $f=$simulate->object_get_attribute($sample,"traffic_file$i");
add_info($info, "Run $bin for $f file \n");
my $cmd="$bin -c $SIM_CLOCK_LIMIT -f \"$project_dir/$f\"";
add_info($info, "$cmd \n");
my $time_strg = localtime;
append_text_to_file($log,"started at:$time_strg\n"); #save simulation output
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout("$cmd");
if($exit){
add_info($info, "Error in running simulation: $stderr \n");
$simulate->object_add_attribute ($sample,"status","failed");
$simulate->object_add_attribute('status',undef,'ideal');
return;
}
append_text_to_file($log,$stdout); #save simulation output
$time_strg = localtime;
append_text_to_file($log,"Ended at:$time_strg\n"); #save simulation output
#my @q =split (/average latency =/,$stdout);
#my $d=$q[1];
#@q =split (/\n/,$d);
#my $avg=$q[0];
my $avg_latency =capture_number_after("average latency =",$stdout);
my $avg_thput =capture_number_after("Avg throughput is:",$stdout);
my %packet_rsvd_per_core = capture_cores_data("total number of received packets:",$stdout);
my %worst_rsvd_delay_per_core = capture_cores_data('worst-case-delay of received pckets \(clks\):',$stdout);
my %packet_sent_per_core = capture_cores_data("total number of sent packets:",$stdout);
my %worst_sent_delay_per_core = capture_cores_data('worst-case-delay of sent pckets \(clks\):',$stdout);
my $total_time =capture_number_after("simulation clock cycles:",$stdout);
#my $avg = sprintf("%.1f", $avg);
next if (!defined $avg_latency);
update_result($simulate,$sample,"latency_result",$i,$avg_latency);
update_result($simulate,$sample,"throughput_result",$i,$avg_thput);
update_result($simulate,$sample,"exe_time_result",$i,$total_time);
foreach my $p (sort keys %packet_rsvd_per_core){
update_result($simulate,$sample,"packet_rsvd_result",$i,$p,$packet_rsvd_per_core{$p} );
update_result($simulate,$sample,"worst_delay_rsvd_result",$i,$p,$worst_rsvd_delay_per_core{$p});
update_result($simulate,$sample,"packet_sent_result",$i,$p,$packet_sent_per_core{$p} );
update_result($simulate,$sample,"worst_delay_sent_result",$i,$p,$worst_sent_delay_per_core{$p});
}
set_gui_status($simulate,"ref",2);
}
$simulate->object_add_attribute ($sample,"status","done");
}
 
 
 
##########
# check_sample
##########
 
sub check_sim_sample{
my ($self,$sample,$info)=@_;
my $status=1;
my $bin_path=$self->object_get_attribute ($sample,"sof_path");
my $bin_file=$self->object_get_attribute ($sample,"sof_file");
my $sof="$bin_path/$bin_file";
# ckeck if sample have sof file
if(!defined $sof){
add_info($info, "Error: bin file has not set for $sample!\n");
$self->object_add_attribute ($sample,"status","failed");
$status=0;
} else {
# ckeck if bin file has info file
my ($name,$path,$suffix) = fileparse("$sof",qr"\..[^.]*$");
my $sof_info= "$path$name.inf";
if(!(-f $sof_info)){
add_info($info, "Could not find $name.inf file in $path. An information file is required for each sof file containig the device name and NoC configuration. Press F4 for more help.\n");
$self->object_add_attribute ($sample,"status","failed");
$status=0;
}else { #add info
my $pp= do $sof_info ;
 
my $p=$pp->{'noc_param'};
$status=0 if $@;
message_dialog("Error reading: $@") if $@;
if ($status==1){
$self->object_add_attribute ($sample,"noc_info",$p) ;
}
}
}
return $status;
}
 
 
 
############
# main
############
sub simulator_main{
227,19 → 909,36
add_color_to_gd();
my $simulate= emulator->emulator_new();
set_gui_status($simulate,"ideal",0);
my $left_table = Gtk2::Table->new (25, 6, FALSE);
my $right_table = Gtk2::Table->new (25, 6, FALSE);
 
my $main_table = Gtk2::Table->new (25, 12, FALSE);
my ($infobox,$info)= create_text();
my $refresh = Gtk2::Button->new_from_stock('ref');
add_colors_to_textview($info);
 
my @pages =(
{page_name=>" Avg. throughput/latency", page_num=>0},
{page_name=>" Injected Packet ", page_num=>1},
{page_name=>" Worst-Case Delay ",page_num=>2},
{page_name=>" Executaion Time ",page_num=>3},
);
 
 
 
my @charts = (
{ type=>"2D_line", page_num=>0, graph_name=> "Latency", result_name => "latency_result", X_Title=> 'Desired Avg. Injected Load Per Router (flits/clock (%))', Y_Title=>'Latency (clock)', Z_Title=>undef, Y_Max=>100},
{ type=>"2D_line", page_num=>0, graph_name=> "Throughput", result_name => "throughput_result", X_Title=> 'Desired Avg. Injected Load Per Router (flits/clock (%))', Y_Title=>'Avg. Throughput (flits/clock (%))', Z_Title=>undef},
{ type=>"3D_bar", page_num=>1, graph_name=> "Received", result_name => "packet_rsvd_result", X_Title=>'Core ID' , Y_Title=>'Received Packets Per Router', Z_Title=>undef},
{ type=>"3D_bar", page_num=>1, graph_name=> "Sent", result_name => "packet_sent_result", X_Title=>'Core ID' , Y_Title=>'Sent Packets Per Router', Z_Title=>undef},
{ type=>"3D_bar", page_num=>2, graph_name=> "Received", result_name => "worst_delay_rsvd_result",X_Title=>'Core ID' , Y_Title=>'Worst-Case Delay (clk)', Z_Title=>undef},
{ type=>"3D_bar", page_num=>2, graph_name=> "Sent", result_name => "worst_delay_sent_result",X_Title=>'Core ID' , Y_Title=>'Worst-Case Delay (clk)', Z_Title=>undef},
{ type=>"2D_line", page_num=>3, graph_name=> "-", result_name => "exe_time_result",X_Title=>'Desired Avg. Injected Load Per Router (flits/clock (%))' , Y_Title=>'Total Simulation Time (clk)', Z_Title=>undef},
);
my ($conf_box,$set_win)=process_notebook_gen($simulate,\$info,"simulate");
my $chart =gen_chart ($simulate);
my ($conf_box,$set_win)=process_notebook_gen($simulate,\$info,"simulate",@charts);
my $chart =gen_multiple_charts ($simulate,\@pages,\@charts);
 
 
270,43 → 969,19
my $v1=gen_vpaned($conf_box,.45,$image);
my $v2=gen_vpaned($infobox,.2,$chart);
my $h1=gen_hpaned($v1,.4,$v2);
$left_table->attach_defaults ($conf_box , 0, 6, 0, 20);
$left_table->attach_defaults ($image , 0, 6, 20, 24);
$left_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
$left_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
$right_table->attach_defaults ($infobox , 0, 6, 0,12);
$right_table->attach_defaults ($chart , 0, 6, 12, 24);
$right_table->attach ($generate, 4, 6, 24,25,'expand','shrink',2,2);
$main_table->attach_defaults ($left_table , 0, 6, 0, 25);
$main_table->attach_defaults ($right_table , 6, 12, 0, 25);
$main_table->attach_defaults ($h1 , 0, 12, 0,24);
$main_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
$main_table->attach ($entrybox,3, 6, 24,25,'expand','shrink',2,2);
$main_table->attach ($generate, 6, 9, 24,25,'expand','shrink',2,2);
 
#referesh the mpsoc generator
$refresh-> signal_connect("clicked" => sub{
my $name=$simulate->object_get_attribute ("simulate_name",undef);
$entry->set_text($name) if(defined $name);
 
 
$conf_box->destroy();
$chart->destroy();
$image->destroy();
$image = get_status_gif($simulate);
($conf_box,$set_win)=process_notebook_gen($simulate,\$info,"simulate");
$chart =gen_chart ($simulate);
$left_table->attach_defaults ($image , 0, 6, 20, 24);
$left_table->attach_defaults ($conf_box , 0, 6, 0, 12);
$right_table->attach_defaults ($chart , 0, 6, 12, 24);
 
$conf_box->show_all();
$main_table->show_all();
 
 
});
 
 
 
#check soc status every 0.5 second. referesh device table if there is any changes
Glib::Timeout->add (100, sub{
315,24 → 990,39
if ($timeout>0){
$timeout--;
set_gui_status($simulate,$state,$timeout);
return TRUE;
}
elsif($state eq 'ref_set_win'){
if($state eq "ideal"){
return TRUE;
}
if($state eq 'ref_set_win'){
my $s=$simulate->object_get_attribute("active_setting",undef);
$set_win->destroy();
$simulate->object_add_attribute("active_setting",undef,$s);
$refresh->clicked;
set_gui_status($simulate,"ideal",0);
}
elsif( $state ne "ideal" ){
$refresh->clicked;
#my $saved_name=$mpsoc->mpsoc_get_mpsoc_name();
#if(defined $saved_name) {$entry->set_text($saved_name);}
set_gui_status($simulate,"ideal",0);
}
#refresh GUI
my $name=$simulate->object_get_attribute ("simulate_name",undef);
$entry->set_text($name) if(defined $name);
$conf_box->destroy();
$chart->destroy();
$image->destroy();
$image = get_status_gif($simulate);
($conf_box,$set_win)=process_notebook_gen($simulate,\$info,"simulate",@charts);
$chart = gen_multiple_charts ($simulate,\@pages,\@charts);
$v1 -> pack1($conf_box, TRUE, TRUE);
$v1 -> pack2($image, TRUE, TRUE);
$v2 -> pack2($chart, TRUE, TRUE);
$conf_box->show_all();
$main_table->show_all();
set_gui_status($simulate,"ideal",0);
return TRUE;
} );
339,9 → 1029,9
$generate-> signal_connect("clicked" => sub{
my $sample_num=$simulate->object_get_attribute("emulate_num",undef);
for (my $i=1; $i<=$sample_num; $i++){
$simulate->object_add_attribute ("sample$i","status","run");
my @samples =$simulate->object_get_attribute_order("samples");
foreach my $sample (@samples){
$simulate->object_add_attribute ("$sample","status","run");
}
run_simulator($simulate,\$info);
#set_gui_status($emulate,"ideal",2);
356,6 → 1046,7
$open-> signal_connect("clicked" => sub{
load_simulation($simulate,\$info);
#print Dumper($simulate);
set_gui_status($simulate,"ref",5);
});
375,6 → 1066,3
 
}
 
 
 
/soc.pm
51,7 → 51,7
foreach my $plug(@plugs){
my ($type,$value,$connection_num)=$ip->ip_get_plug ($category,$module,$plug);
soc_add_plug_to_instance($self,$instance_id,$plug,$type,$value,$connection_num);
#add plug names anf deafult connection as IO
#add plug names anf Default connection as IO
my $int_num=($type eq 'num')? $value :1;
for (my $i=0;$i<$int_num;$i++){
my $name=$ip->ip_get_plug_name($category,$module, $plug,$i);
/soc_gen.pl
152,6 → 152,8
my ($default,$type,$content,$info)= $ip->ip_get_parameter($category,$module,$p);
my $value=$param_value{$p};
#$value = $default if (!defined $value && defined $default);
#print "$value\n";
if ($type eq "File_Entry"){
my $entry=gen_entry($value);
my $brows=get_file_name(undef,undef,$entry,undef,undef,undef,undef,undef);
980,6 → 982,13
open(FILE, ">lib/verilog/write_memory.sh") || die "Can not open: $!";
print FILE $prog;
close(FILE) || die "Error closing file: $!";
 
#generate prog_mem
open(FILE, ">lib/verilog/program.sh") || die "Can not open: $!";
print FILE soc_mem_prog();
close(FILE) || die "Error closing file: $!";
 
 
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../");
1005,6 → 1014,7
move ("$dir/lib/verilog/${name}_top.v","$hw_path/");
move ("$dir/lib/verilog/README" ,"$sw_path/");
move ("$dir/lib/verilog/write_memory.sh" ,"$sw_path/");
move ("$dir/lib/verilog/program.sh" ,"$sw_path/");
}
# Copy Software files
1012,7 → 1022,7
copy_file_and_folders($file_ref,$project_dir,$sw_path);
# Write system.h and Software gen files
generate_header_file($soc,$project_dir,$sw_path,$dir);
generate_header_file($soc,$project_dir,$sw_path,$hw_path,$dir);
1496,7 → 1506,19
return ($old_v,$new_v);
}
 
sub check_for_ni{
my $self=shift;
my $ckeck=0;
my @instances=$self->soc_get_all_instances();
foreach my $id (@instances){
my $category = $self->soc_get_category($id);
if ($category eq 'NoC') {
$ckeck=1;
}
}
return $ckeck;
 
}
 
 
sub get_ram_init{
1540,7 → 1562,7
my $soc=shift;
my $name=$soc->object_get_attribute('soc_name');
if (length($name)==0){
message_dialog("Please define the SoC name!");
message_dialog("Please define the Tile name!");
return ;
}
my $target_dir = "$ENV{'PRONOC_WORK'}/SOC/$name";
1551,15 → 1573,18
 
 
my $make = def_image_button('icons/gen.png','Compile');
my $regen=def_image_button('icons/refresh.png','Regenerate main.c');
my $regen= def_image_button('icons/refresh.png','Regenerate main.c');
my $prog= def_image_button('icons/write.png','Program the memory');
 
$table->attach ($regen,0, 1, 1,2,'shrink','shrink',0,0);
$table->attach ($make,9, 10, 1,2,'shrink','shrink',0,0);
$table->attach ($make,5, 6, 1,2,'shrink','shrink',0,0);
$table->attach ($prog,9, 10, 1,2,'shrink','shrink',0,0);
$regen -> signal_connect ("clicked" => sub{
my $dialog = Gtk2::MessageDialog->new (my $window,
'destroy-with-parent',
'question', # message type
'yes-no', # which set of buttons?
"Are you sure you want to regenaret the Top.v file? Note that any changes you have made will be lost");
"Are you sure you want to regenaret the main.c file? Note that any changes you have made will be lost");
my $response = $dialog->run;
if ($response eq 'yes') {
1566,8 → 1591,8
save_file ("$sw/main.c",main_c_template($name));
$app->load_source("$sw/main.c");
}
$dialog->destroy;
 
 
});
 
$make -> signal_connect("clicked" => sub{
1576,11 → 1601,85
 
});
 
#Programe the board
$prog-> signal_connect("clicked" => sub{
my $error = 0;
my $bash_file="$target_dir/sw/program.sh";
 
add_info(\$tview,"Programe the board using quartus_pgm and $bash_file file\n");
#check if the programming file exists
unless (-f $bash_file) {
add_colored_info(\$tview,"\tThe $bash_file does not exists! \n", 'red');
$error=1;
}
return if($error);
my $command = "cd $target_dir/sw; sh program.sh";
add_info(\$tview,"$command\n");
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout($command);
if(length $stderr>1){
add_colored_info(\$tview,"$stderr\n",'red');
add_colored_info(\$tview,"Memory was not programed successfully!\n",'red');
}else {
 
if($exit){
add_colored_info(\$tview,"$stdout\n",'red');
add_colored_info(\$tview,"Memory was not programed successfully!\n",'red');
}else{
add_info(\$tview,"$stdout\n");
add_colored_info(\$tview,"Memory is programed successfully!\n",'blue');
 
}
}
});
 
}
 
 
sub soc_mem_prog {
my $string='
#!/bin/sh
 
 
#JTAG_INTFC="$PRONOC_WORK/toolchain/bin/JTAG_INTFC"
source ./jtag_intfc.sh
 
#reset and disable cpus, then release the reset but keep the cpus disabled
 
$JTAG_INTFC -n 127 -d "I:1,D:2:3,D:2:2,I:0"
 
# jtag instruction
# 0: bypass
# 1: getting data
# jtag data :
# bit 0 is reset
# bit 1 is disable
# I:1 set jtag_enable in active mode
# D:2:3 load jtag_enable data register with 0x3 reset=1 disable=1
# D:2:2 load jtag_enable data register with 0x2 reset=0 disable=1
# I:0 set jtag_enable in bypass mode
 
 
 
#programe the memory
 
sh write_memory.sh
 
#Enable the cpu
$JTAG_INTFC -n 127 -d "I:1,D:2:0,I:0"
# I:1 set jtag_enable in active mode
# D:2:0 load jtag_enable data register with 0x0 reset=0 disable=0
# I:0 set jtag_enable in bypass mode
';
return $string;
}
 
 
 
 
############
# main
############
1590,6 → 1689,7
my $ip = ip->lib_new ();
my $soc = soc->soc_new();
set_gui_status($soc,"ideal",0);
#my $soc= eval { do 'lib/soc/soc.SOC' };
#message_dialog("$ENV{'PRONOC_WORK'}\n");
1616,7 → 1716,7
my $generate = def_image_button('icons/gen.png','Generate RTL');
my $compile = def_image_button('icons/gate.jpg','Compile RTL');
my $compile = def_image_button('icons/gate.png','Compile RTL');
my $software = def_image_button('icons/binary.png','Software');
my $diagram = def_image_button('icons/diagram.png','Diagram');
my $ram = def_image_button('icons/RAM.png','Memory');
1674,7 → 1774,7
my $name=$soc->object_get_attribute('soc_name');
if (length($name)==0){
message_dialog("Please define the SoC name!");
message_dialog("Please define the Tile name!");
return ;
}
1697,19 → 1797,23
$soc->object_add_attribute('global_param','CORE_ID',0);
generate_soc($soc,$info,$target_dir,$hw_dir,$sw_path,1,1);
#message_dialog("SoC \"$name\" has been created successfully at $target_dir/ " );
my $dialog = Gtk2::MessageDialog->new (my $window,
'destroy-with-parent',
'question', # message type
'yes-no', # which set of buttons?
"Processing Tile \"$name\" has been created successfully at $target_dir/. In order to see this tile in MPSoC Generator you need to restar the ProNoC. Do you ant to reset the ProNoC now?");
my $response = $dialog->run;
if ($response eq 'yes') {
exec($^X, $0, @ARGV);# reset ProNoC to apply changes
}
$dialog->destroy;
my $has_ni= check_for_ni($soc);
if($has_ni){
my $dialog = Gtk2::MessageDialog->new (my $window,
'destroy-with-parent',
'question', # message type
'yes-no', # which set of buttons?
"Processing Tile \"$name\" has been created successfully at $target_dir/. In order to include this tile in MPSoC Generator you need to restar the ProNoC. Do you ant to reset the ProNoC now?");
my $response = $dialog->run;
if ($response eq 'yes') {
exec($^X, $0, @ARGV);# reset ProNoC to apply changes
}
$dialog->destroy;
} else {
message_dialog("Processing Tile \"$name\" has been created successfully at $target_dir/.");
 
}
 
 
 
1725,16 → 1829,20
 
});
 
 
$compile -> signal_connect("clicked" => sub{
$soc->object_add_attribute('compile','compilers',"QuartusII,Verilator,Modelsim");
my $name=$soc->object_get_attribute('soc_name');
if (length($name)==0){
message_dialog("Please define the SoC name!");
message_dialog("Please define the Tile name!");
return ;
}
my $target_dir = "$ENV{'PRONOC_WORK'}/SOC/$name";
my $hw_dir = "$target_dir/src_verilog";
my $sw_path = "$target_dir/sw";
my $top = "$target_dir/src_verilog/${name}_top.v";
if (-f $top){
if (-f $top){
generate_soc($soc,$info,$target_dir,$hw_dir,$sw_path,1,1);
select_compiler($soc,$name,$top,$target_dir);
} else {
message_dialog("Cannot find $top file. Please run RTL Generator first!");
/software_editor.pl
82,8 → 82,7
 
my ($scwin_info,$tview)= create_text();
add_colored_tag($tview,'red');
add_colored_tag($tview,'blue');
add_colors_to_textview($tview);
$vpaned-> pack1 ($hpaned, TRUE, TRUE);
$vpaned ->set_position ($hight*.5);
$vpaned-> pack2 ($scwin_info, TRUE, TRUE);
730,25 → 729,34
 
 
sub run_make_file {
my ($dir,$outtext)=@_;
my $cmd = "cd \"$dir/\" \n make ";
my ($dir,$outtext, $args)=@_;
my $cmd = (defined $args) ? "cd \"$dir/\" \n make $args" : "cd \"$dir/\" \n make ";
my $error=0;
show_info(\$outtext,"$cmd\n");
add_info(\$outtext,"$cmd\n");
my ($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout( $cmd);
#($stdout,$exit,$stderr)=run_cmd_in_back_ground_get_stdout( $cmd);
 
if($stderr){
$stderr=~ s/[‘,’]//g;
add_info(\$outtext,"$stdout\n");
add_colored_info(\$outtext,"$stderr\n","red");
if($exit){
if($stderr){
$stderr=~ s/[‘,’]//g;
add_info(\$outtext,"$stdout\n");
add_colored_info(\$outtext,"$stderr\n","red");
}
add_colored_info(\$outtext,"Compilation failed.\n",'red');
return 0;
 
}else{
 
add_info(\$outtext,"$stdout\n");
if($stderr){ #probebly had warning
$stderr=~ s/[‘,’]//g;
#add_info(\$outtext,"$stdout\n");
add_colored_info(\$outtext,"$stderr\n","green");
}
add_colored_info(\$outtext,"Compilation finished successfully.\n",'blue');
return 1;
}
#add_info(\$outtext,"**********Quartus compilation is done successfully in $target_dir!*************\n") if($error==0);
/temp.pl
1,43 → 1,9
#!/usr/bin/perl
 
use strict;
use warnings;
use strict;
use List::Util 'shuffle';
 
 
 
sub remove_scolar_from_array{
my ($array_ref,$item)=@_;
my @array=@{$array_ref};
my @new;
foreach my $p (@array){
if($p ne $item ){
push(@new,$p);
}
}
return @new;
}
 
sub random_dest_gen {
my $n=shift;
my @c=(0..$n-1);
my @o;
for (my $i=0; $i<$n; $i++){
my @l= shuffle @c;
@l=remove_scolar_from_array(\@l,$i);
$o[$i]=\@l;
}
return \@o;
 
}
 
my $ref=random_dest_gen(16);
my @random= @{$ref};
 
for (my $i=0; $i<16; $i++){
for (my $j=0; $j<15; $j++){
print @{$random[$i]}[$j];
print ",";
}
print "\n";
}
my $scalar = "a1b.2";
$scalar =~ s/\D//g;
print "\n $scalar \n";
/trace_gen.pl
0,0 → 1,1818
#!/usr/bin/perl
use strict;
use warnings;
 
use Glib qw(TRUE FALSE);
use Gtk2 '-init';
use Gtk2::SourceView2;
use Data::Dumper;
use List::Util 'shuffle';
use File::Path;
use File::Copy;
use POSIX qw(ceil floor);
use Cwd 'abs_path';
 
 
 
use base 'Class::Accessor::Fast';
require "widget.pl";
require "diagram.pl";
 
 
__PACKAGE__->mk_accessors(qw{
window
sourceview
buffer
filename
search_regexp
search_case
search_entry
regexp
highlighted
});
 
my $NAME = 'Trace_gen';
 
 
exit trace_gen_main() unless caller;
 
 
sub trace_gen_main {
my $app = __PACKAGE__->new();
my $table=$app->build_trace_gui();
return $table;
}
 
 
 
sub build_trace_gui {
my ($self) = @_;
$self->object_add_attribute("file_id",undef,'a');
$self->object_add_attribute("trace_id",undef,0);
$self->object_add_attribute('select_multiple','action',"_");
$self->object_add_attribute('Auto','Auto_inject',"1\'b1");
set_gui_status($self,"ideal",0);
 
my $main_table= def_table(2,10,FALSE);
my ($scwin_info,$tview)= create_text();
my $traces=trace_pad($self,$tview);
my $traces_ctrl=trace_pad_ctrl($self,$tview);
my $map= trace_map($self,$tview);
my $map_ctrl= trace_map_ctrl($self,$tview);
my $map_info=map_info($self);
my $h1=gen_hpaned($traces_ctrl,.25,$traces);
my $h2=gen_hpaned($map_ctrl,.25,$map);
my $h3=gen_hpaned($h2,.65,$map_info);
 
my $v1=gen_vpaned($h1,.3,$h3);
#my $v2=gen_vpaned($v1,.6,$scwin_info);
my $generate = def_image_button('icons/gen.png','Generate');
my $open = def_image_button('icons/browse.png','Load');
my ($entrybox,$entry) = def_h_labeled_entry('Save as:',undef);
$entry->signal_connect( 'changed'=> sub{
my $name=$entry->get_text();
$self->object_add_attribute ("save_as",undef,$name);
});
my $entry2=gen_entry_object($self,'out_name',undef,undef,undef,undef);
my $entrybox2=labele_widget_info(" Output file name:",$entry2);
my $save = def_image_button('icons/save.png','Save');
$entrybox->pack_end($save, FALSE, FALSE,0);
 
$main_table->attach_defaults ($v1 , 0, 12, 0,24);
$main_table->attach ($open,0, 3, 24,25,'expand','shrink',2,2);
$main_table->attach ($entrybox,3, 5, 24,25,'expand','shrink',2,2);
$main_table->attach ($entrybox2,5,6 , 24,25,'expand','shrink',2,2);
$main_table->attach ($generate, 6, 9, 24,25,'expand','shrink',2,2);
 
my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
$sc_win->set_policy( "automatic", "automatic" );
$sc_win->add_with_viewport($main_table);
$open-> signal_connect("clicked" => sub{
load_workspace($self);
set_gui_status($self,"ref",5);
});
 
$save-> signal_connect("clicked" => sub{
save_as($self);
set_gui_status($self,"ref",5);
});
$generate->signal_connect("clicked" => sub{
genereate_output($self);
});
#check soc status every 0.5 second. referesh device table if there is any changes
Glib::Timeout->add (100, sub{
my ($state,$timeout)= get_gui_status($self);
if ($timeout>0){
$timeout--;
set_gui_status($self,$state,$timeout);
return TRUE;
}
if($state eq "ideal"){
return TRUE;
}
#refresh GUI
my $saved_name=$self->object_get_attribute('save_as');
if(defined $saved_name) {$entry->set_text($saved_name);}
$saved_name=$self->object_get_attribute('out_name');
if(defined $saved_name) {$entry2->set_text($saved_name);}
$traces->destroy();
$traces=trace_pad($self,$tview);
$map->destroy();
$map= trace_map($self,$tview);
$map_ctrl->destroy();
$map_ctrl= trace_map_ctrl($self,$tview);
$traces_ctrl->destroy();
$traces_ctrl=trace_pad_ctrl($self,$tview);
$map_info->destroy();
$map_info=map_info($self);
$h1 -> pack1($traces_ctrl, TRUE, TRUE);
$h1 -> pack2($traces, TRUE, TRUE);
$h2 -> pack1($map_ctrl, TRUE, TRUE);
$h2 -> pack2($map, TRUE, TRUE);
$h3 -> pack2($map_info, TRUE, TRUE);
$traces->show_all();
$map->show_all();
$main_table->show_all();
set_gui_status($self,"ideal",0);
return TRUE;
} );
 
 
 
return $sc_win;
 
}
 
########
# trace_ctr
########
 
sub trace_pad_ctrl{
my ($self,$tview)=@_;
my $table= def_table(2,10,FALSE);
#my $separator = Gtk2::HSeparator->new;
my $row=0;
my $col=0;
#$table->attach ($separator , 0, 10 , $row, $row+1,'fill','fill',2,2); $row++;
my $add = def_image_button('icons/import.png');
set_tip($add,'Load Task Graph');
my $remove = def_image_button('icons/cancel.png');
set_tip($remove,'Remove Selected Trace(s)');
my $draw = def_image_button('icons/diagram.png');
set_tip($draw,'View Task Graph');
my $auto = def_image_button('icons/refresh.png');
set_tip($auto,'Automatically calculate the traces burst size and injection ratio according to their bandwith');
my $box=def_pack_hbox(FALSE,FALSE,$add,$draw,$remove,$auto);
#my $auto = def_image_button('icons/setting.png');
#set_tip($auto,'Automatically set the burst size and injection ratio according to the packet size and bandwidth');
$col=0;
$table->attach ($box,$col, $col+1, $row, $row+1,'shrink','shrink',2,2);$col++;
$row++;
$col=0;
my $info="Automatically set the burst size and injection ratio according to the packet size and bandwidth";
#add_param_widget($self,"Auto inject rate \& burst size",'Auto_inject', 0,"Check-box",1,$info, $table,$row,$col,1,'Auto',0,'ref',"vertical");
$row++;
$col=0;
my $info1="If hard-bulid QoS is enabled in NoC by using Wieghted round robin arbiter (WRRA) instead of RRA, then the initial weights allow QoS support in NoC as in presence of contention, packets with higher initial weights receive higher bandwidth and lower worst case delay compared to others." ;
my $selects="tornado,transposed 1,transposed 2,bit reverse,bit complement,random,hot spot";
my $min=$self->object_get_attribute('select_multiple','min_pck_size');
my $max=$self->object_get_attribute('select_multiple','max_pck_size');
$min=$max=5 if(!defined $min);
my @selectedinfo;
$self->object_add_attribute('Auto','Auto_inject',"1\'b0" );
my $a= $self->object_get_attribute('Auto','Auto_inject');
if ($a eq "1\'b0"){
@selectedinfo = (
{ label=>" Initial weight ", param_name=>'init_weight', type=>'Spin-button', default_val=>1, content=>"1,16,1", info=>$info1, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
{ label=>" Min pck size ", param_name=>'min_pck_size', type=>'Spin-button', default_val=>5, content=>"2,$max,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
{ label=>" Max pck size ",param_name=>'max_pck_size', type=>'Spin-button', default_val=>5, content=>"$min,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
{ label=>" Burst_size ", param_name=>'burst_size', type=>'Spin-button', default_val=>1, content=>"1,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
{ label=>" Inject rate(%) ", param_name=>'injct_rate', type=>'Spin-button', default_val=>10, content=>"1,100,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
{ label=>" Inject rate variation(%) ", param_name=>'injct_rate_var', type=>'Spin-button', default_val=>20, content=>"0,100,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
 
);
}else{
@selectedinfo = (
{ label=>" Initial weight ", param_name=>'init_weight', type=>'Spin-button', default_val=>1, content=>"1,16,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
{ label=>" Min pck size ", param_name=>'min_pck_size', type=>'Spin-button', default_val=>5, content=>"2,$max,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
{ label=>" Max pck size ",param_name=>'max_pck_size', type=>'Spin-button', default_val=>5, content=>"$min,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
);
}
my @traces= $self->get_trace_list();
my $any_selected=0;
foreach my $p (@traces) {
my ($src,$dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
$any_selected=1 if($self->object_get_attribute("trace_$p",'selected')==1);
}
if($any_selected){
$table->attach (Gtk2::HSeparator->new,0, 10, $row, $row+1,'fill','fill',2,2);$row++;
$table->attach (gen_label_in_center('Apply to all selected traces'),0, 10, $row, $row+1,'fill','fill',2,2);$row++;
}
foreach my $d (@selectedinfo) {
my $apply= def_image_button("icons/enter.png",undef);
$apply->signal_connect( 'clicked'=> sub{
$self->object_add_attribute('select_multiple','action',$d->{param_name});
$self->set_gui_status('ref',0);
});
if($any_selected){
($row,$col)=add_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,$col,1, $d->{param_parent}, $d->{ref_delay},$d->{new_status},"horizental");
$table->attach ($apply , $col, $col+1, $row,$row+1,'shrink','shrink',2,2);$row++;$col=0;
# $row=noc_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay}, $d->{new_status});
}
}
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/.."); #mpsoc directory address
$add->signal_connect ( 'clicked'=> sub{
my $file;
my $dialog = Gtk2::FileChooserDialog->new(
'Select a File', undef,
'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok',
);
my $open_in = abs_path("${project_dir}/perl_gui/lib/simulate/embedded_app_graphs");
$dialog->set_current_folder ($open_in);
my $filter = Gtk2::FileFilter->new();
$filter->set_name("app");
$filter->add_pattern("*.app");
$dialog->add_filter ($filter);
 
if ( "ok" eq $dialog->run ) {
$file = $dialog->get_filename;
$self->load_tarce_file($file,$tview);
}
$dialog->destroy;
});
$draw->signal_connect ( 'clicked'=> sub{
show_trace_diagram($self,'trace');
});
$remove->signal_connect ( 'clicked'=> sub{
$self->remove_selected_traces();
});
$auto->signal_connect ( 'clicked'=> sub{
$self->auto_generate_injtratio();
});
my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
$sc_win->set_policy( "automatic", "automatic" );
$sc_win->add_with_viewport($table);
return $sc_win;
}
 
 
######
# map_ctr
######
sub trace_map_ctrl{
my ($self,$tview)=@_;
my $table= def_table(2,10,FALSE);
my $run_map= def_image_button("icons/enter.png",undef);
my $drawmap = def_image_button('icons/diagram.png');
set_tip($drawmap,'View Task Mapping');
my $auto = def_image_button('icons/refresh.png');
set_tip($auto,'Automatically set the network dimentions acording to the task number');
my $clean = def_image_button('icons/clear.png');
set_tip($clean,'Remove mapping');
my $box=def_pack_hbox(FALSE,FALSE,$drawmap,$clean,$auto);
my $col=0;
my $row=0;
$table->attach ($box,$col, $col+1, $row, $row+1,'shrink','shrink',2,2);$row++;
my @info = (
{ label=>'Routers per Row', param_name=>'NX', type=>"Spin-button", default_val=>2, content=>"2,64,1", info=>undef, param_parent=>'noc_param', ref_delay=>1,placement=>'vertical'},
{ label=>"Routers per Column", param_name=>"NY", type=>"Spin-button", default_val=>2, content=>"1,64,1", info=>undef, param_parent=>'noc_param',ref_delay=>1, placement=>'vertical'},
{ label=>"Mapping Algorithm", param_name=>"Map_Algrm", type=>"Combo-box", default_val=>'Random', content=>"Nmap,Random,Reverse-NMAP,Direct", info=>undef, param_parent=>'map_param',ref_delay=>undef,placement=>'horizental'},
);
foreach my $d (@info) {
($row,$col)=add_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,$col,1, $d->{param_parent}, $d->{ref_delay},'ref',$d->{placement});
if($d->{param_name} eq "Map_Algrm"){$table->attach ($run_map , $col, $col+1, $row,$row+1,'shrink','shrink',2,2);$row++;$col=0;}
}
$run_map->signal_connect( 'clicked'=> sub{
my $alg=$self->object_get_attribute('map_param','Map_Algrm');
$self->random_map() if ($alg eq 'Random');
$self->worst_map_algorithm() if ($alg eq 'Reverse-NMAP');
$self->nmap_algorithm() if ($alg eq 'Nmap');
$self->direct_map() if ($alg eq 'Direct');
});
$drawmap->signal_connect ( 'clicked'=> sub{
show_trace_diagram($self,'map');
});
$auto->signal_connect ( 'clicked'=> sub{
my @tasks = $self->get_all_tasks();
my $task_num= scalar @tasks;
return if($task_num ==0);
my ($nx,$ny) =network_dim_cal($task_num);
$self->object_add_attribute('noc_param','NX',$nx);
$self->object_add_attribute('noc_param','NY',$ny);
set_gui_status($self,"ref",1);
});
$clean->signal_connect ( 'clicked'=> sub{
remove_mapping($self);
set_gui_status($self,"ref",1);
});
my $sc_win = new Gtk2::ScrolledWindow (undef, undef);
$sc_win->set_policy( "automatic", "automatic" );
$sc_win->add_with_viewport($table);
return $sc_win;
}
#########
# trace
#########
 
sub trace_pad{
my ($self,$tview)=@_;
my $table= def_table(10,10,FALSE);
#my $separator = Gtk2::HSeparator->new;
my $row=0;
my $col=0;
my @selectedinfo = (
{ label=>" Initial weight ", param_name=>'init_weight', type=>'Spin-button', default_val=>1, content=>"1,16,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
{ label=>" Min pck size ", param_name=>'min_pck_size', type=>'Spin-button', default_val=>5, content=>"2,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
{ label=>" Max pck size ",param_name=>'max_pck_size', type=>'Spin-button', default_val=>5, content=>"2,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> 10, new_status=>'ref'},
{ label=>" Burst_size ", param_name=>'burst_size', type=>'Spin-button', default_val=>1, content=>"1,1024,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
{ label=>" Inject rate(%) ", param_name=>'injct_rate', type=>'Spin-button', default_val=>10, content=>"1,100,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
{ label=>" Inject rate variation (%) ", param_name=>'injct_rate_var', type=>'Spin-button', default_val=>20, content=>"0,100,1", info=>undef, param_parent=>'select_multiple', ref_delay=> undef, new_status=>undef},
);
my @traces= $self->get_trace_list();
my %f;
my $sel=$self->object_get_attribute('select_multiple','action');
foreach my $p (@traces) {
my ($src,$dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
$f{$file_id}=$file_id.'*';
$self->object_add_attribute("trace_$p",'selected', 1 ) if ($sel eq 'All');
$self->object_add_attribute("trace_$p",'selected', 0 ) if ($sel eq 'None');
$self->object_add_attribute("trace_$p",'selected', 1 ) if ($sel eq "All-$file_id*");
$self->object_add_attribute("trace_$p",'selected', 0 ) if ($sel eq "None-$file_id*");
my $seleceted =$self->object_get_attribute("trace_$p",'selected');
foreach my $d (@selectedinfo) {
my $val=$self->object_get_attribute($d->{param_parent},$d->{param_name}) if ($sel eq $d->{param_name} && $seleceted);
$self->object_add_attribute("trace_$p",$d->{param_name}, $val ) if ($sel eq $d->{param_name}&& $seleceted);
}
}
my $sel_options= "Select,All,None";
if( keys %f > 1){
foreach my $p (sort keys %f) {
$sel_options="$sel_options,All-$f{$p}";
$sel_options="$sel_options,None-$f{$p}";
}
}
$self->object_add_attribute('select_multiple','action',"Select");
my $selcombo = $self-> gen_combobox_object ('select_multiple',"action", $sel_options,'-','ref',1);
if(scalar @traces ){$table-> attach ($selcombo, $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;}
my @titles = (scalar @traces ) ? (" # "," Source "," Destination "," Bandwidth(MB) ", " Initial weight ", " Min pck size ", " Max pck size "):
("Load a task graph");
my $auto=$self->object_get_attribute('Auto','Auto_inject');
push (@titles, (" Burst_size ", " Inject rate(%) ", " Inject rate variation(%) ")) if ($auto eq "1\'b0");
foreach my $p (@titles){
$table-> attach (gen_label_in_left($p), $col, $col+1, $row, $row+1,'shrink','shrink',2,2);
$col++;
}
$row++;
my $i=0;
#my @t=sort { $a cmp $b } @traces;
foreach my $p (@traces) {
$col=0;
my ($src,$dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
my $check = gen_check_box_object ($self,"trace_$p",'selected',0,'ref',0);
my $weight= gen_spin_object ($self,"trace_$p",'init_weight',"1,16,1", 1,undef,undef);
my $min=$self->object_get_attribute("trace_$p",'min_pck_size');
my $max=$self->object_get_attribute("trace_$p",'max_pck_size');
$min=$max=5 if(!defined $min);
my $min_pck_size= gen_spin_object ($self,"trace_$p",'min_pck_size',"2,$max,1", 5,'ref',10);
my $max_pck_size= gen_spin_object ($self,"trace_$p",'max_pck_size',"$min,1024,1", 5,'ref',10);
my $burst_size = gen_spin_object ($self,"trace_$p",'burst_size',"1,1024,1", 1,undef,undef);
my $injct_rate = gen_spin_object ($self,"trace_$p",'injct_rate',"1,100,1", 10,undef,undef);
my $injct_rate_var = gen_spin_object ($self,"trace_$p",'injct_rate_var',"0,100,1", 20,undef,undef);
#my $weight= trace_$trace_id",'init_weight'
$table-> attach ($check, $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach (gen_label_in_left($i), $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach (gen_label_in_left("$src") ,$col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach (gen_label_in_left("$dst") , $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach (gen_label_in_left("$Mbytes") ,$col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach ($weight ,$col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach ($min_pck_size, $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach ($max_pck_size, $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
if ($auto eq "1\'b0"){
$table-> attach ($burst_size ,$col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach ($injct_rate ,$col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach ($injct_rate_var ,$col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
}
$row++;
$i++;
}
my $sc_win = gen_scr_win_with_adjst($self,'trace_pad');
$sc_win->add_with_viewport($table);
return $sc_win;
}
 
 
 
sub load_tarce_file{
my ($self,$file,$tview)=@_;
#open file
my @x;
my %traces;
if (!defined $file) {return; }
if (-e $file) {
my $f_id=$self->object_get_attribute("file_id",undef);
my $t_id=$self->object_get_attribute("trace_id",undef);
open(my $fh, '<:encoding(UTF-8)', $file) or die "Could not open file '$file' $!";
while (my $row = <$fh>) {
chomp $row;
my @data = split (/\s/,$row);
next if (! defined $data[0]);
next if ($data[0] eq '#' || scalar @data < 3);
$self->add_trace($f_id,$t_id,$data[0],$data[1],$data[2],$file);
$t_id++;
}
$f_id++;
$self->object_add_attribute("trace_id",undef,$t_id);
$self->object_add_attribute("file_id",undef,$f_id);
}
set_gui_status($self,"ref",1);
}
 
 
 
 
########
# map
#######
 
 
sub trace_map {
my ($self,$tview)=@_;
my $table= def_table(10,10,FALSE);
my $sc_win = gen_scr_win_with_adjst($self,'trace_map');
$sc_win->add_with_viewport($table);
my $row=0;
my $col=0;
my @titles = (" # "," Task-name ", " Mapped-to " ,"Lock ", " Sent-Bandwidth ", " Resvd-Bandwidth ", " Total-Bandwidth ");
foreach my $p (@titles){
$table-> attach (gen_label_in_left($p), $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
}
$col=0;
$row++;
# { label=>'Routers per Row', param_name=>'NX', type=>"Spin-button", default_val=>2, content=>"2,64,1", info=>undef, param_parent=>'noc_param', ref_delay=>undef},
 
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my @tiles=get_tiles_name($self);
my $i=0;
my @tasks=get_all_tasks($self);
my @assigned = $self->get_assigned_tiles();
#a-b
my @list= get_diff_array(\@tiles ,\@assigned);
push(@list,'-');
#print "tils=@tiles \nass=@assigned \nlist=@list\n";
my %com_tasks= $self->get_communication_task();
foreach my $p (@tasks){
my $value=$self->object_get_attribute("MAP_TILE",$p);
$value = "-" if (!defined $value);
my @l=($value eq "-" || grep (/^\Q$value\E$/,@tiles)==0 )? @list : (@list,$value);
my $combo= map_combobox ($self,"$p",\@l,'-');
#my $lock=$self->object_get_attribute("MAP_LOCK",$p);
#$lock = 0 if (!defined $lock);
my $lock = gen_check_box_object ($self,"MAP_LOCK",$p,0,undef,undef);
$table-> attach (gen_label_in_left($i), $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach (gen_label_in_left($p), $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach ($combo, $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
$table-> attach ($lock, $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
my @a=('sent','rsv','total');
foreach my $q (@a){
my $s = (defined $com_tasks{$p}{$q}) ? $com_tasks{$p}{$q} : '-';
$table-> attach (gen_label_in_left($s), $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $col++;
}
$i++;
$col=0;
$row++;
}
return $sc_win;
}
 
 
 
########
# map_info
#######
 
 
sub map_info {
my ($self)=@_;
my $sc_win = gen_scr_win_with_adjst($self,'map_info');
my $table= def_table(10,10,FALSE);
$sc_win->add_with_viewport($table);
my $row=0;
my $col=0;
my ($avg,$max,$min,$norm)=get_map_info($self);
my @data = (
{label => "Average distance", value =>"$avg"},
{label => "Max distance", value =>"$max" },
{label => "Min distance",value => "$min"},
{label => "Normlized data per hop", value =>"$norm" }
);
# create list store
my $store = Gtk2::ListStore->new (#'Glib::Boolean', # => G_TYPE_BOOLEAN
#'Glib::Uint', # => G_TYPE_UINT
'Glib::String', # => G_TYPE_STRING
'Glib::String'); # you get the idea
 
# add data to the list store
foreach my $d (@data) {
my $iter = $store->append;
$store->set ($iter,
0, $d->{label},
1, $d->{value},
);
}
 
my $treeview = Gtk2::TreeView->new ($store);
$treeview->set_rules_hint (TRUE);
 
$treeview->set_search_column (1);
 
# add columns to the tree view
my $renderer = Gtk2::CellRendererToggle->new;
$renderer->signal_connect (toggled => \&fixed_toggled, $store);
 
 
# column for severities
$renderer = Gtk2::CellRendererText->new;
my $column = Gtk2::TreeViewColumn->new_with_attributes ("Mapping summary",
$renderer,
text => 0);
$column->set_sort_column_id (0);
$treeview->append_column ($column);
 
# column for description
$renderer = Gtk2::CellRendererText->new;
$column = Gtk2::TreeViewColumn->new_with_attributes (" ",
$renderer,
text => 1);
$column->set_sort_column_id (1);
$treeview->append_column ($column);
 
$table-> attach ($treeview, $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $row++;
#$table-> attach (gen_label_in_left("Max distance: $max "), $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $row++;
#$table-> attach (gen_label_in_left("Min distance: $min "), $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $row++;
#$table-> attach (gen_label_in_left("Normlized data per hop: $norm"), $col, $col+1, $row, $row+1,'shrink','shrink',2,2); $row++;
return $sc_win;
 
}
 
 
 
 
sub get_map_info {
my $self=shift;
my ($avg,$max,$min,$norm)=(0,0,999999,0);
my $sum=0;
my $num=0;
my $data=0;
my $comtotal=0;
my @traces= $self->get_trace_list();
foreach my $p (@traces) {
my ($src, $dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
my $src_tile = $self->object_get_attribute('MAP_TILE',"$src");
my $dst_tile = $self->object_get_attribute('MAP_TILE',"$dst");
next if(!defined $src_tile || !defined $dst_tile );
next if($src_tile eq '-' || $dst_tile eq "-" );
my ($src_x,$src_y)= tile_id_to_loc($src_tile);
my ($dst_x,$dst_y)= tile_id_to_loc($dst_tile);
#print" ($dst_x,$dst_y)= tile_id_to_loc($dst_tile)\n";
my $mah_distance=get_mah_distance($src_x,$src_y,$dst_x,$dst_y);
#print "$mah_distance=get_mah_distance($src_x,$src_y,$dst_x,$dst_y);\n";
$min = $mah_distance if($min> $mah_distance);
$max = $mah_distance if($max< $mah_distance);
$sum+=$mah_distance;
$num++;
$data+=($Mbytes*$mah_distance);
$comtotal+=$Mbytes;
}
$avg=$sum/$num if($num!=0);
$min = 0 if $min == 999999;
$norm = $data/$comtotal if ($comtotal !=0);
return ($avg,$max,$min,$norm);
}
 
 
 
 
 
sub map_combobox {
my ($object,$task_name,$content,$default)=@_;
my @combo_list=@{$content};
my $value=$object->object_get_attribute("MAP_TILE",$task_name);
my $pos;
$pos=get_pos($value, @combo_list) if (defined $value);
if(!defined $pos && defined $default){
$object->object_add_attribute("MAP_TILE",$task_name,$default);
$pos=get_item_pos($default, @combo_list);
}
#print " my $pos=get_item_pos($value, @combo_list);\n";
my $widget=gen_combo(\@combo_list, $pos);
$widget-> signal_connect("changed" => sub{
my $new_tile=$widget->get_active_text();
$object->map_task($task_name,$new_tile);
set_gui_status($object,'ref',1);
});
return $widget;
}
 
 
##########
# save_as
##########
sub save_as{
my ($self)=@_;
# read emulation name
my $name=$self->object_get_attribute ("save_as",undef);
my $s= (!defined $name)? 0 : (length($name)==0)? 0 :1;
if ($s == 0){
message_dialog("Please define file name!");
return 0;
}
# Write object file
open(FILE, ">lib/simulate/$name.TRC") || die "Can not open: $!";
print FILE perl_file_header("$name.TRC");
print FILE Data::Dumper->Dump([\%$self],['Trace']);
close(FILE) || die "Error closing file: $!";
message_dialog("workspace has been saved as lib/simulate/$name.TRC!");
return 1;
}
 
 
 
 
#############
# load_workspace
############
 
sub load_workspace {
my $self=shift;
my $file;
my $dialog = Gtk2::FileChooserDialog->new(
'Select a File', undef,
'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok',
);
 
my $filter = Gtk2::FileFilter->new();
$filter->set_name("TRC");
$filter->add_pattern("*.TRC");
$dialog->add_filter ($filter);
my $dir = Cwd::getcwd();
$dialog->set_current_folder ("$dir/lib/simulate");
 
 
if ( "ok" eq $dialog->run ) {
$file = $dialog->get_filename;
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
if($suffix eq '.TRC'){
my $pp= eval { do $file };
if ($@ || !defined $pp){
message_dialog("**Error reading $file file: $@\n");
$dialog->destroy;
return;
}
clone_obj($self,$pp);
#message_dialog("done!");
}
}
$dialog->destroy;
}
 
 
########
# genereate_output
########
 
sub genereate_output{
my $self=shift;
my $name= $self->object_get_attribute('out_name');
my $size= (defined $name)? length($name) :0;
if ($size ==0) {
message_dialog("Please define the output file name!");
return 0;
}
# make target dir
my $dir = Cwd::getcwd();
my $target_dir = "$ENV{'PRONOC_WORK'}/traffic_pattern";
mkpath("$target_dir",1,0755);
my @tasks=get_all_tasks($self);
foreach my $p (@tasks) {
my $tile=$self->object_get_attribute("MAP_TILE",$p);
if ( $tile eq "-" ){
message_dialog("Error: unmapped task. Please map task $p to a tile", 'error' );
return;
}
}
#creat output file
open(FILE, ">$target_dir/$name.cfg") || die "Can not open: $!";
print FILE get_cfg_content($self);
close(FILE) || die "Error closing file: $!";
message_dialog("The traffic pattern is saved as $target_dir/$name.cfg" );
}
 
sub get_cfg_content{
my $self=shift;
my $file="% source tile, destination tile, bytes, initial_weight, min_pck_size, max_pck_size, burst_size, injection_rate(%), injection_rate variation(%)\n";
 
my @traces= $self->get_trace_list();
foreach my $p (@traces) {
my ($src,$dst, $Mbytes, $file_id, $file_name,$init_weight,$min_pck, $max_pck, $burst, $injct_rate, $injct_rate_var)=$self->get_trace($p);
my $src_tile=$self->get_tile_id($src);
my $dst_tile=$self->get_tile_id($dst);
my $auto=$self->object_get_attribute('Auto','Auto_inject');
my $bytes = $Mbytes * 1000000;
$file=$file."$src_tile, $dst_tile, $bytes, $init_weight, $min_pck, $max_pck";
$file=$file.", $burst, $injct_rate, $injct_rate_var \n" if ($auto eq "1\'b0");
$file=$file." \n" if ($auto eq "1\'b1");
}
return $file;
}
 
sub get_tile_id{
my ($self,$task)=@_;
my $nx=$self->object_get_attribute('noc_param','NX');
my $tile=$self->object_get_attribute("MAP_TILE",$task);
my ($x, $y) = $tile =~ /(\d+)/g;
$y=0 if(!defined $y);
my $IP_NUM = ($y * $nx) + $x;
return $IP_NUM;
}
 
sub object_add_attribute{
my ($self,$attribute1,$attribute2,$value)=@_;
if(!defined $attribute2){$self->{$attribute1}=$value;}
else {$self->{$attribute1}{$attribute2}=$value;}
 
}
 
 
 
sub object_get_attribute{
my ($self,$attribute1,$attribute2)=@_;
if(!defined $attribute2) {return $self->{$attribute1};}
return $self->{$attribute1}{$attribute2};
 
 
}
 
 
sub object_add_attribute_order{
my ($self,$attribute,@param)=@_;
$self->{'parameters_order'}{$attribute}=[] if (!defined $self->{parameters_order}{$attribute});
foreach my $p (@param){
push (@{$self->{parameters_order}{$attribute}},$p);
 
}
}
sub object_get_attribute_order{
my ($self,$attribute)=@_;
return @{$self->{parameters_order}{$attribute}};
}
 
sub object_remove_attribute{
my ($self,$attribute1,$attribute2)=@_;
if(!defined $attribute2){
delete $self->{$attribute1} if ( exists( $self->{$attribute1}));
}
else {
delete $self->{$attribute1}{$attribute2} if ( exists( $self->{$attribute1}{$attribute2})); ;
 
}
 
}
 
sub add_trace{
my ($self, $file_id,$trace_id, $source,$dest, $Mbytes, $file_name)=@_;
$self->object_add_attribute("trace_$trace_id",'file',$file_id);
$self->object_add_attribute("trace_$trace_id",'source',"${file_id}${source}");
$self->object_add_attribute("trace_$trace_id",'destination',"${file_id}${dest}");
$self->object_add_attribute("trace_$trace_id",'Mbytes', $Mbytes);
$self->object_add_attribute("trace_$trace_id",'file_name', $file_name);
$self->object_add_attribute("trace_$trace_id",'selected', 0);
$self->object_add_attribute("trace_$trace_id",'init_weight', 1);
$self->{'traces'}{$trace_id}=1;
}
 
sub remove_trace{
my ($self, $trace_id)=@_;
delete $self->{"trace_$trace_id"};
delete $self->{'traces'}{$trace_id};
}
 
sub get_trace_list{
my ($self)=@_;
return sort (keys %{$self->{'traces'}});
}
 
sub get_trace{
my ($self,$trace_id)=@_;
my $file_id = $self->object_get_attribute("trace_$trace_id",'file');
my $source = $self->object_get_attribute("trace_$trace_id",'source');
my $dest = $self->object_get_attribute("trace_$trace_id",'destination');
my $Mbytes = $self->object_get_attribute("trace_$trace_id",'Mbytes');
my $file_name = $self->object_get_attribute("trace_$trace_id",'file_name');
my $init_weight = $self->object_get_attribute("trace_$trace_id",'init_weight');
my $min_pck_size= $self->object_get_attribute("trace_$trace_id",'min_pck_size');
my $max_pck_size= $self->object_get_attribute("trace_$trace_id",'max_pck_size');
my $burst_size = $self->object_get_attribute("trace_$trace_id",'burst_size');
my $injct_rate = $self->object_get_attribute("trace_$trace_id",'injct_rate');
my $injct_rate_var = $self->object_get_attribute("trace_$trace_id",'injct_rate_var');
return ($source,$dest, $Mbytes, $file_id,$file_name,$init_weight,$min_pck_size, $max_pck_size, $burst_size, $injct_rate, $injct_rate_var);
}
 
sub get_all_tasks{
my $self=shift;
my @traces= $self->get_trace_list();
my @x;
foreach my $p (@traces){
my ($src,$dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
push(@x,$src);
push(@x,$dst);
}
my @x2 = uniq(sort @x) if (scalar @x);
return @x2;
}
 
 
sub remove_mapping{
my $self=shift;
$self->object_add_attribute('MAP_TASK',undef,undef);
$self->object_add_attribute('MAP_TILE',undef,undef);
}
 
 
 
sub remove_nlock_mapping{
my $self=shift;
my @tasks=get_all_tasks($self);
foreach my $p (@tasks){
my $lock=$self->object_get_attribute("MAP_LOCK",$p);
$lock = 0 if (!defined $lock);
if($lock == 0){
my $tile=$self->object_get_attribute("MAP_TILE",$p);
$self->object_add_attribute("MAP_TILE",$p,undef);
$self->object_add_attribute("MAP_TASK",$tile,undef);
}
}
}
 
 
sub get_nlock_tasks {
#my ($self,$taskref,$tileref)=shift;
my $self=shift;
my @unluck_tasks;
my @tasks=get_all_tasks($self);
foreach my $p (@tasks){
my $lock=$self->object_get_attribute("MAP_LOCK",$p);
$lock = 0 if (!defined $lock);
if($lock == 0){
push(@unluck_tasks,$p);
}
}
return @unluck_tasks;
}
 
sub get_nlock_tiles {
#my ($self,$taskref,$tileref)=shift;
my $self=shift;
my @luck_tiles;
my @tasks=get_all_tasks($self);
foreach my $task (@tasks){
my $lock=$self->object_get_attribute("MAP_LOCK",$task);
$lock = 0 if (!defined $lock);
if($lock == 1){
my $tile=$self->object_get_attribute('MAP_TILE',"$task");
push(@luck_tiles,$tile);
}
}
my @tiles=get_tiles_name($self);
#a-b
return get_diff_array(\@tiles,\@luck_tiles);
}
 
 
sub get_locked_map {
my $self=shift;
my %map;
my @tasks=get_all_tasks($self);
foreach my $task (@tasks){
my $lock=$self->object_get_attribute("MAP_LOCK",$task);
$lock = 0 if (!defined $lock);
if($lock == 1){
my $tile=$self->object_get_attribute('MAP_TILE',"$task");
$map{$task}=$tile;
}
}
return %map;
}
 
 
#########
# Mapping algorithm
#########
sub random_map{
my $self=shift;
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my $nc= $nx * $ny;
my @tasks=get_nlock_tasks($self);
my @tiles=get_nlock_tiles($self);
$self->remove_nlock_mapping() ;
my @rnd= shuffle @tiles;
my $i=0;
foreach my $task (@tasks){
if($i>=scalar @rnd){
last;
};
my $tile=$rnd[$i];
$self->object_add_attribute('MAP_TILE',"$task",$tile);
$self->object_add_attribute('MAP_TASK',"$tile",$task);
$i++;
}
set_gui_status($self,"ref",1);
}
 
sub direct_map {
my $self=shift;
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my $nc= $nx * $ny;
my @tasks=get_nlock_tasks($self);
my @tiles=get_nlock_tiles($self);
$self->remove_nlock_mapping() ;
my @sort_tiles;
my %tilenum;
foreach my $tile (@tiles){
my ($x,$y)=tile_id_to_loc($tile);
my $id= $y*$nx+$x;
$tilenum{$id}=$tile;
}
foreach my $id (sort keys %tilenum){
push(@sort_tiles, $tilenum{$id});
}
my @sort_tasks = sort @tasks;
my $i=0;
foreach my $task (@sort_tasks){
if($i>=scalar @sort_tiles){
last;
};
my $tile=$sort_tiles[$i];
$self->object_add_attribute('MAP_TILE',"$task",$tile);
$self->object_add_attribute('MAP_TASK',"$tile",$task);
$i++;
}
set_gui_status($self,"ref",1);
}
 
 
 
 
 
 
 
sub network_dim_cal{
my $n_tasks= shift;
my $dim_y = floor(sqrt($n_tasks));
 
my $dim_x = ceil($n_tasks/$dim_y);
return ($dim_x,$dim_y);
 
#cout << "dim_x = " << dim_x << "; dim_y = " << dim_y << endl;
}
 
 
sub get_tiles_name{
my $self=shift;
my @tiles;
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
if(defined $ny){
if($ny == 1){
for(my $x=0; $x<$nx; $x++){
push(@tiles,"tile($x)");
}
}
else{
for(my $y=0; $y<$ny; $y++){my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
for(my $x=0; $x<$nx; $x++){
push(@tiles,"tile(${x}_$y)");
}
}
}
}
return @tiles;
}
 
sub get_tile_name{
my ($self,$x,$y)=@_;
 
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
if(defined $ny){
return "tile($x)" if($ny == 1);
}
return "tile(${x}_$y)";
}
 
 
sub tile_id_to_loc{
my $tile=shift;
my ($x, $y) = $tile =~ /(\d+)/g;
$y=0 if(!defined $y);
return ($x,$y);
}
 
sub get_mah_distance{
my ($x1,$y1,$x2,$y2)=@_;
my $x_diff = ($x1 > $x2) ? ($x1 - $x2) : ($x2 - $x1);
my $y_diff = ($y1 > $y2) ? ($y1 - $y2) : ($y2 - $y1);
my $mah_distance = $x_diff + $y_diff;
return $mah_distance;
}
 
sub get_communication_task{
my $self=shift;
my %com_tasks;
my @traces= $self->get_trace_list();
my @tasks=get_all_tasks($self);
foreach my $p (@tasks){
$com_tasks{$p}{'total'}= 0;
foreach my $q (@tasks){
$com_tasks{$p}{$q}= 0;
}
}
foreach my $p (@traces){
my ($src,$dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
$com_tasks{$src}{'sent'} += $Mbytes;
$com_tasks{$dst}{'rsv'} += $Mbytes;
$com_tasks{$src}{'total'} += $Mbytes;
$com_tasks{$dst}{'total'} += $Mbytes;
$com_tasks{$src}{$dst} += $Mbytes;
$com_tasks{$file_id}{'maxsent'} = $com_tasks{$src}{'sent'} if(!defined $com_tasks{$file_id}{'maxsent'});
$com_tasks{$file_id}{'maxsent'} = $com_tasks{$src}{'sent'} if( $com_tasks{$file_id}{'maxsent'}<$com_tasks{$src}{'sent'});
my $minpck = $self->object_get_attribute("trace_$p",'min_pck_size');
my $maxpck = $self->object_get_attribute("trace_$p",'max_pck_size');
my $avg_pck_size =($minpck+ $maxpck)/2;
my $pck_num = ($Mbytes*8) /($avg_pck_size*64);
$pck_num= 1 if($pck_num==0);
$com_tasks{$src}{'min_pck_num'} =$pck_num if(!defined $com_tasks{$src}{'min_pck_num'});
$com_tasks{$src}{'min_pck_num'} =$pck_num if( $com_tasks{$src}{'min_pck_num'} > $pck_num);
}
return %com_tasks;
}
 
 
sub find_max_neighbor_tile{
my $self=shift;
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my $x_mid = floor($nx/2);
my $y_mid = floor($ny/2);
#my $centered_tile= get_tile_name($self,$x_mid ,$y_mid);
#Select the tile located in center as the max-neighbor if its not locked for any other task
#therwise select the tile with the min manhatan distance to center tile
my @tiles=get_nlock_tiles($self);
my $min=1000000;
my $max_neighbors_tile_id;
foreach my $tile (@tiles){
my ($x,$y)=tile_id_to_loc($tile);
my $mah_distance=get_mah_distance($x,$y,$x_mid,$y_mid);
if($min > $mah_distance ){
$min = $mah_distance;
$max_neighbors_tile_id=$tile;
}
}
 
return $max_neighbors_tile_id;
}
sub find_min_neighbor_tile {
my $self=shift;
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my $x_mid = 0;
my $y_mid = 0;
#my $centered_tile= get_tile_name($self,$x_mid ,$y_mid);
#Select the tile located in center as the max-neighbor if its not locked for any other task
#therwise select the tile with the min manhatan distance to center tile
my @tiles=get_nlock_tiles($self);
my $min=1000000;
my $min_neighbors_tile_id;
foreach my $tile (@tiles){
my ($x,$y)=tile_id_to_loc($tile);
my $mah_distance=get_mah_distance($x,$y,$x_mid,$y_mid);
if($min > $mah_distance ){
$min = $mah_distance;
$min_neighbors_tile_id=$tile;
}
}
 
return $min_neighbors_tile_id;
}
 
 
sub nmap_algorithm{
 
my $self=shift;
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my $nc= $nx * $ny;
my @tasks=get_all_tasks($self);
my @tiles= get_tiles_name($self);
my $n_tasks = scalar @tasks;
my @unmapped_tasks_set=@tasks; # unmapped set of tasks
my @unallocated_tiles_set=@tiles; # tile ids which are not allocated yet
#------ step 1: find the task with highest weighted communication volume
# find the max of com_vol
# consider all incoming and outgoing connections of each tasks
my %com_tasks= $self->get_communication_task();
#print Data::Dumper->Dump([\%com_tasks],['mpsoc']);
my $max_com_task;
my $max_com =0;
foreach my $p (sort keys %com_tasks){
#print "$p\n";
if(defined $com_tasks{$p}{'total'}){
if ($com_tasks{$p}{'total'} >$max_com){
$max_com = $com_tasks{$p}{'total'};
$max_com_task = $p;
}}
}
#------ step 2: find the tile with max number of neighbors
# normally, this tile is in the middle of the array
my $max_neighbors_tile_id = find_max_neighbor_tile($self);
my %map=get_locked_map ($self);
$self->remove_nlock_mapping();
foreach my $mapped_task (sort keys %map){
my $mapped_tile=$map{$mapped_task};
@unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$mapped_task);
@unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$mapped_tile);
}
# add this task with highest weighted communication volume to the mapped task set
#push(@mapped_tasks_set,$max_com_task);
#task_mapping[max_com_task] = max_neighbors_tile_id;
if(!defined $map{$max_com_task}){
$map{$max_com_task}=$max_neighbors_tile_id;
@unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$max_com_task);
@unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$max_neighbors_tile_id);
}
 
 
 
 
 
 
 
#------ step 3: map all unmapped tasks
while(scalar @unmapped_tasks_set){
$max_com =0;
my $max_com_unmapped_task;
my $max_overall_com=0;
#--------- step 3.1:
# find the unmapped task which communicates most with mapped_tasks_set
# among many tasks which have the same communication volume with mapped_tasks,
# choose the task with highest communication volume with others
foreach my $unmapped_task (@unmapped_tasks_set){
my $com_vol=0;
foreach my $mapped_task (sort keys %map){
$com_vol += $com_tasks{$unmapped_task}{$mapped_task};
$com_vol += $com_tasks{$mapped_task}{$unmapped_task};
}
my $overall_com_vol = 0;
foreach my $p (@tasks){
$overall_com_vol += $com_tasks{$unmapped_task}{$p};
$overall_com_vol += $com_tasks{$p}{$unmapped_task};
}
if ($com_vol > $max_com){
$max_com = $com_vol;
$max_com_unmapped_task = $unmapped_task;
$max_overall_com = $overall_com_vol;
}
elsif ($com_vol == $max_com){ # choose if it have higher comm volume
if ($overall_com_vol > $max_overall_com){
$max_com_unmapped_task = $unmapped_task;
$max_overall_com = $overall_com_vol;
}
}
}#foreach my $unmapped_task (@unmapped_tasks_set)
 
#--------- step 3.2, find the unallocated tile with lowest communication cost to/from allocated_tile_set
my $min_com_cost;
my $min_com_cost_tile_id;
foreach my $unallocated_tile(@unallocated_tiles_set){
my $com_cost = 0;
my ($unallocated_x,$unallocated_y)=tile_id_to_loc($unallocated_tile);
# scan all mapped tasks
foreach my $mapped_task (sort keys %map){
# get location of this mapped task
my $mapped_tile=$map{$mapped_task};
my ($allocated_x,$allocated_y)=tile_id_to_loc($mapped_tile);
# mahattan distance of 2 tiles
my $mah_distance=get_mah_distance($unallocated_x,$unallocated_y,$allocated_x,$allocated_y);
 
$com_cost += $com_tasks{$max_com_unmapped_task}{$mapped_task} * $mah_distance;
$com_cost += $com_tasks{$mapped_task}{$max_com_unmapped_task} * $mah_distance;
}
$min_com_cost = $com_cost+1 if(!defined $min_com_cost);
if ($com_cost < $min_com_cost){
$min_com_cost = $com_cost;
$min_com_cost_tile_id = $unallocated_tile;
}
}
# add max_com_unmapped_task to the mapped_tasks_set set
#task_mapping[max_com_unmapped_task] = min_com_cost_tile_id;
$map{$max_com_unmapped_task}=$min_com_cost_tile_id;
@unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$max_com_unmapped_task);
@unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$min_com_cost_tile_id);
}
foreach my $mapped_task (sort keys %map){
my $mapped_tile=$map{$mapped_task};
#print "$mapped_tile=\$map{$mapped_task};\n";
$self->object_add_attribute('MAP_TILE',"$mapped_task", $mapped_tile) if(defined $mapped_tile);
$self->object_add_attribute('MAP_TASK',"$mapped_tile",$mapped_task) if(defined $mapped_tile);
}
set_gui_status($self,"ref",1);
}
 
 
 
 
 
 
sub worst_map_algorithm{
 
my $self=shift;
my $nx=$self->object_get_attribute('noc_param','NX');
my $ny=$self->object_get_attribute('noc_param','NY');
my $nc= $nx * $ny;
my @tasks=get_all_tasks($self);
my @tiles= get_tiles_name($self);
my $n_tasks = scalar @tasks;
my @unmapped_tasks_set=@tasks; # unmapped set of tasks
my @unallocated_tiles_set=@tiles; # tile ids which are not allocated yet
#------ step 1: find the task with highest weighted communication volume
# find the max of com_vol
# consider all incoming and outgoing connections of each tasks
my %com_tasks= $self->get_communication_task();
#print Data::Dumper->Dump([\%com_tasks],['mpsoc']);
my $max_com_task;
my $max_com =0;
foreach my $p (sort keys %com_tasks){
#print "$p\n";
if(defined $com_tasks{$p}{'total'}){
if ($com_tasks{$p}{'total'} >$max_com){
$max_com = $com_tasks{$p}{'total'};
$max_com_task = $p;
}}
}
#------ step 2: find the tile with min number of neighbors
# normally, this tile is in the corners
my $min_neighbors_tile_id = find_min_neighbor_tile($self);
my %map=get_locked_map ($self);
$self->remove_nlock_mapping();
foreach my $mapped_task (sort keys %map){
my $mapped_tile=$map{$mapped_task};
@unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$mapped_task);
@unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$mapped_tile);
}
# add this task with highest weighted communication volume to the mapped task set
#push(@mapped_tasks_set,$max_com_task);
#task_mapping[max_com_task] = max_neighbors_tile_id;
if(!defined $map{$max_com_task}){
$map{$max_com_task}=$min_neighbors_tile_id;
@unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$max_com_task);
@unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$min_neighbors_tile_id);
}
 
 
 
 
 
 
 
#------ step 3: map all unmapped tasks
while(scalar @unmapped_tasks_set){
$max_com =0;
my $max_com_unmapped_task;
my $max_overall_com=0;
#--------- step 3.1:
# find the unmapped task which communicates most with mapped_tasks_set
# among many tasks which have the same communication volume with mapped_tasks,
# choose the task with highest communication volume with others
foreach my $unmapped_task (@unmapped_tasks_set){
my $com_vol=0;
foreach my $mapped_task (sort keys %map){
$com_vol += $com_tasks{$unmapped_task}{$mapped_task};
$com_vol += $com_tasks{$mapped_task}{$unmapped_task};
}
my $overall_com_vol = 0;
foreach my $p (@tasks){
$overall_com_vol += $com_tasks{$unmapped_task}{$p};
$overall_com_vol += $com_tasks{$p}{$unmapped_task};
}
if ($com_vol > $max_com){
$max_com = $com_vol;
$max_com_unmapped_task = $unmapped_task;
$max_overall_com = $overall_com_vol;
}
elsif ($com_vol == $max_com){ # choose if it have higher comm volume
if ($overall_com_vol > $max_overall_com){
$max_com_unmapped_task = $unmapped_task;
$max_overall_com = $overall_com_vol;
}
}
}#foreach my $unmapped_task (@unmapped_tasks_set)
 
#--------- step 3.2, find the unallocated tile with highest communication cost to/from allocated_tile_set
my $max_com_cost;
my $max_com_cost_tile_id;
foreach my $unallocated_tile(@unallocated_tiles_set){
my $com_cost = 0;
my ($unallocated_x,$unallocated_y)=tile_id_to_loc($unallocated_tile);
# scan all mapped tasks
foreach my $mapped_task (sort keys %map){
# get location of this mapped task
my $mapped_tile=$map{$mapped_task};
my ($allocated_x,$allocated_y)=tile_id_to_loc($mapped_tile);
# mahattan distance of 2 tiles
my $mah_distance=get_mah_distance($unallocated_x,$unallocated_y,$allocated_x,$allocated_y);
 
$com_cost += $com_tasks{$max_com_unmapped_task}{$mapped_task} * $mah_distance;
$com_cost += $com_tasks{$mapped_task}{$max_com_unmapped_task} * $mah_distance;
}
$max_com_cost = $com_cost-1 if(!defined $max_com_cost);
if ($com_cost > $max_com_cost){
$max_com_cost = $com_cost;
$max_com_cost_tile_id = $unallocated_tile;
}
}
# add max_com_unmapped_task to the mapped_tasks_set set
#task_mapping[max_com_unmapped_task] = min_com_cost_tile_id;
$map{$max_com_unmapped_task}=$max_com_cost_tile_id;
@unmapped_tasks_set=remove_scolar_from_array(\@unmapped_tasks_set,$max_com_unmapped_task);
@unallocated_tiles_set=remove_scolar_from_array(\@unallocated_tiles_set,$max_com_cost_tile_id);
}
foreach my $mapped_task (sort keys %map){
my $mapped_tile=$map{$mapped_task};
#print "$mapped_tile=\$map{$mapped_task};\n";
$self->object_add_attribute('MAP_TILE',"$mapped_task", $mapped_tile) if(defined $mapped_tile);
$self->object_add_attribute('MAP_TASK',"$mapped_tile",$mapped_task) if(defined $mapped_tile);
}
set_gui_status($self,"ref",1);
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sub get_task_assigned_to_tile {
my ($self,$x,$y)=@_;
my $p;
$p= $self->object_get_attribute("MAP_TASK","tile($x)");
return $p if (defined $p);
$p= $self->object_get_attribute("MAP_TASK","tile(${x}_$y)");
return $p;
}
 
 
 
sub get_assigned_tiles{
my $self=shift;
my @tiles = sort keys %{$self->{'MAP_TASK'}};
return @tiles;
}
 
sub map_task {
my ($self,$task,$tile)=@_;
my $oldtile= $self->{"MAP_TILE"}{$task};
if($tile eq "-"){
delete $self->{"MAP_TILE"}{$task};
}else{
$self->{"MAP_TILE"}{$task}= $tile;
$self->{'MAP_TASK'}{$tile}= $task;
}
delete $self->{"MAP_TASK"}{$oldtile} if(defined $oldtile);
}
 
sub remove_selected_traces{
my $self=shift;
my @traces= $self->get_trace_list();
foreach my $p (@traces) {
my $select=$self->object_get_attribute("trace_$p",'selected', 0);
if($select){
$self->remove_trace("$p");
}
}
set_gui_status($self,"ref",1);
}
 
 
 
sub auto_generate_injtratio{
my $self=shift;
my %com_tasks= $self->get_communication_task();
my @traces= $self->get_trace_list();
foreach my $p (@traces) {
my ($src,$dst, $Mbytes, $file_id, $file_name)=$self->get_trace($p);
my $max= $com_tasks{$file_id}{'maxsent'};
my $sent= $com_tasks{$src}{'sent'};
my $ratio = ($sent*100)/$max;
$self->object_add_attribute("trace_$p",'injct_rate',$ratio);
my $minpck = $self->object_get_attribute("trace_$p",'min_pck_size');
my $maxpck = $self->object_get_attribute("trace_$p",'max_pck_size' );
my $avg_pck_size =($minpck+ $maxpck)/2;
my $pck_num = ($Mbytes*8) /($avg_pck_size*64);
my $burst =$pck_num/ $com_tasks{$src}{'min_pck_num'} ;
$self->object_add_attribute("trace_$p",'burst_size',ceil($burst));
#my $burst_size = gen_spin_object ($self,"trace_$p",'burst_size',"1,1024,1", 1,undef,undef);
}
set_gui_status($self,"ref",1);
}
/verilog_gen.pl
27,6 → 27,7
my @instances=$soc->soc_get_all_instances();
my $io_sim_v;
my $io_top_sim_v;
my $core_id= $soc->object_get_attribute('global_param','CORE_ID');
$core_id= 0 if(!defined $core_id);
my $param_as_in_v="\tparameter\tCORE_ID=$core_id,
38,12 → 39,12
my $param_pass_v="\t.CORE_ID(CORE_ID),\n\t.SW_LOC(SW_LOC)";
my $body_v;
my ($param_v_all, $local_param_v_all, $wire_def_v_all, $inst_v_all, $plugs_assign_v_all, $sockets_assign_v_all,$io_full_v_all);
my ($param_v_all, $local_param_v_all, $wire_def_v_all, $inst_v_all, $plugs_assign_v_all, $sockets_assign_v_all,$io_full_v_all,$io_top_full_v_all);
my $wires=soc->new_wires();
my $intfc=interface->interface_new();
foreach my $id (@instances){
my ($param_v, $local_param_v, $wire_def_v, $inst_v, $plugs_assign_v, $sockets_assign_v,$io_full_v)=gen_module_inst($id,$soc,\$io_sim_v,\$param_as_in_v,$top_ip,$intfc,$wires,\$param_pass_v);
my ($param_v, $local_param_v, $wire_def_v, $inst_v, $plugs_assign_v, $sockets_assign_v,$io_full_v,$io_top_full_v)=gen_module_inst($id,$soc,\$io_sim_v,\$io_top_sim_v,\$param_as_in_v,$top_ip,$intfc,$wires,\$param_pass_v);
my $inst = $soc->soc_get_instance_name($id);
add_text_to_string(\$body_v,"/*******************\n*\n*\t$inst\n*\n*\n*********************/\n");
53,6 → 54,7
add_text_to_string(\$plugs_assign_v_all,"$plugs_assign_v\n") if(defined($plugs_assign_v));
add_text_to_string(\$sockets_assign_v_all,"$sockets_assign_v\n")if(defined($sockets_assign_v));
add_text_to_string(\$io_full_v_all,"$io_full_v\n") if(defined($io_full_v));
add_text_to_string(\$io_top_full_v_all,"$io_top_full_v\n") if(defined($io_top_full_v));
#print "$param_v $local_param_v $wire_def_v $inst_v $plugs_assign_v $sockets_assign_v $io_full_v";
90,10 → 92,10
 
#generate topmodule
my $top_v = (defined $param_as_in_v )? "module ${soc_name}_top #(\n $param_as_in_v\n)(\n$io_sim_v\n);\n": "module ${soc_name}_top (\n $io_sim_v\n);\n";
my $top_v = (defined $param_as_in_v )? "module ${soc_name}_top #(\n $param_as_in_v\n)(\n$io_top_sim_v\n);\n": "module ${soc_name}_top (\n $io_top_sim_v\n);\n";
my $ins= gen_soc_instance_v($soc,$soc_name,$param_pass_v);
add_text_to_string(\$top_v,$functions_all);
add_text_to_string(\$top_v,$local_param_v_all."\n".$io_full_v_all);
add_text_to_string(\$top_v,$local_param_v_all."\n".$io_top_full_v_all);
add_text_to_string(\$top_v,$ins);
my ($readme,$prog)=gen_system_info($soc,$param_as_in_v);
return ("$soc_v",$top_v,$readme,$prog);
106,7 → 108,7
###############
 
sub gen_module_inst {
my ($id,$soc,$io_sim_v,$param_as_in_v,$top_ip, $intfc,$wires,$param_pass_v)=@_;
my ($id,$soc,$io_sim_v,$io_top_sim_v,$param_as_in_v,$top_ip, $intfc,$wires,$param_pass_v)=@_;
my $module =$soc->soc_get_module($id);
my $module_name =$soc->soc_get_module_name($id);
my $category =$soc->soc_get_category($id);
117,7 → 119,7
my $ip = ip->lib_new ();
my @ports=$ip->ip_list_ports($category,$module);
my ($inst_v,$intfc_v,$plugs_assign_v,$sockets_assign_v,$io_full_v);
my ($inst_v,$intfc_v,$plugs_assign_v,$sockets_assign_v,$io_full_v,$io_top_full_v);
my $wire_def_v="";
$plugs_assign_v="\n";
161,7 → 163,7
if($connect_id eq 'IO'){ $IO='yes';}
if($connect_id eq 'NC'){ $NC='yes';}
}
if($i_type eq 'socket' && $i_name ne'wb_addr_map'){
if($i_type eq 'socket' && $i_name ne'wb_addr_map'){
my ($ref1,$ref2)= $soc->soc_get_modules_plug_connected_to_socket($id,$i_name,$i_num);
my %connected_plugs=%$ref1;
172,6 → 174,7
if ( length( $v || '' )){ $IO='no';} else {$IO='yes';}
}
}
if($NC eq 'yes'){
182,9 → 185,11
}else {
$assigned_port="$inst\_$port";
$$io_sim_v= (!defined $$io_sim_v)? "\t$assigned_port" : "$$io_sim_v, \n\t$assigned_port";
$$io_top_sim_v= (!defined $$io_top_sim_v)? "\t$assigned_port" : "$$io_top_sim_v, \n\t$assigned_port" if ($i_name ne 'RxD_sim');
my $new_range = add_instantc_name_to_parameters(\%params,$inst,$range);
my $port_def=(length ($range)>1 )? "\t$type\t [ $new_range ] $assigned_port;\n": "\t$type\t\t\t$assigned_port;\n";
add_text_to_string(\$io_full_v,$port_def);
add_text_to_string(\$io_top_full_v,$port_def) if ($i_name ne 'RxD_sim');
# $top_ip->ipgen_add_port($assigned_port, $new_range, $type ,$intfc_name,$i_port);
$top_ip->top_add_port($id,$assigned_port, $new_range, $type ,$intfc_name,$i_port);
}
296,7 → 301,7
return ($param_v, $local_param_v, $wire_def_v, $inst_v, $plugs_assign_v, $sockets_assign_v,$io_full_v,$param_pass_v);
return ($param_v, $local_param_v, $wire_def_v, $inst_v, $plugs_assign_v, $sockets_assign_v,$io_full_v,$io_top_full_v,$param_pass_v);
}
306,7 → 311,7
my ($params_ref,$inst,$range)=@_;
my $new_range=$range;
#print "$new_range\n";
 
return $new_range if(!defined $range);
my @list=sort keys%{$params_ref};
foreach my $param (@list){
my $new_param= "$inst\_$param";
342,7 → 347,7
#print parameters
foreach my $param (@list){
my $inst_param= "$inst\_$param";
my ($deafult,$type,$content,$info,$vfile_param_type,$redefine_param)= $ip->ip_get_parameter($category,$module,$param);
my ($default,$type,$content,$info,$vfile_param_type,$redefine_param)= $ip->ip_get_parameter($category,$module,$param);
$vfile_param_type= "Don't include" if (!defined $vfile_param_type );
$vfile_param_type= "Parameter" if ($vfile_param_type eq 1);
$vfile_param_type= "Localparam" if ($vfile_param_type eq 0);
605,6 → 610,17
}
#RxD_sim
elsif( $intfc eq 'socket:RxD_sim[0]'){
#This interface is for simulation only donot include it in top module
my @ports=$top->top_get_intfc_ports_list($intfc);
foreach my $p (@ports){
$mm="$mm," if ($i);
$mm="$mm\n\t\t.$p( )";
$i=1;
}
}
else {
#other interface
my @ports=$top->top_get_intfc_ports_list($intfc);
709,7 → 725,8
#Generate memory programming command
my $prog='#!/bin/sh
 
JTAG_MAIN="$PRONOC_WORK/toolchain/bin/jtag_main"
#JTAG_INTFC="$PRONOC_WORK/toolchain/bin/JTAG_INTFC"
source ./jtag_intfc.sh
 
';
 
731,13 → 748,13
my $BINFILE=$soc->soc_get_module_param_value($instance_id,'JTAG_MEM_FILE');
($BINFILE)=$BINFILE=~ /"([^"]*)"/ if(defined $BINFILE);
$BINFILE=(defined $BINFILE) ? $BINFILE.'.bin' : 'ram0.bin';
$BINFILE=(defined $BINFILE) ? "./RAM/".$BINFILE.'.bin' : './RAM/ram0.bin';
my $OFSSET="0x00000000";
my $end=((1 << $aw)*($dw/8))-1;
my $BOUNDRY=sprintf("0x%08x", $end);
if($jtag_connect =~ /JTAG_WB/){
$prog= "$prog \$JTAG_MAIN -n $JTAG_INDEX -s \"$OFSSET\" -e \"$BOUNDRY\" -i \"$BINFILE\" -c";
$prog= "$prog \$JTAG_INTFC -n $JTAG_INDEX -s \"$OFSSET\" -e \"$BOUNDRY\" -i \"$BINFILE\" -c";
#print "prog= $prog\n";
}elsif ($jtag_connect eq 'ALTERA_IMCE'){
755,7 → 772,7
if(defined $JTAG_INDEX){
$v= $soc->object_get_attribute('global_param',$JTAG_INDEX);
$JTAG_INDEX = $v if (defined $v);
$prog= "$prog \$JTAG_MAIN -n $JTAG_INDEX -s \"$OFSSET\" -e \"$BOUNDRY\" -i \"$BINFILE\" -c";
$prog= "$prog \$JTAG_INTFC -n $JTAG_INDEX -s \"$OFSSET\" -e \"$BOUNDRY\" -i \"$BINFILE\" -c";
#print "prog= $prog\n";
}
/widget.pl
5,9 → 5,31
 
 
 
 
use Gtk2::Pango;
#use Tk::Animation;
 
use String::Similarity;
 
sub find_the_most_similar_position{
my ($item ,@list)=@_;
my $most_similar_pos=0;
my $lastsim=0;
my $i=0;
# convert item to lowercase
$item = lc $item;
foreach my $p(@list){
my $similarity= similarity $item, $p;
if ($similarity > $lastsim){
$lastsim=$similarity;
$most_similar_pos=$i;
}
$i++;
}
return $most_similar_pos;
}
 
##############
# combo box
#############
485,6 → 507,16
}
 
 
 
sub set_tip{
my ($widget,$tip)=@_;
my $tooltips = Gtk2::Tooltips->new;
$tooltips->set_tip($widget,$tip);
}
 
 
############
# window
###########
549,13 → 581,9
my $scrolled_window = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_window->set_policy( "automatic", "automatic" );
$scrolled_window->add_with_viewport($box);
 
 
$window->add($scrolled_window);
$window->show_all;
$box->show_all;
 
return ($box,$window);
 
}
592,7 → 620,70
 
}
 
sub gen_scr_win_with_adjst {
my ($self,$name)=@_;
my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
$scrolled_win->set_policy( "automatic", "automatic" );
$scrolled_win->signal_connect("destroy"=> sub{
save_scrolled_win_adj($self,$scrolled_win, $name);
});
my $adjast=0;
$scrolled_win->signal_connect("size-allocate"=> sub{
if($adjast==0){
load_scrolled_win_adj($self,$scrolled_win, $name);
$adjast=1;
}
});
return $scrolled_win;
}
 
 
sub save_scrolled_win_adj {
my ($self,$scrolled_win,$name)=@_;
my $ha= $scrolled_win->get_hadjustment();
my $va =$scrolled_win->get_vadjustment();
return if(!defined $ha);
return if(!defined $va);
save_adj ($self,$ha,$name,"ha");
save_adj ($self,$va,$name,"va");
}
 
 
sub load_scrolled_win_adj {
my ($self,$scrolled_win,$name)=@_;
my $ha= $scrolled_win->get_hadjustment();
my $va =$scrolled_win->get_vadjustment();
my $h=load_adj ($self,$ha,$name,"ha");
my $v=load_adj ($self,$va,$name,"va");
#$ha->set_value($h) if(defined $h);
#$va->set_value($v) if(defined $v);
}
sub save_adj {
my ($self,$adjustment,$at1,$at2)=@_;
my $value = $adjustment->value;
$self->object_add_attribute($at1,$at2,$value);
}
 
 
sub load_adj {
my ($self,$adjustment,$at1,$at2)=@_;
return if(!defined $at1);
my $value= $self->object_get_attribute($at1,$at2);
return if(!defined $value);
my $lower = $adjustment->lower;
my $upper = $adjustment->upper - $adjustment->page_size;
$value= ($value < $lower || $value > $upper ) ? 0 : $value;
$adjustment->set_value($value);
}
 
 
##############
# box
#############
679,6 → 770,7
$tview->set_wrap_mode ('word');
$tview->set_pixels_above_lines (2);
$tview->set_pixels_below_lines (2);
# $scrolled_window->set_placement('bottom_left' );
return ($scrolled_window,$tview);
}
 
696,11 → 788,29
 
}
 
sub attach_widget_to_table {
my ($table,$row,$label,$inf_bt,$widget,$column)=@_;
$column = 0 if(!defined $column);
$column *=4;
#my $tmp=gen_label_in_left(" ");
if(defined $label) {$table->attach ($label , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
if(defined $inf_bt) {$table->attach ($inf_bt , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
if(defined $widget) {$table->attach ($widget , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
#$table->attach ($tmp , $column+3, $column+4, $row,$row+1,'fill','shrink',2,2);
}
 
 
#sub attach_widget_to_table2 {
# my ($table,$row,$label,$inf_bt,$widget)=@_;
# my $tmp=gen_label_in_left(" ");
# $table->attach ($label , 0, 4, $row,$row+1,'fill','shrink',2,2);
# $table->attach ($inf_bt , 4, 5, $row,$row+1,'fill','shrink',2,2);
# $table->attach ($widget , 5, 9, $row,$row+1,'fill','shrink',2,2);
# $table->attach ($tmp , 9, 10, $row,$row+1,'fill','shrink',2,2);
#}
 
 
 
######
# state
#####
753,6 → 863,24
}
 
 
sub new_on_textview{
my ($textview,$info)=@_;
my $buffer = $textview->get_buffer();
$buffer->set_text($info);
}
 
sub append_to_textview{
my ($textview,$info)=@_;
my $buffer = $textview->get_buffer();
my $textiter = $buffer->get_end_iter();
#Insert some text into the buffer
$buffer->insert($textiter,$info);
}
 
 
sub show_colored_info{
my ($textview_ref,$info,$color)=@_;
my $buffer = $$textview_ref->get_buffer();
771,6 → 899,14
}
 
sub add_colors_to_textview{
my $tview= shift;
add_colored_tag($tview,'red');
add_colored_tag($tview,'blue');
add_colored_tag($tview,'green');
}
 
 
sub add_colored_tag{
my ($textview_ref,$color)=@_;
my $buffer = $textview_ref->get_buffer();
827,7 → 963,7
 
sub save_file {
my ($file_path,$text)=@_;
open(my $fd, ">$file_path");
open my $fd, ">$file_path" or die "could not open $file_path: $!";
print $fd $text;
close $fd;
}
1051,23 → 1187,23
my $ref= ref ($self->{$p}{$q}{$z});
if( $ref eq 'HASH' ){
foreach my $w (keys %{$clone->{$p}{$q}{$q}}){
foreach my $w (keys %{$clone->{$p}{$q}{$z}}){
$self->{$p}{$q}{$z}{$w}= $clone->{$p}{$q}{$z}{$w};
my $ref= ref ($self->{$p}{$q}{$z}{$w});
if( $ref eq 'HASH' ){
foreach my $m (keys %{$clone->{$p}{$q}{$q}{$w}}){
foreach my $m (keys %{$clone->{$p}{$q}{$z}{$w}}){
$self->{$p}{$q}{$z}{$w}{$m}= $clone->{$p}{$q}{$z}{$w}{$m};
my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m});
if( $ref eq 'HASH' ){
foreach my $n (keys %{$clone->{$p}{$q}{$q}{$w}{$m}}){
foreach my $n (keys %{$clone->{$p}{$q}{$z}{$w}{$m}}){
$self->{$p}{$q}{$z}{$w}{$m}{$n}= $clone->{$p}{$q}{$z}{$w}{$m}{$n};
my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m}{$n});
if( $ref eq 'HASH' ){
foreach my $l (keys %{$clone->{$p}{$q}{$q}{$w}{$m}{$n}}){
foreach my $l (keys %{$clone->{$p}{$q}{$z}{$w}{$m}{$n}}){
$self->{$p}{$q}{$z}{$w}{$m}{$n}{$l}= $clone->{$p}{$q}{$z}{$w}{$m}{$n}{$l};
my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m}{$n}{$l});
if( $ref eq 'HASH' ){
1128,13 → 1264,27
 
}
 
sub remove_project_dir_from_addr{
my $file=shift;
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../"); #mpsoc directory address
$file =~ s/$project_dir//;
return $file;
}
 
sub add_project_dir_to_addr{
my $file=shift;
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../"); #mpsoc directory address
return $file if(-f $file );
return "$project_dir/$file";
}
 
sub get_file_name {
my ($object,$title,$entry,$attribute1,$attribute2,$extension,$lable,$open_in)= @_;
my $browse= def_image_button("icons/browse.png");
my $dir = Cwd::getcwd();
my $project_dir = abs_path("$dir/../../"); #mpsoc directory address
 
$browse->signal_connect("clicked"=> sub{
my $entry_ref=$_[1];
my $file;
1158,9 → 1308,9
}
if ( "ok" eq $dialog->run ) {
$file = $dialog->get_filename;
$file = $dialog->get_filename;
#remove $project_dir form beginig of each file
$file =~ s/$project_dir//;
$file =remove_project_dir_from_addr($file);
$$entry_ref->set_text($file);
$object->object_add_attribute($attribute1,$attribute2,$file) if(defined $object);
my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1263,14 → 1413,17
$value=$default;
$object->object_add_attribute($attribute1,$attribute2,$value);
}
$value=~ s/\D//g;
$min=~ s/\D//g;
$max=~ s/\D//g;
$step=~ s/\D//g;
$value=~ s/[^0-9.]//g;
$min=~ s/[^0-9.]//g;
$max=~ s/[^0-9.]//g;
$step=~ s/[^0-9.]//g;
my $widget=gen_spin($min,$max,$step);
$widget->set_value($value);
$widget-> signal_connect("value_changed" => sub{
my $new_param_value=$widget->get_value_as_int();
my $new_param_value=$widget->get_value();
$object->object_add_attribute($attribute1,$attribute2,$new_param_value);
set_gui_status($object,$status,$timeout) if (defined $status);
});
1360,9 → 1513,11
 
 
sub get_dir_in_object {
my ($object,$attribute1,$attribute2,$content,$status,$timeout)=@_;
my ($object,$attribute1,$attribute2,$content,$status,$timeout,$default)=@_;
my $widget = def_hbox(FALSE,0);
my $value=$object->object_get_attribute($attribute1,$attribute2);
$object->object_add_attribute($attribute1,$attribute2, $default) if (!defined $value );
$value = $default if (!defined $value );
my $entry=gen_entry($value);
$entry-> signal_connect("changed" => sub{
my $new_param_value=$entry->get_text();
1398,6 → 1553,152
return $widget;
}
 
 
 
 
 
 
 
 
 
 
 
sub add_param_widget {
my ($mpsoc,$name,$param, $default,$type,$content,$info, $table,$row,$column,$show,$attribut1,$ref_delay,$new_status,$loc)=@_;
my $label;
$label =gen_label_in_left(" $name") if(defined $name);
my $widget;
my $value=$mpsoc->object_get_attribute($attribut1,$param);
if(! defined $value) {
$mpsoc->object_add_attribute($attribut1,$param,$default);
$mpsoc->object_add_attribute_order($attribut1,$param);
$value=$default;
}
if(! defined $new_status){
$new_status='ref';
}
if ($type eq "Entry"){
$widget=gen_entry($value);
$widget-> signal_connect("changed" => sub{
my $new_param_value=$widget->get_text();
$mpsoc->object_add_attribute($attribut1,$param,$new_param_value);
set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
 
});
}
elsif ($type eq "Combo-box"){
my @combo_list=split(",",$content);
my $pos=get_pos($value, @combo_list) if(defined $value);
if(!defined $pos){
$mpsoc->object_add_attribute($attribut1,$param,$default);
$pos=get_item_pos($default, @combo_list) if (defined $default);
}
#print " my $pos=get_item_pos($value, @combo_list);\n";
$widget=gen_combo(\@combo_list, $pos);
$widget-> signal_connect("changed" => sub{
my $new_param_value=$widget->get_active_text();
$mpsoc->object_add_attribute($attribut1,$param,$new_param_value);
set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
 
 
});
}
elsif ($type eq "Spin-button"){
my ($min,$max,$step)=split(",",$content);
$value=~ s/\D//g;
$min=~ s/\D//g;
$max=~ s/\D//g;
$step=~ s/\D//g;
$widget=gen_spin($min,$max,$step);
$widget->set_value($value);
$widget-> signal_connect("value_changed" => sub{
my $new_param_value=$widget->get_value_as_int();
$mpsoc->object_add_attribute($attribut1,$param,$new_param_value);
set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
 
});
# $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
}
elsif ( $type eq "Check-box"){
$widget = def_hbox(FALSE,0);
my @check;
for (my $i=0;$i<$content;$i++){
$check[$i]= Gtk2::CheckButton->new;
}
for (my $i=0;$i<$content;$i++){
$widget->pack_end( $check[$i], FALSE, FALSE, 0);
my @chars = split("",$value);
#check if saved value match the size of check box
if($chars[0] ne $content ) {
$mpsoc->object_add_attribute($attribut1,$param,$default);
$value=$default;
@chars = split("",$value);
}
#set initial value
#print "\@chars=@chars\n";
for (my $i=0;$i<$content;$i++){
my $loc= (scalar @chars) -($i+1);
if( $chars[$loc] eq '1') {$check[$i]->set_active(TRUE);}
else {$check[$i]->set_active(FALSE);}
}
 
 
#get new value
$check[$i]-> signal_connect("toggled" => sub{
my $new_val="$content\'b";
for (my $i=$content-1; $i >= 0; $i--){
if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
else {$new_val="${new_val}0" ;}
}
$mpsoc->object_add_attribute($attribut1,$param,$new_val);
#print "\$new_val=$new_val\n";
set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
});
}
 
 
 
 
}
elsif ( $type eq "DIR_path"){
$widget =get_dir_in_object ($mpsoc,$attribut1,$param,$value,'ref',10);
set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
}
elsif ( $type eq "FILE_path"){ # use $content as extention
$widget =get_file_name_object ($mpsoc,$attribut1,$param,$content,undef);
set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
}
else {
$widget =gen_label_in_left("unsuported widget type!");
}
 
my $inf_bt= (defined $info)? gen_button_message ($info,"icons/help.png"):gen_label_in_left(" ");
if($show==1){
attach_widget_to_table ($table,$row,$label,$inf_bt,$widget,$column);
if ($loc eq "vertical"){
#print "$loc\n";
$row ++;}
else {
$column+=4;
}
}
return ($row,$column);
}
 
 
 
 
################
# ADD info and label to widget
################
1491,7 → 1792,7
my @B=@{$b_ref};
my @C;
foreach my $p (@A){
if( grep (/^$p$/,@B)){push(@C,$p)};
if( grep (/^\Q$p\E$/,@B)){push(@C,$p)};
}
return @C;
}
1503,7 → 1804,7
my @B=@{$b_ref};
my @C;
foreach my $p (@A){
if( !grep (/^$p$/,@B)){push(@C,$p)};
if( !grep (/^\Q$p\E$/,@B)){push(@C,$p)};
}
return @C;
1596,7 → 1897,21
}
 
 
sub capture_number_after {
my ($after,$text)=@_;
my @q =split (/$after/,$text);
#my $d=$q[1];
my @d = split (/[^0-9. ]/,$q[1]);
return $d[0];
 
}
 
sub capture_string_between {
my ($start,$text,$end)=@_;
my @q =split (/$start/,$text);
my @d = split (/$end/,$q[1]);
return $d[0];
}
 
 
1

powered by: WebSVN 2.1.0

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