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

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

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
#!/usr/bin/perl -w
2
use strict;
3
use warnings;
4
 
5
use constant::boolean;
6
 
7
use FindBin;
8
use lib $FindBin::Bin;
9
 
10
use Data::Dumper;
11
use File::Which;
12
use File::Basename;
13
 
14
use IPC::Run qw( harness start pump finish timeout );
15
 
16
use Consts;
17
BEGIN {
18
    my $module = (Consts::GTK_VERSION==2) ? 'Gtk2' : 'Gtk3';
19
    my $file = $module;
20
    $file =~ s[::][/]g;
21
    $file .= '.pm';
22
    require $file;
23
    $module->import;
24
}
25
 
26
 
27
 
28
require "widget.pl";
29
require "uart.pl";
30
require "compile.pl";
31
 
32
 
33
use String::Scanf; # imports sscanf()
34
 
35
 
36
use constant JTAG_UPDATE_WB_ADDR => 7;
37
use constant JTAG_UPDATE_WB_WR_DATA=>  6;
38
use constant JTAG_UPDATE_WB_RD_DATA => 5;
39
 
40
 
41
use base 'Class::Accessor::Fast';
42
__PACKAGE__->mk_accessors(qw{
43
        window
44
        sourceview
45
});
46
 
47
my $NAME = 'Soure Probe';
48
my      $path = "";
49
 
50 54 alirezamon
 
51
 
52 48 alirezamon
my %memory;
53
my %status;
54
 
55
 
56
sub source_probe_stand_alone(){
57
        $path = "../../";
58
        set_path_env();
59
        my $project_dir   = get_project_dir(); #mpsoc dir addr
60
        my $paths_file= "$project_dir/mpsoc/perl_gui/lib/Paths";
61
        if (-f  $paths_file){#} && defined $ENV{PRONOC_WORK} ) {
62
                my $paths= do $paths_file;
63 54 alirezamon
                set_gui_setting($paths);
64 48 alirezamon
        }
65
 
66
        set_defualt_font_size();
67
        my $window=source_probe_main();
68
        $window->signal_connect (destroy => sub { gui_quite();});
69
}
70
 
71
exit gtk_gui_run(\&source_probe_stand_alone) unless caller;
72
 
73
 
74
sub get_jtag_intfc_rst_cmd {
75
        my $self=shift;
76
 
77
        my $vendor = $self->object_get_attribute('CTRL','VENDOR');
78
        my $board  = $self->object_get_attribute('CTRL','Board_Name');
79
        my $chain  = $self->object_get_attribute('CTRL','RESET_CHAIN');
80
        my $index  = 127;
81
        my $pronoc = get_project_dir();
82
        my $intfc = "$pronoc/mpsoc/boards/$vendor/$board/jtag_intfc.sh";
83
        #my $script  = "$ENV{'PRONOC_WORK'}/tmp/script.bash";
84
 
85
        my $t = ($vendor eq 'Xilinx') ? "-t  $chain " : "";
86
 
87
        my $cmd = "bash -c \"source $intfc; \\\$JTAG_INTFC $t -n $index";
88
        return $cmd;
89
 
90
}
91
 
92
 
93
sub jtag_enable_cpus_func{
94
        my ($self,$new,$tview)=@_;
95
        my $intfc = get_jtag_intfc_rst_cmd($self);
96
    my $e = ($new eq 'Enabled')? 0 : 2;
97
        my $cmd =       "$intfc  -d   I:1,D:2:$e,I:0\"";
98
        add_info($tview,"$cmd\n");
99
        my $results =run_cmd_textview_errors($cmd,$tview);
100
        return 1 if(!defined $results);
101
 
102
}
103
 
104
sub jtag_reset_cpus_func {
105
        my ($self,$tview)=@_;
106
        my $intfc = get_jtag_intfc_rst_cmd($self);
107
 
108
        my $cmd =       "$intfc  -d   I:1,D:2:1,D:2:0,I:0\"";
109
        add_info($tview,"$cmd\n");
110
        my $results =run_cmd_textview_errors($cmd,$tview);
111
        return 1 if(!defined $results);
112
 
113
};
114
 
115
 
116
 
117
 
118
 
119
sub source_probe_ctrl {
120
        my ($self,$tview)=@_;
121
        my $table= def_table(2,10,FALSE);
122
 
123
        my $vendor= $self->object_get_attribute('CTRL','VENDOR');
124
        $vendor= 'Xilinx' if(!defined $vendor);
125
 
126
 
127
        #get the list of boards located in "boards/*" folder
128
        my $pronoc = get_project_dir();
129
 
130
        my @dirs = grep {-d} glob("$pronoc/mpsoc/boards/$vendor/*");
131
        my ($fpgas,$init);
132
 
133
 
134
        foreach my $dir (@dirs) {
135
                my ($name,$path,$suffix) = fileparse("$dir",qr"\..[^.]*$");
136
                $fpgas= (defined $fpgas)? "$fpgas,$name" : "$name";
137
                $init="$name";
138
        }
139
 
140
 
141
        my @info = (
142
        { label=>" FPGA Vendor name: ", param_name=>'VENDOR', type=>"Combo-box", default_val=>'Xilinx', content=>"Xilinx,Altera", info=>undef, param_parent=>'CTRL', ref_delay=> 1, new_status=>'ref_ctrl', loc=>'vertical'},
143
        { label=>" Board Name ", param_name=>'Board_Name', type=>"Combo-box", default_val=>$init, content=>$fpgas, info=>undef, param_parent=>'CTRL', ref_delay=> undef, new_status=>undef, loc=>'vertical'},
144
        { label=>" JTAG Index: ", param_name=>'JTAG_INDEX', type=>"Spin-button", default_val=>0, content=>"0,128,1", info=>undef, param_parent=>'CTRL', ref_delay=> undef, new_status=> undef, loc=>'vertical'}
145
        );
146
 
147
 
148
 
149
        if ($vendor eq "Xilinx" ) {
150
                push (@info,{ label=>" JTAG CHAIN ", param_name=>'JTAG_CHAIN', type=>"Combo-box", default_val=>4, content=>"1,2,3,4", info=>undef, param_parent=>'CTRL', ref_delay=> 0, new_status=>'ref_ctrl', loc=>'vertical'}) ;
151
 
152
        }
153
 
154
 
155
        my ($row,$col)=(0,6);
156
 
157
        foreach my $d (@info) {
158
                my $wiget;
159
                ($row,$col,$wiget)=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}, $d->{loc});
160
                my $sc=$col;
161
                if($d->{param_name} eq 'Board_Name'){
162
                        my $add=def_image_button("icons/plus.png");
163
                        $table->attach ($add,  $sc+4, $sc+5,$row-1,$row,'shrink','shrink',2,2);
164
                        set_tip($add, "Add new FPGA Board");
165
                        $add-> signal_connect("clicked" => sub{
166
                                add_new_fpga_board($self,undef,undef,undef,undef,$vendor);
167
                        });
168
 
169
                }
170
 
171
 
172
        }
173
 
174
 
175
         $table->attach (  gen_Vsep(), 5, 6 , 0, $row+1,'fill','fill',2,2);
176
 
177
        #Column 2
178
        $row=0;$col=0;
179
        my $d={ label=>" Number of Sources/Probes:", param_name=>'SP_NUM', type=>"Spin-button", default_val=>1, content=>"1,128,1", info=>undef, param_parent=>'CTRL', ref_delay=> 1, new_status=>'ref_all', loc=>'vertical'};
180
        ($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}, $d->{loc});
181
        $d={ label=>" Address format: ", param_name=>'R_ADDR_FORMAT', type=>"Combo-box", default_val=>'Decimal', content=>"Decimal,Hexadecimal", info=>undef, param_parent=>'FILE_VIEW', ref_delay=> 1, new_status=>'ref_file_view', loc=>'vertical'},
182
        ($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}, $d->{loc});
183
 
184
 
185
        #enable
186
        my $en_state=$self->object_get_attribute("CTRL","enable");
187
        if (!defined $en_state){
188
                $en_state='Enabled' ;
189
                $self->object_add_attribute("CTRL","enable",$en_state);
190
        }
191
        my $enable= ($en_state eq 'Enabled')? def_colored_button('Enabled',17): def_colored_button('Disabled',4);
192
 
193
        my $reset= def_button('Reset');
194
 
195
        if ($vendor eq "Xilinx" ) {
196
 
197
                my $w=gen_combobox_object ($self,'CTRL','RESET_CHAIN',"4,3,2,1","4",undef,undef);
198
                my $h=gen_button_message ("The JTAG remote reset/enable is connected to the Jtag tab chain with the largest chain number in each tile.  ","icons/help.png");
199
                my $b= def_pack_hbox(FALSE,0,(gen_label_in_center  ("CPU(s) Chain:"),$w,$h));
200
                $table->attach ($b ,  $col, $col+1,$row,$row+1,'shrink','shrink',2,2); $col+=1;
201
 
202
        }else{
203
                $table->attach (gen_label_in_center  ("CPU(s)") ,  $col, $col+1,$row,$row+1,'shrink','shrink',2,2); $col+=1;
204
        }
205
 
206
        $table->attach ($reset ,  $col, $col+1,$row,$row+1,'shrink','shrink',2,2); $col+=1;
207
        $table->attach ($enable ,  $col, $col+1,$row,$row+1,'shrink','shrink',2,2); $row++;
208
 
209
        $enable -> signal_connect("clicked" => sub{
210
                        my $en_state=$self->object_get_attribute("CTRL","enable");
211
                        my $new = ($en_state eq 'Enabled')? 'Disabled' : 'Enabled';
212
                        jtag_enable_cpus_func($self,$new,$tview);
213
                        $self->object_add_attribute("CTRL","enable",$new);
214
                        set_gui_status($self,"ref",1);
215
        });
216
 
217
        $reset -> signal_connect("clicked" => sub{
218
                        jtag_reset_cpus_func($self,$tview);
219
        });
220
 
221
 
222
        my $scrolled_win=gen_scr_win_with_adjst ($self,"receive_box");
223
        add_widget_to_scrolled_win($table,$scrolled_win);
224
        return $scrolled_win;
225
}
226
 
227
 
228
 
229
 
230
 
231
 
232
 
233
 
234
sub soure_probe_widgets_old {
235
        my $self=shift;
236
        my $table= def_table(2,10,FALSE);
237
        my $scrolled_win=gen_scr_win_with_adjst ($self,"receive_box");
238
        add_widget_to_scrolled_win($table,$scrolled_win);
239
        my $num = $self->object_get_attribute('CTRL','SP_NUM');
240
 
241
        my $y= 0;
242
        my $x= 0;
243
 
244
        $table->attach (gen_label_in_center(" Source "), 0, 3 , $y, $y+1,'shrink','shrink',2,2);
245
        $table->attach (gen_label_in_center(" Probe  "), 4, 7 , $y, $y+1,'shrink','shrink',2,2);
246
        $y++;
247
        $table->attach ( gen_Hsep(), 0, 7 , $y, $y+1, 'fill','shrink',2,2);
248
 
249
        $y++;
250
        my @sources;
251
        for (my $i=0; $i<$num; $i+=1){
252
                        my $n=$i+1;
253
                        $table->attach (gen_label_in_left("  $n- "), $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x++;
254
                        my $entry=gen_entry( );
255
                        $table->attach ($entry, $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x++;
256
 
257
                my $enter=def_image_button("icons/write.png","Write");
258
 
259
                $table->attach ($enter, $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x++;
260
 
261
                $x++; #sep
262
 
263
                #probe 
264
                #$table->attach (gen_label_in_left(" Probe:  " )        , $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x++; 
265
                my $probe_val = $self-> object_get_attribute('SP','PROBE_$n');
266
 
267
                my $probe_label= gen_label_in_left(" ");
268
 
269
                ${probe_val}=25 if ($n ==1);
270
 
271
                $probe_label->set_markup("<span  foreground= 'red' ><b>XXXX</b></span>") if(!defined $probe_val );
272
                $probe_label->set_markup("<span  foreground= 'blue' ><b></b>    ${probe_val}   </span>") unless(!defined $probe_val );
273
 
274
                my $frame = gen_frame();
275
                        $frame->set_shadow_type ('in');
276
                        # Animation
277
                        $frame->add ($probe_label);
278
 
279
 
280
                $table->attach ($frame, $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x++;
281
                my $read=def_image_button("icons/simulator.png","Read");
282
                $table->attach ($read, $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x++;
283
 
284
                $y++; $x=0;
285
                $table->attach (gen_Hsep(), 0, 7 , $y, $y+1, 'fill','shrink',2,2);
286
                $y++;
287
 
288
        }
289
 
290
          $table->attach ( gen_Vsep(), 3, 4 , 0, $y+1,'fill','fill',2,2);
291
          $table->attach ( gen_Vsep(), 6, 7 , 0, $y+1,'fill','fill',2,2);
292
 
293
        return ($scrolled_win,\@sources);
294
}
295
 
296
sub read_mem_specefic_addr{
297
        my ($self,$addr,$tview)=@_;
298
        add_info($tview,"Read addr: $addr\n");
299
        my $intfc = get_jtag_intfc_cmd($self);
300
        $addr=($addr>>2);
301
        $addr=sprintf("%x",$addr);
302
        my $cmd =       "$intfc -d  I:${\JTAG_UPDATE_WB_RD_DATA},R:32:$addr,I:0\"";
303
        add_info($tview,"$cmd\n");
304
        my $results =run_cmd_textview_errors($cmd,$tview);
305
        return 1 if(!defined $results);
306
        my ($hex)= sscanf("###read data#0x%s###read data#", $results);
307
        ###read data#0x18000000###read data#
308
        #add_info($tview," $results \n");       
309
        #add_info($tview," $hex \n");   
310
        return $hex;
311
}
312
 
313
 
314
sub write_mem_specefic_addr {
315
        my ($self,$addr,$value,$tview)=@_;
316
        my $intfc = get_jtag_intfc_cmd($self);
317
        $addr=($addr>>2);
318
        $addr=sprintf("%x",$addr);
319
        my $cmd =       "$intfc -d  I:${\JTAG_UPDATE_WB_ADDR},D:32:$addr,I:${\JTAG_UPDATE_WB_WR_DATA},D:32:$value,I:0\"";
320
        add_info($tview,"$cmd\n");
321
        my $results =run_cmd_textview_errors($cmd,$tview);
322
        return 1 if(!defined $results);
323
}
324
 
325
sub soure_probe_widgets {
326
        my ($self,$tview)=@_;
327
        my $table= def_table(2,10,FALSE);
328
        my $scrolled_win=gen_scr_win_with_adjst ($self,"receive_box");
329
        add_widget_to_scrolled_win($table,$scrolled_win);
330
        my $num = $self->object_get_attribute('CTRL','SP_NUM');
331
        $num = 1 if (!defined $num);
332
        my $y= 0;
333
        my $x= 0;
334
 
335
 
336
 
337
 
338
 
339
        $table->attach (gen_label_in_center(" Address (in byte)"), 0, 1 , $y, $y+1,'shrink','shrink',2,2);
340
        $table->attach (gen_label_in_center(" Memory Content  "), 2, 3 , $y, $y+1,'shrink','shrink',2,2);
341
        $table->attach (gen_label_in_center(" Action "), 4, 6 , $y, $y+1,'shrink','shrink',2,2);
342
        $y++;
343
 
344
        $table->attach ( gen_Hsep(), 0, 6 , $y, $y+1, 'fill','shrink',2,2);
345
 
346
        $y++;
347
        $x= 0;
348
 
349
        for (my $i=0; $i<$num; $i+=1){
350
                        my $n=$i+1;
351
                        my $status=0;
352
                        #$table->attach (gen_label_in_left("  $n-address "), $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x++;
353
                #       ($y,$x,$addr)=add_param_widget  ($self,"$n-", "$n-address", 0, "Spin-button", "0,99999999,1", undef, $table,$y,$x,1, "JTAG_WB", undef, undef, 'horizontal');
354
                   # ($y,$x,$entry)=add_param_widget  ($self,undef, "$n-value", 0, "Entry", undef, undef, $table,$y,$x,1, "JTAG_WB", undef, undef, 'horizontal');
355
 
356
                    my $addr = gen_entry(0);
357
                    my $entry =gen_entry('xxxxxxxx');
358
                    my $read=def_image_button($path."icons/simulator.png","Read");
359
                    my $write=def_image_button($path."icons/write.png","Write");
360
 
361
 
362
                    $entry->set_max_length (8);
363
                        $entry->set_width_chars(8);
364
 
365
                        $table->attach ($addr, $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x+=2;
366
                    $table->attach ($entry, $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x+=2;
367
                $table->attach ($read, $x, $x+1 , $y, $y+1,'shrink','shrink',2,2);  $x++;
368
                        $table->attach ($write, $x, $x+1 , $y, $y+1,'shrink','shrink',2,2); $x++;
369
                        my $sy= $y;
370
                        my $sx=7;
371
 
372
                $y++; $x=0;
373
                $table->attach ( gen_Hsep(), 0, $sx , $y, $y+1, 'fill','shrink',2,2);
374
                $y++;
375
 
376
 
377
 
378
                $read-> signal_connect("clicked" => sub{
379
                        my $address=$addr->get_text();
380
                        my $format =$self->     object_get_attribute('FILE_VIEW','R_ADDR_FORMAT');
381
                                $format= 'Decimal' if (!defined $format);
382
                        $address = hex($address) unless($format eq 'Decimal');
383
                        my $load= show_gif("icons/load.gif");
384
                                $table->attach ($load,$sx, $sx+1 , $sy, $sy+1,'shrink','shrink',0,0);
385
                                $table->show_all();
386
                        my $val =read_mem_specefic_addr($self,$address,$tview);
387
                        $entry->set_text($val) if (defined $val);
388
                        $status =1;
389
                        entry_set_text_color($entry,-1);
390
                        $load->destroy;
391
                });
392
 
393
                $write-> signal_connect("clicked" => sub{
394
                        my $value = $entry->get_text();
395
                        my $address=$addr->get_text();
396
                        my $format =$self->     object_get_attribute('FILE_VIEW','R_ADDR_FORMAT');
397
                                $format= 'Decimal' if (!defined $format);
398
                        $address = hex($address) unless($format eq 'Decimal');
399
                        my $load= show_gif("icons/load.gif");
400
                                $table->attach ($load,$sx, $sx+1 , $sy, $sy+1,'shrink','shrink',0,0);
401
                                $table->show_all();
402
                        write_mem_specefic_addr($self,$address,$value,$tview);
403
                        $status =1;
404
                        entry_set_text_color($entry,-1);
405
                        $load->destroy;
406
 
407
                });
408
 
409
                $entry->signal_connect("changed" => sub{
410
                                if($status==0 || $status==1 ){
411
                                        $status =2;#modified
412
                                        #change color to red
413
                                        entry_set_text_color($entry,11);
414
 
415
                                }
416
                                my $in = $entry->get_text();
417
                                $entry->set_text(remove_not_hex($in));
418
 
419
                        });
420
 
421
 
422
                        $addr->signal_connect("changed" => sub{
423
                                my $format =$self->     object_get_attribute('FILE_VIEW','R_ADDR_FORMAT');
424
                                $format= 'Decimal' if (!defined $format);
425
                                my $in = $addr->get_text();
426
                                $addr->set_text(remove_not_hex($in)) if ($format ne 'Decimal' );
427
                                $addr->set_text(remove_not_number($in)) if ($format eq 'Decimal' );
428
                        });
429
 
430
        }
431
 
432
        $table->attach ( gen_Vsep(), 1, 2 , 0, $y+1,'fill','fill',2,2);
433
        $table->attach ( gen_Vsep(), 3, 4 , 0, $y+1,'fill','fill',2,2);
434
        $table->attach ( gen_Vsep(), 6, 7 , 0, $y+1,'fill','fill',2,2);
435
 
436
        return $scrolled_win;
437
}
438
 
439
sub get_file_b_setting{
440
        my($self)=@_;
441
        my $window = def_popwin_size (30,30,'Source Probe','percent');
442
    my $table= def_table(2,10,FALSE);
443
    my @info = (
444
        #{ label=>" Address format: ", param_name=>'R_ADDR_FORMAT', type=>"Combo-box", default_val=>'Decimal', content=>"Decimal,Hexadecimal", info=>undef, param_parent=>'FILE_VIEW', ref_delay=> 1, new_status=>'ref_file_view', loc=>'vertical'},
445
        { label=>" Page row number: ", param_name=>'PAGE_MAX_X', type=>"Spin-button", default_val=>10, content=>"0,128,1", info=>undef, param_parent=>'FILE_VIEW', ref_delay=> 1, new_status=>'ref_file_view', loc=>'vertical'},
446
        { label=>" Page column number:", param_name=>'PAGE_MAX_Y', type=>"Spin-button", default_val=>10, content=>"1,128,1", info=>undef, param_parent=>'FILE_VIEW', ref_delay=> 1, new_status=>'ref_file_view', loc=>'vertical'}
447
        );
448
        my $row=0;
449
        my $col=0;
450
        foreach my $d (@info) {
451
                ($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}, $d->{loc});
452
        }
453
        $table->attach (gen_label_in_center(' '), 2, 3,$row,$row+1,'shrink','shrink',2,2); $row++;
454
        $table->attach (gen_label_in_center(' '), 2, 3,$row,$row+1,'shrink','shrink',2,2); $row++;
455
        $table->attach (gen_label_in_center(' '), 2, 3,$row,$row+1,'shrink','shrink',2,2); $row++;
456
 
457
 
458
        my $ok=def_image_button($path."icons/select.png",'OK');
459
        $table->attach ($ok, 2, 3,$row,$row+1,'shrink','shrink',2,2);
460
        $ok-> signal_connect("clicked" => sub{
461
                $window->destroy();
462
        });
463
 
464
        $window->add(add_widget_to_scrolled_win($table));
465
        $window->show_all;
466
 
467
}
468
 
469
sub fill_memory_array_from_file{
470
        my  ($self,$fname,$tview)=@_;
471
 
472
        my $offset = $self->object_get_attribute('FILE_VIEW','IN_FILE_OFFSET');
473
        my $BLOCK_SIZE =4;
474
 
475
        open(F,"<$fname") or die("Unable to open file $fname, $!");
476
        binmode(F);
477
        my $buf;
478
        my $ct=($offset>>2);
479
 
480
        my $start = ($offset>>2);
481
        my $r=read(F,$buf,$BLOCK_SIZE);
482
        while($r){
483
                my $v='';
484
                foreach(split(//, $buf)){
485
                        $v.=sprintf("%02x",ord($_));
486
                }
487
                if($r!=4){
488
                        $v.='0'x(( 4 - $r)*2);
489
                }
490
                $memory{$ct}= $v;
491
            $status{$ct}=2;
492
                $ct++;
493
                $r=read(F,$buf,$BLOCK_SIZE);
494
        }
495
        close(F);
496
 
497
        add_info($tview,"Load $fname\n");
498
        $ct=($ct << 2);
499
        add_info($tview,"address $offset to $ct\n");
500
}
501
 
502
sub get_file_in_name{
503
        my ($self,$tview)=@_;
504
 
505
        my $file;
506
        my $title ='select bin file';
507
        my $dialog = gen_file_dialog ($title);
508
 
509
        if ( "ok" eq $dialog->run ) {
510
                $file = $dialog->get_filename;
511
                        $dialog->destroy;
512
                        $self->object_add_attribute('FILE_VIEW','IN_FILE',$file);
513
 
514
                        #get offset address;
515
                        my $window = def_popwin_size (30,20,'Get Offset Address','percent');
516
                        my $table= def_table(2,10,FALSE);
517
                        my $d=
518
                        { label=>" Offset address (in byte): ", param_name=>'IN_FILE_OFFSET', type=>"Spin-button", default_val=>0, content=>'0,9999999999,1', info=>'The Wishbone bus offset address where the beginning of the memory bin file is written there (It can be the base address of the peripheral device where the memory file is intended to be written to.)   ', param_parent=>'FILE_VIEW', ref_delay=> undef, new_status=>undef, loc=>'vertical'};
519
                        my $row=0;
520
                        my $col=0;
521
                        ($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}, $d->{loc});
522
                        my $ok=def_image_button($path."icons/select.png",'OK');
523
                        $table->attach ($ok, 2, 3,$row,$row+1,'shrink','shrink',2,2);
524
                        $ok-> signal_connect("clicked" => sub{
525
                                fill_memory_array_from_file ($self,$file,$tview);
526
                                set_gui_status($self,'ref_file_view',1);
527
                                $window->destroy();
528
                        });
529
                        $window->add(add_widget_to_scrolled_win($table));
530
                        $window->show_all;
531
 
532
 
533
        }
534
 
535
 
536
 
537
}
538
 
539
 
540
 
541
 
542
sub get_jtag_intfc_cmd {
543
        my $self=shift;
544
 
545
        my $vendor = $self->object_get_attribute('CTRL','VENDOR');
546
        my $board  = $self->object_get_attribute('CTRL','Board_Name');
547
        my $chain  = $self->object_get_attribute('CTRL','JTAG_CHAIN');
548
        my $index  = $self->object_get_attribute('CTRL','JTAG_INDEX');
549
        my $pronoc = get_project_dir();
550
        my $intfc = "$pronoc/mpsoc/boards/$vendor/$board/jtag_intfc.sh";
551
        #my $script  = "$ENV{'PRONOC_WORK'}/tmp/script.bash";
552
 
553
        my $t = ($vendor eq 'Xilinx') ? "-t  $chain " : "";
554
 
555
        my $cmd = "bash -c \"source $intfc; \\\$JTAG_INTFC $t -n $index";
556
        return $cmd;
557
 
558
}
559
 
560
 
561
sub read_memory_array_from_device {
562
        my ($self,$tview)=@_;
563
        my $lower  = $self->object_get_attribute('FILE_VIEW','READ_LBA');
564
        my $upper  = $self->object_get_attribute('FILE_VIEW','READ_UBA');
565
 
566
        $lower= sprintf("0x%x",$lower);
567
        $upper= sprintf("0x%x",$upper);
568
 
569
        my $intfc = get_jtag_intfc_cmd($self);
570
        #my $comand = "#!/bin/bash\n  source $intfc\n \$JTAG_INTFC $t -n $index -s \"$lower\" -e \"$upper\" -r";
571
        my $cmd = "$intfc -s $lower -e $upper -r\"";
572
 
573
        #save_file ($script,$comand);
574
        #chmod 0755, $script;
575
 
576
        #my $cmd = "bash -c \"  $script \"";    
577
        add_info($tview,"$cmd\n");
578
        my $results =run_cmd_textview_errors($cmd,$tview);
579
        return 1 if(!defined $results);
580
 
581
 
582
 
583
        my @nn = split (/###read data#\n/,$results);
584
        if(!defined $nn[1]){
585
                add_colored_info($tview,"Got an Error:$results!\n",'red');
586
                return 1;
587
        }
588
        my @nums=split (/\n/,$nn[1]);
589
 
590
        $lower  = $self->object_get_attribute('FILE_VIEW','READ_LBA');
591
        $lower>>=2; #change to word
592
        foreach my $n ( @nums) {
593
                $n='0'x( 8 - length $n).$n;
594
                $memory{$lower }= $n;
595
            $status{$lower}=1; #valid
596
            $lower++;
597
 
598
        }
599
}
600
 
601
 
602
sub print_32_bit_val {
603
        my ($file,$v)=@_;
604
        for (my $i= 24; $i >=0 ; $i-=8) {
605
                my $byte= ($v >> $i ) & 0xFF;
606
                print $file pack('C*',$byte);
607
                #printf ("%02x\t",$byte);
608
        }
609
}
610
 
611
 
612
sub write_memory_array_from_device {
613
        my ($self,$tview)=@_;
614
        my $lower  = $self->object_get_attribute('FILE_VIEW','READ_LBA');
615
        my $upper  = $self->object_get_attribute('FILE_VIEW','READ_UBA');
616
 
617
        my $tmp_bin= "$ENV{'PRONOC_WORK'}/tmp/tmp.bin";
618
 
619
 
620
        #create binfile
621
        unlink $tmp_bin;
622
        open(my $F,">$tmp_bin") or die("Unable to open file $tmp_bin, $!");
623
        #binmode($F);
624
        my $warning;
625
        my $n;
626
        for (my $i=($lower>>2); $i< ($upper>>2); $i++){
627
                 my $s =(defined $status{$i}) ? $status{$i} : 0;
628
                 if( $s==0) {
629
                        $n= 0;
630
                        $warning=$i;
631
                 }
632
                 else{
633
                        $n= $memory{$i};
634
                        $status{$i}=1;
635
                }
636
                print_32_bit_val ($F, hex($n));
637
        }
638
        close ($F);
639
 
640
 
641
 
642
 
643
        $lower= sprintf("0x%x",$lower);
644
        $upper= sprintf("0x%x",$upper);
645
 
646
 
647
        #my $comand = "#!/bin/bash\n  source $intfc\n \$JTAG_INTFC $t -n $index -s \"$lower\" -e \"$upper\"  -i  $tmp_bin -c";
648
 
649
        #save_file ($script,$comand);
650
        #chmod 0755, $script;
651
 
652
        #my $cmd = "bash -c \"  $script \"";
653
        my $intfc = get_jtag_intfc_cmd($self);
654
        my $cmd = "$intfc -s $lower -e $upper  -i  $tmp_bin -c\"";
655
 
656
        add_info($tview,"$cmd\n");
657
        my $results =run_cmd_textview_errors($cmd,$tview);
658
        return 1 if(!defined $results);
659
 
660
        my @lines = split (/\n/, $results);
661
        foreach my $line (@lines) {
662
                add_colored_info($tview,"$line\n",'red') if      ($line =~ /Error/);
663
        }
664
}
665
 
666
 
667
 
668
 
669
 
670
 
671
 
672
 
673
 
674
sub read_write_widget {
675
        my ($self,$tview,$rw)=@_;
676
        #get start & end addresses;
677
        my $window = def_popwin_size (30,20,'Select Memory Boundary Addresses','percent');
678
        my $table= def_table(2,10,FALSE);
679
        my $l ={ label=>" Lower-bound address (in byte): ", param_name=>'READ_LBA', type=>"Spin-button", default_val=>0, content=>'0,9999999999,1', info=>'The Wishbone bus offset address where the beginning of the memory bin file is written there (It can be the base address of the peripheral device where the memory file is intended to be written to.)   ', param_parent=>'FILE_VIEW', ref_delay=> undef, new_status=>undef, loc=>'vertical'};
680
        my $u ={ label=>" Upper-bound address (in byte): ", param_name=>'READ_UBA', type=>"Spin-button", default_val=>0, content=>'0,9999999999,1', info=>'The Wishbone bus offset address where the end of the memory bin file is written there (It can be the base address of the peripheral device where the memory file is intended to be written to plus bin file size in byte.)   ', param_parent=>'FILE_VIEW', ref_delay=> undef, new_status=>undef, loc=>'vertical'};
681
        my ($l_spin,$u_spin);
682
        my $row=0;
683
        my $col=0;
684
        ($row,$col,$l_spin)=add_param_widget  ($self, $l->{label}, $l->{param_name}, $l->{default_val}, $l->{type}, $l->{content}, $l->{info}, $table,$row,$col,1, $l->{param_parent}, $l->{ref_delay}, $l->{new_status}, $l->{loc});
685
        ($row,$col,$u_spin)=add_param_widget  ($self, $u->{label}, $u->{param_name}, $u->{default_val}, $u->{type}, $u->{content}, $u->{info}, $table,$row,$col,1, $u->{param_parent}, $u->{ref_delay}, $l->{new_status}, $u->{loc});
686
 
687
        $l_spin-> signal_connect("value_changed" => sub{
688
                my $lower=$l_spin->get_value();
689
                $u_spin->set_range ($lower, 9999999999);
690
 
691
        });
692
 
693
        $u_spin-> signal_connect("value_changed" => sub{
694
                my $upper=$u_spin->get_value();
695
                $l_spin->set_range (0,$upper);
696
 
697
        });
698
 
699
 
700
 
701
 
702
        my $ok=def_image_button($path."icons/select.png",'OK');
703
        $table->attach ($ok, 2, 3,$row,$row+1,'shrink','shrink',2,2);
704
        $ok-> signal_connect("clicked" => sub{
705
                my $vendor= $self->object_get_attribute('CTRL','VENDOR');
706
                my $load= show_gif("icons/load.gif");
707
                $table->attach ($load,1, 2, $row,$row+ 1,'shrink','shrink',0,0);
708
                $table->show_all();
709
                read_memory_array_from_device ($self,$tview)  if ($rw eq 'READ');
710
                write_memory_array_from_device ($self,$tview) if ($rw eq 'WRITE');
711
                set_gui_status($self,'ref_file_view',1);
712
                $window->destroy();
713
        });
714
        $window->add(add_widget_to_scrolled_win($table));
715
        $window->show_all;
716
}
717
 
718
 
719
 
720
 
721
 
722
 
723
 
724
sub read_write_bin_file {
725
        my ($self,$tview)=@_;
726
        my $table= def_table(2,10,FALSE);
727
        my $scrolled_win=gen_scr_win_with_adjst ($self,"receive_box");
728
        add_widget_to_scrolled_win($table,$scrolled_win);
729
        my @data;
730
 
731
 
732
        my $MAX_X=$self->       object_get_attribute('FILE_VIEW','PAGE_MAX_X');
733
        $MAX_X=10 if (!defined $MAX_X);
734
        my $MAX_Y=$self->       object_get_attribute('FILE_VIEW','PAGE_MAX_Y');
735
        $MAX_Y=10 if (!defined $MAX_Y);
736
        my $format =$self->     object_get_attribute('FILE_VIEW','R_ADDR_FORMAT');
737
        $format= 'Decimal' if (!defined $format);
738
 
739
 
740
        my $OFFSET=0;
741
 
742
        my $table1= def_table(2,10,FALSE);
743
 
744
        #$page_num= 0 if(!defined $page_num);
745
 
746
 
747
 
748
 
749
        my $setting=def_image_button("icons/setting.png","setting");
750
        my $load=def_image_button("icons/download.png","Load File");
751
        my $read=def_image_button($path."icons/simulator.png","Read Memory");
752
        my $write=def_image_button($path."icons/write.png","Write Memory");
753
        my $clear=def_image_button($path."icons/clear.png");
754
        my $x=0;
755
 
756
 
757
        $table->attach ($setting, $x, $x+1, 0, 1,'fill','fill',2,2);$x++;
758
        $table->attach ($load, $x, $x+1 , 0, 1,'fill','fill',2,2);$x++;
759
        $table->attach ($read, $x, $x+1 , 0, 1,'shrink','shrink',2,2); $x++;
760
        $table->attach ($write, $x, $x+1 , 0, 1,'shrink','shrink',2,2); $x++;
761
        $table->attach ($clear, $x, $x+1 , 0, 1,'shrink','shrink',2,2); $x++;
762
 
763
        add_param_widget  ($self,"Page_num", 'FILE_VIEW',  0, "Spin-button", "0,999999,1", undef, $table,0, $x, 1, "R_PAGE_NUM",1,'ref_file_view');
764
 
765
        my $page_num =$self->object_get_attribute("R_PAGE_NUM",'FILE_VIEW');
766
 
767
 
768
 
769
 
770
        $setting-> signal_connect("clicked" => sub{
771
                                get_file_b_setting($self);
772
        });
773
 
774
        $load-> signal_connect("clicked" => sub{
775
                                get_file_in_name($self,$tview);
776
        });
777
 
778
        $clear-> signal_connect("clicked" => sub{
779
                undef %memory;
780
                undef %status;
781
                set_gui_status($self,'ref_file_view',1);
782
        });
783
 
784
        $read-> signal_connect("clicked" => sub{
785
                read_write_widget($self,$tview,'READ');
786
        });
787
 
788
        $write->signal_connect("clicked" => sub{
789
                read_write_widget($self,$tview,'WRITE');
790
        });
791
 
792
        my $base_addr=$page_num*$MAX_X*$MAX_Y+$OFFSET;
793
 
794
 
795
        #column address labels
796
        for (my $y=1; $y<=$MAX_Y; $y++){
797
                my $addr=(($y-1) << 2);
798
                $addr =($format eq 'Hexadecimal')? sprintf("%x", $addr) : $addr;
799
 
800
                my $l=gen_label_in_center (" $addr ");
801
                $table1->attach ( $l, $y, $y+1 , 0, 1,'fill','fill',2,2);
802
        }
803
 
804
 
805
        #row address labels
806
        for (my $x=1; $x<=$MAX_X; $x++){
807
                my $addr=$base_addr+($x-1) * $MAX_Y;
808
 
809
                $addr = ($format eq 'Hexadecimal')? sprintf("%x",($addr << 2))   : ($addr << 2);
810
 
811
 
812
                my $l=gen_label_in_left (" $addr ");
813
                $table1->attach ( $l, 0, 1 , $x, $x+1,'fill','fill',2,2);
814
        }
815
 
816
        #entries        
817
        for (my $x=1; $x<=$MAX_X; $x++){
818
                for (my $y=1; $y<=$MAX_Y; $y++){
819
 
820
 
821
                        my $state=0;# not modified
822
 
823
                        my $addr =$base_addr+ (($x-1) * $MAX_Y ) + $y-1;
824
                        my $addr_tip=($format eq 'Hexadecimal')? sprintf("0x%x",($addr << 2))   : ($addr << 2);
825
 
826
                        my $v= $memory{$addr};
827
                        my $s = $status{$addr};
828
 
829
                        $v= "xxxxxxxx" if (!defined $v);
830
                        $s = 0 if (!defined $s); #0 dontcare                     
831
 
832
 
833
                        my $entry =gen_entry($v );
834
 
835
                        $entry->set_max_length (8);
836
                        $entry->set_width_chars(8);
837
                        set_tip($entry,"$addr_tip");
838
                        $table1->attach ( $entry, $y, $y+1 , $x, $x+1,'fill','fill',2,2);
839
 
840
                        if($s==2 ){
841
                                #change color to red
842
                                entry_set_text_color($entry,11);
843
                        }
844
 
845
                        $entry->signal_connect("changed" => sub{
846
                                if($s==0 || $s==1 ){
847
                                        $status{$addr} =2;#modified
848
                                        #change color to red
849
                                        entry_set_text_color($entry,11);
850
 
851
                                }
852
                                my $in = $entry->get_text();
853
                                $memory{$addr}=$in;
854
                                $entry->set_text(remove_not_hex($in));
855
 
856
                        });
857
 
858
                }
859
        }
860
 
861
 
862
 
863
 
864
        $table->attach ( $table1, 0, 20 , 1, 10,'fill','fill',2,2);
865
 
866
        $scrolled_win->show_all;
867
        return $scrolled_win;
868
 
869
}
870
 
871
 
872
 
873
############
874
#       main
875
############
876
 
877
 
878
 
879
sub source_probe_main {
880
        my $self = __PACKAGE__->new();
881
 
882
 
883
 
884
        set_gui_status($self,"ideal",0);
885
        my $window = def_popwin_size (85,85,'Run time JTAG debug','percent');
886
        my ($sw,$tview) =create_txview();# a textveiw for showing the info, erro messages etc
887
        my $ctrl = source_probe_ctrl($self,$tview);
888
        my $sp= soure_probe_widgets ($self,$tview);
889
        my $bin_f = read_write_bin_file($self,$tview);
890
        #my $bin_ctrl = file_bin_ctrl($self,$tview);
891
 
892
 
893
        my $h1 = gen_hpaned ($sp,0.35,$ctrl);
894
        #my $h2 = gen_hpaned ($bin_f,0.55,$bin_ctrl);
895
        my $v1 = gen_vpaned ($h1,0.2,$bin_f);
896
        my $v2 = gen_vpaned ($v1,0.65,$sw);
897
 
898
 
899
 
900
 
901
 
902
        #check soc status every ? second. referesh device table if there is any changes 
903
    Glib::Timeout->add (100, sub{
904
        my ($state,$timeout)= get_gui_status($self);
905
 
906
        if ($timeout>0){
907
            $timeout--;
908
            set_gui_status($self,$state,$timeout);
909
        }
910
        elsif( $state ne "ideal" ){
911
            if($state eq 'ref_all') {
912
                $sp->destroy();
913
                $sp= soure_probe_widgets ($self,$tview);
914
                $bin_f->destroy();
915
                $bin_f = read_write_bin_file($self,$tview);
916
                $h1-> pack1($sp, TRUE, TRUE);
917
                $v1-> pack2($bin_f, TRUE, TRUE);
918
                $v2-> show_all();
919
            }
920
            elsif ($state eq  'ref_file_view'){
921
                $bin_f->destroy();
922
                $bin_f = read_write_bin_file($self,$tview);
923
                $v1-> pack2($bin_f, TRUE, TRUE);
924
                $v2-> show_all();
925
 
926
 
927
            }
928
 
929
            $ctrl->destroy();
930
            $ctrl = source_probe_ctrl($self,$tview);
931
            $h1-> pack2($ctrl, TRUE, TRUE);
932
            $v2-> show_all();
933
            set_gui_status($self,"ideal",0);
934
 
935
 
936
       }
937
 
938
        return TRUE;
939
 
940
    } );
941
 
942
 
943
 
944
        $window->add($v2);
945
        $window->show_all();
946
        return $window;
947
}
948
 
949
 
950
 

powered by: WebSVN 2.1.0

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