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

Subversion Repositories openmsp430

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

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

powered by: WebSVN 2.1.0

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