Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 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 | |
| 9 | require "serialport.so" |
| 10 | require "optparse" |
| 11 | |
| 12 | $PORT_PATH = "/dev/ttyUSB0" |
| 13 | $PORT_BAUD = 115200 |
| 14 | $TIMESCALE = "10ns" |
| 15 | |
| 16 | opts = 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 "" |
| 49 | end |
| 50 | |
| 51 | ### |
| 52 | # Check arguments |
| 53 | begin |
| 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] |
| 62 | rescue => e |
| 63 | STDERR.puts "\n#{e.message}" |
| 64 | STDERR.puts |
| 65 | STDERR.puts opts |
| 66 | exit 1 |
| 67 | end |
| 68 | |
| 69 | ### |
| 70 | # Open serial port |
| 71 | begin |
| 72 | ser = SerialPort.new( $PORT_PATH, $PORT_BAUD, 8, 1, SerialPort::NONE ) |
| 73 | ser.flow_control=SerialPort::NONE; |
| 74 | rescue => e |
| 75 | STDERR.puts "\nCould not open serial port: #{e.message}" |
| 76 | exit 1 |
| 77 | end |
| 78 | |
| 79 | begin |
| 80 | f = File.open( filename, mode="w" ); |
| 81 | rescue => e |
| 82 | STDERR.puts "\nCould not open output file: #{e.message}" |
| 83 | exit 1 |
| 84 | end |
| 85 | |
| 86 | # Write VCD header |
| 87 | f.puts "$date" |
| 88 | f.puts "\t" + Time.now.to_s |
| 89 | f.puts "$end" |
| 90 | f.puts "$version" |
| 91 | f.puts "\tLogicAnalyzerComponent (http://www.das-labor.org/)" |
| 92 | f.puts "$end" |
| 93 | f.puts "$timescale" |
| 94 | f.puts "\t#{$TIMESCALE}" |
| 95 | f.puts "$end" |
| 96 | |
| 97 | # Declare wires |
| 98 | f.puts "$scope module lac $end" |
| 99 | f.puts "$var wire 8 P probe[7:0] $end" |
| 100 | f.puts "$enddefinitions $end" |
| 101 | |
| 102 | # RESET LM |
| 103 | 6.times do |
| 104 | ser.putc 0x00 # CMD_DISARM |
| 105 | end |
| 106 | |
| 107 | # Here we go |
| 108 | ser.putc 0x01 # send CMD_ARM |
| 109 | ser.putc select # set select value |
| 110 | ser.putc trigmask # set trigger mask |
| 111 | ser.putc trig # set trigger compare value |
| 112 | ser.putc 0x00 # set pre-trigger value |
| 113 | |
| 114 | puts "LAC armed; waiting for trigger condition..." |
| 115 | |
| 116 | size = ser.getc; |
| 117 | size = 1 << size; |
| 118 | |
| 119 | printf( "TRIGGERED -- Reading 0x%x bytes...\n", size ); |
| 120 | |
| 121 | size.times { |step| |
| 122 | byte = ser.getc |
| 123 | f.puts "\##{step}" |
| 124 | f.printf "b%08b P\n", byte |
| 125 | } |
| 126 | |
| 127 | ser.close |
| 128 | f.close |
| 129 |
Branches:
master
