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 48

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

powered by: WebSVN 2.1.0

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