Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1dd3892

Browse files
author
Brian Nez
committed
Improved server code
1 parent 911e095 commit 1dd3892

File tree

6 files changed

+72
-166
lines changed

6 files changed

+72
-166
lines changed

tcl/vjtag_server.tcl

Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,100 @@
11
# 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
53

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.
76

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
2311

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+
}
3026

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}
3546
}
3647

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}
4853
}
4954

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}
5760
}
58-
61+
5962
proc ConnAccept {sock addr port} {
6063
global conn
61-
# Record the client's information
62-
puts "Accept $sock from $addr port $port"
64+
puts "* Connection from $addr $port opened"
6365
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
6667
fconfigure $sock -buffering line
6768
# Set up a callback for when the client sends data
6869
fileevent $sock readable [list IncomingData $sock]
70+
# Set IR to 1 which is "write to register" mode
71+
Write_JTAG_IR 1
6972
}
7073

7174
proc IncomingData {sock} {
7275
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
7477
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
7581
close $sock
76-
puts "Close $conn(addr,$sock)"
82+
puts "* Connection with $conn(addr,$sock) closed"
7783
unset conn(addr,$sock)
7884
} else {
79-
# Let's check for it and trap it
85+
# Incoming data from the client
8086
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"
8693
}
8794
}
8895
}
8996

90-
#Start thet Server at Port 1337
91-
Start_Server 1337
97+
# Start the script!
98+
Script_Main
9299

93100
#EOF

tcl/vjtag_server_fast.tcl

Lines changed: 0 additions & 97 deletions
This file was deleted.

vhdl/config.vhd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,17 @@ package rgbmatrix is
3131
-- User configurable options
3232
constant NUM_PANELS_WIDE : integer := 2; -- Number of panels daisy-chained together side by side
3333
constant NUM_PANELS_TALL : integer := 1; -- Number of panels in the matrix top to bottom
34-
constant DEPTH_PER_PIXEL : integer := 1; -- Number of bits per subpixel (multiply by 3 to get BPP)
35-
-- Common values are: 1 => 3bpp, 4 => 12bpp, 8 => 24bpp
3634

3735
-- Special constants (change these at your own risk, stuff might break!)
3836
constant PANEL_WIDTH : integer := 32; -- width of the panel in pixels
3937
constant PANEL_HEIGHT : integer := 16; -- height of the panel in pixels
40-
4138
constant DATA_WIDTH : positive := 6; -- one bit for each subpixel (3), times the number
4239
-- of simultaneous lines (a.k.a. pixels per word) (2)
4340
constant ADDR_WIDTH : positive := positive(log2(real(NUM_PANELS_WIDE*NUM_PANELS_TALL*256)));
4441
-- total number of panels (width*height) times number
4542
-- of pixels per panel (512) divided by the number of
4643
-- simultaneous lines (2)
47-
48-
constant IMG_HEIGHT : positive := PANEL_HEIGHT*NUM_PANELS_TALL; -- TODO UNUSED
4944
constant IMG_WIDTH : positive := PANEL_WIDTH*NUM_PANELS_WIDE;
45+
constant IMG_WIDTH_LOG2 : positive := positive(log2(real(IMG_WIDTH)));
5046

5147
end rgbmatrix;

vhdl/ledctrl.vhd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ architecture bhv of ledctrl is
5757
signal state, next_state : STATE_TYPE;
5858

5959
-- State machine signals
60-
signal col_count, next_col_count : unsigned(6 downto 0); -- TODO dimensions are: (log2(IMG_WIDTH) downto 0)
60+
signal col_count, next_col_count : unsigned(IMG_WIDTH_LOG2 downto 0);
6161
signal s_led_addr, next_led_addr : std_logic_vector(2 downto 0);
6262
signal s_ram_addr, next_ram_addr : std_logic_vector(ADDR_WIDTH-1 downto 0);
6363
signal s_rgb1, next_rgb1, s_rgb2, next_rgb2 : std_logic_vector(2 downto 0);
@@ -67,7 +67,7 @@ begin
6767
-- A simple clock divider is used here because the LED matrix should be run relatively slow
6868
U_CLKDIV : entity work.clk_div
6969
generic map (
70-
clk_in_freq => 10,
70+
clk_in_freq => 25,
7171
clk_out_freq => 1
7272
)
7373
port map (
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)