Root/lm32/logic/sakc/tools/lac-tool/lac-tool

1#!/usr/bin/env ruby
2#
3# Tool to control a LogicAnalyzerComponent
4#
5# You need to install ruby 1.8 (or later) and ruby-serialport
6# There are various programs to view .vcd files -- e.g. GtkWave
7#
8
9require "serialport.so"
10require "optparse"
11
12$PORT_PATH = "/dev/ttyUSB0"
13$PORT_BAUD = 115200
14$TIMESCALE = "10ns"
15
16opts = OptionParser.new do |o|
17    o.banner = "Usage: lac-tool [options] SELECT TRIGGER TRIGGERMASK FILENAME\n"
18    o.separator ""
19    o.separator " SELECT Hexadevimal select value transferred to the LAC"
20    o.separator " TRIGGER Hexadecimal trigger value"
21    o.separator " TRIGGERMASK Haxadevimal triggermask"
22    o.separator " FILENAME .vcd file to be written"
23    o.separator ""
24
25    o.on( "-b", "--baud BAUDRATE", Integer,
26             "Serial port baudrate (default: #{$PORT_BAUD})" ) do |baud|
27        $PORT_BAUD = baud
28    end
29
30    o.on( "-s", "--serial SERIALPORT",
31             "Path to serial port (default: #{$PORT_PATH})" ) do |port|
32        $PORT_PATH = port
33    end
34
35    o.on( "-t", "--timescale TIMESCALE",
36             "Timescale announced in .vcd file (default: 10ns)" ) do |ts|
37        $TIMESCALE = ts
38    end
39
40    o.on( "-h", "--help", "Display this help message" ) do
41        puts o
42        exit 0
43    end
44
45    o.separator ""
46    o.separator "Example:"
47    o.separator " ./lac-tool 0x00 0x02 0x03 trace.vcd -- Sets SELECT to 0 and waits for probe to be ??????10"
48    o.separator ""
49end
50
51###
52# Check arguments
53begin
54    opts.parse!( ARGV )
55
56    raise "Missing arguments" if ARGV.length != 4;
57
58    select = ARGV[1].hex
59    trig = ARGV[2].hex
60    trigmask = ARGV[3].hex
61    filename = ARGV[4]
62rescue => e
63    STDERR.puts "\n#{e.message}"
64    STDERR.puts
65    STDERR.puts opts
66    exit 1
67end
68
69###
70# Open serial port
71begin
72    ser = SerialPort.new( $PORT_PATH, $PORT_BAUD, 8, 1, SerialPort::NONE )
73    ser.flow_control=SerialPort::NONE;
74rescue => e
75    STDERR.puts "\nCould not open serial port: #{e.message}"
76    exit 1
77end
78
79begin
80    f = File.open( filename, mode="w" );
81rescue => e
82    STDERR.puts "\nCould not open output file: #{e.message}"
83    exit 1
84end
85
86# Write VCD header
87f.puts "$date"
88f.puts "\t" + Time.now.to_s
89f.puts "$end"
90f.puts "$version"
91f.puts "\tLogicAnalyzerComponent (http://www.das-labor.org/)"
92f.puts "$end"
93f.puts "$timescale"
94f.puts "\t#{$TIMESCALE}"
95f.puts "$end"
96
97# Declare wires
98f.puts "$scope module lac $end"
99f.puts "$var wire 8 P probe[7:0] $end"
100f.puts "$enddefinitions $end"
101
102# RESET LM
1036.times do
104    ser.putc 0x00 # CMD_DISARM
105end
106
107# Here we go
108ser.putc 0x01 # send CMD_ARM
109ser.putc select # set select value
110ser.putc trigmask # set trigger mask
111ser.putc trig # set trigger compare value
112ser.putc 0x00 # set pre-trigger value
113
114puts "LAC armed; waiting for trigger condition..."
115
116size = ser.getc;
117size = 1 << size;
118
119printf( "TRIGGERED -- Reading 0x%x bytes...\n", size );
120
121size.times { |step|
122    byte = ser.getc
123    f.puts "\##{step}"
124    f.printf "b%08b P\n", byte
125}
126
127ser.close
128f.close
129

Archive Download this file

Branches:
master



interactive