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

Subversion Repositories openmsp430

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

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: 110 $
33
# $LastChangedBy: olivier.girard $
34
# $LastChangedDate: 2011-05-19 22:33:51 +0200 (Thu, 19 May 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 2 olivier.gi
        putsLog "ERROR: Could not open $serial_device"
102
        return 0
103
    }
104
 
105 110 olivier.gi
    if {$omsp_info(alias)==""} {
106
        .info.cpu.con   configure -text "Connected" -fg "\#00ae00"
107
    } else {
108
        .info.cpu.con   configure -text "Connected to $omsp_info(alias)" -fg "\#00ae00"
109
    }
110
 
111 2 olivier.gi
    # Display info
112
    putsLog "INFO: Sucessfully connected with the openMSP430 target."
113
    set sizes [GetCPU_ID_SIZE]
114 110 olivier.gi
    if {$omsp_info(asic)} {
115
        putsLog "INFO: CPU Version              - $omsp_info(cpu_ver) / ASIC"
116
    } else {
117
        putsLog "INFO: CPU Version              - $omsp_info(cpu_ver) / FPGA"
118
    }
119
    putsLog "INFO: User Version             - $omsp_info(user_ver)"
120
    if {$omsp_info(cpu_ver)==1} {
121
        putsLog "INFO: Hardware Multiplier      - --"
122
    } elseif {$omsp_info(mpy)} {
123
        putsLog "INFO: Hardware Multiplier      - Yes"
124
    } else {
125
        putsLog "INFO: Hardware Multiplier      - No"
126
    }
127
    putsLog "INFO: Program Memory Size      - $omsp_info(pmem_size) B"
128
    putsLog "INFO: Data Memory Size         - $omsp_info(dmem_size) B"
129
    putsLog "INFO: Peripheral Address Space - $omsp_info(per_size) B"
130
    putsLog "INFO: $hw_break(num) Hardware Brea/Watch-point unit(s) detected"
131
    putsLog ""
132 2 olivier.gi
 
133 87 olivier.gi
    # Activate Load TCL script section
134
    .tclscript.ft.l          configure -state normal
135
    .tclscript.ft.file       configure -state normal
136
    .tclscript.ft.browse     configure -state normal
137
    .tclscript.fb.read       configure -state normal
138
 
139 110 olivier.gi
    # Activate extra cpu info button
140
    .info.cpu.more           configure -state normal
141
 
142 2 olivier.gi
    # Reset & Stop CPU
143
    ExecutePOR_Halt
144
 
145
    # Start server for GDB
146
    if {![startServer]} {
147 110 olivier.gi
        .info.server.con configure -text "Connection problem" -fg red
148 2 olivier.gi
        return 0
149
    }
150 110 olivier.gi
    .info.server.con     configure -text "Running" -fg "\#00ae00"
151 2 olivier.gi
 
152
    # Disable gui entries
153 110 olivier.gi
    .connect.config.serial_port.p1      configure -state disabled
154
    .connect.config.serial_baudrate.p2  configure -state disabled
155
    .connect.config.server_port.p       configure -state disabled
156
    .connect.start.but                  configure -state disabled
157 2 olivier.gi
}
158
 
159
###############################################################################
160
#                                                                             #
161
#                        RECEIVE / SEND RSP PACKETS                           #
162
#                                                                             #
163
###############################################################################
164
 
165
proc receiveRSPpacket {sock} {
166
 
167
    # Get client info
168
    set ip   [lindex [fconfigure $sock -peername] 0]
169
    set port [lindex [fconfigure $sock -peername] 2]
170
 
171
    # Check if a new packet arrives
172
    set rx_packet 0
173
    set rsp_cmd [getDebugChar $sock]
174
    set rsp_sum ""
175
    if {[string eq $rsp_cmd "\$"]} {
176
        set rx_packet 1
177
        set rsp_cmd ""
178
    } else {
179
        binary scan $rsp_cmd H* rsp_cmd
180
        if {$rsp_cmd=="03"} {
181
            putsVerbose "--> BREAK"
182
            HaltCPU
183
        }
184
    }
185
    # Receive packet
186
    while {$rx_packet} {
187
        set char [getDebugChar $sock]
188
        if {$char==-1} {
189
            set    rx_packet 0
190
        } elseif {[string eq $char "\#"]} {
191
            set    rx_packet 0
192
            set    rsp_sum   [getDebugChar $sock]
193
            append rsp_sum   [getDebugChar $sock]
194
 
195
            # Re-calculate the checksum
196
            set    tmp_sum   [RSPcheckSum  $rsp_cmd]
197
 
198
            # Acknowledge and analyse the packet
199
            if {[string eq $rsp_sum $tmp_sum]} {
200
                putDebugChar $sock "+"
201
 
202
                # Remove escape characters
203
                set rsp_cmd [removeEscapeChar $rsp_cmd]
204
                putsVerbose "+ w $rsp_cmd"
205
 
206
                # Parse packet and send back the answer
207
                set rsp_answer [rspParse $sock $rsp_cmd]
208
                if {$rsp_answer != "-1"} {
209
                    sendRSPpacket $sock $rsp_answer
210
                }
211
            } else {
212
                putDebugChar $sock "-"
213
            }
214
        } else {
215
            append rsp_cmd $char
216
        }
217
    }
218
}
219
 
220
 
221
proc sendRSPpacket {sock rsp_cmd} {
222
 
223
    # Set escape characters
224
    set rsp_cmd [setEscapeChar $rsp_cmd]
225
 
226
    # Calculate checksum
227
    set rsp_sum [RSPcheckSum  $rsp_cmd]
228
 
229
    # Format the packet
230
    set rsp_packet "\$$rsp_cmd\#$rsp_sum"
231
 
232
    # Send the packet until the "+" aknowledge is received
233
    set send_ok 0
234
    while {!$send_ok} {
235
        putDebugChar $sock "$rsp_packet"
236
        set char [getDebugChar $sock]
237
 
238
        putsVerbose "$char r $rsp_cmd"
239
 
240
        if {$char==-1} {
241
            set    send_ok 1
242
        } elseif {[string eq $char "+"]} {
243
            set    send_ok 1
244
        }
245
    }
246
}
247
 
248
 
249
###############################################################################
250
#                                                                             #
251
#                   CHECKSUM / ESCAPE CHAR / RX / TX FUNCTIONS                #
252
#                                                                             #
253
###############################################################################
254
 
255
proc RSPcheckSum {rsp_cmd} {
256
 
257
    set    rsp_sum   0
258
    for {set i 0} {$i<[string length $rsp_cmd]} {incr i} {
259
        scan [string index $rsp_cmd $i] "%c" char_val
260
        set rsp_sum [expr $rsp_sum+$char_val]
261
    }
262
    set rsp_sum [format %02x [expr $rsp_sum%256]]
263
 
264
    return $rsp_sum
265
}
266
 
267
proc removeEscapeChar {rsp_cmd} {
268
 
269
    # Replace all '\}0x03' characters with '#'
270
    regsub -all "\}[binary format H* 03]" $rsp_cmd "\#" rsp_cmd
271
 
272
    # Replace all '\}0x04' characters with '$'
273
    regsub -all "\}[binary format H* 04]" $rsp_cmd "\$" rsp_cmd
274
 
275
    # Replace all '\}\]' characters with '\}'
276
    regsub -all "\}\]" $rsp_cmd "\}" rsp_cmd
277
 
278
    return "$rsp_cmd"
279
}
280
 
281
proc setEscapeChar {rsp_cmd} {
282
 
283
    # Escape all '\}' characters with '\}\]'
284
    regsub -all "\}" $rsp_cmd "\}\]" rsp_cmd
285
 
286
    # Escape all '$' characters with '\}0x04'
287
    regsub -all "\\$" $rsp_cmd "\}[binary format H* 04]" rsp_cmd
288
 
289
    # Escape all '#' characters with '\}0x03'
290
    regsub -all "\#" $rsp_cmd "\}[binary format H* 03]" rsp_cmd
291
 
292
    return "$rsp_cmd"
293
}
294
 
295
 
296
proc getDebugChar {sock} {
297
    global clients
298
 
299
    # Get client info
300
    set ip   [lindex [fconfigure $sock -peername] 0]
301
    set port [lindex [fconfigure $sock -peername] 2]
302
 
303
    if {[eof $sock] || [catch {set char [read $sock 1]}]} {
304
        # end of file or abnormal connection drop
305
        close $sock
306
        putsLog "Connection closed: $ip ($port)\n"
307
        unset clients(addr,$sock)
308
        return -1
309
    } else {
310
        return $char
311
    }
312
}
313
 
314
 
315
proc putDebugChar {sock char} {
316
    puts -nonewline $sock $char
317
}
318 110 olivier.gi
 
319
###############################################################################
320
#                                                                             #
321
#                          GUI: DISPLAY EXTRA INFO                            #
322
#                                                                             #
323
###############################################################################
324
 
325
proc displayMore  { } {
326
 
327
    global omsp_info
328
 
329
    # Destroy windows if already existing
330
    if {[lsearch -exact [winfo children .] .omsp_extra_info]!=-1} {
331
        destroy .omsp_extra_info
332
    }
333
 
334
    # Create master window
335
    toplevel    .omsp_extra_info
336
    wm title    .omsp_extra_info "openMSP430 extra info"
337
    wm geometry .omsp_extra_info +380+200
338
    wm resizable .omsp_extra_info 0 0
339
 
340
    # Title
341
    set title "openMSP430"
342
    if {$omsp_info(alias)!=""} {
343
        set title $omsp_info(alias)
344
    }
345
    label  .omsp_extra_info.title  -text "$title"   -anchor center -fg "\#00ae00" -font {-weight bold -size 16}
346
    pack   .omsp_extra_info.title  -side top -padx {20 20} -pady {20 10}
347
 
348
    # Add extra info
349
    frame     .omsp_extra_info.extra
350
    pack      .omsp_extra_info.extra         -side top  -padx 10  -pady {10 10}
351
    scrollbar .omsp_extra_info.extra.yscroll -orient vertical   -command {.omsp_extra_info.extra.text yview}
352
    pack      .omsp_extra_info.extra.yscroll -side right -fill both
353
    text      .omsp_extra_info.extra.text    -wrap word -height 20 -font TkFixedFont -yscrollcommand {.omsp_extra_info.extra.yscroll set}
354
    pack      .omsp_extra_info.extra.text    -side right
355
 
356
    # Create OK button
357
    button .omsp_extra_info.okay -text "OK" -font {-weight bold}  -command {destroy .omsp_extra_info}
358
    pack   .omsp_extra_info.okay -side bottom -expand true -fill x -padx 5 -pady {0 10}
359
 
360
 
361
    # Fill the text widget will configuration info
362
    .omsp_extra_info.extra.text tag configure bold -font {-family TkFixedFont -weight bold}
363
    .omsp_extra_info.extra.text insert end         "Configuration\n\n" bold
364
    .omsp_extra_info.extra.text insert end [format "CPU Version                : %5s\n" $omsp_info(cpu_ver)]
365
    .omsp_extra_info.extra.text insert end [format "User Version               : %5s\n" $omsp_info(user_ver)]
366
    if {$omsp_info(cpu_ver)==1} {
367
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" --]
368
    } elseif {$omsp_info(asic)==0} {
369
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" FPGA]
370
    } elseif {$omsp_info(asic)==1} {
371
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" ASIC]
372
    }
373
    if {$omsp_info(mpy)==1} {
374
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" Yes]
375
    } elseif {$omsp_info(mpy)==0} {
376
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" No]
377
    } else {
378
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" --]
379
    }
380
    .omsp_extra_info.extra.text insert end [format "Program memory size        : %5s B\n" $omsp_info(pmem_size)]
381
    .omsp_extra_info.extra.text insert end [format "Data memory size           : %5s B\n" $omsp_info(dmem_size)]
382
    .omsp_extra_info.extra.text insert end [format "Peripheral address space   : %5s B\n" $omsp_info(per_size)]
383
    if {$omsp_info(alias)==""} {
384
    .omsp_extra_info.extra.text insert end [format "Alias                      : %5s\n\n\n" None]
385
    } else {
386
    .omsp_extra_info.extra.text insert end [format "Alias                      : %5s\n\n\n" $omsp_info(alias)]
387
    }
388
 
389
    .omsp_extra_info.extra.text insert end         "Extra Info\n\n" bold
390
 
391
    if {$omsp_info(alias)!=""} {
392
 
393
        set aliasEXTRA  [lsort -increasing [array names omsp_info -glob "extra,*"]]
394
        if {[llength $aliasEXTRA]} {
395
 
396
            foreach currentEXTRA $aliasEXTRA {
397
                regexp {^.+,.+,(.+)$} $currentEXTRA whole_match extraATTR
398
                .omsp_extra_info.extra.text insert end     [format "%-15s: %s\n" $extraATTR  $omsp_info($currentEXTRA)]
399
            }
400
            .omsp_extra_info.extra.text insert end         "\n\n"
401
        }
402
    } else {
403
        .omsp_extra_info.extra.text insert end  "No alias found in 'omsp_alias.xml' file"
404
    }
405
}

powered by: WebSVN 2.1.0

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