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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [tools/] [openmsp430-gdbproxy/] [server.tcl] - Blame information for rev 158

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

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

powered by: WebSVN 2.1.0

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