OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [tools/] [bin/] [openmsp430-minidebug.tcl] - Blame information for rev 198

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 olivier.gi
#!/usr/bin/wish
2
#------------------------------------------------------------------------------
3
# Copyright (C) 2001 Authors
4
#
5
# This source file may be used and distributed without restriction provided
6
# that this copyright statement is not removed from the file and that any
7
# derivative work contains the original copyright notice and the associated
8
# disclaimer.
9
#
10
# This source file is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU Lesser General Public License as published
12
# by the Free Software Foundation; either version 2.1 of the License, or
13
# (at your option) any later version.
14
#
15
# This source is distributed in the hope that it will be useful, but WITHOUT
16
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18
# License for more details.
19
#
20
# You should have received a copy of the GNU Lesser General Public License
21
# along with this source; if not, write to the Free Software Foundation,
22
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23
#
24
#------------------------------------------------------------------------------
25
# 
26 158 olivier.gi
# File Name: openmsp430-minidebug.tcl
27 2 olivier.gi
# 
28 14 olivier.gi
# Author(s):
29
#             - Olivier Girard,    olgirard@gmail.com
30
#
31 2 olivier.gi
#------------------------------------------------------------------------------
32 14 olivier.gi
# $Rev: 169 $
33
# $LastChangedBy: olivier.girard $
34
# $LastChangedDate: 2012-12-06 22:11:29 +0100 (Thu, 06 Dec 2012) $
35
#------------------------------------------------------------------------------
36 2 olivier.gi
 
37
###############################################################################
38
#                                                                             #
39 158 olivier.gi
#                            SOURCE LIBRARIES                                 #
40
#                                                                             #
41
###############################################################################
42
 
43
# Get library path
44
set current_file [info script]
45
if {[file type $current_file]=="link"} {
46
    set current_file [file readlink $current_file]
47
}
48
set lib_path [file dirname $current_file]/../lib/tcl-lib
49
 
50
# Source library
51
source $lib_path/dbg_functions.tcl
52
source $lib_path/dbg_utils.tcl
53
source $lib_path/combobox.tcl
54
package require combobox 2.3
55
catch {namespace import combobox::*}
56
 
57
 
58
###############################################################################
59
#                                                                             #
60 2 olivier.gi
#                            GLOBAL VARIABLES                                 #
61
#                                                                             #
62
###############################################################################
63
 
64 158 olivier.gi
global CpuNr
65
 
66
global omsp_conf
67 110 olivier.gi
global omsp_info
68 158 olivier.gi
 
69
global omsp_nr
70
 
71
global current_file_name
72
global connection_status
73 2 olivier.gi
global cpu_status
74
global reg
75
global mem
76 110 olivier.gi
global mem_sizes
77 87 olivier.gi
global sr
78
global codeSelect
79
global binFileType
80 158 olivier.gi
global binFileName
81
global pmemIHEX
82
global isPmemRead
83 110 olivier.gi
global brkpt
84
global color
85 2 olivier.gi
 
86 158 olivier.gi
# Initialize to default values
87
set CpuNr                 0
88
set omsp_nr               1
89
set omsp_conf(interface)  uart_generic
90
#set omsp_nr               4
91
#set omsp_conf(interface)  i2c_usb-iss
92
set omsp_conf(device)     [lindex [utils::uart_port_list] end]
93
set omsp_conf(baudrate)   [lindex [GetAllowedSpeeds] 1]
94
set omsp_conf(0,cpuaddr)  50
95
set omsp_conf(1,cpuaddr)  51
96
set omsp_conf(2,cpuaddr)  52
97
set omsp_conf(3,cpuaddr)  53
98
 
99 110 olivier.gi
# Color definitions
100
set color(PC)             "\#c1ffc1"
101
set color(Brk0_active)    "\#ba55d3"
102
set color(Brk0_disabled)  "\#dda0dd"
103
set color(Brk1_active)    "\#ff7256"
104
set color(Brk1_disabled)  "\#ffc1c1"
105
set color(Brk2_active)    "\#ffff30"
106
set color(Brk2_disabled)  "\#ffffe0"
107
 
108 2 olivier.gi
# Initializations
109 158 olivier.gi
set codeSelect        2
110
set binFileType       ""
111
set binFileName       ""
112
set pmemIHEX          ""
113
set mem_sizes         ""
114
set isPmemRead        0
115
set connection_status 0
116 2 olivier.gi
set cpu_status    1
117 110 olivier.gi
for {set i 0} {$i<3} {incr i} {
118
    set brkpt(addr_$i)  0x0000
119
    set brkpt(data_$i)  0x0000
120
    set brkpt(en_$i)    0
121
}
122 2 olivier.gi
for {set i 0} {$i<16} {incr i} {
123
    set reg($i)         0x0000
124
    set mem(address_$i) [format "0x%04x" [expr 0x0200+$i*2]]
125
    set mem(data_$i)    0x0000
126
}
127 158 olivier.gi
for {set i 0} {$i<3} {incr i} {
128
    set backup($i,current_file_name) ""
129 2 olivier.gi
}
130
 
131
 
132
###############################################################################
133
#                                                                             #
134
#                                    FUNCTIONS                                #
135
#                                                                             #
136
###############################################################################
137
 
138
proc connect_openMSP430 {} {
139 158 olivier.gi
    global connection_status
140 2 olivier.gi
    global reg
141
    global mem
142 110 olivier.gi
    global brkpt
143
    global mem_sizes
144
    global color
145 158 olivier.gi
    global omsp_conf
146 110 olivier.gi
    global omsp_info
147 158 olivier.gi
    global omsp_nr
148
    global CpuNr
149 2 olivier.gi
 
150 169 olivier.gi
    set connection_sum 0
151
    for {set ii 0} {$ii < $omsp_nr} {incr ii} {
152
        set connection_ok  [GetDevice $ii]
153
        set connection_sum [expr $connection_sum + $connection_ok]
154
        if {$connection_ok==0} {
155
            set error_msg "Could not connect to Core $ii"
156
        }
157
    }
158
    if {$connection_sum==$omsp_nr} {
159
        set connection_status 1
160
    }
161 2 olivier.gi
 
162 158 olivier.gi
    if {$connection_status} {
163
        set mem_sizes [GetCPU_ID_SIZE $CpuNr]
164 2 olivier.gi
 
165 158 olivier.gi
        if {[lindex $mem_sizes 0]==-1 | [lindex $mem_sizes 1]==-1 | [lindex $mem_sizes 2]==-1} {
166
            .ctrl.connect.info.l1.con     configure -text "Connection problem" -fg red
167 87 olivier.gi
 
168 158 olivier.gi
        } else {
169
            # Update Core selection section
170
            regexp {(.+)_(.+)} $omsp_conf(interface) whole_match interface adapter
171
            set interface [string toupper $interface]
172
            if {$interface=="I2C"} {
173
                if {$omsp_nr>1} {
174
                    .menu.cpusel          configure -state normal
175
                    .menu.cpu0            configure -state normal
176
                    .menu.cpu1            configure -state normal
177
                }
178
                if {$omsp_nr>2} {.menu.cpu2 configure -state normal}
179
                if {$omsp_nr>3} {.menu.cpu3 configure -state normal}
180
            }
181 87 olivier.gi
 
182 158 olivier.gi
            # Disable connection section
183
            .ctrl.connect.serial.p1       configure -state disabled
184
            .ctrl.connect.serial.p2       configure -state disabled
185
            .ctrl.connect.serial.connect  configure -state disabled
186 87 olivier.gi
 
187 158 olivier.gi
            if {$omsp_info($CpuNr,alias)==""} {
188
                .ctrl.connect.info.l1.con configure -text "Connected" -fg "\#00ae00"
189
            } else {
190
                .ctrl.connect.info.l1.con configure -text "Connected to $omsp_info($CpuNr,alias)" -fg "\#00ae00"
191
            }
192
            .ctrl.connect.info.l1.more    configure -state normal
193 87 olivier.gi
 
194 158 olivier.gi
            # Activate ELF file section
195
            .ctrl.load.ft.l               configure -state normal
196
            .ctrl.load.ft.file            configure -state normal
197
            .ctrl.load.ft.browse          configure -state normal
198
            .ctrl.load.fb.load            configure -state normal
199
            .ctrl.load.fb.open            configure -state normal
200
            .ctrl.load.fb.readpmem        configure -state normal
201
            .ctrl.load.info.t             configure -state normal
202
            .ctrl.load.info.l             configure -state normal
203 87 olivier.gi
 
204 158 olivier.gi
            # Activate CPU control section
205
            .ctrl.cpu.cpu.l1              configure -state normal
206
            .ctrl.cpu.cpu.reset           configure -state normal
207
            .ctrl.cpu.cpu.run             configure -state normal
208
            .ctrl.cpu.cpu.l2              configure -state normal
209
            .ctrl.cpu.cpu.l3              configure -state normal
210
            if {[IsHalted $CpuNr]} {
211
                .ctrl.cpu.cpu.step        configure -state normal
212
                .ctrl.cpu.cpu.run         configure -text "Run"
213
                .ctrl.cpu.cpu.l3          configure -text "Stopped" -fg "\#cdad00"
214
                set cpu_status 0
215
            } else {
216
                .ctrl.cpu.cpu.step        configure -state disabled
217
                .ctrl.cpu.cpu.run         configure -text "Stop"
218
                .ctrl.cpu.cpu.l3          configure -text "Running" -fg "\#00ae00"
219
                set cpu_status 1
220
            }
221 110 olivier.gi
 
222 158 olivier.gi
            # Activate CPU Breakpoints section
223
            .ctrl.cpu.brkpt.l1                configure -state normal
224
            for {set i 0} {$i<3} {incr i} {
225
                set brkpt(addr_$i)  [format "0x%04x" [expr 0x10000-[lindex $mem_sizes 0]]]
226
                .ctrl.cpu.brkpt.addr$i        configure -state normal
227
                .ctrl.cpu.brkpt.addr$i        configure -bg $color(Brk$i\_disabled)
228
                .ctrl.cpu.brkpt.addr$i        configure -readonlybackground $color(Brk$i\_active)
229
                .ctrl.cpu.brkpt.chk$i         configure -state normal
230
            }
231 87 olivier.gi
 
232 158 olivier.gi
            # Activate CPU status register section
233
            .ctrl.cpu.reg_stat.l1             configure -state normal
234
            .ctrl.cpu.reg_stat.v              configure -state normal
235
            .ctrl.cpu.reg_stat.scg1           configure -state normal
236
            .ctrl.cpu.reg_stat.oscoff         configure -state normal
237
            .ctrl.cpu.reg_stat.cpuoff         configure -state normal
238
            .ctrl.cpu.reg_stat.gie            configure -state normal
239
            .ctrl.cpu.reg_stat.n              configure -state normal
240
            .ctrl.cpu.reg_stat.z              configure -state normal
241
            .ctrl.cpu.reg_stat.c              configure -state normal
242 87 olivier.gi
 
243 158 olivier.gi
            # Activate CPU registers and memory section
244
            .ctrl.cpu.reg_mem.reg.title.e     configure -state normal
245
            .ctrl.cpu.reg_mem.mem.title.l     configure -state normal
246
            .ctrl.cpu.reg_mem.mem.title.e     configure -state normal
247
            .ctrl.cpu.reg_mem.reg.refresh     configure -state normal
248
            .ctrl.cpu.reg_mem.mem.refresh     configure -state normal
249
            for {set i 0} {$i<16} {incr i} {
250
                .ctrl.cpu.reg_mem.reg.f$i.l$i        configure -state normal
251
                .ctrl.cpu.reg_mem.reg.f$i.e$i        configure -state normal
252
                .ctrl.cpu.reg_mem.mem.f$i.addr_e$i   configure -state normal
253
                .ctrl.cpu.reg_mem.mem.f$i.data_e$i   configure -state normal
254
            }
255
            .ctrl.cpu.reg_mem.reg.f0.e0              configure -bg $color(PC)
256
            refreshReg
257
            refreshMem
258 2 olivier.gi
 
259 158 olivier.gi
            # Activate Load TCL script section
260
            .ctrl.tclscript.ft.l          configure -state normal
261
            .ctrl.tclscript.ft.file       configure -state normal
262
            .ctrl.tclscript.ft.browse     configure -state normal
263
            .ctrl.tclscript.fb.read       configure -state normal
264
 
265
            # Activate the code debugger section
266
            .code.rb.txt                  configure -state normal
267
            .code.rb.none                 configure -state normal
268
            .code.rb.asm                  configure -state normal
269
            .code.rb.mix                  configure -state normal
270
 
271
            # Initial context save for all CPUs
272
            saveContext 0
273
            saveContext 1
274
            saveContext 2
275
            saveContext 3
276
        }
277
 
278 2 olivier.gi
    } else {
279 169 olivier.gi
        for {set ii 0} {$ii < $omsp_nr} {incr ii} {
280
            set omsp_info($ii,connected) 0
281
        }
282
        .ctrl.connect.info.l1.con         configure -text $error_msg -fg red
283 2 olivier.gi
    }
284
}
285
 
286 110 olivier.gi
proc displayMore  { } {
287 2 olivier.gi
 
288 110 olivier.gi
    global omsp_info
289 158 olivier.gi
    global CpuNr
290 110 olivier.gi
 
291
    # Destroy windows if already existing
292
    if {[lsearch -exact [winfo children .] .omsp_extra_info]!=-1} {
293 158 olivier.gi
        destroy .omsp_extra_info
294 110 olivier.gi
    }
295
 
296
    # Create master window
297 158 olivier.gi
    toplevel     .omsp_extra_info
298
    wm title     .omsp_extra_info "openMSP430 extra info"
299
    wm geometry  .omsp_extra_info +380+200
300 110 olivier.gi
    wm resizable .omsp_extra_info 0 0
301
 
302
    # Title
303
    set title "openMSP430"
304 158 olivier.gi
    if {$omsp_info($CpuNr,alias)!=""} {
305
        set title $omsp_info($CpuNr,alias)
306 110 olivier.gi
    }
307
    label  .omsp_extra_info.title  -text "$title"   -anchor center -fg "\#00ae00" -font {-weight bold -size 16}
308
    pack   .omsp_extra_info.title  -side top -padx {20 20} -pady {20 10}
309
 
310
    # Add extra info
311
    frame     .omsp_extra_info.extra
312
    pack      .omsp_extra_info.extra         -side top  -padx 10  -pady {10 10}
313
    scrollbar .omsp_extra_info.extra.yscroll -orient vertical   -command {.omsp_extra_info.extra.text yview}
314
    pack      .omsp_extra_info.extra.yscroll -side right -fill both
315
    text      .omsp_extra_info.extra.text    -wrap word -height 20 -font TkFixedFont -yscrollcommand {.omsp_extra_info.extra.yscroll set}
316
    pack      .omsp_extra_info.extra.text    -side right
317
 
318
    # Create OK button
319
    button .omsp_extra_info.okay -text "OK" -font {-weight bold}  -command {destroy .omsp_extra_info}
320
    pack   .omsp_extra_info.okay -side bottom -expand true -fill x -padx 5 -pady {0 10}
321
 
322
 
323
    # Fill the text widget will configuration info
324
    .omsp_extra_info.extra.text tag configure bold -font {-family TkFixedFont -weight bold}
325
    .omsp_extra_info.extra.text insert end         "Configuration\n\n" bold
326 158 olivier.gi
    .omsp_extra_info.extra.text insert end [format "CPU Version                : %5s\n" $omsp_info($CpuNr,cpu_ver)]
327
    .omsp_extra_info.extra.text insert end [format "User Version               : %5s\n" $omsp_info($CpuNr,user_ver)]
328
    if {$omsp_info($CpuNr,cpu_ver)==1} {
329 110 olivier.gi
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" --]
330 158 olivier.gi
    } elseif {$omsp_info($CpuNr,asic)==0} {
331 110 olivier.gi
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" FPGA]
332 158 olivier.gi
    } elseif {$omsp_info($CpuNr,asic)==1} {
333 110 olivier.gi
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" ASIC]
334
    }
335 158 olivier.gi
    if {$omsp_info($CpuNr,mpy)==1} {
336 110 olivier.gi
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" Yes]
337 158 olivier.gi
    } elseif {$omsp_info($CpuNr,mpy)==0} {
338 110 olivier.gi
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" No]
339
    } else {
340
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" --]
341
    }
342 158 olivier.gi
    .omsp_extra_info.extra.text insert end [format "Program memory size        : %5s B\n" $omsp_info($CpuNr,pmem_size)]
343
    .omsp_extra_info.extra.text insert end [format "Data memory size           : %5s B\n" $omsp_info($CpuNr,dmem_size)]
344
    .omsp_extra_info.extra.text insert end [format "Peripheral address space   : %5s B\n" $omsp_info($CpuNr,per_size)]
345
    if {$omsp_info($CpuNr,alias)==""} {
346 110 olivier.gi
    .omsp_extra_info.extra.text insert end [format "Alias                      : %5s\n\n\n" None]
347
    } else {
348 158 olivier.gi
    .omsp_extra_info.extra.text insert end [format "Alias                      : %5s\n\n\n" $omsp_info($CpuNr,alias)]
349 110 olivier.gi
    }
350
 
351
    .omsp_extra_info.extra.text insert end         "Extra Info\n\n" bold
352
 
353 158 olivier.gi
    if {$omsp_info($CpuNr,alias)!=""} {
354 110 olivier.gi
 
355 158 olivier.gi
        set aliasEXTRA  [lsort -increasing [array names omsp_info -glob "$CpuNr,extra,*"]]
356
        if {[llength $aliasEXTRA]} {
357 110 olivier.gi
 
358 158 olivier.gi
            foreach currentEXTRA $aliasEXTRA {
359
                regexp {^.+,.+,(.+)$} $currentEXTRA whole_match extraATTR
360
                .omsp_extra_info.extra.text insert end     [format "%-15s: %s\n" $extraATTR  $omsp_info($currentEXTRA)]
361
            }
362
            .omsp_extra_info.extra.text insert end         "\n\n"
363
        }
364 110 olivier.gi
    } else {
365 158 olivier.gi
        .omsp_extra_info.extra.text insert end  "No alias found in 'omsp_alias.xml' file"
366 110 olivier.gi
    }
367 87 olivier.gi
}
368
 
369 110 olivier.gi
proc highlightLine { line tagNameNew tagNameOld type } {
370
    .code.text tag remove $tagNameOld 1.0     end
371
    .code.text tag remove $tagNameNew 1.0     end
372
 
373
    switch -exact -- $type {
374 158 olivier.gi
        "0"     {.code.text tag add    $tagNameNew $line.0 $line.4}
375
        "1"     {.code.text tag add    $tagNameNew $line.2 $line.4}
376
        "2"     {.code.text tag add    $tagNameNew $line.3 $line.4}
377
        default {.code.text tag add    $tagNameNew $line.4 [expr $line+1].0}
378 110 olivier.gi
    }
379
}
380
 
381
proc highlightCode   { } {
382 87 olivier.gi
    global codeSelect
383 110 olivier.gi
    global reg
384
    global brkpt
385
    global color
386 87 olivier.gi
 
387
    if {$codeSelect!=1} {
388 158 olivier.gi
 
389
        # Update PC
390
        regsub {0x} $reg(0) {} pc_val
391
        set code_match [.code.text search "$pc_val:" 1.0 end]
392
        set code_line 1
393
        regexp {(\d+).(\d+)} $code_match whole_match code_line code_column
394
        highlightLine $code_line highlightPC highlightPC 3
395
        .code.text see    $code_line.0
396 110 olivier.gi
 
397 158 olivier.gi
        # Some pre-processing
398
        set brkType(0) 0
399
        if {$brkpt(addr_0)==$brkpt(addr_1)} {
400
            set brkType(1) 1
401
        } else {
402
            set brkType(1) 0
403
        }
404
        if {$brkType(1)==1} {
405
            if {$brkpt(addr_1)==$brkpt(addr_2)} {
406
                set brkType(2) 2
407
            } else {
408
                set brkType(2) 0
409
            }
410
        } else {
411
            if {$brkpt(addr_0)==$brkpt(addr_2)} {
412
                set brkType(2) 1
413
            } else {
414
                if {$brkpt(addr_1)==$brkpt(addr_2)} {
415
                    set brkType(2) 1
416
                } else {
417
                    set brkType(2) 0
418
                }
419
            }
420
        }
421 110 olivier.gi
 
422 158 olivier.gi
        # Update Breakpoints if required
423
        for {set i 0} {$i<3} {incr i} {
424
            regsub {0x} $brkpt(addr_$i) {} brkpt_val
425
            set code_match [.code.text search "$brkpt_val:" 1.0 end]
426
            set code_line 1
427
            regexp {(\d+).(\d+)} $code_match whole_match code_line code_column
428
            if {$brkpt(en_$i)==1} {
429
                highlightLine $code_line "highlightBRK${i}_ACT" "highlightBRK${i}_DIS" $brkType($i)
430
            } else {
431
                highlightLine $code_line "highlightBRK${i}_DIS" "highlightBRK${i}_ACT" $brkType($i)
432
            }
433
        }
434 110 olivier.gi
 
435 87 olivier.gi
     }
436
}
437
 
438 158 olivier.gi
proc waitForFile {fileName} {
439
 
440
    # Wait until file is present on the filesystem
441
    set timeout 1000
442
    for {set i 0} {$i <= $timeout} {incr i} {
443
        after 50
444
        if {[file exists $fileName]} {
445
            return 1
446
        }
447
    }
448
    return 0
449
}
450
 
451
proc updateCodeView {} {
452 87 olivier.gi
    global codeSelect
453
    global reg
454
    global binFileType
455 158 olivier.gi
    global binFileName
456
    global pmemIHEX
457 110 olivier.gi
    global brkpt
458 158 olivier.gi
    global isPmemRead
459 87 olivier.gi
 
460 158 olivier.gi
    if {($binFileName!="") | ($isPmemRead==1)} {
461
 
462
        if {$isPmemRead==1} {
463
 
464
            set currentFileType ihex
465
            set currentFileName "[expr [clock clicks]  ^ 0xffffffff].ihex"
466
 
467
            set fileId [open $currentFileName "w"]
468
            puts -nonewline $fileId $pmemIHEX
469
            close $fileId
470
            if {![waitForFile $currentFileName]} {
471
                .ctrl.load.info.l configure -text "Timeout: error writing temprary IHEX file" -fg red
472
                return 0
473
            }
474
 
475
        } else {
476
            set currentFileType $binFileType
477
            set currentFileName $binFileName
478
        }
479
 
480
        set temp_elf_file  "[clock clicks].elf"
481
        set temp_ihex_file "[clock clicks].ihex"
482
        if {[catch {exec msp430-objcopy -I $currentFileType -O elf32-msp430 $currentFileName $temp_elf_file} debug_info]} {
483
            .ctrl.load.info.l configure -text "$debug_info" -fg red
484
            return 0
485
        }
486
        if {![waitForFile $temp_elf_file]} {
487
            .ctrl.load.info.l configure -text "Timeout: ELF file conversion problem with \"msp430-objcopy\" executable" -fg red
488
            return 0
489
        }
490
        if {[string eq $currentFileType "ihex"]} {
491
            set dumpOpt "-D"
492
        } else {
493
            set dumpOpt "-d"
494
        }
495
 
496
        if {$codeSelect==1} {
497
 
498
            clearBreakpoints
499
            for {set i 0} {$i<3} {incr i} {
500
                set brkpt(en_$i) 0
501
                .ctrl.cpu.brkpt.chk$i  configure -state disable
502
                updateBreakpoint $i
503
            }
504
            if {[catch {exec msp430-objcopy -I $currentFileType -O ihex $temp_elf_file $temp_ihex_file} debug_info]} {
505
                .ctrl.load.info.l configure -text "$debug_info" -fg red
506
                return 0
507
            }
508
            if {![waitForFile  $temp_ihex_file]} {
509
                .ctrl.load.info.l configure -text "Timeout: IHEX file conversion problem with \"msp430-objcopy\" executable" -fg red
510
                return 0
511
            }
512
            set fp [open $temp_ihex_file r]
513
            set debug_info [read $fp]
514
            close $fp
515
 
516
            file delete $temp_ihex_file
517
 
518
        } elseif {$codeSelect==2} {
519
            for {set i 0} {$i<3} {incr i} {
520
                .ctrl.cpu.brkpt.chk$i  configure -state normal
521
            }
522
            if {[catch {exec msp430-objdump $dumpOpt $temp_elf_file} debug_info]} {
523
                .ctrl.load.info.l configure -text "$debug_info" -fg red
524
                return 0
525
            }
526
        } elseif {$codeSelect==3} {
527
            for {set i 0} {$i<3} {incr i} {
528
                .ctrl.cpu.brkpt.chk$i  configure -state normal
529
            }
530
            if {[catch {exec msp430-objdump $dumpOpt\S $temp_elf_file} debug_info]} {
531
                .ctrl.load.info.l configure -text "$debug_info" -fg red
532
                return 0
533
            }
534
        }
535
        file delete $temp_elf_file
536
        if {$isPmemRead==1} {
537
            file delet $currentFileName
538
        }
539
 
540
        .code.text configure -state normal
541
        .code.text delete 1.0 end
542
        .code.text insert end $debug_info
543
        highlightCode
544
        .code.text configure -state disabled
545
        return 1
546 2 olivier.gi
    }
547 158 olivier.gi
}
548 87 olivier.gi
 
549 158 olivier.gi
proc bin2ihex {startAddr binData } {
550 87 olivier.gi
 
551 158 olivier.gi
    set full_line_size       16
552
    set full_line_nr         [expr [llength $binData] / $full_line_size]
553
    set last_line_size       [expr [llength $binData] -($full_line_size*$full_line_nr)]
554
    set line_nr              $full_line_nr
555
    if {$last_line_size!=0} {incr line_nr}
556
 
557
    set ihex ""
558
 
559
    for {set ii 0} {$ii<$line_nr} {incr ii} {
560
 
561
        set line_size $full_line_size
562
        if {$ii==$full_line_nr} {
563
            set line_size $last_line_size
564
        }
565
 
566
        set currentAddr [expr $startAddr+($full_line_size*$ii)]
567
        set chksum $line_size
568
        set chksum [expr $chksum+($currentAddr/256)+($currentAddr&255)]
569
        append ihex ":"
570
        append ihex [format "%02x" $line_size]
571
        append ihex [format "%04x" $currentAddr]
572
        append ihex "00"
573
        for {set jj 0} {$jj<$line_size} {incr jj} {
574
            set byte [lindex $binData [expr ($full_line_size*$ii)+$jj]]
575
            set chksum [expr $chksum + $byte]
576
            append ihex [format "%02x" $byte]
577
        }
578
        append ihex [format "%02x\n" [expr 255 & (0x100 - $chksum)]]
579 87 olivier.gi
    }
580 158 olivier.gi
    append ihex ":00000001FF\n"
581
    set ihex [string toupper $ihex]
582
    return $ihex
583
}
584 87 olivier.gi
 
585 158 olivier.gi
proc readPmem {} {
586
 
587
    global CpuNr
588
    global pmemIHEX
589
    global mem_sizes
590
    global isPmemRead
591
 
592
    # Get program memory start address
593
    set startAddr [format "0x%04x" [expr 0x10000-[lindex $mem_sizes 0]]]
594
 
595
    # Retrieve the program memory content
596
    clearBreakpoints
597
    set binData [ReadMemQuick8 $CpuNr $startAddr [lindex $mem_sizes 0]]
598
    setBreakpoints
599
    .ctrl.load.info.l configure -text "Program memory successfully read" -fg "\#00ae00"
600
 
601
    # Update buttons
602
    .ctrl.load.fb.load     configure  -fg "\#000000" -activeforeground "\#000000"
603
    .ctrl.load.fb.open     configure  -fg "\#000000" -activeforeground "\#000000"
604
    .ctrl.load.fb.readpmem configure  -fg "\#909000" -activeforeground "\#909000"
605
    update
606
 
607
    # Convert the binary content into Intel-HEX format
608
    set pmemIHEX [bin2ihex $startAddr $binData]
609
 
610
    # Update debugger view
611
    set isPmemRead 1
612
    updateCodeView
613
 
614 2 olivier.gi
}
615
 
616 158 olivier.gi
proc loadProgram {load} {
617
    global current_file_name
618 2 olivier.gi
    global cpu_status
619
    global reg
620
    global mem
621 110 olivier.gi
    global mem_sizes
622 87 olivier.gi
    global binFileType
623 158 olivier.gi
    global binFileName
624 110 olivier.gi
    global brkpt
625 158 olivier.gi
    global CpuNr
626
    global isPmemRead
627
    global pmemIHEX
628
    global backup
629 2 olivier.gi
 
630 158 olivier.gi
    # Check if the file exists
631
    #----------------------------------------
632
    if {![file exists $current_file_name]} {
633
        .ctrl.load.info.l configure -text "Specified file doesn't exists: \"$current_file_name\"" -fg red
634
        return 0
635
    }
636
 
637
    # Eventually initialite other CPU path
638
    for {set i 0} {$i<4} {incr i} {
639
        if {$backup($i,current_file_name)==""} {
640
            set backup($i,current_file_name) "[file dirname $current_file_name]/"
641
        }
642
    }
643
 
644
    # Detect the file format depending on the file extention
645 87 olivier.gi
    #--------------------------------------------------------
646 158 olivier.gi
    set binFileType [file extension $current_file_name]
647 87 olivier.gi
    set binFileType [string tolower $binFileType]
648
    regsub {\.} $binFileType {} binFileType
649
 
650
    if {![string eq $binFileType "ihex"] & ![string eq $binFileType "hex"] & ![string eq $binFileType "elf"]} {
651 158 olivier.gi
        .ctrl.load.info.l configure -text "[string toupper $binFileType] file format not supported\"" -fg red
652
        return 0
653 87 olivier.gi
    }
654
 
655
    if {[string eq $binFileType "hex"]} {
656 158 olivier.gi
        set binFileType "ihex"
657 87 olivier.gi
    }
658
    if {[string eq $binFileType "elf"]} {
659 158 olivier.gi
        set binFileType "elf32-msp430"
660 87 olivier.gi
    }
661
 
662
 
663
    # Create and read debug informations
664
    #----------------------------------------
665 158 olivier.gi
    set  binFileName $current_file_name
666
    set isPmemRead 0
667
    updateCodeView
668 87 olivier.gi
 
669 158 olivier.gi
    # Update buttons
670
    if {$load} {
671
        .ctrl.load.fb.load     configure  -fg "\#909000" -activeforeground "\#909000"
672
        .ctrl.load.fb.open     configure  -fg "\#000000" -activeforeground "\#000000"
673
    } else {
674
        .ctrl.load.fb.load     configure  -fg "\#000000" -activeforeground "\#000000"
675
        .ctrl.load.fb.open     configure  -fg "\#909000" -activeforeground "\#909000"
676
    }
677
    .ctrl.load.fb.readpmem     configure  -fg "\#000000" -activeforeground "\#000000"
678
    update
679 87 olivier.gi
 
680 2 olivier.gi
    # Create and read binary executable file
681
    #----------------------------------------
682
 
683
    # Generate binary file
684
    set bin_file "[clock clicks].bin"
685 158 olivier.gi
    if {[catch {exec msp430-objcopy -I $binFileType -O binary $binFileName $bin_file} errMsg]} {
686
        .ctrl.load.info.l configure -text "$errMsg" -fg red
687
        return 0
688 77 olivier.gi
    }
689
 
690
    # Wait until bin file is present on the filesystem
691 158 olivier.gi
    if {![waitForFile $bin_file]} {
692
        .ctrl.load.info.l configure -text "Timeout: ELF to BIN file conversion problem with \"msp430-objcopy\" executable" -fg red
693
        return 0
694 77 olivier.gi
    }
695 2 olivier.gi
 
696
    # Read file
697
    set fp [open $bin_file r]
698
    fconfigure $fp -translation binary
699
    binary scan [read $fp] H* hex_data yop
700
    close $fp
701
 
702
    # Cleanup
703
    file delete $bin_file
704
 
705
    # Get program size
706
    set hex_size  [string length $hex_data]
707
    set byte_size [expr $hex_size/2]
708
    set word_size [expr $byte_size/2]
709
 
710 77 olivier.gi
    # Make sure ELF program size is the same as the available program memory
711 110 olivier.gi
    if {[lindex $mem_sizes 0] != [expr $hex_size/2]} {
712 158 olivier.gi
        .ctrl.load.info.l configure -text "ERROR: ELF program size ([expr $hex_size/2] B) is different than the available program memory ([lindex $mem_sizes 0] B)" -fg red
713
        return 0
714 77 olivier.gi
    }
715
 
716 2 olivier.gi
    # Format data
717
    for {set i 0} {$i < $hex_size} {set i [expr $i+4]} {
718 158 olivier.gi
        set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
719
        set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
720
        lappend DataArray "0x$hex_msb$hex_lsb"
721 2 olivier.gi
    }
722
 
723
    # Load program to openmsp430 target
724
    #-----------------------------------
725
 
726 158 olivier.gi
    # Get program memory start address
727 2 olivier.gi
    set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
728
 
729 158 olivier.gi
    # Clear active breakpoints
730
    clearBreakpoints
731
 
732
    if {$load==1} {
733
 
734
        # Reset & Stop CPU
735
        ExecutePOR_Halt $CpuNr
736
 
737
        # Load Program Memory
738
        .ctrl.load.info.l configure -text "Load..." -fg "\#cdad00"
739
        update
740
        WriteMemQuick $CpuNr $StartAddr $DataArray
741
    }
742
 
743
    # Verify program memory of the openmsp430 target
744
    #------------------------------------------------
745
 
746 2 olivier.gi
    # Check Data
747 158 olivier.gi
    .ctrl.load.info.l configure -text "Verify..." -fg "\#cdad00"
748 2 olivier.gi
    update
749 158 olivier.gi
    if {[VerifyMem $CpuNr $StartAddr $DataArray 1]} {
750
        if {$load==1} {
751
            .ctrl.load.info.l configure -text "Binary file successfully loaded" -fg "\#00ae00"
752
        } else {
753
            .ctrl.load.info.l configure -text "Binary file successfully opened" -fg "\#00ae00"
754
            setBreakpoints
755
        }
756
        set pmemIHEX ""
757
   } else {
758
        if {$load==1} {
759
            .ctrl.load.info.l configure -text "ERROR while loading the firmware " -fg red
760
        } else {
761
            .ctrl.load.info.l configure -text "ERROR: Specified binary file doesn't match the program memory content" -fg red
762
            setBreakpoints
763
        }
764 2 olivier.gi
    }
765
    update
766
 
767 158 olivier.gi
    if {$load==1} {
768
        # Re-initialize breakpoints
769
        for {set i 0} {$i<3} {incr i} {
770
            .ctrl.cpu.brkpt.addr$i  configure -state normal
771
            set brkpt(en_$i)    0
772
        }
773
 
774
        # Reset & Stop CPU
775
        ExecutePOR_Halt $CpuNr
776
        .ctrl.cpu.cpu.step  configure -state normal
777
        .ctrl.cpu.cpu.run   configure -text "Run"
778
        .ctrl.cpu.cpu.l3    configure -text "Stopped" -fg "\#cdad00"
779
        set cpu_status 0
780 110 olivier.gi
    }
781 2 olivier.gi
    refreshReg
782
    refreshMem
783
}
784
 
785
proc runCPU {} {
786
    global cpu_status
787
    global reg
788
    global mem
789 158 olivier.gi
    global CpuNr
790 2 olivier.gi
 
791
    if {$cpu_status} {
792 158 olivier.gi
        HaltCPU $CpuNr
793
        .ctrl.cpu.cpu.step  configure -state normal
794
        .ctrl.cpu.cpu.run   configure -text "Run"
795
        .ctrl.cpu.cpu.l3    configure -text "Stopped" -fg "\#cdad00"
796
        set cpu_status 0
797 2 olivier.gi
    } else {
798 158 olivier.gi
        clearBreakpoints
799
        StepCPU $CpuNr
800
        setBreakpoints
801
        ReleaseCPU $CpuNr
802
        .ctrl.cpu.cpu.step  configure -state disabled
803
        .ctrl.cpu.cpu.run   configure -text "Stop"
804
        .ctrl.cpu.cpu.l3    configure -text "Running" -fg "\#00ae00"
805
        set cpu_status 1
806 2 olivier.gi
    }
807
    refreshReg
808
    refreshMem
809
}
810
 
811
proc resetCPU {} {
812
    global cpu_status
813
    global reg
814
    global mem
815 158 olivier.gi
    global CpuNr
816 2 olivier.gi
 
817
    if {$cpu_status} {
818 158 olivier.gi
        ExecutePOR $CpuNr
819 2 olivier.gi
    } else {
820 158 olivier.gi
        ExecutePOR_Halt $CpuNr
821 2 olivier.gi
    }
822
    refreshReg
823
    refreshMem
824
}
825
 
826 87 olivier.gi
proc singleStepCPU {} {
827
    global cpu_status
828
    global reg
829
    global mem
830 158 olivier.gi
    global CpuNr
831 87 olivier.gi
 
832
    if {$cpu_status==0} {
833 158 olivier.gi
        clearBreakpoints
834
        StepCPU $CpuNr
835
        setBreakpoints
836 87 olivier.gi
    }
837
    refreshReg
838
    refreshMem
839
}
840
 
841
proc statRegUpdate {} {
842
    global cpu_status
843
    global reg
844
    global mem
845
    global sr
846
 
847
    set tmp_reg [expr ($sr(v)      * 0x0100) |  \
848
                      ($sr(scg1)   * 0x0080) |  \
849
                      ($sr(oscoff) * 0x0020) |  \
850
                      ($sr(cpuoff) * 0x0010) |  \
851
                      ($sr(gie)    * 0x0008) |  \
852
                      ($sr(n)      * 0x0004) |  \
853
                      ($sr(z)      * 0x0002) |  \
854 158 olivier.gi
                      ($sr(c)      * 0x0001)]
855 87 olivier.gi
 
856
    set reg(2) [format "0x%04x" $tmp_reg]
857
 
858
    write2Reg 2
859
}
860
 
861
 
862 2 olivier.gi
proc refreshReg {} {
863
    global reg
864
    global mem
865 87 olivier.gi
    global sr
866 158 olivier.gi
    global CpuNr
867 2 olivier.gi
 
868 87 olivier.gi
    # Read register values
869 158 olivier.gi
    set new_vals [ReadRegAll $CpuNr]
870 2 olivier.gi
    for {set i 0} {$i<16} {incr i} {
871 158 olivier.gi
        set reg($i) [lindex $new_vals $i]
872 2 olivier.gi
    }
873 87 olivier.gi
    set sr(c)      [expr $reg(2) & 0x0001]
874
    set sr(z)      [expr $reg(2) & 0x0002]
875
    set sr(n)      [expr $reg(2) & 0x0004]
876
    set sr(gie)    [expr $reg(2) & 0x0008]
877
    set sr(cpuoff) [expr $reg(2) & 0x0010]
878
    set sr(oscoff) [expr $reg(2) & 0x0020]
879
    set sr(scg1)   [expr $reg(2) & 0x0080]
880
    set sr(v)      [expr $reg(2) & 0x0100]
881
 
882
    # Update highlighted line in the code view
883 110 olivier.gi
    highlightCode
884 2 olivier.gi
}
885
 
886
proc write2Reg {reg_num} {
887
    global reg
888
    global mem
889 158 olivier.gi
    global CpuNr
890 2 olivier.gi
 
891 158 olivier.gi
    WriteReg $CpuNr $reg_num $reg($reg_num)
892 2 olivier.gi
    refreshReg
893
    refreshMem
894
}
895
 
896
proc refreshMem {} {
897
    global reg
898
    global mem
899 158 olivier.gi
    global CpuNr
900 2 olivier.gi
 
901
    for {set i 0} {$i<16} {incr i} {
902 158 olivier.gi
        # Check if address lay in 16 or 8 bit space
903
        if {[expr $mem(address_$i)]>=[expr 0x100]} {
904
            set Format 0
905
        } else {
906
            set Format 1
907
        }
908 2 olivier.gi
 
909 158 olivier.gi
        # Read data
910
        set mem(data_$i) [ReadMem $CpuNr $Format $mem(address_$i)]
911 2 olivier.gi
    }
912
}
913
 
914
proc write2Mem {mem_num} {
915
    global reg
916
    global mem
917 158 olivier.gi
    global CpuNr
918 2 olivier.gi
 
919
    # Check if address lay in 16 or 8 bit space
920
    if {[expr $mem(address_$mem_num)]>=[expr 0x100]} {
921 158 olivier.gi
        set Format 0
922 2 olivier.gi
    } else {
923 158 olivier.gi
        set Format 1
924 2 olivier.gi
    }
925
 
926 158 olivier.gi
    WriteMem $CpuNr $Format $mem(address_$mem_num) $mem(data_$mem_num)
927 2 olivier.gi
    refreshReg
928
    refreshMem
929
}
930
 
931 110 olivier.gi
proc updateBreakpoint {brkpt_num} {
932
    global brkpt
933
    global mem_sizes
934 158 olivier.gi
    global CpuNr
935 110 olivier.gi
 
936
    # Set the breakpoint
937
    if {$brkpt(en_$brkpt_num)==1} {
938 158 olivier.gi
 
939
        # Make sure the specified address is an opcode
940
        regsub {0x} $brkpt(addr_$brkpt_num) {} brkpt_val
941
        set code_match [.code.text search "$brkpt_val:" 1.0 end]
942
        if {![string length $code_match]} {
943
            .ctrl.cpu.brkpt.addr$brkpt_num    configure -state normal
944
            set brkpt(en_$brkpt_num) 0
945 110 olivier.gi
 
946 158 olivier.gi
        } else {
947
            set brkpt(data_$brkpt_num) [ReadMem $CpuNr 0 $brkpt(addr_$brkpt_num)]
948
 
949
            # Only set a breakpoint if there is not already one there :-P
950
            if {$brkpt(data_$brkpt_num)=="0x4343"} {
951
                .ctrl.cpu.brkpt.addr$brkpt_num    configure -state normal
952
                set brkpt(en_$brkpt_num) 0
953
            } else {
954
                .ctrl.cpu.brkpt.addr$brkpt_num    configure -state readonly
955
                WriteMem $CpuNr 0 $brkpt(addr_$brkpt_num) 0x4343
956
            }
957
        }
958 110 olivier.gi
 
959
    # Clear the breakpoint
960
    } else {
961 158 olivier.gi
        .ctrl.cpu.brkpt.addr$brkpt_num    configure -state normal
962
        set opcode [ReadMem $CpuNr 0 $brkpt(addr_$brkpt_num)]
963
        if {$opcode=="0x4343"} {
964
            WriteMem $CpuNr 0 $brkpt(addr_$brkpt_num) $brkpt(data_$brkpt_num)
965
        }
966 110 olivier.gi
    }
967
 
968
    highlightCode
969
}
970
 
971
proc clearBreakpoints {} {
972 158 olivier.gi
    global connection_status
973 110 olivier.gi
    global brkpt
974
    global mem_sizes
975 158 olivier.gi
    global CpuNr
976 110 olivier.gi
 
977 158 olivier.gi
    if {$connection_status} {
978
        for {set i 0} {$i<3} {incr i} {
979
            if {$brkpt(en_$i)==1} {
980
                WriteMem $CpuNr 0 $brkpt(addr_$i) $brkpt(data_$i)
981
            }
982
        }
983 110 olivier.gi
    }
984
}
985
 
986
proc setBreakpoints {} {
987
    global brkpt
988
    global mem_sizes
989 158 olivier.gi
    global CpuNr
990 110 olivier.gi
 
991
    for {set i 0} {$i<3} {incr i} {
992 158 olivier.gi
        if {$brkpt(en_$i)==1} {
993
            set brkpt(data_$i) [ReadMem $CpuNr 0 $brkpt(addr_$i)]
994
            WriteMem $CpuNr 0 $brkpt(addr_$i) 0x4343
995
        }
996 110 olivier.gi
    }
997
}
998
 
999 158 olivier.gi
proc selectCPU {CpuNr_next} {
1000 110 olivier.gi
 
1001 158 olivier.gi
    global CpuNr
1002 110 olivier.gi
 
1003 158 olivier.gi
    # Read current font
1004
    set font [.menu.cpu1 cget -font]
1005
    set family      [font actual $font -family];
1006
    set size        [font actual $font -size];
1007
    set slant       [font actual $font -slant];
1008
    set underline   [font actual $font -underline];
1009
    set overstrike  [font actual $font -overstrike];
1010
 
1011
    # Create normal font
1012 163 olivier.gi
    set font_normal "-family \"$family\" -size $size -weight normal -slant $slant -underline $underline -overstrike $overstrike"
1013 158 olivier.gi
 
1014
    # Create bold font
1015 163 olivier.gi
    set font_bold   "-family \"$family\" -size $size -weight bold   -slant $slant -underline $underline -overstrike $overstrike"
1016 158 olivier.gi
 
1017
    if {$CpuNr_next==0} {
1018
        .menu.cpu0     configure -relief sunken  -font $font_bold   -fg "\#00ae00" -activeforeground "\#00ae00"
1019
        .menu.cpu1     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1020
        .menu.cpu2     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1021
        .menu.cpu3     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1022
 
1023
    } elseif {$CpuNr_next==1} {
1024
        .menu.cpu0     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1025
        .menu.cpu1     configure -relief sunken  -font $font_bold   -fg "\#00ae00" -activeforeground "\#00ae00"
1026
        .menu.cpu2     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1027
        .menu.cpu3     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1028
 
1029
    } elseif {$CpuNr_next==2} {
1030
        .menu.cpu0     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1031
        .menu.cpu1     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1032
        .menu.cpu2     configure -relief sunken  -font $font_bold   -fg "\#00ae00" -activeforeground "\#00ae00"
1033
        .menu.cpu3     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1034
 
1035
    } else {
1036
        .menu.cpu0     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1037
        .menu.cpu1     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1038
        .menu.cpu2     configure -relief raised  -font $font_normal -fg "\#000000" -activeforeground "\#000000"
1039
        .menu.cpu3     configure -relief sunken  -font $font_bold   -fg "\#00ae00" -activeforeground "\#00ae00"
1040
    }
1041
 
1042
    saveContext    $CpuNr
1043
    set CpuNr      $CpuNr_next
1044
    restoreContext $CpuNr
1045
 
1046
    return 1
1047
}
1048
 
1049
proc advancedConfiguration {} {
1050
 
1051
    global omsp_info
1052
    global omsp_conf
1053
    global omsp_nr
1054
 
1055
    # Initialize temp variables
1056
    global temp_nrcore
1057
    global temp_if
1058
    global temp_adapt
1059
    global temp_addr
1060
    regexp {(.+)_(.+)} $omsp_conf(interface) whole_match temp_if temp_adapt
1061
    set temp_if      [string toupper $temp_if]
1062
    set temp_adapt   [string toupper $temp_adapt]
1063
    set temp_nrcore  $omsp_nr
1064
    set temp_addr(0) $omsp_conf(0,cpuaddr)
1065
    set temp_addr(1) $omsp_conf(1,cpuaddr)
1066
    set temp_addr(2) $omsp_conf(2,cpuaddr)
1067
    set temp_addr(3) $omsp_conf(3,cpuaddr)
1068
 
1069
    # Destroy windows if already existing
1070
    if {[lsearch -exact [winfo children .] .omsp_adapt_config]!=-1} {
1071
        destroy .omsp_adapt_config
1072
    }
1073
 
1074
    # Create master window
1075
    toplevel     .omsp_adapt_config
1076
    wm title     .omsp_adapt_config "Advanced configuration"
1077
    wm geometry  .omsp_adapt_config +380+200
1078
    wm resizable .omsp_adapt_config 0 0
1079
 
1080
    # Title
1081
    label  .omsp_adapt_config.title  -text "Advanced configuration"   -anchor center -fg "\#ae0000" -font {-weight bold -size 16}
1082
    pack   .omsp_adapt_config.title  -side top -padx {20 20} -pady {20 10}
1083
 
1084
    # Create the main configuration area
1085
    frame    .omsp_adapt_config.main  -bd 2
1086
    pack     .omsp_adapt_config.main  -side top  -padx 10      -pady 10
1087
 
1088
    # Create the ok/cancel area
1089
    frame    .omsp_adapt_config.ok    -bd 2
1090
    pack     .omsp_adapt_config.ok    -side top  -padx 10      -pady 10
1091
 
1092
 
1093
    # Create the Adapter Menu
1094
    frame    .omsp_adapt_config.main.adapter     -bd 2 -relief ridge
1095
    pack     .omsp_adapt_config.main.adapter     -side left  -padx 10      -pady 10 -fill both
1096
 
1097
    # Create the I2C Menu
1098
    frame    .omsp_adapt_config.main.i2c           -bd 2 -relief ridge
1099
    pack     .omsp_adapt_config.main.i2c           -side right -padx 10      -pady 10  -fill both
1100
 
1101
 
1102
    # Adapter stuff
1103
    label    .omsp_adapt_config.main.adapter.title    -text "Adapter configuration"   -anchor center -fg "\#000000" -font {-weight bold -size 12}
1104
    pack     .omsp_adapt_config.main.adapter.title    -side top -padx 10 -pady 10
1105
    frame    .omsp_adapt_config.main.adapter.ser
1106
    pack     .omsp_adapt_config.main.adapter.ser      -side top  -padx 10      -pady 10
1107
 
1108
    label    .omsp_adapt_config.main.adapter.ser.l    -text "Serial Debug Interface:" -anchor center
1109
    pack     .omsp_adapt_config.main.adapter.ser.l    -side left
1110
    combobox .omsp_adapt_config.main.adapter.ser.p    -textvariable temp_if -editable false -width 10 -command {updateAdvancedConfiguration}
1111
    eval     .omsp_adapt_config.main.adapter.ser.p    list insert end [list "UART" "I2C"]
1112
    pack     .omsp_adapt_config.main.adapter.ser.p    -side right -padx 5
1113
 
1114
    frame    .omsp_adapt_config.main.adapter.ada
1115
    pack     .omsp_adapt_config.main.adapter.ada -side top  -padx 10      -pady 10  -fill x
1116
 
1117
    label    .omsp_adapt_config.main.adapter.ada.l    -text "Adapter selection:" -anchor w
1118
    pack     .omsp_adapt_config.main.adapter.ada.l    -side left
1119
    combobox .omsp_adapt_config.main.adapter.ada.p    -textvariable temp_adapt -editable false -width 10
1120
    eval     .omsp_adapt_config.main.adapter.ada.p    list insert end [list "GENERIC"]
1121
    pack     .omsp_adapt_config.main.adapter.ada.p    -side right -padx 5
1122
 
1123
 
1124
    # I2C stuff
1125
    label    .omsp_adapt_config.main.i2c.title         -text "I2C configuration"   -anchor center -fg "\#000000" -font {-weight bold -size 12}
1126
    pack     .omsp_adapt_config.main.i2c.title         -side top -padx 10 -pady 10
1127
    frame    .omsp_adapt_config.main.i2c.cpunr
1128
    pack     .omsp_adapt_config.main.i2c.cpunr        -side top  -padx 10      -pady 10  -fill x
1129
    label    .omsp_adapt_config.main.i2c.cpunr.l      -text "Number of cores:" -anchor w
1130
    pack     .omsp_adapt_config.main.i2c.cpunr.l      -side left -padx 5
1131
    spinbox  .omsp_adapt_config.main.i2c.cpunr.s      -from 1 -to 4 -textvariable temp_nrcore -state readonly -width 4 -command {updateAdvancedConfiguration}
1132
    pack     .omsp_adapt_config.main.i2c.cpunr.s      -side right -padx 5
1133
 
1134
    frame    .omsp_adapt_config.main.i2c.cpu0
1135
    pack     .omsp_adapt_config.main.i2c.cpu0         -side top  -padx 10      -pady 10  -fill x
1136
    label    .omsp_adapt_config.main.i2c.cpu0.l       -text "I2C Address (Core 0):" -anchor w
1137
    pack     .omsp_adapt_config.main.i2c.cpu0.l       -side left -padx 5
1138
    spinbox  .omsp_adapt_config.main.i2c.cpu0.s       -from 8 -to 119 -textvariable temp_addr(0) -width 4
1139
    pack     .omsp_adapt_config.main.i2c.cpu0.s       -side right -padx 5
1140
 
1141
    frame    .omsp_adapt_config.main.i2c.cpu1
1142
    pack     .omsp_adapt_config.main.i2c.cpu1         -side top  -padx 10      -pady 10  -fill x
1143
    label    .omsp_adapt_config.main.i2c.cpu1.l       -text "I2C Address (Core 1):" -anchor w
1144
    pack     .omsp_adapt_config.main.i2c.cpu1.l       -side left -padx 5
1145
    spinbox  .omsp_adapt_config.main.i2c.cpu1.s       -from 8 -to 119 -textvariable temp_addr(1) -width 4
1146
    pack     .omsp_adapt_config.main.i2c.cpu1.s       -side right -padx 5
1147
 
1148
    frame    .omsp_adapt_config.main.i2c.cpu2
1149
    pack     .omsp_adapt_config.main.i2c.cpu2         -side top  -padx 10      -pady 10  -fill x
1150
    label    .omsp_adapt_config.main.i2c.cpu2.l       -text "I2C Address (Core 2):" -anchor w
1151
    pack     .omsp_adapt_config.main.i2c.cpu2.l       -side left -padx 5
1152
    spinbox  .omsp_adapt_config.main.i2c.cpu2.s       -from 8 -to 119 -textvariable temp_addr(2) -width 4
1153
    pack     .omsp_adapt_config.main.i2c.cpu2.s       -side right -padx 5
1154
 
1155
    frame    .omsp_adapt_config.main.i2c.cpu3
1156
    pack     .omsp_adapt_config.main.i2c.cpu3         -side top  -padx 10      -pady 10  -fill x
1157
    label    .omsp_adapt_config.main.i2c.cpu3.l       -text "I2C Address (Core 3):" -anchor w
1158
    pack     .omsp_adapt_config.main.i2c.cpu3.l       -side left -padx 5
1159
    spinbox  .omsp_adapt_config.main.i2c.cpu3.s       -from 8 -to 119 -textvariable temp_addr(3) -width 4
1160
    pack     .omsp_adapt_config.main.i2c.cpu3.s       -side right -padx 5
1161
 
1162
 
1163
    # Create OK/Cancel button
1164
    button .omsp_adapt_config.ok.okay   -text "OK"     -command {set omsp_conf(interface) [string tolower "${temp_if}_${temp_adapt}"]
1165
                                                                 set omsp_nr              $temp_nrcore;
1166
                                                                 set omsp_conf(0,cpuaddr) $temp_addr(0);
1167
                                                                 set omsp_conf(1,cpuaddr) $temp_addr(1);
1168
                                                                 set omsp_conf(2,cpuaddr) $temp_addr(2);
1169
                                                                 set omsp_conf(3,cpuaddr) $temp_addr(3);
1170
                                                                 .ctrl.connect.serial.p2 configure -editable  1;
1171
                                                                 eval .ctrl.connect.serial.p2 list delete 0 end;
1172
                                                                 eval .ctrl.connect.serial.p2 list insert   end [lindex [GetAllowedSpeeds] 2];
1173
                                                                 set omsp_conf(baudrate) [lindex [GetAllowedSpeeds] 1];
1174
                                                                 .ctrl.connect.serial.p2 configure -editable  [lindex [GetAllowedSpeeds] 0];
1175
                                                                 destroy .omsp_adapt_config}
1176
    pack   .omsp_adapt_config.ok.okay   -side bottom   -side left  -expand true -fill x -padx 5 -pady 10
1177
    button .omsp_adapt_config.ok.cancel -text "CANCEL" -command {destroy .omsp_adapt_config}
1178
    pack   .omsp_adapt_config.ok.cancel -side bottom   -side right -expand true -fill x -padx 5 -pady 10
1179
 
1180
    updateAdvancedConfiguration
1181
}
1182
 
1183
proc updateAdvancedConfiguration {{w ""} {sel ""}} {
1184
 
1185
    global temp_if
1186
    global temp_adapt
1187
    global temp_nrcore
1188
    global connection_status
1189
 
1190
    if {$connection_status} {
1191
        .omsp_adapt_config.main.adapter.ser.p configure -state disabled
1192
        .omsp_adapt_config.main.adapter.ada.p configure -state disabled
1193
        .omsp_adapt_config.main.i2c.cpunr.s   configure -state disabled
1194
        .omsp_adapt_config.main.i2c.cpu0.s    configure -state disabled
1195
        .omsp_adapt_config.main.i2c.cpu1.s    configure -state disabled
1196
        .omsp_adapt_config.main.i2c.cpu2.s    configure -state disabled
1197
        .omsp_adapt_config.main.i2c.cpu3.s    configure -state disabled
1198
 
1199
    } else {
1200
        if {$sel=="UART"} {
1201
            eval .omsp_adapt_config.main.adapter.ada.p  list delete 0 end
1202
            eval .omsp_adapt_config.main.adapter.ada.p  list insert   end [list "GENERIC"]
1203
            set temp_adapt "GENERIC"
1204
 
1205
        } elseif {$sel=="I2C"} {
1206
 
1207
            eval .omsp_adapt_config.main.adapter.ada.p  list delete 0 end
1208
            eval .omsp_adapt_config.main.adapter.ada.p  list insert   end [list "USB-ISS"]
1209
            set temp_adapt "USB-ISS"
1210
 
1211
        }
1212
 
1213
        if {$temp_if=="UART"} {
1214
 
1215
            .omsp_adapt_config.main.i2c.cpunr.s configure -state disabled
1216
            .omsp_adapt_config.main.i2c.cpu0.s  configure -state disabled
1217
            .omsp_adapt_config.main.i2c.cpu1.s  configure -state disabled
1218
            .omsp_adapt_config.main.i2c.cpu2.s  configure -state disabled
1219
            .omsp_adapt_config.main.i2c.cpu3.s  configure -state disabled
1220
 
1221
        } elseif {$temp_if=="I2C"} {
1222
 
1223 169 olivier.gi
            .omsp_adapt_config.main.i2c.cpunr.s configure -state normal
1224 158 olivier.gi
#           .omsp_adapt_config.main.i2c.cpunr.s configure -state normal
1225
            .omsp_adapt_config.main.i2c.cpu0.s  configure -state normal
1226
 
1227
            if {$temp_nrcore < 2} {.omsp_adapt_config.main.i2c.cpu1.s configure -state disabled
1228
            } else                {.omsp_adapt_config.main.i2c.cpu1.s configure -state normal}
1229
 
1230
            if {$temp_nrcore < 3} {.omsp_adapt_config.main.i2c.cpu2.s configure -state disabled
1231
            } else                {.omsp_adapt_config.main.i2c.cpu2.s configure -state normal}
1232
 
1233
            if {$temp_nrcore < 4} {.omsp_adapt_config.main.i2c.cpu3.s configure -state disabled
1234
            } else                {.omsp_adapt_config.main.i2c.cpu3.s configure -state normal}
1235
 
1236
 
1237
        }
1238
    }
1239
}
1240
 
1241
proc saveContext {CpuNr} {
1242
 
1243
    global current_file_name
1244
    global brkpt
1245
    global mem
1246
    global mem_sizes
1247
    global codeSelect
1248
    global isPmemRead
1249
    global binFileType
1250
    global binFileName
1251
    global pmemIHEX
1252
 
1253
    global backup
1254
 
1255
    set backup($CpuNr,current_file_name) $current_file_name
1256
 
1257
    set backup($CpuNr,load_color)        [.ctrl.load.fb.load     cget  -fg]
1258
    set backup($CpuNr,open_color)        [.ctrl.load.fb.open     cget  -fg]
1259
    set backup($CpuNr,readpmem_color)    [.ctrl.load.fb.readpmem cget  -fg]
1260
 
1261
    set backup($CpuNr,info_text)         [.ctrl.load.info.l      cget -text]
1262
    set backup($CpuNr,info_color)        [.ctrl.load.info.l      cget -fg]
1263
 
1264
    for {set i 0} {$i<3} {incr i} {
1265
        set backup($CpuNr,brkpt_addr_$i)     $brkpt(addr_$i)
1266
        set backup($CpuNr,brkpt_en_$i)       $brkpt(en_$i)
1267
        set backup($CpuNr,brkpt_readonly_$i) [.ctrl.cpu.brkpt.addr$i cget -state]
1268
    }
1269
 
1270
    for {set i 0} {$i<16} {incr i} {
1271
        set backup($CpuNr,mem_addr_$i)   $mem(address_$i)
1272
    }
1273
    set backup($CpuNr,mem_sizes)         $mem_sizes
1274
 
1275
    set backup($CpuNr,codeSelect)        $codeSelect
1276
    set backup($CpuNr,isPmemRead)        $isPmemRead
1277
    set backup($CpuNr,binFileType)       $binFileType
1278
    set backup($CpuNr,binFileName)       $binFileName
1279
    set backup($CpuNr,pmemIHEX)          $pmemIHEX
1280
 
1281
    return 1
1282
}
1283
 
1284
proc restoreContext {CpuNr} {
1285
 
1286
    global current_file_name
1287
    global brkpt
1288
    global mem
1289
    global mem_sizes
1290
    global codeSelect
1291
    global isPmemRead
1292
    global binFileType
1293
    global binFileName
1294
    global pmemIHEX
1295
    global cpu_status
1296
    global connection_status
1297
 
1298
    global backup
1299
 
1300
    set pmemIHEX    $backup($CpuNr,pmemIHEX)
1301
    set binFileName $backup($CpuNr,binFileName)
1302
    set binFileType $backup($CpuNr,binFileType)
1303
    set isPmemRead  $backup($CpuNr,isPmemRead)
1304
    set codeSelect  $backup($CpuNr,codeSelect)
1305
 
1306
    for {set i 0} {$i<16} {incr i} {
1307
        set mem(address_$i) $backup($CpuNr,mem_addr_$i)
1308
    }
1309
    set mem_sizes $backup($CpuNr,mem_sizes)
1310
 
1311
    for {set i 0} {$i<3} {incr i} {
1312
        set brkpt(addr_$i) $backup($CpuNr,brkpt_addr_$i)
1313
        set brkpt(en_$i)   $backup($CpuNr,brkpt_en_$i)
1314
        .ctrl.cpu.brkpt.addr$i configure -state $backup($CpuNr,brkpt_readonly_$i)
1315
    }
1316
 
1317
    .ctrl.load.info.l      configure -text $backup($CpuNr,info_text)
1318
    .ctrl.load.info.l      configure -fg   $backup($CpuNr,info_color)
1319
 
1320
    .ctrl.load.fb.load     configure -fg   $backup($CpuNr,load_color)     -activeforeground $backup($CpuNr,load_color)
1321
    .ctrl.load.fb.open     configure -fg   $backup($CpuNr,open_color)     -activeforeground $backup($CpuNr,open_color)
1322
    .ctrl.load.fb.readpmem configure -fg   $backup($CpuNr,readpmem_color) -activeforeground $backup($CpuNr,readpmem_color)
1323
 
1324
    set current_file_name  $backup($CpuNr,current_file_name)
1325
 
1326
    update
1327
 
1328
    if {$connection_status} {
1329
        if {[IsHalted $CpuNr]} {
1330
            .ctrl.cpu.cpu.step  configure -state normal
1331
            .ctrl.cpu.cpu.run   configure -text "Run"
1332
            .ctrl.cpu.cpu.l3    configure -text "Stopped" -fg "\#cdad00"
1333
            set cpu_status 0
1334
        } else {
1335
            .ctrl.cpu.cpu.step  configure -state disabled
1336
            .ctrl.cpu.cpu.run   configure -text "Stop"
1337
            .ctrl.cpu.cpu.l3    configure -text "Running" -fg "\#00ae00"
1338
            set cpu_status 1
1339
        }
1340
        refreshReg
1341
        refreshMem
1342
        .code.text configure -state normal
1343
        .code.text delete 1.0 end
1344
        .code.text configure -state disabled
1345
        updateCodeView
1346
    }
1347
 
1348
 return 1
1349
}
1350
 
1351 2 olivier.gi
###############################################################################
1352
#                                                                             #
1353
#                           CREATE GRAPHICAL INTERFACE                        #
1354
#                                                                             #
1355
###############################################################################
1356
 
1357
####################################
1358
#   CREATE & PLACE MAIN WIDGETS    #
1359
####################################
1360
 
1361 87 olivier.gi
wm title    . "openMSP430 mini debugger"
1362
wm iconname . "openMSP430 mini debugger"
1363 2 olivier.gi
 
1364 87 olivier.gi
# Create the Main Menu
1365 2 olivier.gi
frame  .menu
1366 158 olivier.gi
pack   .menu                  -side top    -padx 10       -pady 10       -fill x
1367 2 olivier.gi
 
1368 110 olivier.gi
# Create the CPU Control field
1369 87 olivier.gi
frame  .ctrl
1370 158 olivier.gi
pack   .ctrl                  -side left   -padx {5 0}    -pady 10       -fill both
1371 2 olivier.gi
 
1372 87 olivier.gi
# Create the Code text field
1373
frame  .code
1374 158 olivier.gi
pack   .code                  -side right  -padx 5        -pady 10       -fill both  -expand true
1375 87 olivier.gi
frame  .code.rb
1376 158 olivier.gi
pack   .code.rb               -side bottom -padx 10       -pady 10       -fill both
1377 87 olivier.gi
 
1378 110 olivier.gi
# Create the connection frame
1379 158 olivier.gi
frame  .ctrl.connect          -bd 2        -relief ridge  ;# solid
1380
pack   .ctrl.connect          -side top    -padx 10       -pady 0        -fill x
1381 110 olivier.gi
 
1382 87 olivier.gi
# Create the Serial Menu
1383 110 olivier.gi
frame  .ctrl.connect.serial
1384 158 olivier.gi
pack   .ctrl.connect.serial   -side top    -padx 10       -pady {10 0}   -fill x
1385 87 olivier.gi
 
1386
# Create the memory size
1387 110 olivier.gi
frame  .ctrl.connect.info
1388 158 olivier.gi
pack   .ctrl.connect.info     -side top    -padx 10       -pady {10 10}  -fill x
1389 87 olivier.gi
 
1390 2 olivier.gi
# Create the Load executable field
1391 158 olivier.gi
frame  .ctrl.load             -bd 2        -relief ridge  ;# solid
1392
pack   .ctrl.load             -side top    -padx 10       -pady {10 10}  -fill x
1393 2 olivier.gi
 
1394 110 olivier.gi
# Create the cpu field
1395 158 olivier.gi
frame  .ctrl.cpu              -bd 2        -relief ridge  ;# solid
1396
pack   .ctrl.cpu              -side top    -padx 10       -pady {0 10}   -fill x
1397 110 olivier.gi
 
1398 2 olivier.gi
# Create the cpu control field
1399 110 olivier.gi
frame  .ctrl.cpu.cpu
1400 158 olivier.gi
pack   .ctrl.cpu.cpu          -side top    -padx 10       -pady {20 10}  -fill x
1401 2 olivier.gi
 
1402 110 olivier.gi
# Create the breakpoint control field
1403
frame  .ctrl.cpu.brkpt
1404 158 olivier.gi
pack   .ctrl.cpu.brkpt        -side top    -padx 10       -pady {10 20}  -fill x
1405 110 olivier.gi
 
1406 87 olivier.gi
# Create the cpu status field
1407 110 olivier.gi
frame  .ctrl.cpu.reg_stat
1408 158 olivier.gi
pack   .ctrl.cpu.reg_stat     -side top    -padx 10       -pady {10 10}  -fill x
1409 87 olivier.gi
 
1410 2 olivier.gi
# Create the cpu registers/memory fields
1411 110 olivier.gi
frame  .ctrl.cpu.reg_mem
1412 158 olivier.gi
pack   .ctrl.cpu.reg_mem      -side top    -padx 10       -pady {5 10}   -fill x
1413 110 olivier.gi
frame  .ctrl.cpu.reg_mem.reg
1414 158 olivier.gi
pack   .ctrl.cpu.reg_mem.reg  -side left   -padx {10 30}                 -fill x
1415 110 olivier.gi
frame  .ctrl.cpu.reg_mem.mem
1416 158 olivier.gi
pack   .ctrl.cpu.reg_mem.mem  -side left   -padx {30 10}                 -fill x
1417 2 olivier.gi
 
1418 87 olivier.gi
# Create the TCL script field
1419 158 olivier.gi
frame  .ctrl.tclscript        -bd 2 -relief ridge         ;# solid
1420
pack   .ctrl.tclscript        -side top    -padx 10       -pady {0 20}   -fill x
1421 2 olivier.gi
 
1422 87 olivier.gi
 
1423 2 olivier.gi
####################################
1424 87 olivier.gi
#  CREATE THE CPU CONTROL SECTION  #
1425 2 olivier.gi
####################################
1426
 
1427
# Exit button
1428 158 olivier.gi
button .menu.exit      -text "Exit" -command {clearBreakpoints; exit 0}
1429 2 olivier.gi
pack   .menu.exit      -side left
1430
 
1431 158 olivier.gi
# CPU selection buttons
1432
label  .menu.cpusel    -text "oMSP core Selection:" -anchor w -state disabled
1433
pack   .menu.cpusel    -side left -padx "100 0"
1434
button .menu.cpu0      -text "Core 0" -command {selectCPU 0}  -state disabled
1435
pack   .menu.cpu0      -side left -padx 10
1436
button .menu.cpu1      -text "Core 1" -command {selectCPU 1}  -state disabled
1437
pack   .menu.cpu1      -side left -padx 10
1438
button .menu.cpu2      -text "Core 2" -command {selectCPU 2}  -state disabled
1439
pack   .menu.cpu2      -side left -padx 10
1440
button .menu.cpu3      -text "Core 3" -command {selectCPU 3}  -state disabled
1441
pack   .menu.cpu3      -side left -padx 10
1442
 
1443 110 olivier.gi
# openMSP430 label
1444
label  .menu.omsp      -text "openMSP430 mini debugger" -anchor center -fg "\#6a5acd" -font {-weight bold -size 16}
1445
pack   .menu.omsp      -side right -padx 20
1446 2 olivier.gi
 
1447
# Serial Port fields
1448 158 olivier.gi
label    .ctrl.connect.serial.l1    -text "Device Port:"  -anchor w
1449 110 olivier.gi
pack     .ctrl.connect.serial.l1    -side left
1450 158 olivier.gi
combobox .ctrl.connect.serial.p1    -textvariable omsp_conf(device)   -width 15 -editable true
1451
eval     .ctrl.connect.serial.p1    list insert end [utils::uart_port_list]
1452 110 olivier.gi
pack     .ctrl.connect.serial.p1    -side left -padx 5
1453 2 olivier.gi
 
1454 158 olivier.gi
label    .ctrl.connect.serial.l2    -text "  Speed:" -anchor w
1455 110 olivier.gi
pack     .ctrl.connect.serial.l2    -side left
1456 158 olivier.gi
combobox .ctrl.connect.serial.p2    -textvariable omsp_conf(baudrate) -width 14 -editable [lindex [GetAllowedSpeeds] 0]
1457
eval     .ctrl.connect.serial.p2    list insert end [lindex [GetAllowedSpeeds] 2]
1458 110 olivier.gi
pack     .ctrl.connect.serial.p2    -side left -padx 5
1459 2 olivier.gi
 
1460 110 olivier.gi
button   .ctrl.connect.serial.connect -text "Connect" -width 9 -command {connect_openMSP430}
1461
pack     .ctrl.connect.serial.connect -side right -padx 5
1462 2 olivier.gi
 
1463 158 olivier.gi
button   .ctrl.connect.serial.extra -text "Advanced..." -width 10 -command {advancedConfiguration}
1464
pack     .ctrl.connect.serial.extra -side left -padx 10
1465
 
1466 110 olivier.gi
# CPU status & info
1467 158 olivier.gi
frame    .ctrl.connect.info.l1
1468
pack     .ctrl.connect.info.l1      -side top    -padx 0      -pady {0 0} -fill x
1469 2 olivier.gi
 
1470 158 olivier.gi
label    .ctrl.connect.info.l1.cpu  -text "CPU Info:"       -anchor w
1471
pack     .ctrl.connect.info.l1.cpu  -side left -padx "0 10"
1472
label    .ctrl.connect.info.l1.con  -text "Disconnected"    -anchor w -fg Red
1473
pack     .ctrl.connect.info.l1.con  -side left
1474
button   .ctrl.connect.info.l1.more -text "More..."         -width 9 -command {displayMore} -state disabled
1475
pack     .ctrl.connect.info.l1.more -side right -padx 5
1476 110 olivier.gi
 
1477
 
1478 2 olivier.gi
# Load ELF file fields
1479 87 olivier.gi
frame  .ctrl.load.ft
1480 110 olivier.gi
pack   .ctrl.load.ft        -side top -fill x -padx "10 0" -pady "10 0"
1481 87 olivier.gi
label  .ctrl.load.ft.l      -text "ELF file:"  -state disabled
1482
pack   .ctrl.load.ft.l      -side left -padx "0 10"
1483 158 olivier.gi
entry  .ctrl.load.ft.file   -width 58 -relief sunken -textvariable current_file_name -state disabled
1484 87 olivier.gi
pack   .ctrl.load.ft.file   -side left -padx 10
1485 158 olivier.gi
button .ctrl.load.ft.browse -text "Browse" -width 9 -state disabled -command {set current_file_name [tk_getOpenFile -filetypes {{{ELF/Intel-Hex Files} {.elf .ihex .hex}} {{All Files} *}}]}
1486 110 olivier.gi
pack   .ctrl.load.ft.browse -side right -padx {5 15}
1487 87 olivier.gi
frame  .ctrl.load.fb
1488 158 olivier.gi
pack   .ctrl.load.fb          -side top -fill x -padx "10 0" -pady "5 5"
1489
button .ctrl.load.fb.load     -text "Load ELF File !"       -state disabled -command {loadProgram 1}
1490
pack   .ctrl.load.fb.load     -side left -padx 5 -fill x
1491
button .ctrl.load.fb.open     -text "Open ELF File !"       -state disabled -command {loadProgram 0}
1492
pack   .ctrl.load.fb.open     -side left -padx 5 -fill x
1493
button .ctrl.load.fb.readpmem -text "Read Program Memory !" -state disabled -command {readPmem}
1494
pack   .ctrl.load.fb.readpmem -side left -padx 5 -fill x
1495
frame  .ctrl.load.info
1496
pack   .ctrl.load.info        -side top -fill x -padx "10 0" -pady "5 10"
1497
label  .ctrl.load.info.t      -text "Firmware info:" -anchor w       -state disabled
1498
pack   .ctrl.load.info.t      -side left -padx "0 10"
1499
label  .ctrl.load.info.l      -text "No info available" -anchor w -fg Red   -state disabled
1500
pack   .ctrl.load.info.l      -side left
1501 2 olivier.gi
 
1502
# CPU Control
1503 110 olivier.gi
label  .ctrl.cpu.cpu.l1     -text "CPU Control:" -anchor w  -state disabled
1504
pack   .ctrl.cpu.cpu.l1     -side left
1505
button .ctrl.cpu.cpu.reset  -text "Reset" -state disabled -command {resetCPU}
1506
pack   .ctrl.cpu.cpu.reset  -side left -padx 5 -fill x
1507
button .ctrl.cpu.cpu.run    -text "Stop"  -state disabled -command {runCPU}
1508
pack   .ctrl.cpu.cpu.run    -side left -padx 5 -fill x
1509
button .ctrl.cpu.cpu.step   -text "Step"  -state disabled -command {singleStepCPU}
1510
pack   .ctrl.cpu.cpu.step   -side left -padx 5 -fill x
1511
label  .ctrl.cpu.cpu.l2     -text "CPU Status:" -anchor w  -state disabled
1512
pack   .ctrl.cpu.cpu.l2     -side left -padx "40 0"
1513
label  .ctrl.cpu.cpu.l3     -text "--" -anchor w  -state disabled
1514
pack   .ctrl.cpu.cpu.l3     -side left
1515 2 olivier.gi
 
1516 110 olivier.gi
# Breakpoints
1517
label       .ctrl.cpu.brkpt.l1       -text "CPU Breakpoints:"    -anchor w  -state disabled
1518
pack        .ctrl.cpu.brkpt.l1       -side left
1519
entry       .ctrl.cpu.brkpt.addr0    -textvariable brkpt(addr_0) -relief sunken -state disabled  -width 10
1520
pack        .ctrl.cpu.brkpt.addr0    -side left -padx "20 0"
1521
bind        .ctrl.cpu.brkpt.addr0    <Return> "highlightCode"
1522
checkbutton .ctrl.cpu.brkpt.chk0     -variable brkpt(en_0)       -state disabled -command "updateBreakpoint 0" -text "Enable"
1523
pack        .ctrl.cpu.brkpt.chk0     -side left -padx "0"
1524
entry       .ctrl.cpu.brkpt.addr1    -textvariable brkpt(addr_1) -relief sunken -state disabled  -width 10
1525
pack        .ctrl.cpu.brkpt.addr1    -side left -padx "20 0"
1526
bind        .ctrl.cpu.brkpt.addr1    <Return> "highlightCode"
1527
checkbutton .ctrl.cpu.brkpt.chk1     -variable brkpt(en_1)       -state disabled -command "updateBreakpoint 1" -text "Enable"
1528
pack        .ctrl.cpu.brkpt.chk1     -side left -padx "0"
1529
entry       .ctrl.cpu.brkpt.addr2    -textvariable brkpt(addr_2) -relief sunken -state disabled  -width 10
1530
pack        .ctrl.cpu.brkpt.addr2    -side left -padx "20 0"
1531
bind        .ctrl.cpu.brkpt.addr2    <Return> "highlightCode"
1532
checkbutton .ctrl.cpu.brkpt.chk2     -variable brkpt(en_2)       -state disabled -command "updateBreakpoint 2" -text "Enable"
1533
pack        .ctrl.cpu.brkpt.chk2     -side left -padx "0"
1534
 
1535
 
1536 87 olivier.gi
# CPU Status register
1537 110 olivier.gi
label       .ctrl.cpu.reg_stat.l1     -text "Status register (r2/sr):" -anchor w -state disabled
1538
pack        .ctrl.cpu.reg_stat.l1     -side left
1539
checkbutton .ctrl.cpu.reg_stat.v      -variable sr(v)      -state disabled -command "statRegUpdate" -text "V"
1540
pack        .ctrl.cpu.reg_stat.v      -side left -padx "0"
1541
checkbutton .ctrl.cpu.reg_stat.scg1   -variable sr(scg1)   -state disabled -command "statRegUpdate" -text "SCG1"
1542
pack        .ctrl.cpu.reg_stat.scg1   -side left -padx "0"
1543
checkbutton .ctrl.cpu.reg_stat.oscoff -variable sr(oscoff) -state disabled -command "statRegUpdate" -text "OSCOFF"
1544
pack        .ctrl.cpu.reg_stat.oscoff -side left -padx "0"
1545
checkbutton .ctrl.cpu.reg_stat.cpuoff -variable sr(cpuoff) -state disabled -command "statRegUpdate" -text "CPUOFF"
1546
pack        .ctrl.cpu.reg_stat.cpuoff -side left -padx "0"
1547
checkbutton .ctrl.cpu.reg_stat.gie    -variable sr(gie)    -state disabled -command "statRegUpdate" -text "GIE"
1548
pack        .ctrl.cpu.reg_stat.gie    -side left -padx "0"
1549
checkbutton .ctrl.cpu.reg_stat.n      -variable sr(n)      -state disabled -command "statRegUpdate" -text "N"
1550
pack        .ctrl.cpu.reg_stat.n      -side left -padx "0"
1551
checkbutton .ctrl.cpu.reg_stat.z      -variable sr(z)      -state disabled -command "statRegUpdate" -text "Z"
1552
pack        .ctrl.cpu.reg_stat.z      -side left -padx "0"
1553
checkbutton .ctrl.cpu.reg_stat.c      -variable sr(c)      -state disabled -command "statRegUpdate" -text "C"
1554
pack        .ctrl.cpu.reg_stat.c      -side left -padx "0"
1555 2 olivier.gi
 
1556
# CPU Registers
1557 110 olivier.gi
frame  .ctrl.cpu.reg_mem.reg.title
1558
pack   .ctrl.cpu.reg_mem.reg.title           -side top
1559
label  .ctrl.cpu.reg_mem.reg.title.l         -text " " -width 8 -anchor w
1560
pack   .ctrl.cpu.reg_mem.reg.title.l         -side left
1561
label  .ctrl.cpu.reg_mem.reg.title.e         -text "Registers" -anchor w  -state disabled
1562
pack   .ctrl.cpu.reg_mem.reg.title.e         -side left
1563 2 olivier.gi
for {set i 0} {$i<16} {incr i} {
1564
    switch $i {
1565 158 olivier.gi
        {0}     {set reg_label "r0 (pc):"}
1566
        {1}     {set reg_label "r1 (sp):"}
1567
        {2}     {set reg_label "r2 (sr):"}
1568
        default {set reg_label "r$i:"}
1569 2 olivier.gi
    }
1570 110 olivier.gi
    frame  .ctrl.cpu.reg_mem.reg.f$i
1571
    pack   .ctrl.cpu.reg_mem.reg.f$i           -side top
1572
    label  .ctrl.cpu.reg_mem.reg.f$i.l$i       -text $reg_label -width 8 -anchor w  -state disabled
1573
    pack   .ctrl.cpu.reg_mem.reg.f$i.l$i       -side left
1574
    entry  .ctrl.cpu.reg_mem.reg.f$i.e$i       -textvariable reg($i) -relief sunken -state disabled
1575
    pack   .ctrl.cpu.reg_mem.reg.f$i.e$i       -side left
1576
    bind   .ctrl.cpu.reg_mem.reg.f$i.e$i       <Return> "write2Reg $i"
1577 2 olivier.gi
}
1578 110 olivier.gi
button .ctrl.cpu.reg_mem.reg.refresh           -text "Refresh Registers"  -state disabled -command {refreshReg}
1579
pack   .ctrl.cpu.reg_mem.reg.refresh           -side top -padx 5 -pady 10 -fill x -expand true
1580 2 olivier.gi
 
1581 87 olivier.gi
 
1582 2 olivier.gi
# CPU Memory
1583 110 olivier.gi
frame  .ctrl.cpu.reg_mem.mem.title
1584
pack   .ctrl.cpu.reg_mem.mem.title             -side top
1585
label  .ctrl.cpu.reg_mem.mem.title.l           -text "      Address      " -anchor w -width 20  -state disabled
1586
pack   .ctrl.cpu.reg_mem.mem.title.l           -side left -fill x -expand true
1587
label  .ctrl.cpu.reg_mem.mem.title.e           -text "        Data       " -anchor w -width 20  -state disabled
1588
pack   .ctrl.cpu.reg_mem.mem.title.e           -side left -fill x -expand true
1589 87 olivier.gi
for {set i 0} {$i<16} {incr i} {
1590 110 olivier.gi
    frame  .ctrl.cpu.reg_mem.mem.f$i
1591
    pack   .ctrl.cpu.reg_mem.mem.f$i           -side top
1592 2 olivier.gi
 
1593 110 olivier.gi
    entry  .ctrl.cpu.reg_mem.mem.f$i.addr_e$i  -textvariable mem(address_$i) -relief sunken -state disabled  -width 20
1594
    pack   .ctrl.cpu.reg_mem.mem.f$i.addr_e$i  -side left
1595
    bind   .ctrl.cpu.reg_mem.mem.f$i.addr_e$i  <Return> "refreshMem"
1596
    entry  .ctrl.cpu.reg_mem.mem.f$i.data_e$i  -textvariable mem(data_$i)    -relief sunken -state disabled  -width 20
1597
    pack   .ctrl.cpu.reg_mem.mem.f$i.data_e$i  -side left
1598
    bind   .ctrl.cpu.reg_mem.mem.f$i.data_e$i  <Return> "write2Mem $i"
1599 87 olivier.gi
}
1600 110 olivier.gi
button .ctrl.cpu.reg_mem.mem.refresh -text "Refresh Memory"     -state disabled -command {refreshMem}
1601
pack   .ctrl.cpu.reg_mem.mem.refresh -side top -padx 5 -pady 10 -fill x -expand true
1602 87 olivier.gi
 
1603
 
1604
# Load TCL script fields
1605
frame  .ctrl.tclscript.ft
1606 110 olivier.gi
pack   .ctrl.tclscript.ft        -side top -padx {10 10} -pady {10 5} -fill x
1607 87 olivier.gi
label  .ctrl.tclscript.ft.l      -text "TCL script:" -state disabled
1608
pack   .ctrl.tclscript.ft.l      -side left -padx "0 10"
1609
entry  .ctrl.tclscript.ft.file   -width 58 -relief sunken -textvariable tcl_file_name -state disabled
1610
pack   .ctrl.tclscript.ft.file   -side left -padx 10
1611 110 olivier.gi
button .ctrl.tclscript.ft.browse -text "Browse" -width 9 -state disabled -command {set tcl_file_name [tk_getOpenFile -filetypes {{{TCL Files} {.tcl}} {{All Files} *}}]}
1612
pack   .ctrl.tclscript.ft.browse -side right -padx 5
1613 87 olivier.gi
frame  .ctrl.tclscript.fb
1614
pack   .ctrl.tclscript.fb        -side top -fill x
1615
button .ctrl.tclscript.fb.read   -text "Source TCL script !" -state disabled -command {if {[file exists $tcl_file_name]} {source $tcl_file_name}}
1616 110 olivier.gi
pack   .ctrl.tclscript.fb.read   -side left -padx 15 -pady {0 10} -fill x
1617 87 olivier.gi
 
1618
 
1619
####################################
1620
#  CREATE THE CODE SECTION         #
1621
####################################
1622
 
1623
label       .code.rb.txt  -text "Code View:" -anchor w     -state disabled
1624
pack        .code.rb.txt  -side left
1625 158 olivier.gi
radiobutton .code.rb.none -value "1" -text "IHEX"          -state disabled -variable codeSelect  -command {updateCodeView}
1626 87 olivier.gi
pack        .code.rb.none -side left
1627 158 olivier.gi
radiobutton .code.rb.asm  -value "2" -text "Assembler"     -state disabled -variable codeSelect  -command {updateCodeView}
1628 87 olivier.gi
pack        .code.rb.asm  -side left
1629 158 olivier.gi
radiobutton .code.rb.mix  -value "3" -text "C & Assembler" -state disabled -variable codeSelect  -command {updateCodeView}
1630 87 olivier.gi
pack        .code.rb.mix  -side left
1631
 
1632
 
1633
scrollbar .code.xscroll -orient horizontal -command {.code.text xview}
1634
pack      .code.xscroll -side bottom -fill both
1635
 
1636
scrollbar .code.yscroll -orient vertical   -command {.code.text yview}
1637
pack      .code.yscroll -side right  -fill both
1638
 
1639
text      .code.text    -width 80 -borderwidth 2  -state disabled  -wrap none -setgrid true -font TkFixedFont \
1640
                        -xscrollcommand {.code.xscroll set} -yscrollcommand {.code.yscroll set}
1641
pack      .code.text    -side left   -fill both -expand true
1642
 
1643 110 olivier.gi
.code.text tag config highlightPC       -background $color(PC)
1644
.code.text tag config highlightBRK0_ACT -background $color(Brk0_active)
1645
.code.text tag config highlightBRK0_DIS -background $color(Brk0_disabled)
1646
.code.text tag config highlightBRK1_ACT -background $color(Brk1_active)
1647
.code.text tag config highlightBRK1_DIS -background $color(Brk1_disabled)
1648
.code.text tag config highlightBRK2_ACT -background $color(Brk2_active)
1649
.code.text tag config highlightBRK2_DIS -background $color(Brk2_disabled)
1650
 
1651
 
1652
#######################################
1653
#  PERIODICALLY CHECK THE CPU STATUS  #
1654
#######################################
1655 158 olivier.gi
selectCPU 0
1656 110 olivier.gi
 
1657
while 1 {
1658
 
1659
    # Wait 1 second
1660
    set ::refresh_flag 0
1661
    after 1000 set ::refresh_flag 1
1662
    vwait refresh_flag
1663
 
1664
    # Check CPU status
1665 158 olivier.gi
    if {$connection_status} {
1666
        if {$cpu_status} {
1667
            if {[IsHalted $CpuNr]} {
1668
                .ctrl.cpu.cpu.step  configure -state normal
1669
                .ctrl.cpu.cpu.run   configure -text "Run"
1670
                .ctrl.cpu.cpu.l3    configure -text "Stopped" -fg "\#cdad00"
1671
                set cpu_status 0
1672
                refreshReg
1673
                refreshMem
1674
            }
1675
        }
1676 110 olivier.gi
    }
1677
}

powered by: WebSVN 2.1.0

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