libfst 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +11 -0
- data/LICENSE +674 -0
- data/README.md +133 -0
- data/ext/extconf.rb +5 -0
- data/ext/fastlz.c +549 -0
- data/ext/fastlz.h +109 -0
- data/ext/fst_config.h +11 -0
- data/ext/fst_win_unistd.h +52 -0
- data/ext/fstapi.c +7204 -0
- data/ext/fstapi.h +466 -0
- data/ext/libfst_rb.c +2525 -0
- data/ext/lz4.c +2789 -0
- data/ext/lz4.h +868 -0
- data/lib/libfst/reader.rb +345 -0
- data/lib/libfst/tfp.rb +112 -0
- data/lib/libfst/vcd.rb +597 -0
- data/lib/libfst/version.rb +4 -0
- data/lib/libfst/writer.rb +50 -0
- data/lib/libfst.rb +6 -0
- data/libfst.gemspec +50 -0
- data/samples/create_file.rb +69 -0
- data/samples/gtkwave.png +0 -0
- data/samples/out.gtkw +46 -0
- data/samples/read2.rb +8 -0
- data/samples/read_file.rb +8 -0
- data/samples/skinny_rand.fst +0 -0
- data/samples/transaction_filter_process/full_boot.fst +0 -0
- data/samples/transaction_filter_process/full_boot.gtkw +39 -0
- data/samples/transaction_filter_process/sdcard.rb +793 -0
- data/samples/transaction_filter_process/uart.rb +141 -0
- data/samples/vcd/skinny_rand.vcd.xz +0 -0
- data/samples/vcd/vcd_read.rb +34 -0
- metadata +72 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (C) 2024 Théotime Bollengier <theotime.bollengier@ensta-bretagne.fr>
|
4
|
+
#
|
5
|
+
# This file is part of libfst.rb <https://gitlab.ensta-bretagne.fr/bollenth/libfst.rb>
|
6
|
+
#
|
7
|
+
# libfst.rb is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License,
|
10
|
+
# or (at your option) any later version.
|
11
|
+
#
|
12
|
+
# libfst.rb is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
+
# See the GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with libfst.rb. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require_relative '../../lib/libfst'
|
21
|
+
require 'colorize'
|
22
|
+
|
23
|
+
|
24
|
+
class UARTDecoder < GTKWave::TransactionFilter
|
25
|
+
def initialize
|
26
|
+
super
|
27
|
+
puts ' UART Decoder '.center(80, '-')
|
28
|
+
puts "name #{@name.inspect}"
|
29
|
+
puts "data_start_tocken #{@data_start_tocken.inspect}"
|
30
|
+
puts "min_time #{@min_time.inspect}"
|
31
|
+
puts "max_time #{@max_time.inspect}"
|
32
|
+
puts "max_seqn #{@max_seqn.inspect}"
|
33
|
+
puts "args #{@args.inspect}"
|
34
|
+
puts "signames #{@signames.inspect}"
|
35
|
+
puts "#{@signames.length} signal#{@signames.length > 1 ? 's' : ''}: #{[@signames[0...-1].join(', '), @signames.last].reject(&:empty?).join(' and ')}"
|
36
|
+
raise "expecting a signle signal, not #{@ivcd.traces.length} signals" if @ivcd.traces.length != 1
|
37
|
+
raise "the signal is expected to be a single bit, not #{@ivcd.traces.values.first.width} bits wide" unless @ivcd.traces.values.first.width == 1
|
38
|
+
|
39
|
+
@args.each do |str|
|
40
|
+
m = str.match(/^\s*baudrate\s*=\s*(\d+)\s*$/)
|
41
|
+
if m then
|
42
|
+
@baudrate = m[1].to_i
|
43
|
+
break
|
44
|
+
end
|
45
|
+
end
|
46
|
+
raise 'Please provide baudrate as argument (ex: "baudrate = 115200")' unless @baudrate
|
47
|
+
@bit_period = (1.0 / (@baudrate * @ivcd.timescale)).round
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def puts(str)
|
52
|
+
$stderr.puts str
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def read
|
57
|
+
state = :wait_start_bit
|
58
|
+
l = nil # last value
|
59
|
+
word = nil # shift register
|
60
|
+
start_bit_date = nil # date of the start bit
|
61
|
+
nb_valid_bits = nil
|
62
|
+
|
63
|
+
$stdout.write "$name #{@name}\n#0\n"
|
64
|
+
|
65
|
+
@ivcd.read do |_,v,t|
|
66
|
+
v = case v
|
67
|
+
when '0' then 0
|
68
|
+
when '1' then 1
|
69
|
+
end
|
70
|
+
case state
|
71
|
+
when :wait_start_bit
|
72
|
+
if v == 0 and l == 1 then
|
73
|
+
if start_bit_date && ((t - start_bit_date).to_f / @bit_period).round > 11
|
74
|
+
$stdout.write "##{start_bit_date + (10.0 / (@baudrate * @ivcd.timescale)).round}\n"
|
75
|
+
end
|
76
|
+
start_bit_date = t
|
77
|
+
word = 0
|
78
|
+
nb_valid_bits = 0
|
79
|
+
state = :recv_bits
|
80
|
+
#puts "start @ #{@ivcd.pretty_time}"
|
81
|
+
end
|
82
|
+
when :recv_bits
|
83
|
+
b = ((t - start_bit_date).to_f / @bit_period).round
|
84
|
+
#puts "b = #{b} @ #{@ivcd.pretty_time}"
|
85
|
+
(nb_valid_bits...[8, b].min).each do |i|
|
86
|
+
word |= (l == 1 ? 1 : 0) << i
|
87
|
+
end
|
88
|
+
nb_valid_bits = b
|
89
|
+
if b > 8 then
|
90
|
+
if v != 1 then
|
91
|
+
puts "[Stop bit not at 1! (#{v.inspect}) @ #{@ivcd.pretty_time}]".light_red
|
92
|
+
end
|
93
|
+
word = (word >> 1) & 0xff
|
94
|
+
|
95
|
+
word = case word
|
96
|
+
when 0x0d
|
97
|
+
w = '\r'
|
98
|
+
"\e[94m\\r\e[0m"
|
99
|
+
when 0x0a
|
100
|
+
w = '\n'
|
101
|
+
"\e[94m\\n\e[0m\n"
|
102
|
+
when 0x1b
|
103
|
+
w = '\e'
|
104
|
+
"\e[94m\\e\e[0m"
|
105
|
+
else
|
106
|
+
if word >= 32
|
107
|
+
w = word == 32 ? "' '" : word.chr
|
108
|
+
"\e[90m#{word.chr}\e[0m"
|
109
|
+
else
|
110
|
+
w = "0x#{word.to_s(16).rjust(2, '0')}"
|
111
|
+
"\e[33m\\x#{word.to_s(16).rjust(2, '0')}\e[0m"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
$stderr.write word
|
115
|
+
$stdout.write "##{start_bit_date} #{w}\n"
|
116
|
+
if b >= 10 && v == 0 && l == 1
|
117
|
+
start_bit_date = t
|
118
|
+
word = 0
|
119
|
+
nb_valid_bits = 0
|
120
|
+
else
|
121
|
+
state = :wait_start_bit
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
l = v
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
def write
|
132
|
+
$stdout.write "$finish\n"
|
133
|
+
$stdout.flush
|
134
|
+
puts ''
|
135
|
+
puts '-'*80
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
UARTDecoder.run
|
141
|
+
|
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../../lib/libfst.rb'
|
3
|
+
|
4
|
+
system 'unxz -k skinny_rand.vcd.xz' unless File.exist?('skinny_rand.vcd')
|
5
|
+
system 'unxz -k skinny_rand_nvc.vcd.xz' unless File.exist?('skinny_rand_nvc.vcd')
|
6
|
+
|
7
|
+
tick = Time.now
|
8
|
+
vcd = VCD::Reader.new 'skinny_rand_nvc.vcd'
|
9
|
+
tock = Time.now
|
10
|
+
|
11
|
+
puts vcd
|
12
|
+
#puts vcd['/test_rand/dut/clk']
|
13
|
+
|
14
|
+
vcd.traces.values.each do |t|
|
15
|
+
puts t.variables.first.path
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "Read VCD file in #{(tock - tick).round(3)} s"
|
19
|
+
|
20
|
+
vcd.on_comment do |comment, time, reader|
|
21
|
+
puts "Comment @#{time*vcd.timescale}: #{comment.inspect}"
|
22
|
+
#vcd.stop_parsing
|
23
|
+
end
|
24
|
+
|
25
|
+
vcd.on_time_change do |time|
|
26
|
+
#puts " #{vcd.real_time} s ".center(80, '-')
|
27
|
+
#puts " #{time} ".center(80, '-')
|
28
|
+
puts " #{vcd.pretty_time} ".center(80, '-')
|
29
|
+
end
|
30
|
+
|
31
|
+
vcd.read('/test_rand', start_time: '0.5us', end_time: '0.001 ms') do |trace, value, time|
|
32
|
+
puts "@#{time}, #{trace.variables.first.path} = #{value}"
|
33
|
+
end
|
34
|
+
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libfst
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Théotime Bollengier
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-02-08 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: fstlib allows to read and write FST files (Fast Signal Trace) from Ruby
|
13
|
+
email: theotime.bollengier@ensta-bretagne.fr
|
14
|
+
executables: []
|
15
|
+
extensions:
|
16
|
+
- ext/extconf.rb
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".yardopts"
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- ext/extconf.rb
|
23
|
+
- ext/fastlz.c
|
24
|
+
- ext/fastlz.h
|
25
|
+
- ext/fst_config.h
|
26
|
+
- ext/fst_win_unistd.h
|
27
|
+
- ext/fstapi.c
|
28
|
+
- ext/fstapi.h
|
29
|
+
- ext/libfst_rb.c
|
30
|
+
- ext/lz4.c
|
31
|
+
- ext/lz4.h
|
32
|
+
- lib/libfst.rb
|
33
|
+
- lib/libfst/reader.rb
|
34
|
+
- lib/libfst/tfp.rb
|
35
|
+
- lib/libfst/vcd.rb
|
36
|
+
- lib/libfst/version.rb
|
37
|
+
- lib/libfst/writer.rb
|
38
|
+
- libfst.gemspec
|
39
|
+
- samples/create_file.rb
|
40
|
+
- samples/gtkwave.png
|
41
|
+
- samples/out.gtkw
|
42
|
+
- samples/read2.rb
|
43
|
+
- samples/read_file.rb
|
44
|
+
- samples/skinny_rand.fst
|
45
|
+
- samples/transaction_filter_process/full_boot.fst
|
46
|
+
- samples/transaction_filter_process/full_boot.gtkw
|
47
|
+
- samples/transaction_filter_process/sdcard.rb
|
48
|
+
- samples/transaction_filter_process/uart.rb
|
49
|
+
- samples/vcd/skinny_rand.vcd.xz
|
50
|
+
- samples/vcd/vcd_read.rb
|
51
|
+
homepage: https://gitlab.ensta-bretagne.fr/bollenth/fstlib.rb
|
52
|
+
licenses:
|
53
|
+
- GPL-3.0-or-later
|
54
|
+
metadata: {}
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.7'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.6.3
|
70
|
+
specification_version: 4
|
71
|
+
summary: Fast Signal Trace bindings for Ruby
|
72
|
+
test_files: []
|