#!/usr/bin/tclsh
|
#!/usr/bin/tclsh
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
# Copyright (C) 2001 Authors
|
# Copyright (C) 2001 Authors
|
#
|
#
|
# This source file may be used and distributed without restriction provided
|
# This source file may be used and distributed without restriction provided
|
# that this copyright statement is not removed from the file and that any
|
# that this copyright statement is not removed from the file and that any
|
# derivative work contains the original copyright notice and the associated
|
# derivative work contains the original copyright notice and the associated
|
# disclaimer.
|
# disclaimer.
|
#
|
#
|
# This source file is free software; you can redistribute it and/or modify
|
# This source file is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU Lesser General Public License as published
|
# it under the terms of the GNU Lesser General Public License as published
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
# (at your option) any later version.
|
# (at your option) any later version.
|
#
|
#
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# License for more details.
|
# License for more details.
|
#
|
#
|
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
# along with this source; if not, write to the Free Software Foundation,
|
# along with this source; if not, write to the Free Software Foundation,
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
#
|
#
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
#
|
#
|
# File Name: openmsp430-gdbproxy.tcl
|
# File Name: openmsp430-gdbproxy.tcl
|
#
|
#
|
# Author(s):
|
# Author(s):
|
# - Olivier Girard, olgirard@gmail.com
|
# - Olivier Girard, olgirard@gmail.com
|
#
|
#
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
# $Rev: 35 $
|
# $Rev: 87 $
|
# $LastChangedBy: olivier.girard $
|
# $LastChangedBy: olivier.girard $
|
# $LastChangedDate: 2009-12-29 21:12:19 +0100 (Tue, 29 Dec 2009) $
|
# $LastChangedDate: 2011-02-05 14:40:22 +0100 (Sat, 05 Feb 2011) $
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
|
|
global serial_baudrate
|
global serial_baudrate
|
global serial_device
|
global serial_device
|
global serial_status
|
global serial_status
|
global hw_break
|
global hw_break
|
global clients
|
global clients
|
global server
|
global server
|
global verbose
|
global verbose
|
global shell
|
global shell
|
|
|
# Initializations
|
# Initializations
|
set serial_status 0
|
set serial_status 0
|
|
|
|
|
###############################################################################
|
###############################################################################
|
# #
|
# #
|
# SOURCE LIBRARIES #
|
# SOURCE LIBRARIES #
|
# #
|
# #
|
###############################################################################
|
###############################################################################
|
|
|
# Get library path
|
# Get library path
|
set current_file [info script]
|
set current_file [info script]
|
if {[file type $current_file]=="link"} {
|
if {[file type $current_file]=="link"} {
|
set current_file [file readlink $current_file]
|
set current_file [file readlink $current_file]
|
}
|
}
|
set lib_path [file dirname $current_file]/../lib/tcl-lib
|
set lib_path [file dirname $current_file]/../lib/tcl-lib
|
|
|
# Source library
|
# Source library
|
source $lib_path/dbg_functions.tcl
|
source $lib_path/dbg_functions.tcl
|
|
|
# Source remaining files
|
# Source remaining files
|
source [file dirname $current_file]/../openmsp430-gdbproxy/server.tcl
|
source [file dirname $current_file]/../openmsp430-gdbproxy/server.tcl
|
source [file dirname $current_file]/../openmsp430-gdbproxy/commands.tcl
|
source [file dirname $current_file]/../openmsp430-gdbproxy/commands.tcl
|
|
|
|
|
###############################################################################
|
###############################################################################
|
# #
|
# #
|
# PARAMETER CHECK #
|
# PARAMETER CHECK #
|
# #
|
# #
|
###############################################################################
|
###############################################################################
|
|
|
proc help {} {
|
proc help {} {
|
puts ""
|
puts ""
|
puts "USAGE : openmsp430-gdbproxy.tcl \[-device <communication device>\]"
|
puts "USAGE : openmsp430-gdbproxy.tcl \[-device <communication device>\]"
|
puts " \[-baudrate <communication speed>\]"
|
puts " \[-baudrate <communication speed>\]"
|
puts " \[-port <server port>\]"
|
puts " \[-port <server port>\]"
|
puts " \[-shell]"
|
puts " \[-shell]"
|
puts " \[-verbose\]"
|
puts " \[-verbose\]"
|
puts " \[-help\]"
|
puts " \[-help\]"
|
puts ""
|
puts ""
|
puts "Examples: openmsp430-gdbproxy.tcl -device /dev/ttyUSB0 -baudrate 9600 -port 2000"
|
puts "Examples: openmsp430-gdbproxy.tcl -device /dev/ttyUSB0 -baudrate 9600 -port 2000"
|
puts " openmsp430-gdbproxy.tcl -device COM2: -baudrate 38400 -port 2000"
|
puts " openmsp430-gdbproxy.tcl -device COM2: -baudrate 38400 -port 2000"
|
puts ""
|
puts ""
|
}
|
}
|
|
|
# Default values
|
# Default values
|
set serial_device [lindex [dbg_list_uart] end]
|
set serial_device [lindex [dbg_list_uart] end]
|
set serial_baudrate 115200
|
set serial_baudrate 115200
|
set server(port) 2000
|
set server(port) 2000
|
set shell 0
|
set shell 0
|
set verbose 0
|
set verbose 0
|
|
|
# Parse arguments
|
# Parse arguments
|
for {set i 0} {$i < $argc} {incr i} {
|
for {set i 0} {$i < $argc} {incr i} {
|
switch -exact -- [lindex $argv $i] {
|
switch -exact -- [lindex $argv $i] {
|
-device {set serial_device [lindex $argv [expr $i+1]]; incr i}
|
-device {set serial_device [lindex $argv [expr $i+1]]; incr i}
|
-baudrate {set serial_baudrate [lindex $argv [expr $i+1]]; incr i}
|
-baudrate {set serial_baudrate [lindex $argv [expr $i+1]]; incr i}
|
-port {set server(port) [lindex $argv [expr $i+1]]; incr i}
|
-port {set server(port) [lindex $argv [expr $i+1]]; incr i}
|
-shell {set shell 1}
|
-shell {set shell 1}
|
-verbose {set verbose 1}
|
-verbose {set verbose 1}
|
-h {help; exit 0}
|
-h {help; exit 0}
|
-help {help; exit 0}
|
-help {help; exit 0}
|
default {}
|
default {}
|
}
|
}
|
}
|
}
|
|
|
# Source additional library for graphical interface
|
# Source additional library for graphical interface
|
if {!$shell} {
|
if {!$shell} {
|
source $lib_path/combobox.tcl
|
source $lib_path/combobox.tcl
|
package require combobox 2.3
|
package require combobox 2.3
|
catch {namespace import combobox::*}
|
catch {namespace import combobox::*}
|
}
|
}
|
|
|
# Small functions to display messages
|
# Small functions to display messages
|
proc putsLog {string {nonewline 0}} {
|
proc putsLog {string {nonewline 0}} {
|
global server
|
global server
|
global shell
|
global shell
|
if {$shell} {
|
if {$shell} {
|
if {$nonewline} {
|
if {$nonewline} {
|
puts -nonewline $string
|
puts -nonewline $string
|
} else {
|
} else {
|
puts $string
|
puts $string
|
}
|
}
|
} else {
|
} else {
|
if {$nonewline} {
|
if {$nonewline} {
|
$server(log) insert end "$string"
|
$server(log) insert end "$string"
|
} else {
|
} else {
|
$server(log) insert end "$string\n"
|
$server(log) insert end "$string\n"
|
}
|
}
|
$server(log) see end
|
$server(log) see end
|
}
|
}
|
}
|
}
|
proc putsVerbose {string} {
|
proc putsVerbose {string} {
|
global verbose
|
global verbose
|
if {$verbose} {
|
if {$verbose} {
|
putsLog "$string"
|
putsLog "$string"
|
}
|
}
|
}
|
}
|
|
|
###############################################################################
|
###############################################################################
|
# SHELL MODE #
|
# SHELL MODE #
|
###############################################################################
|
###############################################################################
|
if {$shell} {
|
if {$shell} {
|
|
|
# Connect to device
|
# Connect to device
|
if {![GetDevice]} {
|
if {![GetDevice]} {
|
puts "ERROR: Could not open $serial_device"
|
puts "ERROR: Could not open $serial_device"
|
puts "INFO: Available serial ports are:"
|
puts "INFO: Available serial ports are:"
|
foreach port [dbg_list_uart] {
|
foreach port [dbg_list_uart] {
|
puts "INFO: - $port"
|
puts "INFO: - $port"
|
}
|
}
|
exit 1
|
exit 1
|
}
|
}
|
|
|
# Display info
|
# Display info
|
puts "INFO: Sucessfully connected with the openMSP430 target."
|
puts "INFO: Sucessfully connected with the openMSP430 target."
|
set sizes [GetCPU_ID_SIZE]
|
set sizes [GetCPU_ID_SIZE]
|
puts "INFO: Program Memory Size - [lindex $sizes 0] B"
|
puts "INFO: Program Memory Size - [lindex $sizes 0] B"
|
puts "INFO: Data Memory Size - [lindex $sizes 1] B"
|
puts "INFO: Data Memory Size - [lindex $sizes 1] B"
|
puts "INFO: $hw_break(num) Hardware Brea/Watch-point unit(s) detected"
|
puts "INFO: $hw_break(num) Hardware Brea/Watch-point unit(s) detected"
|
puts ""
|
puts ""
|
|
|
# Reset & Stop CPU
|
# Reset & Stop CPU
|
ExecutePOR_Halt
|
ExecutePOR_Halt
|
|
|
# Start server for GDB
|
# Start server for GDB
|
if {![startServer]} {
|
if {![startServer]} {
|
exit 1
|
exit 1
|
}
|
}
|
|
|
vwait forever
|
vwait forever
|
}
|
}
|
|
|
|
|
###############################################################################
|
###############################################################################
|
# GUI MODE #
|
# GUI MODE #
|
###############################################################################
|
###############################################################################
|
|
|
####################################
|
####################################
|
# CREATE & PLACE MAIN WIDGETS #
|
# CREATE & PLACE MAIN WIDGETS #
|
####################################
|
####################################
|
|
|
wm title . "openMSP430 GDB Proxy"
|
wm title . "openMSP430 GDB Proxy"
|
wm iconname . "openMSP430 GDB Proxy"
|
wm iconname . "openMSP430 GDB Proxy"
|
|
|
# Create the Main Menu budget
|
# Create the Main Menu budget
|
frame .menu
|
frame .menu
|
pack .menu -side top -padx 10 -pady 10 -fill x
|
pack .menu -side top -padx 10 -pady 10 -fill x
|
|
|
# Create the Serial port Menu budget
|
# Create the Serial port Menu budget
|
frame .serial
|
frame .serial
|
pack .serial -side top -padx 10 -pady 10 -fill x
|
pack .serial -side top -padx 10 -pady 10 -fill x
|
|
|
# Create the Server Menu budget
|
# Create the Server Menu budget
|
frame .server
|
frame .server
|
pack .server -side top -padx 10 -pady 10 -fill x
|
pack .server -side top -padx 10 -pady 10 -fill x
|
|
|
|
# Create the TCL script field
|
|
frame .tclscript
|
|
pack .tclscript -side top -padx 10 -pady 10 -fill x
|
|
|
|
|
####################################
|
####################################
|
# CREATE THE REST #
|
# CREATE THE REST #
|
####################################
|
####################################
|
|
|
# Exit button
|
# Exit button
|
button .menu.exit -text "Exit" -command {stopServer; exit 0}
|
button .menu.exit -text "Exit" -command {stopServer; exit 0}
|
pack .menu.exit -side left
|
pack .menu.exit -side left
|
|
|
|
|
# Serial Port fields
|
# Serial Port fields
|
label .serial.l1 -text "Serial Port:" -anchor w
|
label .serial.l1 -text "Serial Port:" -anchor w
|
pack .serial.l1 -side left
|
pack .serial.l1 -side left
|
set serial_device [lindex [dbg_list_uart] end]
|
set serial_device [lindex [dbg_list_uart] end]
|
combobox .serial.p1 -textvariable serial_device -editable true
|
combobox .serial.p1 -textvariable serial_device -editable true
|
eval .serial.p1 list insert end [dbg_list_uart]
|
eval .serial.p1 list insert end [dbg_list_uart]
|
pack .serial.p1 -side left -padx 5
|
pack .serial.p1 -side left -padx 5
|
label .serial.l2 -text " Baudrate:" -anchor w
|
label .serial.l2 -text " Baudrate:" -anchor w
|
pack .serial.l2 -side left
|
pack .serial.l2 -side left
|
set serial_baudrate 115200
|
set serial_baudrate 115200
|
combobox .serial.p2 -textvariable serial_baudrate -editable true
|
combobox .serial.p2 -textvariable serial_baudrate -editable true
|
eval .serial.p2 list insert end [list 9600 19200 38400 57600 115200 \
|
eval .serial.p2 list insert end [list 9600 19200 38400 57600 115200 \
|
230400 460800 500000 576000 921600 \
|
230400 460800 500000 576000 921600 \
|
1000000 1152000]
|
1000000 1152000]
|
pack .serial.p2 -side left -padx 5
|
pack .serial.p2 -side left -padx 5
|
label .serial.l3 -text "Disconnected" -anchor w -fg Red
|
label .serial.l3 -text "Disconnected" -anchor w -fg Red
|
pack .serial.l3 -side left -padx 10
|
pack .serial.l3 -side left -padx 10
|
|
|
|
|
# Server Port field
|
# Server Port field
|
frame .server.port
|
frame .server.port
|
pack .server.port -side top -fill x
|
pack .server.port -side top -fill x
|
label .server.port.l1 -text "Proxy Server Port:" -anchor w
|
label .server.port.l1 -text "Proxy Server Port:" -anchor w
|
pack .server.port.l1 -side left
|
pack .server.port.l1 -side left
|
entry .server.port.p -textvariable server(port) -relief sunken
|
entry .server.port.p -textvariable server(port) -relief sunken
|
pack .server.port.p -side left -padx 5
|
pack .server.port.p -side left -padx 5
|
label .server.port.l2 -text "Not running" -anchor w -fg Red
|
label .server.port.l2 -text "Not running" -anchor w -fg Red
|
pack .server.port.l2 -side left -padx 10
|
pack .server.port.l2 -side left -padx 10
|
button .server.port.start -text "Start Proxy Server" -command {startServerGUI}
|
button .server.port.start -text "Start Proxy Server" -command {startServerGUI}
|
pack .server.port.start -side right
|
pack .server.port.start -side right
|
|
|
|
|
# Create the text widget to log received messages
|
# Create the text widget to log received messages
|
frame .server.t
|
frame .server.t
|
pack .server.t -side top -padx 10 -pady 10 -fill x
|
pack .server.t -side top -padx 10 -pady 10 -fill x
|
set server(log) [text .server.t.log -width 80 -height 10 -borderwidth 2 \
|
set server(log) [text .server.t.log -width 80 -height 10 -borderwidth 2 \
|
-setgrid true -yscrollcommand {.server.t.scroll set}]
|
-setgrid true -yscrollcommand {.server.t.scroll set}]
|
pack .server.t.log -side left -fill both -expand true
|
pack .server.t.log -side left -fill both -expand true
|
scrollbar .server.t.scroll -command {.server.t.log yview}
|
scrollbar .server.t.scroll -command {.server.t.log yview}
|
pack .server.t.scroll -side right -fill both -expand true
|
pack .server.t.scroll -side right -fill both
|
|
|
|
|
# Log commands
|
# Log commands
|
frame .server.cmd
|
frame .server.cmd
|
pack .server.cmd -side top -fill x
|
pack .server.cmd -side top -fill x
|
button .server.cmd.clear -text "Clear log" -command {$server(log) delete 1.0 end}
|
button .server.cmd.clear -text "Clear log" -command {$server(log) delete 1.0 end}
|
pack .server.cmd.clear -side left -padx 10
|
pack .server.cmd.clear -side left -padx 10
|
checkbutton .server.cmd.verbose -text "Verbose" -variable verbose
|
checkbutton .server.cmd.verbose -text "Verbose" -variable verbose
|
pack .server.cmd.verbose -side right -padx 10
|
pack .server.cmd.verbose -side right -padx 10
|
|
|
No newline at end of file
|
No newline at end of file
|
|
|
|
# Load TCL script fields
|
|
frame .tclscript.ft
|
|
pack .tclscript.ft -side top -fill x
|
|
label .tclscript.ft.l -text "TCL script:" -state disabled
|
|
pack .tclscript.ft.l -side left -padx "0 10"
|
|
entry .tclscript.ft.file -width 58 -relief sunken -textvariable tcl_file_name -state disabled
|
|
pack .tclscript.ft.file -side left -padx 10
|
|
button .tclscript.ft.browse -text "Browse" -state disabled -command {set tcl_file_name [tk_getOpenFile -filetypes {{{TCL Files} {.tcl}} {{All Files} *}}]}
|
|
pack .tclscript.ft.browse -side left -padx 5
|
|
frame .tclscript.fb
|
|
pack .tclscript.fb -side top -fill x
|
|
button .tclscript.fb.read -text "Source TCL script !" -state disabled -command {if {[file exists $tcl_file_name]} {source $tcl_file_name}}
|
|
pack .tclscript.fb.read -side left -padx 5 -fill x
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|