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

Subversion Repositories openmsp430

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

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

powered by: WebSVN 2.1.0

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