1
1
# Basic TCP server gateway for the (virtual) JTAG Interface
2
- # WORK IN PROGRESS!
3
- # TCL script derived from the example posted on
4
- # http://idle-logic.com/2012/04/15/talking-to-the-de0-nano-using-the-virtual-jtag-interface/
2
+ # Part of the Adafruit RGB LED Matrix Display Driver project
5
3
6
- # This portion of the script is derived from some of the examples from Altera
4
+ # You can run this script through the Quartus II SignalTap II Tcl interpreter
5
+ # (quartus_stp.exe) by invoking it with the -t parameter.
7
6
8
- global usbblaster_name
9
- global test_device
10
- foreach hardware_name [get_hardware_names] {
11
- if { [string match " USB-Blaster*" $hardware_name ] } {
12
- set usbblaster_name $hardware_name
13
- }
14
- }
15
- puts " Select JTAG chain connected to $usbblaster_name ." ;
16
- # List all devices on the chain, and select the first device on the chain.
17
- foreach device_name [get_device_names -hardware_name $usbblaster_name ] {
18
- if { [string match " @1*" $device_name ] } {
19
- set test_device $device_name
20
- }
21
- }
22
- puts " Selected device: $test_device " ;
7
+ # This TCL script is derived from the example posted online at
8
+ # http://idle-logic.com/2012/04/15/talking-to-the-de0-nano-using-the-virtual-jtag-interface/
9
+ # TCP/IP server code dervied from Tcl Developer Exchange - http://www.tcl.tk/about/netserver.html
10
+ # The JTAG portion of the script is derived from some of the examples from Altera
23
11
24
- # Open device
25
- proc openport {} {
26
- global usbblaster_name
27
- global test_device
28
- open_device -hardware_name $usbblaster_name -device_name $test_device
29
- }
12
+ proc Script_Main {} {
13
+ # Print welcome banner
14
+ puts " ------------------------------------------------"
15
+ puts " "
16
+ puts " <<-=*\[ JTAG server for RGB LED Matrix \] *-=>> "
17
+ puts " "
18
+
19
+ # Find the USB-Blaster device attached to the system
20
+ puts " * Locating USB-Blaster device..."
21
+ foreach hardware_name [get_hardware_names] {
22
+ if { [string match " USB-Blaster*" $hardware_name ] } {
23
+ set usbblaster_name $hardware_name
24
+ }
25
+ }
30
26
31
- # Close device. Just used if communication error occurs
32
- proc closeport { } {
33
- catch {device_unlock}
34
- catch {close_device}
27
+ # List all devices on the chain, and select the first device on the chain.
28
+ puts " * Finding devices attached to $usbblaster_name ..."
29
+ foreach device_name [get_device_names -hardware_name $usbblaster_name ] {
30
+ if { [string match " @1*" $device_name ] } {
31
+ set jtag_device $device_name
32
+ }
33
+ }
34
+
35
+ # Open the selected JTAG device
36
+ puts " * Opening $jtag_device "
37
+ open_device -hardware_name $usbblaster_name -device_name $jtag_device
38
+
39
+ # Start the TCP/IP listener
40
+ puts " * Starting server on port 1337..."
41
+ set s [socket -server ConnAccept 1337]
42
+
43
+ # Wait for connections...
44
+ vwait forever
45
+ # catch {close_device}
35
46
}
36
47
37
- proc Write_JTAG {send_data} {
38
- openport
39
- device_lock -timeout 1000
40
- # Shift through DR. Note that -dr_value is unimportant since we're not actually capturing the value inside the part, just seeing what shifts out
41
- puts " Writing -> $send_data "
42
- # set IR to 1 which is write to reg mode
43
- device_virtual_ir_shift -instance_index 0 -ir_value 1 -no_captured_ir_value
44
- device_virtual_dr_shift -dr_value $send_data -instance_index 0 -length 6 -no_captured_dr_value
45
- # Set IR back to 0, which is bypass mode
46
- device_virtual_ir_shift -instance_index 0 -ir_value 0 -no_captured_ir_value
47
- closeport
48
+ proc Write_JTAG_DR {send_data} {
49
+ # puts "DEBUG: Write_JTAG_DR $send_data"
50
+ device_lock -timeout 10000
51
+ device_virtual_dr_shift -dr_value $send_data -instance_index 0 -length 6 -value_in_hex -no_captured_dr_value
52
+ catch {device_unlock}
48
53
}
49
54
50
- # TCP/IP Server
51
- # Code Dervied from Tcl Developer Exchange - http://www.tcl.tk/about/netserver.html
52
-
53
- proc Start_Server {port} {
54
- set s [socket -server ConnAccept $port ]
55
- puts " Started socket server on port $port "
56
- vwait forever
55
+ proc Write_JTAG_IR {send_data} {
56
+ puts " DEBUG: Write_JTAG_IR $send_data "
57
+ device_lock -timeout 10000
58
+ device_virtual_ir_shift -instance_index 0 -ir_value $send_data -no_captured_ir_value
59
+ catch {device_unlock}
57
60
}
58
-
61
+
59
62
proc ConnAccept {sock addr port} {
60
63
global conn
61
- # Record the client's information
62
- puts " Accept $sock from $addr port $port "
64
+ puts " * Connection from $addr $port opened"
63
65
set conn(addr,$sock ) [list $addr $port ]
64
- # Ensure that each "puts" by the server
65
- # results in a network transmission
66
+ # Ensure that each "puts" by the server results in a network transmission
66
67
fconfigure $sock -buffering line
67
68
# Set up a callback for when the client sends data
68
69
fileevent $sock readable [list IncomingData $sock ]
70
+ # Set IR to 1 which is "write to register" mode
71
+ Write_JTAG_IR 1
69
72
}
70
73
71
74
proc IncomingData {sock} {
72
75
global conn
73
- # Check end of file or abnormal connection drop, then write the data to the vJTAG
76
+ # Check for EOF or abnormal connection drop
74
77
if {[eof $sock ] || [catch {gets $sock line}]} {
78
+ # Set IR back to 0, which is "bypass" mode
79
+ Write_JTAG_IR 0
80
+ # Clean up the socket
75
81
close $sock
76
- puts " Close $conn(addr,$sock) "
82
+ puts " * Connection with $conn(addr,$sock) closed "
77
83
unset conn(addr,$sock )
78
84
} else {
79
- # Let's check for it and trap it
85
+ # Incoming data from the client
80
86
set data_len [string length $line ]
81
- if {$data_len >= 6} then {
82
- # Extract the first 6 bits
83
- set line [string range $line 0 5]
84
- # Send the vJTAG Commands to update the register
85
- Write_JTAG $line
87
+ # Check length
88
+ if {$data_len == 2} then {
89
+ # Write to the data register
90
+ Write_JTAG_DR $line
91
+ } else {
92
+ puts " DEBUG: Ignored incoming data of length $data_len "
86
93
}
87
94
}
88
95
}
89
96
90
- # Start thet Server at Port 1337
91
- Start_Server 1337
97
+ # Start the script!
98
+ Script_Main
92
99
93
100
# EOF
0 commit comments