1 |
2 |
olivier.gi |
#!/usr/bin/wish
|
2 |
|
|
#------------------------------------------------------------------------------
|
3 |
|
|
# Copyright (C) 2001 Authors
|
4 |
|
|
#
|
5 |
|
|
# This source file may be used and distributed without restriction provided
|
6 |
|
|
# that this copyright statement is not removed from the file and that any
|
7 |
|
|
# derivative work contains the original copyright notice and the associated
|
8 |
|
|
# disclaimer.
|
9 |
|
|
#
|
10 |
|
|
# This source file is free software; you can redistribute it and/or modify
|
11 |
|
|
# it under the terms of the GNU Lesser General Public License as published
|
12 |
|
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
13 |
|
|
# (at your option) any later version.
|
14 |
|
|
#
|
15 |
|
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
16 |
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
17 |
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
18 |
|
|
# License for more details.
|
19 |
|
|
#
|
20 |
|
|
# You should have received a copy of the GNU Lesser General Public License
|
21 |
|
|
# along with this source; if not, write to the Free Software Foundation,
|
22 |
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
23 |
|
|
#
|
24 |
|
|
#------------------------------------------------------------------------------
|
25 |
|
|
#
|
26 |
|
|
# File Name: server.tcl
|
27 |
|
|
#
|
28 |
15 |
olivier.gi |
# Author(s):
|
29 |
|
|
# - Olivier Girard, olgirard@gmail.com
|
30 |
|
|
#
|
31 |
2 |
olivier.gi |
#------------------------------------------------------------------------------
|
32 |
15 |
olivier.gi |
# $Rev: 124 $
|
33 |
|
|
# $LastChangedBy: olivier.girard $
|
34 |
|
|
# $LastChangedDate: 2011-10-27 09:38:36 +0200 (Thu, 27 Oct 2011) $
|
35 |
|
|
#------------------------------------------------------------------------------
|
36 |
2 |
olivier.gi |
|
37 |
|
|
global clients
|
38 |
|
|
global server
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
###############################################################################
|
42 |
|
|
# #
|
43 |
|
|
# START/STOP LOCAL SERVER #
|
44 |
|
|
# #
|
45 |
|
|
###############################################################################
|
46 |
|
|
|
47 |
|
|
proc startServer { } {
|
48 |
|
|
|
49 |
|
|
global server
|
50 |
|
|
if {![info exists server(socket)]} {
|
51 |
|
|
putsLog "Open socket on port $server(port) ... " 1
|
52 |
|
|
if {[catch {socket -server clientAccept $server(port)} server(socket)]} {
|
53 |
|
|
putsLog "failed"
|
54 |
|
|
putsLog "ERROR: $server(socket)."
|
55 |
|
|
unset server(socket)
|
56 |
|
|
return 0
|
57 |
|
|
}
|
58 |
|
|
putsLog "done"
|
59 |
|
|
putsLog "INFO: Waiting on TCP port $server(port)"
|
60 |
|
|
} else {
|
61 |
|
|
putsLog "Server is already up."
|
62 |
|
|
}
|
63 |
|
|
return 1
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
proc stopServer { } {
|
67 |
|
|
global serial_status
|
68 |
|
|
global server
|
69 |
|
|
|
70 |
|
|
if {[info exists server(socket)]} {
|
71 |
|
|
set port [lindex [fconfigure $server(socket) -sockname] 2]
|
72 |
|
|
putsLog "Stop server (port $port)"
|
73 |
|
|
close $server(socket)
|
74 |
|
|
unset server(socket)
|
75 |
|
|
}
|
76 |
|
|
if {$serial_status} {
|
77 |
|
|
ReleaseDevice 0xfffe
|
78 |
|
|
}
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
proc clientAccept {sock addr port} {
|
82 |
|
|
global clients
|
83 |
|
|
|
84 |
|
|
putsLog "Accept client: $addr ($port)\n"
|
85 |
|
|
|
86 |
|
|
set clients(addr,$sock) [list $addr $port]
|
87 |
|
|
fconfigure $sock -buffering none
|
88 |
|
|
fileevent $sock readable [list receiveRSPpacket $sock]
|
89 |
|
|
|
90 |
|
|
InitBreakUnits
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
proc startServerGUI { } {
|
94 |
|
|
global serial_device
|
95 |
|
|
global hw_break
|
96 |
110 |
olivier.gi |
global omsp_info
|
97 |
2 |
olivier.gi |
|
98 |
|
|
# Connect to device
|
99 |
|
|
if {![GetDevice]} {
|
100 |
110 |
olivier.gi |
.info.cpu.con configure -text "Connection problem" -fg red
|
101 |
124 |
olivier.gi |
putsLog "ERROR: Could not open \"$serial_device\""
|
102 |
|
|
putsLog ""
|
103 |
|
|
putsLog " -------------------------------------------------------------"
|
104 |
|
|
putsLog " !!!! Please consider the following options: !!!!"
|
105 |
|
|
putsLog " !!!! !!!!"
|
106 |
|
|
putsLog " !!!! - check the physical connection to the board. !!!!"
|
107 |
|
|
putsLog " !!!! - adjust the serial connection baudrate. !!!!"
|
108 |
|
|
putsLog " !!!! - don't forget to reset the serial debug interface !!!!"
|
109 |
|
|
putsLog " !!!! between each attempt. !!!!"
|
110 |
|
|
putsLog " -------------------------------------------------------------"
|
111 |
|
|
putsLog ""
|
112 |
2 |
olivier.gi |
return 0
|
113 |
|
|
}
|
114 |
|
|
|
115 |
110 |
olivier.gi |
if {$omsp_info(alias)==""} {
|
116 |
|
|
.info.cpu.con configure -text "Connected" -fg "\#00ae00"
|
117 |
|
|
} else {
|
118 |
|
|
.info.cpu.con configure -text "Connected to $omsp_info(alias)" -fg "\#00ae00"
|
119 |
|
|
}
|
120 |
|
|
|
121 |
2 |
olivier.gi |
# Display info
|
122 |
|
|
putsLog "INFO: Sucessfully connected with the openMSP430 target."
|
123 |
|
|
set sizes [GetCPU_ID_SIZE]
|
124 |
110 |
olivier.gi |
if {$omsp_info(asic)} {
|
125 |
|
|
putsLog "INFO: CPU Version - $omsp_info(cpu_ver) / ASIC"
|
126 |
|
|
} else {
|
127 |
|
|
putsLog "INFO: CPU Version - $omsp_info(cpu_ver) / FPGA"
|
128 |
|
|
}
|
129 |
|
|
putsLog "INFO: User Version - $omsp_info(user_ver)"
|
130 |
|
|
if {$omsp_info(cpu_ver)==1} {
|
131 |
|
|
putsLog "INFO: Hardware Multiplier - --"
|
132 |
|
|
} elseif {$omsp_info(mpy)} {
|
133 |
|
|
putsLog "INFO: Hardware Multiplier - Yes"
|
134 |
|
|
} else {
|
135 |
|
|
putsLog "INFO: Hardware Multiplier - No"
|
136 |
|
|
}
|
137 |
|
|
putsLog "INFO: Program Memory Size - $omsp_info(pmem_size) B"
|
138 |
|
|
putsLog "INFO: Data Memory Size - $omsp_info(dmem_size) B"
|
139 |
|
|
putsLog "INFO: Peripheral Address Space - $omsp_info(per_size) B"
|
140 |
124 |
olivier.gi |
putsLog "INFO: $hw_break(num) Hardware Break/Watch-point unit(s) detected"
|
141 |
110 |
olivier.gi |
putsLog ""
|
142 |
2 |
olivier.gi |
|
143 |
87 |
olivier.gi |
# Activate Load TCL script section
|
144 |
|
|
.tclscript.ft.l configure -state normal
|
145 |
|
|
.tclscript.ft.file configure -state normal
|
146 |
|
|
.tclscript.ft.browse configure -state normal
|
147 |
|
|
.tclscript.fb.read configure -state normal
|
148 |
|
|
|
149 |
110 |
olivier.gi |
# Activate extra cpu info button
|
150 |
|
|
.info.cpu.more configure -state normal
|
151 |
|
|
|
152 |
2 |
olivier.gi |
# Reset & Stop CPU
|
153 |
|
|
ExecutePOR_Halt
|
154 |
|
|
|
155 |
|
|
# Start server for GDB
|
156 |
|
|
if {![startServer]} {
|
157 |
110 |
olivier.gi |
.info.server.con configure -text "Connection problem" -fg red
|
158 |
2 |
olivier.gi |
return 0
|
159 |
|
|
}
|
160 |
110 |
olivier.gi |
.info.server.con configure -text "Running" -fg "\#00ae00"
|
161 |
2 |
olivier.gi |
|
162 |
|
|
# Disable gui entries
|
163 |
110 |
olivier.gi |
.connect.config.serial_port.p1 configure -state disabled
|
164 |
|
|
.connect.config.serial_baudrate.p2 configure -state disabled
|
165 |
|
|
.connect.config.server_port.p configure -state disabled
|
166 |
|
|
.connect.start.but configure -state disabled
|
167 |
2 |
olivier.gi |
}
|
168 |
|
|
|
169 |
|
|
###############################################################################
|
170 |
|
|
# #
|
171 |
|
|
# RECEIVE / SEND RSP PACKETS #
|
172 |
|
|
# #
|
173 |
|
|
###############################################################################
|
174 |
|
|
|
175 |
|
|
proc receiveRSPpacket {sock} {
|
176 |
|
|
|
177 |
|
|
# Get client info
|
178 |
|
|
set ip [lindex [fconfigure $sock -peername] 0]
|
179 |
|
|
set port [lindex [fconfigure $sock -peername] 2]
|
180 |
|
|
|
181 |
|
|
# Check if a new packet arrives
|
182 |
|
|
set rx_packet 0
|
183 |
|
|
set rsp_cmd [getDebugChar $sock]
|
184 |
|
|
set rsp_sum ""
|
185 |
|
|
if {[string eq $rsp_cmd "\$"]} {
|
186 |
|
|
set rx_packet 1
|
187 |
|
|
set rsp_cmd ""
|
188 |
|
|
} else {
|
189 |
|
|
binary scan $rsp_cmd H* rsp_cmd
|
190 |
|
|
if {$rsp_cmd=="03"} {
|
191 |
|
|
putsVerbose "--> BREAK"
|
192 |
|
|
HaltCPU
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
# Receive packet
|
196 |
|
|
while {$rx_packet} {
|
197 |
|
|
set char [getDebugChar $sock]
|
198 |
|
|
if {$char==-1} {
|
199 |
|
|
set rx_packet 0
|
200 |
|
|
} elseif {[string eq $char "\#"]} {
|
201 |
|
|
set rx_packet 0
|
202 |
|
|
set rsp_sum [getDebugChar $sock]
|
203 |
|
|
append rsp_sum [getDebugChar $sock]
|
204 |
|
|
|
205 |
|
|
# Re-calculate the checksum
|
206 |
|
|
set tmp_sum [RSPcheckSum $rsp_cmd]
|
207 |
|
|
|
208 |
|
|
# Acknowledge and analyse the packet
|
209 |
|
|
if {[string eq $rsp_sum $tmp_sum]} {
|
210 |
|
|
putDebugChar $sock "+"
|
211 |
|
|
|
212 |
|
|
# Remove escape characters
|
213 |
|
|
set rsp_cmd [removeEscapeChar $rsp_cmd]
|
214 |
|
|
putsVerbose "+ w $rsp_cmd"
|
215 |
|
|
|
216 |
|
|
# Parse packet and send back the answer
|
217 |
|
|
set rsp_answer [rspParse $sock $rsp_cmd]
|
218 |
|
|
if {$rsp_answer != "-1"} {
|
219 |
|
|
sendRSPpacket $sock $rsp_answer
|
220 |
|
|
}
|
221 |
|
|
} else {
|
222 |
|
|
putDebugChar $sock "-"
|
223 |
|
|
}
|
224 |
|
|
} else {
|
225 |
|
|
append rsp_cmd $char
|
226 |
|
|
}
|
227 |
|
|
}
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
proc sendRSPpacket {sock rsp_cmd} {
|
232 |
|
|
|
233 |
|
|
# Set escape characters
|
234 |
|
|
set rsp_cmd [setEscapeChar $rsp_cmd]
|
235 |
|
|
|
236 |
|
|
# Calculate checksum
|
237 |
|
|
set rsp_sum [RSPcheckSum $rsp_cmd]
|
238 |
|
|
|
239 |
|
|
# Format the packet
|
240 |
|
|
set rsp_packet "\$$rsp_cmd\#$rsp_sum"
|
241 |
|
|
|
242 |
|
|
# Send the packet until the "+" aknowledge is received
|
243 |
|
|
set send_ok 0
|
244 |
|
|
while {!$send_ok} {
|
245 |
|
|
putDebugChar $sock "$rsp_packet"
|
246 |
|
|
set char [getDebugChar $sock]
|
247 |
|
|
|
248 |
|
|
putsVerbose "$char r $rsp_cmd"
|
249 |
|
|
|
250 |
|
|
if {$char==-1} {
|
251 |
|
|
set send_ok 1
|
252 |
|
|
} elseif {[string eq $char "+"]} {
|
253 |
|
|
set send_ok 1
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
}
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
###############################################################################
|
260 |
|
|
# #
|
261 |
|
|
# CHECKSUM / ESCAPE CHAR / RX / TX FUNCTIONS #
|
262 |
|
|
# #
|
263 |
|
|
###############################################################################
|
264 |
|
|
|
265 |
|
|
proc RSPcheckSum {rsp_cmd} {
|
266 |
|
|
|
267 |
|
|
set rsp_sum 0
|
268 |
|
|
for {set i 0} {$i<[string length $rsp_cmd]} {incr i} {
|
269 |
|
|
scan [string index $rsp_cmd $i] "%c" char_val
|
270 |
|
|
set rsp_sum [expr $rsp_sum+$char_val]
|
271 |
|
|
}
|
272 |
|
|
set rsp_sum [format %02x [expr $rsp_sum%256]]
|
273 |
|
|
|
274 |
|
|
return $rsp_sum
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
proc removeEscapeChar {rsp_cmd} {
|
278 |
|
|
|
279 |
|
|
# Replace all '\}0x03' characters with '#'
|
280 |
|
|
regsub -all "\}[binary format H* 03]" $rsp_cmd "\#" rsp_cmd
|
281 |
|
|
|
282 |
|
|
# Replace all '\}0x04' characters with '$'
|
283 |
|
|
regsub -all "\}[binary format H* 04]" $rsp_cmd "\$" rsp_cmd
|
284 |
|
|
|
285 |
|
|
# Replace all '\}\]' characters with '\}'
|
286 |
|
|
regsub -all "\}\]" $rsp_cmd "\}" rsp_cmd
|
287 |
|
|
|
288 |
|
|
return "$rsp_cmd"
|
289 |
|
|
}
|
290 |
|
|
|
291 |
|
|
proc setEscapeChar {rsp_cmd} {
|
292 |
|
|
|
293 |
|
|
# Escape all '\}' characters with '\}\]'
|
294 |
|
|
regsub -all "\}" $rsp_cmd "\}\]" rsp_cmd
|
295 |
|
|
|
296 |
|
|
# Escape all '$' characters with '\}0x04'
|
297 |
|
|
regsub -all "\\$" $rsp_cmd "\}[binary format H* 04]" rsp_cmd
|
298 |
|
|
|
299 |
|
|
# Escape all '#' characters with '\}0x03'
|
300 |
|
|
regsub -all "\#" $rsp_cmd "\}[binary format H* 03]" rsp_cmd
|
301 |
|
|
|
302 |
|
|
return "$rsp_cmd"
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
proc getDebugChar {sock} {
|
307 |
|
|
global clients
|
308 |
|
|
|
309 |
|
|
# Get client info
|
310 |
|
|
set ip [lindex [fconfigure $sock -peername] 0]
|
311 |
|
|
set port [lindex [fconfigure $sock -peername] 2]
|
312 |
|
|
|
313 |
|
|
if {[eof $sock] || [catch {set char [read $sock 1]}]} {
|
314 |
|
|
# end of file or abnormal connection drop
|
315 |
|
|
close $sock
|
316 |
|
|
putsLog "Connection closed: $ip ($port)\n"
|
317 |
|
|
unset clients(addr,$sock)
|
318 |
|
|
return -1
|
319 |
|
|
} else {
|
320 |
|
|
return $char
|
321 |
|
|
}
|
322 |
|
|
}
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
proc putDebugChar {sock char} {
|
326 |
|
|
puts -nonewline $sock $char
|
327 |
|
|
}
|
328 |
110 |
olivier.gi |
|
329 |
|
|
###############################################################################
|
330 |
|
|
# #
|
331 |
|
|
# GUI: DISPLAY EXTRA INFO #
|
332 |
|
|
# #
|
333 |
|
|
###############################################################################
|
334 |
|
|
|
335 |
|
|
proc displayMore { } {
|
336 |
|
|
|
337 |
|
|
global omsp_info
|
338 |
|
|
|
339 |
|
|
# Destroy windows if already existing
|
340 |
|
|
if {[lsearch -exact [winfo children .] .omsp_extra_info]!=-1} {
|
341 |
|
|
destroy .omsp_extra_info
|
342 |
|
|
}
|
343 |
|
|
|
344 |
|
|
# Create master window
|
345 |
|
|
toplevel .omsp_extra_info
|
346 |
|
|
wm title .omsp_extra_info "openMSP430 extra info"
|
347 |
|
|
wm geometry .omsp_extra_info +380+200
|
348 |
|
|
wm resizable .omsp_extra_info 0 0
|
349 |
|
|
|
350 |
|
|
# Title
|
351 |
|
|
set title "openMSP430"
|
352 |
|
|
if {$omsp_info(alias)!=""} {
|
353 |
|
|
set title $omsp_info(alias)
|
354 |
|
|
}
|
355 |
|
|
label .omsp_extra_info.title -text "$title" -anchor center -fg "\#00ae00" -font {-weight bold -size 16}
|
356 |
|
|
pack .omsp_extra_info.title -side top -padx {20 20} -pady {20 10}
|
357 |
|
|
|
358 |
|
|
# Add extra info
|
359 |
|
|
frame .omsp_extra_info.extra
|
360 |
|
|
pack .omsp_extra_info.extra -side top -padx 10 -pady {10 10}
|
361 |
|
|
scrollbar .omsp_extra_info.extra.yscroll -orient vertical -command {.omsp_extra_info.extra.text yview}
|
362 |
|
|
pack .omsp_extra_info.extra.yscroll -side right -fill both
|
363 |
|
|
text .omsp_extra_info.extra.text -wrap word -height 20 -font TkFixedFont -yscrollcommand {.omsp_extra_info.extra.yscroll set}
|
364 |
|
|
pack .omsp_extra_info.extra.text -side right
|
365 |
|
|
|
366 |
|
|
# Create OK button
|
367 |
|
|
button .omsp_extra_info.okay -text "OK" -font {-weight bold} -command {destroy .omsp_extra_info}
|
368 |
|
|
pack .omsp_extra_info.okay -side bottom -expand true -fill x -padx 5 -pady {0 10}
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
# Fill the text widget will configuration info
|
372 |
|
|
.omsp_extra_info.extra.text tag configure bold -font {-family TkFixedFont -weight bold}
|
373 |
|
|
.omsp_extra_info.extra.text insert end "Configuration\n\n" bold
|
374 |
|
|
.omsp_extra_info.extra.text insert end [format "CPU Version : %5s\n" $omsp_info(cpu_ver)]
|
375 |
|
|
.omsp_extra_info.extra.text insert end [format "User Version : %5s\n" $omsp_info(user_ver)]
|
376 |
|
|
if {$omsp_info(cpu_ver)==1} {
|
377 |
|
|
.omsp_extra_info.extra.text insert end [format "Implementation : %5s\n" --]
|
378 |
|
|
} elseif {$omsp_info(asic)==0} {
|
379 |
|
|
.omsp_extra_info.extra.text insert end [format "Implementation : %5s\n" FPGA]
|
380 |
|
|
} elseif {$omsp_info(asic)==1} {
|
381 |
|
|
.omsp_extra_info.extra.text insert end [format "Implementation : %5s\n" ASIC]
|
382 |
|
|
}
|
383 |
|
|
if {$omsp_info(mpy)==1} {
|
384 |
|
|
.omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" Yes]
|
385 |
|
|
} elseif {$omsp_info(mpy)==0} {
|
386 |
|
|
.omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" No]
|
387 |
|
|
} else {
|
388 |
|
|
.omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" --]
|
389 |
|
|
}
|
390 |
|
|
.omsp_extra_info.extra.text insert end [format "Program memory size : %5s B\n" $omsp_info(pmem_size)]
|
391 |
|
|
.omsp_extra_info.extra.text insert end [format "Data memory size : %5s B\n" $omsp_info(dmem_size)]
|
392 |
|
|
.omsp_extra_info.extra.text insert end [format "Peripheral address space : %5s B\n" $omsp_info(per_size)]
|
393 |
|
|
if {$omsp_info(alias)==""} {
|
394 |
|
|
.omsp_extra_info.extra.text insert end [format "Alias : %5s\n\n\n" None]
|
395 |
|
|
} else {
|
396 |
|
|
.omsp_extra_info.extra.text insert end [format "Alias : %5s\n\n\n" $omsp_info(alias)]
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
.omsp_extra_info.extra.text insert end "Extra Info\n\n" bold
|
400 |
|
|
|
401 |
|
|
if {$omsp_info(alias)!=""} {
|
402 |
|
|
|
403 |
|
|
set aliasEXTRA [lsort -increasing [array names omsp_info -glob "extra,*"]]
|
404 |
|
|
if {[llength $aliasEXTRA]} {
|
405 |
|
|
|
406 |
|
|
foreach currentEXTRA $aliasEXTRA {
|
407 |
|
|
regexp {^.+,.+,(.+)$} $currentEXTRA whole_match extraATTR
|
408 |
|
|
.omsp_extra_info.extra.text insert end [format "%-15s: %s\n" $extraATTR $omsp_info($currentEXTRA)]
|
409 |
|
|
}
|
410 |
|
|
.omsp_extra_info.extra.text insert end "\n\n"
|
411 |
|
|
}
|
412 |
|
|
} else {
|
413 |
|
|
.omsp_extra_info.extra.text insert end "No alias found in 'omsp_alias.xml' file"
|
414 |
|
|
}
|
415 |
|
|
}
|